binutils-gdb/gdb/dwarf2
Simon Marchi f8c4185131 gdb: really share partial symtabs when using .gdb_index or .debug_names
Fix/follow-up to commit 17ee85fc2a ("Share DWARF partial symtabs").

In the non-index case, where GDB builds partial symbols from scratch,
two objfiles around the same BFD correctly share partial symtabs.  The
first objfile, which has to do all the work, saves a reference to the
created partial symtabs in the shared per_bfd object (at the end of
dwarf2_build_psymtabs).  The second objfile, when it reaches
dwarf2_build_psymtabs, sees that there are already partial symtabs built
for this BFD and just uses it.

However, that commit missed implementing the same sharing for cases
where GDB uses .gdb_index or .debug_names to build the partial symtabs.

This patch fixes it by having the first objfile to use the BFD set
per_bfd->partial_symtabs at the end of dwarf2_read_gdb_index /
dwarf2_read_debug_names.  For the subsequent objfiles using that BFD,
the partial symtabs are then picked up in dwarf2_initialize_objfile.

This patch adds a test that mimics how the issue was originally
triggered:

  1. Load the test file twice, such that the second objfile re-uses the
     per_bfd object created for the first objfile.
  2. Run to some point where in the backtrace there is a frame for a
     function that's in a CU that's not yet read in.
  3. Check that this frame's information is complete in the "backtrace"
     output.

Step 2 requires an address -> symbol lookup which uses the addrmap at
objfile->partial_symtabs->psymtabs_addrmap.  If the
objfile->partial_symtabs link is not properly setup (as is the case
before this patch), the symbol for that frame won't be found and we'll
get a frame with incomplete information.

The test fails without the fix when using boards "cc-with-gdb-index" and
"cc-with-debug-names".

gdb/ChangeLog:

	* dwarf2/read.c (dwarf2_read_gdb_index): Save partial_symtabs in
	the per_bfd object.
	(dwarf2_read_debug_names): Likewise.
	(dwarf2_initialize_objfile): Use partial_symtabs from per_bfd
	object when re-using a per_bfd object with an index.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/share-psymtabs-bt.exp: New file.
	* gdb.dwarf2/share-psymtabs-bt.c: New file.
	* gdb.dwarf2/share-psymtabs-bt-2.c: New file.

Change-Id: Ibb26210e2dfc03b80ba9fa56b875ba4cc58c0352
2020-06-04 13:58:48 -04:00
..
abbrev.c Inline abbrev lookup 2020-05-27 11:48:19 -06:00
abbrev.h Inline abbrev lookup 2020-05-27 11:48:19 -06:00
attribute.c Attribute method inlining 2020-05-27 11:48:18 -06:00
attribute.h Attribute method inlining 2020-05-27 11:48:18 -06:00
comp-unit.c gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
comp-unit.h gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
die.h Rewrite new die_info methods 2020-03-26 09:28:26 -06:00
dwz.c Add dwz.c and dwz_file::read_string 2020-03-26 09:28:09 -06:00
dwz.h Add dwz.c and dwz_file::read_string 2020-03-26 09:28:09 -06:00
expr.c Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache 2020-05-27 11:15:56 -04:00
expr.h Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache 2020-05-27 11:15:56 -04:00
frame-tailcall.c Fix remaining inline/tailcall unwinding breakage for x86_64 2020-04-27 09:04:55 -03:00
frame-tailcall.h Move DWARF code to dwarf2/ subdirectory 2020-02-08 13:40:59 -07:00
frame.c Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache 2020-05-27 11:15:56 -04:00
frame.h Don't forward-declare struct objfile in dwarf2/frame.h 2020-02-11 17:57:46 -07:00
index-cache.c gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
index-cache.h gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
index-common.c Move DWARF code to dwarf2/ subdirectory 2020-02-08 13:40:59 -07:00
index-common.h Move DWARF code to dwarf2/ subdirectory 2020-02-08 13:40:59 -07:00
index-write.c gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
index-write.h gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
leb.c Move read_offset_1 to leb.c 2020-02-08 13:43:24 -07:00
leb.h Move two more functions to dwarf2/leb.h 2020-02-08 13:43:24 -07:00
line-header.c gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
line-header.h gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
loc.c gdb: add comment in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value 2020-05-28 15:47:53 -04:00
loc.h Remove dwarf2_per_cu_data::objfile () 2020-05-27 11:15:57 -04:00
macro.c gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
macro.h gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
read.c gdb: really share partial symtabs when using .gdb_index or .debug_names 2020-06-04 13:58:48 -04:00
read.h gdb: rename dwarf2_per_objfile variables/fields to per_objfile 2020-05-29 15:15:10 -04:00
section.c Add dwarf2_section_info::read_string method 2020-03-26 09:28:14 -06:00
section.h Add dwarf2_section_info::read_string method 2020-03-26 09:28:14 -06:00
stringify.c Move DWARF-constant stringifying code to new file 2020-03-26 09:28:26 -06:00
stringify.h Move DWARF-constant stringifying code to new file 2020-03-26 09:28:26 -06:00