Bug 28539 - segfault in search_one_symtab
Summary: segfault in search_one_symtab
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 12.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-03 16:43 UTC by Tom de Vries
Modified: 2021-11-29 15:23 UTC (History)
2 users (show)

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 Tom de Vries 2021-11-03 16:43:29 UTC
A user reported a gdb crash with gdb-11.1 ( https://bugzilla.opensuse.org/show_bug.cgi?id=1192285 ) and shared the reproducer with me.

The reproducer is something like:
...
$ gdb -q -batch exec core -ex bt
...

I managed to reproduce with master.

AFAIU, the following happens.

psymbol_functions::expand_symtabs_matching is called and we arrive here:
...
          struct compunit_symtab *symtab =
            psymtab_to_symtab (objfile, ps);

          if (expansion_notify != NULL)
            if (!expansion_notify (symtab))
              return false;
...
with symtab == nullptr due to ps being a dwarf2_include_psymtab.

The expansion_notify is lambda function search_one_symtab, as passed by objfile::lookup_symbol and the null pointer is dereferenced here:
...
  auto search_one_symtab = [&] (compunit_symtab *stab)
  {
    ...
    const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
...
Comment 1 Tom de Vries 2021-11-03 16:45:04 UTC
I tried this patch:
...
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 48fb55c308c..9cd9ab4fbf1 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5787,7 +5787,7 @@ struct dwarf2_include_psymtab : public partial_symtab
 
   compunit_symtab *get_compunit_symtab (struct objfile *objfile) const override
   {
-    return nullptr;
+    return includer ()->get_compunit_symtab (objfile);
   }
 
 private:
...
and I was able to finish the backtrace.
Comment 3 Tom de Vries 2021-11-14 18:23:18 UTC
Reproduced with:
- master
- gdb-11-branch

On 10.2, runs into PR26327.
Comment 4 Jiri Slaby 2021-11-29 11:40:48 UTC
Any news on this? I am repeatedly hitting it.