From patchwork Wed Mar 21 13:15:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 26396 Received: (qmail 37566 invoked by alias); 21 Mar 2018 13:15:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24569 invoked by uid 89); 21 Mar 2018 13:15:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=gdbpatches, gdb-patches X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Mar 2018 13:15:33 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2LDE6Jr018792 for ; Wed, 21 Mar 2018 09:15:25 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gupn7cc1e-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 21 Mar 2018 09:15:24 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Mar 2018 13:15:22 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 21 Mar 2018 13:15:21 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2LDFKXK63569982 for ; Wed, 21 Mar 2018 13:15:20 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B639052041 for ; Wed, 21 Mar 2018 12:06:43 +0000 (GMT) Received: from oc1027705133.ibm.com (unknown [9.152.212.64]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id A51B652047 for ; Wed, 21 Mar 2018 12:06:43 +0000 (GMT) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH] Make "info proc cmdline" show args on GNU/Linux Date: Wed, 21 Mar 2018 14:15:16 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18032113-0044-0000-0000-0000053E5317 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032113-0045-0000-0000-0000287D56EB Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-21_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803210158 X-IsSubscribed: yes Currently "info proc cmdline" on GNU/Linux does not show the full command line, but only argument 0. And even a warning is shown if there are more. This was discussed in 2014 already: https://sourceware.org/ml/gdb-patches/2014-04/msg00212.html Follow the advice there and avoid target_fileio_read_stralloc. Instead, use target_fileio_read_alloc to read the whole command line and then replace NUL characters by spaces. Also add an appropriate test case. Note that gdbserver already handles this correctly. gdb/ChangeLog: * linux-tdep.c (linux_info_proc): For "info proc cmdline", print command line args instead of emitting a warning. gdb/testsuite/ChangeLog: * gdb.base/info-proc.exp: Add test for "info proc cmdline". --- gdb/linux-tdep.c | 20 ++++++++++++++++---- gdb/testsuite/gdb.base/info-proc.exp | 13 +++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index b4b87dd..0ac78c2 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -754,10 +754,22 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, if (cmdline_f) { xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", pid); - gdb::unique_xmalloc_ptr cmdline - = target_fileio_read_stralloc (NULL, filename); - if (cmdline) - printf_filtered ("cmdline = '%s'\n", cmdline.get ()); + gdb_byte *buffer; + ssize_t len = target_fileio_read_alloc (NULL, filename, &buffer); + + if (len > 0) + { + gdb::unique_xmalloc_ptr cmdline ((char *) buffer); + ssize_t pos; + + for (pos = 0; pos < len - 1; pos++) + { + if (buffer[pos] == '\0') + buffer[pos] = ' '; + } + buffer[len - 1] = '\0'; + printf_filtered ("cmdline = '%s'\n", buffer); + } else warning (_("unable to open /proc file '%s'"), filename); } diff --git a/gdb/testsuite/gdb.base/info-proc.exp b/gdb/testsuite/gdb.base/info-proc.exp index 72355bf..eadcb15 100644 --- a/gdb/testsuite/gdb.base/info-proc.exp +++ b/gdb/testsuite/gdb.base/info-proc.exp @@ -38,6 +38,16 @@ gdb_test_multiple "info proc" "info proc without a process" { } } +# Set command line arguments to be verified later with "info proc +# cmdline". However, if we're using a stub, then "set args" would not +# have any effect, so then just skip this. + +set cmdline "" +if { ! [target_info exists use_gdb_stub] } { + set cmdline "-i foo bar -o baz 1234" + gdb_test_no_output "set args $cmdline" "set args" +} + if { ! [ runto_main ] } then { untested "could not run to main" return -1 @@ -50,6 +60,9 @@ gdb_test "info proc mapping" \ "info proc mapping" if {[istarget "*-*-linux*"]} { + if { $cmdline != "" } { + gdb_test "info proc cmdline" "cmdline = \'.* $cmdline\'" + } set gcorefile [standard_output_file $testfile.gcore] if {[gdb_gcore_cmd $gcorefile "save a core file"]} { clean_restart $binfile