Make dwarf2_get_dwz_file take a dwarf2_per_bfd

This allows removing a per_bfd->dwarf2_per_objfile reference in
get_abbrev_section_for_cu.

This requires saving the bfd in dwarf2_per_bfd.  The constructor of
dwarf2_per_bfd already accepts the bfd, so it's just a matter of saving
it in a field.

I replaced uses of objfile_name with bfd_get_filename, which should be
equivalent in this case.

gdb/ChangeLog:

	* dwarf2/read.h (struct dwarf2_per_bfd) <obfd>: New member.
	(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
	* dwarf2/read.c (dwarf2_per_bfd::dwarf2_per_bfd): Assign obfd
	field.
	(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
	(create_cus_from_index): Update.
	(dwarf2_read_gdb_index): Update.
	(create_cus_from_debug_names): Update.
	(dwarf2_read_debug_names): Update.
	(get_abbrev_section_for_cu): Update.
	(create_all_comp_units): Update.
	(read_attribute_value): Update.
	(get_debug_line_section): Update.
	* dwarf2/index-cache.c (index_cache::store): Update.
	* dwarf2/index-write.c (save_gdb_index_command): Update.
	* dwarf2/macro.c (dwarf_decode_macro_bytes): Update.
This commit is contained in:
Simon Marchi
2020-04-06 12:55:09 -04:00
committed by Simon Marchi
parent 89b41af1b1
commit 1d2852ed0a
5 changed files with 32 additions and 28 deletions

View File

@@ -108,7 +108,7 @@ index_cache::store (struct dwarf2_per_objfile *dwarf2_per_objfile)
/* Get build id of dwz file, if present. */ /* Get build id of dwz file, if present. */
gdb::optional<std::string> dwz_build_id_str; gdb::optional<std::string> dwz_build_id_str;
const dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); const dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
const char *dwz_build_id_ptr = NULL; const char *dwz_build_id_ptr = NULL;
if (dwz != nullptr) if (dwz != nullptr)

View File

@@ -1761,7 +1761,8 @@ save_gdb_index_command (const char *arg, int from_tty)
try try
{ {
const char *basename = lbasename (objfile_name (objfile)); const char *basename = lbasename (objfile_name (objfile));
const dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); const dwz_file *dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
const char *dwz_basename = NULL; const char *dwz_basename = NULL;
if (dwz != NULL) if (dwz != NULL)

View File

@@ -507,7 +507,7 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
|| section_is_dwz) || section_is_dwz)
{ {
struct dwz_file *dwz struct dwz_file *dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile); = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
body = dwz->read_string (objfile, str_offset); body = dwz->read_string (objfile, str_offset);
} }
@@ -644,7 +644,8 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
if (macinfo_type == DW_MACRO_import_sup) if (macinfo_type == DW_MACRO_import_sup)
{ {
struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); struct dwz_file *dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
dwz->macro.read (objfile); dwz->macro.read (objfile);

View File

@@ -1752,7 +1752,8 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names, dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names,
bool can_copy_) bool can_copy_)
: can_copy (can_copy_) : obfd (obfd),
can_copy (can_copy_)
{ {
if (names == NULL) if (names == NULL)
names = &dwarf2_elf_names; names = &dwarf2_elf_names;
@@ -2112,19 +2113,19 @@ locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
/* See dwarf2read.h. */ /* See dwarf2read.h. */
struct dwz_file * struct dwz_file *
dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
{ {
const char *filename; const char *filename;
bfd_size_type buildid_len_arg; bfd_size_type buildid_len_arg;
size_t buildid_len; size_t buildid_len;
bfd_byte *buildid; bfd_byte *buildid;
if (dwarf2_per_objfile->per_bfd->dwz_file != NULL) if (per_bfd->dwz_file != NULL)
return dwarf2_per_objfile->per_bfd->dwz_file.get (); return per_bfd->dwz_file.get ();
bfd_set_error (bfd_error_no_error); bfd_set_error (bfd_error_no_error);
gdb::unique_xmalloc_ptr<char> data gdb::unique_xmalloc_ptr<char> data
(bfd_get_alt_debug_link_info (dwarf2_per_objfile->objfile->obfd, (bfd_get_alt_debug_link_info (per_bfd->obfd,
&buildid_len_arg, &buildid)); &buildid_len_arg, &buildid));
if (data == NULL) if (data == NULL)
{ {
@@ -2144,7 +2145,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
if (!IS_ABSOLUTE_PATH (filename)) if (!IS_ABSOLUTE_PATH (filename))
{ {
gdb::unique_xmalloc_ptr<char> abs gdb::unique_xmalloc_ptr<char> abs
= gdb_realpath (objfile_name (dwarf2_per_objfile->objfile)); = gdb_realpath (bfd_get_filename (per_bfd->obfd));
abs_storage = ldirname (abs.get ()) + SLASH_STRING + filename; abs_storage = ldirname (abs.get ()) + SLASH_STRING + filename;
filename = abs_storage.c_str (); filename = abs_storage.c_str ();
@@ -2165,7 +2166,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
if (dwz_bfd == nullptr) if (dwz_bfd == nullptr)
{ {
gdb::unique_xmalloc_ptr<char> alt_filename; gdb::unique_xmalloc_ptr<char> alt_filename;
const char *origname = dwarf2_per_objfile->objfile->original_name; const char *origname = bfd_get_filename (per_bfd->obfd);
scoped_fd fd (debuginfod_debuginfo_query (buildid, scoped_fd fd (debuginfod_debuginfo_query (buildid,
buildid_len, buildid_len,
@@ -2187,7 +2188,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
if (dwz_bfd == NULL) if (dwz_bfd == NULL)
error (_("could not find '.gnu_debugaltlink' file for %s"), error (_("could not find '.gnu_debugaltlink' file for %s"),
objfile_name (dwarf2_per_objfile->objfile)); bfd_get_filename (per_bfd->obfd));
std::unique_ptr<struct dwz_file> result std::unique_ptr<struct dwz_file> result
(new struct dwz_file (std::move (dwz_bfd))); (new struct dwz_file (std::move (dwz_bfd)));
@@ -2195,10 +2196,9 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections, bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections,
result.get ()); result.get ());
gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ());
result->dwz_bfd.get ()); per_bfd->dwz_file = std::move (result);
dwarf2_per_objfile->per_bfd->dwz_file = std::move (result); return per_bfd->dwz_file.get ();
return dwarf2_per_objfile->per_bfd->dwz_file.get ();
} }
/* DWARF quick_symbols_functions support. */ /* DWARF quick_symbols_functions support. */
@@ -2526,7 +2526,7 @@ create_cus_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
if (dwz_elements == 0) if (dwz_elements == 0)
return; return;
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
create_cus_from_index_list (dwarf2_per_objfile, dwz_list, dwz_elements, create_cus_from_index_list (dwarf2_per_objfile, dwz_list, dwz_elements,
&dwz->info, 1); &dwz->info, 1);
} }
@@ -3073,7 +3073,7 @@ dwarf2_read_gdb_index
/* If there is a .dwz file, read it so we can get its CU list as /* If there is a .dwz file, read it so we can get its CU list as
well. */ well. */
dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
if (dwz != NULL) if (dwz != NULL)
{ {
struct mapped_index dwz_map; struct mapped_index dwz_map;
@@ -5135,7 +5135,7 @@ create_cus_from_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
if (dwz_map.cu_count == 0) if (dwz_map.cu_count == 0)
return; return;
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info, create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info,
true /* is_dwz */); true /* is_dwz */);
} }
@@ -5162,7 +5162,7 @@ dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
/* If there is a .dwz file, read it so we can get its CU list as /* If there is a .dwz file, read it so we can get its CU list as
well. */ well. */
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
if (dwz != NULL) if (dwz != NULL)
{ {
if (!read_debug_names_from_section (objfile, if (!read_debug_names_from_section (objfile,
@@ -5994,12 +5994,12 @@ static struct dwarf2_section_info *
get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu) get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
{ {
struct dwarf2_section_info *abbrev; struct dwarf2_section_info *abbrev;
struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile; dwarf2_per_bfd *per_bfd = this_cu->per_bfd;
if (this_cu->is_dwz) if (this_cu->is_dwz)
abbrev = &dwarf2_get_dwz_file (dwarf2_per_objfile)->abbrev; abbrev = &dwarf2_get_dwz_file (per_bfd)->abbrev;
else else
abbrev = &dwarf2_per_objfile->per_bfd->abbrev; abbrev = &per_bfd->abbrev;
return abbrev; return abbrev;
} }
@@ -8020,7 +8020,7 @@ create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->per_bfd->info, read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->per_bfd->info,
&dwarf2_per_objfile->per_bfd->abbrev, 0); &dwarf2_per_objfile->per_bfd->abbrev, 0);
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
if (dwz != NULL) if (dwz != NULL)
read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev, read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev,
1); 1);
@@ -19064,7 +19064,7 @@ read_attribute_value (const struct die_reader_specs *reader,
/* FALLTHROUGH */ /* FALLTHROUGH */
case DW_FORM_GNU_strp_alt: case DW_FORM_GNU_strp_alt:
{ {
struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
LONGEST str_offset = cu_header->read_offset (abfd, info_ptr, LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
&bytes_read); &bytes_read);
@@ -19659,7 +19659,7 @@ get_debug_line_section (struct dwarf2_cu *cu)
section = &cu->dwo_unit->dwo_file->sections.line; section = &cu->dwo_unit->dwo_file->sections.line;
else if (cu->per_cu->is_dwz) else if (cu->per_cu->is_dwz)
{ {
struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
section = &dwz->line; section = &dwz->line;
} }

View File

@@ -136,6 +136,9 @@ private:
const dwarf2_debug_sections &names); const dwarf2_debug_sections &names);
public: public:
/* The corresponding BFD. */
bfd *obfd;
/* Objects that can be shared across objfiles are stored in this /* Objects that can be shared across objfiles are stored in this
obstack or on the psymtab obstack, while objects that are obstack or on the psymtab obstack, while objects that are
objfile-specific are stored on the objfile obstack. */ objfile-specific are stored on the objfile obstack. */
@@ -578,8 +581,7 @@ struct signatured_type
there is no .gnu_debugaltlink section in the file. Error if there there is no .gnu_debugaltlink section in the file. Error if there
is such a section but the file cannot be found. */ is such a section but the file cannot be found. */
extern struct dwz_file *dwarf2_get_dwz_file extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd);
(struct dwarf2_per_objfile *dwarf2_per_objfile);
/* Return the type of the DIE at DIE_OFFSET in the CU named by /* Return the type of the DIE at DIE_OFFSET in the CU named by
PER_CU. */ PER_CU. */