]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: fix signature_type created with nullptr section
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 25 Feb 2025 20:54:56 +0000 (15:54 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Wed, 26 Feb 2025 03:43:49 +0000 (22:43 -0500)
Commit c44ab627b02 ("gdb/dwarf: pass section to dwarf2_per_cu_data
constructor") introduced a regression when using dwp.  It can be
reproduced with:

    $ make check TESTS="gdb.base/ptype-offsets.exp" RUNTESTFLAGS="--target_board=fission-dwp"

Then, to investigate:

    $ ./gdb  -nx -q --data-directory=data-directory testsuite/outputs/gdb.base/ptype-offsets/ptype-offsets -ex 'ptype int'
    Reading symbols from testsuite/outputs/gdb.base/ptype-offsets/ptype-offsets...
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3195:38: runtime error: member call on null pointer of type 'struct dwarf2_section_info'

Commit c44ab627b02 removed the assignment of signatured_type::section
(dwarf2_per_cu_data::section, really) in
fill_in_sig_entry_from_dwo_entry with the justification that the section
was already set when constructing the signatured_type.  Well, that was
true except for one spot in lookup_dwp_signatured_type which passes a
nullptr section to add_type_unit.

Fix that by passing the section to add_type_unit in that one spot.  This
is the same section that would have been set by
fill_in_sig_entry_from_dwo_entry before.

Add some asserts in the dwarf2_per_cu_data constructor to verity that
the passed dwarf2_per_bfd and dwarf2_section_info are non-nullptr.

Change-Id: If27dae6b4727957c96defc058c7e4be31472005b
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32739
Co-Authored-By: Tom de Vries <tdevries@suse.de>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index 27f4f09685f447f59ecb2de76c3d99cdd7c283be..e044d1eb0e4de2d274e2f1023650eb9c65b5a1c4 100644 (file)
@@ -2836,7 +2836,8 @@ lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
   if (dwo_entry == NULL)
     return NULL;
 
-  sig_type_it = add_type_unit (per_bfd, nullptr, dwo_entry->sect_off, sig);
+  sig_type_it
+    = add_type_unit (per_bfd, dwo_entry->section, dwo_entry->sect_off, sig);
   fill_in_sig_entry_from_dwo_entry (per_objfile, *sig_type_it, dwo_entry);
 
   return *sig_type_it;
index 596578919c8a242e75635d94c7ad808ee89717a5..e0c0e1fe3f0aff3bf76e88a3e2931ea91f167a14 100644 (file)
@@ -112,6 +112,8 @@ struct dwarf2_per_cu_data
       section (section),
       per_bfd (per_bfd)
   {
+    gdb_assert (per_bfd != nullptr);
+    gdb_assert (section != nullptr);
   }
 
   /* The start offset and length of this compilation unit.