Bug 23974 - "info os" crash when specifying invalid object
Summary: "info os" crash when specifying invalid object
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 8.2.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-11 04:40 UTC by Simon Marchi
Modified: 2018-12-21 18:45 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Marchi 2018-12-11 04:40:31 UTC
On Linux, compiled with _GLIBCXX_DEBUG:

(gdb) info os hello
/usr/include/c++/8.2.1/debug/vector:447:
Error: attempt to access an element in an empty container.

Objects involved in the operation:
    sequence "this" @ 0x0x7ffd63c42660 {
      type = std::__debug::vector<char, gdb::default_init_allocator<char, std::allocator<char> > >;
    }
[2]    31964 abort (core dumped)  gdb -q
Comment 1 Simon Marchi 2018-12-12 18:53:03 UTC
This bug has been introduced (by me, most likely) in 8.2, so I suggest we fix it in 8.2.1.

It should be quite easy to fix, I plan to look at it with a colleague to introduce him to gdb and c++ development.
Comment 2 cvs-commit@gcc.gnu.org 2018-12-21 18:05:55 UTC
The master branch has been updated by Simon Marchi <simark@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d00a27c5addfb6b7350a39215b48f4aaffa5960c

commit d00a27c5addfb6b7350a39215b48f4aaffa5960c
Author: Paul Marechal <paul.marechal@ericsson.com>
Date:   Fri Dec 21 12:02:33 2018 -0500

    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.
Comment 3 cvs-commit@gcc.gnu.org 2018-12-21 18:25:37 UTC
The gdb-8.2-branch branch has been updated by Simon Marchi <simark@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6ef08cc9a8e7ce3f64ebbb67ea7b628129d3dc4f

commit 6ef08cc9a8e7ce3f64ebbb67ea7b628129d3dc4f
Author: Paul Marechal <paul.marechal@ericsson.com>
Date:   Fri Dec 21 12:02:33 2018 -0500

    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.
Comment 4 Simon Marchi 2018-12-21 18:45:06 UTC
Fixed by the above.