From 424eb552c27a1574974d9052dff4ff252a7db22d Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Wed, 6 Feb 2019 09:45:50 -0800 Subject: [PATCH] Fix 'info proc cmdline' for native FreeBSD processes. The kern.proc.args. 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(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0ce33f2..1ac3b55 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2019-02-06 John Baldwin + + * fbsd-nat.c (fbsd_fetch_cmdline): Join arguments with spaces. + 2019-02-05 Tom Tromey * target.c (target_stack::unpush): Move assertion earlier. diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 712f9d3..184d639 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; } -- 2.7.4