]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Fix "info os <unknown>" command
authorPaul Marechal <paul.marechal@ericsson.com>
Fri, 21 Dec 2018 17:02:33 +0000 (12:02 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Fri, 21 Dec 2018 18:05:47 +0000 (13:05 -0500)
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/ChangeLog
gdb/target.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/info-os.exp

index ff5a5380d845fb43ae283e5692c32c7c3cfbba24..270fdc7a0203d4b50d57fd2ac9965befb5e84b6b 100644 (file)
@@ -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-19  Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
 
        PR gdb/23999:
index f88444fa2544dfd71105e5f8e6a8e5f6dffe68b1..f9c5b0a8b5500d521f9706abc98ce5ee4ef9f5dc 100644 (file)
@@ -1875,7 +1875,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.  */
index a5e0a4fae2888d2fcb38ec306212b5ad5d3ada18..7f2739082f9bd56258238e54a99e766dd856df3b 100644 (file)
@@ -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-11-21  Benno Fünfstück  <benno.fuenfstueck@gmail.com>
 
        PR python/23714
index 8d7eab9c530b6ff945032b7efa2048d5b212a41d..c44e6b27c38919b8b4010e98dc712c70a1ed1235 100644 (file)
@@ -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