]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[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)
commitccad8be7eb4aaab6b9e76b88109ca1885af9d775
tree3c98134e50cee54f2604ce433c7749dda66b517c
parent6eca49d098990ce0a01a9043ecbe1b2220bdeaaa
[gdb/symtab] Fix segfault in cutu_reader::read_toplevel_die

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