From: Paul Marechal <paul.marechal@ericsson.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: Paul Marechal <paul.marechal@ericsson.com>
Subject: [PATCH] gdb: Fix "info os <unknown>" command
Date: Mon, 17 Dec 2018 22:13:00 -0000 [thread overview]
Message-ID: <20181217221253.13314-1-paul.marechal@ericsson.com> (raw)
Running `info os someUnknownOsType` is crashing when gdb is built with
-D_GLIBCXX_DEBUG:
/usr/include/c++/5/debug/vector:439:error: attempt to
access an element in
an empty container.
In target_read_stralloc from target.c, the call to
target_read_alloc_1 can return an empty vector, we then call vector::back on
this vector, which is invalid.
This commit adds a check for emptiness before trying to call
vector::back on it. It also adds test to check for `info os <unknown>`
to return the proper error message.
This is a regression in gdb 8.2 and this patch restores the behavior of
previous versions.
gdb/ChangeLog:
PR gdb/23974
* target.c (target_read_stralloc): Check for empty vector.
gdb/testsuite/ChangeLog:
PR gdb/23974
* gdb.base/info-os.exp: Check return for unknown "info os" type.
---
gdb/target.c | 2 +-
gdb/testsuite/gdb.base/info-os.exp | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/gdb/target.c b/gdb/target.c
index 80b8453176..6c63255d03 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1793,7 +1793,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object,
if (!buf)
return {};
- if (buf->back () != '\0')
+ if (buf->empty () || buf->back () != '\0')
buf->push_back ('\0');
/* Check for embedded NUL bytes; but allow trailing NULs. */
diff --git a/gdb/testsuite/gdb.base/info-os.exp b/gdb/testsuite/gdb.base/info-os.exp
index 8d7eab9c53..c44e6b27c3 100644
--- a/gdb/testsuite/gdb.base/info-os.exp
+++ b/gdb/testsuite/gdb.base/info-os.exp
@@ -175,6 +175,9 @@ expect_multiline "info os semaphores" "$semkey +$semid +666 +1 .*" "get semaphor
# key msqid perm num used bytes num messages last msgsnd() command last msgrcv() command user group creator user creator group last msgsnd() time last msgrcv() time last msgctl() time
expect_multiline "info os msg" "$msgkey +$msqid +666 .*" "get message queues"
+gdb_test "info os unknown_entry" [multi_line \
+ "warning: Empty data returned by target. Wrong osdata type\\\?" \
+ "Can not fetch data now."]
# The SysV IPC primitives linger on after the creating process is killed
# unless they are destroyed explicitly, so allow the test program to tidy
--
2.20.1
next reply other threads:[~2018-12-17 22:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-17 22:13 Paul Marechal [this message]
2018-12-21 17:31 ` Tom Tromey
2018-12-21 18:06 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181217221253.13314-1-paul.marechal@ericsson.com \
--to=paul.marechal@ericsson.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox