diff options
author | Tom Tromey <tom@tromey.com> | 2024-01-25 06:48:22 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2024-03-08 07:15:08 -0700 |
commit | e9b738dfbdc504589e1a365ce32981f4b23c22c3 (patch) | |
tree | 289bc9e3c5315007ac2f9ab9dae5a6994ccbf83e /gdb/dwarf2/read.c | |
parent | cdabd12b186e8e794045372b753416a18c387d7b (diff) | |
download | gdb-e9b738dfbdc504589e1a365ce32981f4b23c22c3.zip gdb-e9b738dfbdc504589e1a365ce32981f4b23c22c3.tar.gz gdb-e9b738dfbdc504589e1a365ce32981f4b23c22c3.tar.bz2 |
Avoid race when reading dwz file
PR gdb/31260 points out a race introduced by the background reading
changes. If a given objfile is re-opened when it is already being
read, dwarf2_initialize_objfile will call dwarf2_read_dwz_file again,
causing the 'dwz_file' to be reset.
This patch fixes the problem by arranging to open the dwz just once:
when the dwarf2_per_bfd object is created.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31260
Diffstat (limited to 'gdb/dwarf2/read.c')
-rw-r--r-- | gdb/dwarf2/read.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 486be7e..4afb026 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1366,6 +1366,7 @@ dwarf2_has_info (struct objfile *objfile, if (per_objfile == NULL) { dwarf2_per_bfd *per_bfd; + bool just_created = false; /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD doesn't require relocations. @@ -1385,6 +1386,7 @@ dwarf2_has_info (struct objfile *objfile, per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names, can_copy); dwarf2_per_bfd_bfd_data_key.set (objfile->obfd.get (), per_bfd); + just_created = true; } } else @@ -1392,9 +1394,25 @@ dwarf2_has_info (struct objfile *objfile, /* No sharing possible, create one specifically for this objfile. */ per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names, can_copy); dwarf2_per_bfd_objfile_data_key.set (objfile, per_bfd); + just_created = true; } per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, per_bfd); + + if (just_created) + { + /* Try to fetch any potential dwz file early, while still on + the main thread. Also, be sure to do it just once per + BFD, to avoid races. */ + try + { + dwarf2_read_dwz_file (per_objfile); + } + catch (const gdb_exception_error &err) + { + warning (_("%s"), err.what ()); + } + } } return (!per_objfile->per_bfd->info.is_virtual @@ -3202,17 +3220,6 @@ dwarf2_initialize_objfile (struct objfile *objfile, dwarf_read_debug_printf ("called"); - /* Try to fetch any potential dwz file early, while still on the - main thread. */ - try - { - dwarf2_read_dwz_file (per_objfile); - } - catch (const gdb_exception_error &err) - { - warning (_("%s"), err.what ()); - } - /* If we're about to read full symbols, don't bother with the indices. In this case we also don't care if some other debug format is making psymtabs, because they are all about to be |