gdb: really share partial symtabs when using .gdb_index or .debug_names
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 4 Jun 2020 17:56:55 +0000 (13:56 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 4 Jun 2020 17:58:48 +0000 (13:58 -0400)
commitf8c4185131758306ddeb7b40479e82cab4dd7f26
tree89cd25ab29ed03533340572e9506d9f79e0b6bdf
parentadd5f777decf9257f46c98dc2aacedb52a3d65e6
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
gdb/ChangeLog
gdb/dwarf2/read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/share-psymtabs-bt-2.c [new file with mode: 0644]
gdb/testsuite/gdb.base/share-psymtabs-bt.c [new file with mode: 0644]
gdb/testsuite/gdb.base/share-psymtabs-bt.exp [new file with mode: 0644]
This page took 0.028286 seconds and 4 git commands to generate.