aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2023-07-19 13:27:45 +0200
committerIlya Leoshkevich <iii@linux.ibm.com>2023-11-24 12:26:16 +0100
commitfa1c74b22aa8c465974ddf792395d8e313199a52 (patch)
tree00ab09e997c05ddf6b69add1ada77f10c095ec56
parent2ec31e54dff83130fbde8d2f674469078ee203d5 (diff)
downloadgdb-fa1c74b22aa8c465974ddf792395d8e313199a52.zip
gdb-fa1c74b22aa8c465974ddf792395d8e313199a52.tar.gz
gdb-fa1c74b22aa8c465974ddf792395d8e313199a52.tar.bz2
gdb: Fix "target file /proc/.../cmdline contained unexpected null characters"
When using the gcore command, GDB prints the following warning: (gdb) gcore warning: target file /proc/.../cmdline contained unexpected null characters The reason is that cmdline is read with target_fileio_read_stralloc(), which warns on seeing null characters. However, it's perfectly valid for cmdline to contain \0s, so switch to target_fileio_read_alloc(). Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/linux-tdep.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 26cf483..5fd64aa 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1884,15 +1884,23 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p)
pid = inferior_ptid.pid ();
xsnprintf (filename, sizeof (filename), "/proc/%d/cmdline", (int) pid);
/* The full name of the program which generated the corefile. */
- gdb::unique_xmalloc_ptr<char> fname
- = target_fileio_read_stralloc (NULL, filename);
+ gdb_byte *buf = NULL;
+ size_t buf_len = target_fileio_read_alloc (NULL, filename, &buf);
+ gdb::unique_xmalloc_ptr<char> fname ((char *)buf);
- if (fname == NULL || fname.get ()[0] == '\0')
+ if (buf_len < 1 || fname.get ()[0] == '\0')
{
/* No program name was read, so we won't be able to retrieve more
information about the process. */
return 0;
}
+ if (fname.get ()[buf_len - 1] != '\0')
+ {
+ warning (_("target file %s "
+ "does not contain a trailing null character"),
+ filename);
+ return 0;
+ }
memset (p, 0, sizeof (*p));