diff options
author | Andreas Arnez <arnez@linux.vnet.ibm.com> | 2018-03-22 10:02:18 +0100 |
---|---|---|
committer | Andreas Arnez <arnez@linux.vnet.ibm.com> | 2018-03-22 10:02:18 +0100 |
commit | 26d6cec4a9291f154e549fb6f4318ace6cfaa2a5 (patch) | |
tree | da74df9be23e23763ab675b4380dc57d8ed679f5 /gdb/linux-tdep.c | |
parent | f69c5afb18871a773af88484a24d7da12c3a104c (diff) | |
download | binutils-gdb-26d6cec4a9291f154e549fb6f4318ace6cfaa2a5.tar.gz |
Make "info proc cmdline" show args on GNU/Linux
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".
Diffstat (limited to 'gdb/linux-tdep.c')
-rw-r--r-- | gdb/linux-tdep.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index b4b87dd8af8..0ac78c22f98 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<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); } |