[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