only be run in the main thread. */
gdb_assert (is_main_thread ());
+ /* This should only be called once. */
+ gdb_assert (!per_bfd->dwz_file.has_value ());
/* Set this early, so that on error it remains NULL. */
per_bfd->dwz_file.emplace (nullptr);
struct dwz_file *
dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require)
{
- gdb_assert (!require || per_bfd->dwz_file.has_value ());
-
- dwz_file *result = nullptr;
- if (per_bfd->dwz_file.has_value ())
- {
- result = per_bfd->dwz_file->get ();
- if (require && result == nullptr)
- error (_("could not read '.gnu_debugaltlink' section"));
- }
+ gdb_assert (per_bfd->dwz_file.has_value ());
+ dwz_file *result = per_bfd->dwz_file->get ();
+ if (require && result == nullptr)
+ error (_("could not read '.gnu_debugaltlink' section"));
return result;
}
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.
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
/* 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
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