Patchwork Fix 'info proc cmdline' for native FreeBSD processes.

login
register
mail settings
Submitter John Baldwin
Date Jan. 28, 2019, 9:58 p.m.
Message ID <d20bb02e5af7b6af292c3b56a15e7ec572901b54.1548712710.git.jhb@FreeBSD.org>
Download mbox | patch
Permalink /patch/31235/
State New
Headers show

Comments

John Baldwin - Jan. 28, 2019, 9:58 p.m.
The kern.proc.args.<pid> sysctl returns the argv array as a packed
array of arguments, each null terminated.  To construct a complete
command line, the arguments must be joined with spaces by converting
the intermediate nul characters to spaces.  Previously only the first
argument was shown in cmdline output.  Now, all arguments are shown.

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_fetch_cmdline): Join arguments with spaces.
---
 gdb/ChangeLog  | 4 ++++
 gdb/fbsd-nat.c | 7 +++++++
 2 files changed, 11 insertions(+)

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5d5f72b817..3cb630255e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@ 
+2019-01-28  John Baldwin  <jhb@FreeBSD.org>
+
+	* fbsd-nat.c (fbsd_fetch_cmdline): Join arguments with spaces.
+
 2019-01-28  John Baldwin  <jhb@FreeBSD.org>
 
 	* aarch64-fbsd-tdep.c (aarch64_fbsd_gregmap)
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 712f9d3b7b..184d63939f 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -231,6 +231,13 @@  fbsd_fetch_cmdline (pid_t pid)
   if (sysctl (mib, 4, cmdline.get (), &len, NULL, 0) == -1)
     return nullptr;
 
+  /* Join the arguments with spaces to form a single string.  */
+  char *cp = cmdline.get ();
+  for (size_t i = 0; i < len - 1; i++)
+    if (cp[i] == '\0')
+      cp[i] = ' ';
+  cp[len - 1] = '\0';
+
   return cmdline;
 }