Bug 32410 - [gdb/symtab] segfault in compunit_symtab::find_call_site
Summary: [gdb/symtab] segfault in compunit_symtab::find_call_site
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-03 15:12 UTC by Tom de Vries
Modified: 2024-12-03 19:20 UTC (History)
2 users (show)

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


Attachments
gdb.log (1.17 KB, text/x-log)
2024-12-03 15:16 UTC, Tom de Vries
Details
overloads exec, gzipped (175.73 KB, application/gzip)
2024-12-03 15:16 UTC, Tom de Vries
Details
gdb.log from gdb with proposed patch (1.71 KB, text/x-log)
2024-12-03 16:12 UTC, Tom de Vries
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2024-12-03 15:12:28 UTC
On s390x I ran into:
...
(gdb) PASS: gdb.stabs/gdb11479.exp: forced_stabs: set breakpoints
continue^M
Continuing.^M
Recursive internal problem.^M
^@ERROR: GDB process no longer exists
GDB process exited with wait status 2741 exp9 0 1
UNRESOLVED: gdb.stabs/gdb11479.exp: forced_stabs: stop at first breakpoint in \
test2 function
...

With gdb we find that it's a segfault:
...
Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
0x00000000014ae41a in std::vector<call_site*, std::allocator<call_site*> >::begin (this=0x0) at /usr/include/c++/7/bits/stl_vector.h:573
573	      { return const_iterator(this->_M_impl._M_start); }
...
due to:
...
(gdb) down
#5  0x0000000001bc339c in compunit_symtab::find_call_site (this=0x420a450, 
    pc=16779034) at /dev/shm/vries/gdb/src/gdb/symtab.c:401
401	  if (auto it = m_call_site_htab->find (static_cast<unrelocated_addr> (pc - delta));
(gdb) p m_call_site_htab
$1 = (call_site_htab_t *) 0x0
(gdb) 
...

Looks like a regression since commit de2b4ab50de ("Convert dwarf2_cu::call_site_htab to new hash table"), which did:
...
 call_site *
 compunit_symtab::find_call_site (CORE_ADDR pc) const
 {
-  if (m_call_site_htab == nullptr)
-    return nullptr;
-
...
Comment 1 Tom de Vries 2024-12-03 15:16:14 UTC
Created attachment 15813 [details]
gdb.log
Comment 2 Tom de Vries 2024-12-03 15:16:43 UTC
Created attachment 15814 [details]
overloads exec, gzipped
Comment 3 Simon Marchi 2024-12-03 15:49:32 UTC
(In reply to Tom de Vries from comment #0)
> On s390x I ran into:
> ...
> (gdb) PASS: gdb.stabs/gdb11479.exp: forced_stabs: set breakpoints
> continue^M
> Continuing.^M
> Recursive internal problem.^M
> ^@ERROR: GDB process no longer exists
> GDB process exited with wait status 2741 exp9 0 1
> UNRESOLVED: gdb.stabs/gdb11479.exp: forced_stabs: stop at first breakpoint
> in \
> test2 function
> ...
> 
> With gdb we find that it's a segfault:
> ...
> Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
> 0x00000000014ae41a in std::vector<call_site*, std::allocator<call_site*>
> >::begin (this=0x0) at /usr/include/c++/7/bits/stl_vector.h:573
> 573	      { return const_iterator(this->_M_impl._M_start); }
> ...
> due to:
> ...
> (gdb) down
> #5  0x0000000001bc339c in compunit_symtab::find_call_site (this=0x420a450, 
>     pc=16779034) at /dev/shm/vries/gdb/src/gdb/symtab.c:401
> 401	  if (auto it = m_call_site_htab->find (static_cast<unrelocated_addr>
> (pc - delta));
> (gdb) p m_call_site_htab
> $1 = (call_site_htab_t *) 0x0
> (gdb) 
> ...
> 
> Looks like a regression since commit de2b4ab50de ("Convert
> dwarf2_cu::call_site_htab to new hash table"), which did:
> ...
>  call_site *
>  compunit_symtab::find_call_site (CORE_ADDR pc) const
>  {
> -  if (m_call_site_htab == nullptr)
> -    return nullptr;
> -
> ...


I see no good reason to remove that `if`.  My guess is that I tried to make `m_call_site_htab` not a pointer, realized I couldn't (`compunit_symtab` doesn't have a destructor that gets called, currently).

I'll send a patch that reverts that bit.
Comment 4 Tom de Vries 2024-12-03 16:12:13 UTC
Created attachment 15817 [details]
gdb.log from gdb with proposed patch
Comment 5 Sourceware Commits 2024-12-03 19:19:43 UTC
The master branch has been updated by Simon Marchi <simark@sourceware.org>:

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

commit 22a7a2d12a81a4c4521d1d9996d06b7abf315acc
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Tue Dec 3 10:52:18 2024 -0500

    gdb: restore nullptr check in compunit_symtab::find_call_site
    
    Commit de2b4ab50de ("Convert dwarf2_cu::call_site_htab to new hash
    table") removed this nullptr check for no good reason.  This causes a
    crash if `m_call_site_htab` is not set, as shown in PR 32410.  My guess
    is that when doing this change, I tried to make `m_call_site_htab` not a
    pointer, removed this check, then realized it wasn't so obvious, and
    forgot to re-add the check.
    
    Change-Id: I455e00cdc0519dfb412dc7826d17a839b77aae69
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32410
    Approved-By: Tom Tromey <tom@tromey.com>
    Approved-By: Tom de Vries <tdevries@suse.de>
Comment 6 Simon Marchi 2024-12-03 19:20:18 UTC
Fixed.