gdb: Fix "info os <unknown>" command
Commit Message
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(-)
Comments
>>>>> "Paul" == Paul Marechal <paul.marechal@ericsson.com> writes:
Paul> Running `info os someUnknownOsType` is crashing when gdb is built with
Paul> -D_GLIBCXX_DEBUG:
Paul> /usr/include/c++/5/debug/vector:439:error: attempt to
Paul> access an element in
Paul> an empty container.
Thank you for the patch.
Someday I hope to send a patch to enable -D_GLIBCXX_DEBUG by default
when building gdb in not-release mode.
Paul> This is a regression in gdb 8.2 and this patch restores the behavior of
Paul> previous versions.
Perhaps it isn't too late to put this on the 8.2 branch, as it seems
simple enough.
Paul> PR gdb/23974
Paul> * target.c (target_read_stralloc): Check for empty vector.
Paul> gdb/testsuite/ChangeLog:
Paul> PR gdb/23974
Paul> * gdb.base/info-os.exp: Check return for unknown "info os" type.
This is ok.
Tom
On 2018-12-21 12:31 p.m., Tom Tromey wrote:
>>>>>> "Paul" == Paul Marechal <paul.marechal@ericsson.com> writes:
>
> Paul> Running `info os someUnknownOsType` is crashing when gdb is built with
> Paul> -D_GLIBCXX_DEBUG:
>
> Paul> /usr/include/c++/5/debug/vector:439:error: attempt to
> Paul> access an element in
> Paul> an empty container.
>
> Thank you for the patch.
> Someday I hope to send a patch to enable -D_GLIBCXX_DEBUG by default
> when building gdb in not-release mode.
Yep, that would be nice!
> Paul> This is a regression in gdb 8.2 and this patch restores the behavior of
> Paul> previous versions.
>
> Perhaps it isn't too late to put this on the 8.2 branch, as it seems
> simple enough.
Yes, it's on the 8.2.1 list:
https://sourceware.org/ml/gdb-patches/2018-12/msg00167.html
> Paul> PR gdb/23974
> Paul> * target.c (target_read_stralloc): Check for empty vector.
>
> Paul> gdb/testsuite/ChangeLog:
>
> Paul> PR gdb/23974
> Paul> * gdb.base/info-os.exp: Check return for unknown "info os" type.
>
> This is ok.
Thanks for looking at it, I'll push it right now (on master and 8.2) on Paul's behalf.
Simon
@@ -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. */
@@ -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