Make "info proc cmdline" show args on GNU/Linux
authorAndreas Arnez <arnez@linux.vnet.ibm.com>
Thu, 22 Mar 2018 09:02:18 +0000 (10:02 +0100)
committerAndreas Arnez <arnez@linux.vnet.ibm.com>
Thu, 22 Mar 2018 09:02:18 +0000 (10:02 +0100)
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/ChangeLog
gdb/linux-tdep.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/info-proc.exp

index 9b41fe1862b5019d5186435d594ba3c49460a729..f1699093e8377613fe13ca24153f49daaee20fbd 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-22  Andreas Arnez  <arnez@linux.vnet.ibm.com>
+
+       * linux-tdep.c (linux_info_proc): For "info proc cmdline", print
+       command line args instead of emitting a warning.
+
 2018-03-22  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * tracepoint.h (struct static_tracepoint_marker): Initialize
index b4b87dd8af8fbfdca54b66c9567fe5f631dc2d77..0ac78c22f986085cff563bd1377b93f236520ab0 100644 (file)
@@ -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<char> 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<char> 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);
     }
index ca0dadf36b40b67755d06e9bab3b11d4b1214918..bbd09912af5d855e7c0aba9f27c797bf277ab375 100644 (file)
@@ -1,3 +1,7 @@
+2018-03-22  Andreas Arnez  <arnez@linux.vnet.ibm.com>
+
+       * gdb.base/info-proc.exp: Add test for "info proc cmdline".
+
 2018-03-20  Stephen Roberts  <stephen.roberts@arm.com>
 
        * gdb.perf/template-breakpoints.cc: New file.
index 72355bfef023e6b3ca98d0c9f034a07193b4f377..7dbf740645828075bc12b8109f96518132d2de01 100644 (file)
@@ -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 { ! [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
This page took 0.032544 seconds and 4 git commands to generate.