aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-03-30 13:37:11 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-03-30 13:37:11 -0400
commit8a91fbdf3b570460afdf0cac0d7f087b9d55f60c (patch)
tree221ffec33f1726400c34965b3ee4eaa6cfce0262 /gdb/dwarf2
parentb953e70356feb6161a2c1c5b18dbebcdb7ea0c94 (diff)
downloadbinutils-8a91fbdf3b570460afdf0cac0d7f087b9d55f60c.zip
binutils-8a91fbdf3b570460afdf0cac0d7f087b9d55f60c.tar.gz
binutils-8a91fbdf3b570460afdf0cac0d7f087b9d55f60c.tar.bz2
gdb/dwarf: disable per-BFD resource sharing for -readnow objfiles
New in v2: - Disable sharing only for -readnow objfiles, not all objfiles. As described in PR 27541, we hit an internal error when loading a binary the standard way and then loading it with the -readnow option: $ ./gdb -nx -q --data-directory=data-directory ~/a.out -ex "set confirm off" -ex "file -readnow ~/a.out" Reading symbols from /home/simark/a.out... Reading symbols from ~/a.out... /home/simark/src/binutils-gdb/gdb/dwarf2/read.c:8098: internal-error: void create_all_comp_units(dwarf2_per_objfile*): Assertion `per_objfile->per_bfd->all_comp_units.empty ()' failed. This is a recurring problem that exposes a design issue in the DWARF per-BFD sharing feature. Things work well when loading a binary with the same method (with/without index, with/without readnow) twice in a row. But they don't work so well when loading a binary with different methods. See this previous fix, for example: efb763a5ea35 ("gdb: check for partial symtab presence in dwarf2_initialize_objfile") That one handled the case where the first load is normal (uses partial symbols) and the second load uses an index. The problem is that when loading an objfile with a method A, we create a dwarf2_per_bfd and some dwarf2_per_cu_data and initialize them with the data belonging to that method. When loading another obfile sharing the same BFD but with a different method B, it's not clear how to re-use the dwarf2_per_bfd/dwarf2_per_cu_data previously created, because they contain the data specific to method A. I think the most sensible fix would be to not share a dwarf2_per_bfd between two objfiles loaded with different methods. That means that two objfiles sharing the same BFD and loaded the same way would share a dwarf2_per_bfd. Two objfiles sharing the same BFD but loaded with different methods would use two different dwarf2_per_bfd structures. However, this isn't a trivial change. So to fix the known issue quickly (including in the gdb 10 branch), this patch just disables all dwarf2_per_bfd sharing for objfiles using READNOW. Generalize the gdb.base/index-cache-load-twice.exp test to test all the possible combinations of loading a file with partial symtabs, index and readnow. Move it to gdb.dwarf2, since it really exercises features of the DWARF reader. gdb/ChangeLog: PR gdb/27541 * dwarf2/read.c (dwarf2_has_info): Don't share dwarf2_per_bfd with objfiles using READNOW. gdb/testsuite/ChangeLog: PR gdb/27541 * gdb.base/index-cache-load-twice.exp: Remove. * gdb.base/index-cache-load-twice.c: Remove. * gdb.dwarf2/per-bfd-sharing.exp: New. * gdb.dwarf2/per-bfd-sharing.c: New. Change-Id: I9ffcf1e136f3e75242f70e4e58e4ba1fd3083389
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r--gdb/dwarf2/read.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 1b98b75..2418301 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1951,9 +1951,14 @@ dwarf2_has_info (struct objfile *objfile,
{
dwarf2_per_bfd *per_bfd;
- /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
- doesn't require relocations. */
- if (!gdb_bfd_requires_relocations (objfile->obfd))
+ /* We can share a "dwarf2_per_bfd" with other objfiles if the
+ BFD doesn't require relocations.
+
+ We don't share with objfiles for which -readnow was requested,
+ because it would complicate things when loading the same BFD with
+ -readnow and then without -readnow. */
+ if (!gdb_bfd_requires_relocations (objfile->obfd)
+ && (objfile->flags & OBJF_READNOW) == 0)
{
/* See if one has been created for this BFD yet. */
per_bfd = dwarf2_per_bfd_bfd_data_key.get (objfile->obfd);