aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Marechal <paul.marechal@ericsson.com>2018-12-21 12:02:33 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2018-12-21 13:04:43 -0500
commitd00a27c5addfb6b7350a39215b48f4aaffa5960c (patch)
tree903bfeed83cd1a7e8abefc60facf29e8648bd3b8
parent50c7c5b8df15aad66a9d2f6759e85689a2a74271 (diff)
downloadgdb-d00a27c5addfb6b7350a39215b48f4aaffa5960c.zip
gdb-d00a27c5addfb6b7350a39215b48f4aaffa5960c.tar.gz
gdb-d00a27c5addfb6b7350a39215b48f4aaffa5960c.tar.bz2
gdb: Fix "info os <unknown>" command
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.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/target.c2
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/info-os.exp3
4 files changed, 14 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4ead538..db7a745 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-12-21 Paul Marechal <paul.marechal@ericsson.com>
+
+ PR gdb/23974
+ * target.c (target_read_stralloc): Check for empty vector.
+
2018-12-21 Дилян Палаузов <dilyan.palauzov@aegee.org>
* top.c (print_gdb_configuration): Print "--without-python"
diff --git a/gdb/target.c b/gdb/target.c
index 80b8453..6c63255 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/ChangeLog b/gdb/testsuite/ChangeLog
index c499d62..f3224d4 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-12-21 Paul Marechal <paul.marechal@ericsson.com>
+
+ PR gdb/23974
+ * gdb.base/info-os.exp: Check return for unknown "info os" type.
+
2018-12-20 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.ada/info_auto_lang.exp: Normalize some_c source file.
diff --git a/gdb/testsuite/gdb.base/info-os.exp b/gdb/testsuite/gdb.base/info-os.exp
index 8d7eab9..c44e6b2 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