Fix for dwz-related crash
authorTom Tromey <tom@tromey.com>
Thu, 12 Apr 2018 14:24:41 +0000 (08:24 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 17 May 2018 16:25:02 +0000 (10:25 -0600)
commit58f0c71853f98afe623ab89c4362682885905ebb
tree90d2c65e7759414aeaf6d0d87c9aaf5d6e43bc01
parent809276d28ad0212dd5a3f9074090e1425e5e4d8e
Fix for dwz-related crash

PR symtab/23010 reports a crash that occurs when using -readnow
on a dwz-generated debuginfo file.

The crash occurs because the DWARF has a partial CU with no language
set, and then a full CU that references this partial CU using
DW_AT_abstract_origin.

In this case, the partial CU is read by dw2_expand_all_symtabs using
language_minimal; but then this conflicts with the creation of the
block's symbol table in the C++ CU.

This patch fixes the problem by arranging for partial CUs not to be
read by -readnow.  I tend to think that it doesn't make sense to read
a partial CU in isolation -- they should only be read when imported
into some other CU.

In conjunction with some other patches I am going to post, this also
fixes the Rust -readnow crash that Jan reported.

There are two problems with this patch:

1. It is difficult to reason about.  There are many cases where I've
   patched the code to call init_cutu_and_read_dies with the flag set
   to "please do read partial units" -- but I find it difficult to be
   sure that this is always correct.

2. It is still missing a standalone test case.  This seemed hard.

2018-05-17  Tom Tromey  <tom@tromey.com>

PR symtab/23010:
* dwarf2read.c (load_cu, dw2_do_instantiate_symtab)
(dw2_instantiate_symtab): Add skip_partial parameter.
(dw2_find_last_source_symtab, dw2_map_expand_apply)
(dw2_lookup_symbol, dw2_expand_symtabs_for_function)
(dw2_expand_all_symtabs, dw2_expand_symtabs_with_fullname)
(dw2_expand_symtabs_matching_one)
(dw2_find_pc_sect_compunit_symtab)
(dw2_debug_names_lookup_symbol)
(dw2_debug_names_expand_symtabs_for_function): Update.
(init_cutu_and_read_dies): Add skip_partial parameter.
(process_psymtab_comp_unit, build_type_psymtabs_1)
(process_skeletonless_type_unit, load_partial_comp_unit)
(psymtab_to_symtab_1): Update.
(load_full_comp_unit): Add skip_partial parameter.
(process_imported_unit_die, dwarf2_read_addr_index)
(follow_die_offset, dwarf2_fetch_die_loc_sect_off)
(dwarf2_fetch_constant_bytes, dwarf2_fetch_die_type_sect_off)
(read_signatured_type): Update.
gdb/ChangeLog
gdb/dwarf2read.c