]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/symtab] Fix segfault in cutu_reader::read_toplevel_die
authorTom de Vries <tdevries@suse.de>
Thu, 22 Jan 2026 09:48:45 +0000 (10:48 +0100)
committerTom de Vries <tdevries@suse.de>
Thu, 22 Jan 2026 09:48:45 +0000 (10:48 +0100)
PR 33818 reports a problem when running test-case
gdb.ada/uninitialized-variable-record.exp:
...
(gdb) print y2
dwarf2/read.c:14073:20: runtime error: member access within null pointer of \
  type 'struct dwarf2_cu'
ERROR: GDB process no longer exists
...
bisecting to commit 2f23cf07253 ("[gdb] Add regression test for PR
symtab/33777").

I managed to reproduce it using target board readnow.

The problem is here in cutu_reader::read_toplevel_die:
...
  m_new_cu.get ()->per_objfile->per_bfd->nr_toplevel_dies_read++;
...

Class cutu_reader has two fields pointing to a dwarf2_cu:
...
  /* The CU of the DIE we are parsing.  */
  struct dwarf2_cu *m_cu;
...
and:
...
  dwarf2_cu_up m_new_cu;
...
and m_new_cu is not always set.

Fix this by using m_cu instead.

Reported-By: Jan Vrany <jan.vrany@labware.com
Suggested-By: Simon Marchi <simon.marchi@efficios.com>
Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33818

gdb/dwarf2/read.c

index 58ea547f35af981572c4056120f2fcca6d406076..d3d4cfdfc23597de84336cbadcb1bf1b4cefc5a6 100644 (file)
@@ -14057,7 +14057,7 @@ cutu_reader::read_full_die (int num_extra_attrs, bool allow_reprocess)
 die_info *
 cutu_reader::read_toplevel_die (gdb::array_view<attribute *> extra_attrs)
 {
-  m_new_cu.get ()->per_objfile->per_bfd->nr_toplevel_dies_read++;
+  m_cu->per_objfile->per_bfd->nr_toplevel_dies_read++;
   const gdb_byte *begin_info_ptr = m_info_ptr;
   die_info *die = this->read_full_die (extra_attrs.size (), false);