Skip to content

Commit

Permalink
gdb/dwarf: make dwarf2_get_dwz_file a method of dwarf2_per_bfd
Browse files Browse the repository at this point in the history
dwarf2_get_dwz_file looks more or less like a simple getter of
dwarf2_per_bfd::dwz_file, so make it into a method.

I typically avoid the `get_` prefix for getters, but that would conflict
with the field name here.

Change-Id: Idd0d5b1bd3813babf438b20aac514b19c77cfc18
Approved-By: Tom Tromey <tom@tromey.com>
  • Loading branch information
simark committed Mar 4, 2025
1 parent 121efb5 commit 66195fe
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 44 deletions.
17 changes: 0 additions & 17 deletions gdb/dwarf2/dwz.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,3 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)

per_bfd->dwz_file = std::move (result);
}

/* See dwz.h. */

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"));
}
return result;
}
8 changes: 0 additions & 8 deletions gdb/dwarf2/dwz.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ struct dwz_file

using dwz_file_up = std::unique_ptr<dwz_file>;

/* Return the separate '.dwz' debug file. If there is no
.gnu_debugaltlink section in the file, then the result depends on
REQUIRE: if REQUIRE is true, then error; if REQUIRE is false,
return NULL. */

extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd,
bool require = false);

/* Open the separate '.dwz' debug file, if needed. This just sets the
appropriate field in the per-BFD structure. If the DWZ file
exists, the relevant sections are read in as well. Throws an error
Expand Down
2 changes: 1 addition & 1 deletion gdb/dwarf2/index-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic,
m_build_id_str = build_id_to_string (build_id);

/* Get build id of dwz file, if present. */
const dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
const dwz_file *dwz = per_bfd->get_dwz_file ();

if (dwz != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion gdb/dwarf2/index-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ save_gdb_index_command (const char *args, int from_tty)
try
{
const char *basename = lbasename (objfile_name (objfile));
const dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
const dwz_file *dwz = per_objfile->per_bfd->get_dwz_file ();
const char *dwz_basename = NULL;

if (dwz != NULL)
Expand Down
6 changes: 2 additions & 4 deletions gdb/dwarf2/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
|| macinfo_type == DW_MACRO_undef_sup
|| section_is_dwz)
{
dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
true);
dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);

body = dwz->read_string (objfile, str_offset);
}
Expand Down Expand Up @@ -710,8 +709,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,

if (macinfo_type == DW_MACRO_import_sup)
{
dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
true);
dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);

include_section = &dwz->macro;
include_bfd = include_section->get_bfd_owner ();
Expand Down
4 changes: 2 additions & 2 deletions gdb/dwarf2/read-debug-names.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ check_cus_from_debug_names (dwarf2_per_bfd *per_bfd,
if (dwz_map.cu_count == 0)
return true;

dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
dwz_file *dwz = per_bfd->get_dwz_file ();
return check_cus_from_debug_names_list (per_bfd, dwz_map, dwz->info,
true /* is_dwz */);
}
Expand All @@ -803,7 +803,7 @@ do_dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)

/* If there is a .dwz file, read it so we can get its CU list as
well. */
dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
dwz_file *dwz = per_bfd->get_dwz_file ();
if (dwz != NULL)
{
if (!read_debug_names_from_section (per_objfile,
Expand Down
5 changes: 2 additions & 3 deletions gdb/dwarf2/read-gdb-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ create_cus_from_gdb_index (dwarf2_per_bfd *per_bfd,
if (dwz_elements == 0)
return;

dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
dwz_file *dwz = per_bfd->get_dwz_file ();
create_cus_from_gdb_index_list (per_bfd, dwz_list, dwz_elements,
&dwz->info, 1);
}
Expand Down Expand Up @@ -1480,7 +1480,6 @@ dwarf2_read_gdb_index
{
const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
struct dwz_file *dwz;
struct objfile *objfile = per_objfile->objfile;
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;

Expand All @@ -1504,7 +1503,7 @@ dwarf2_read_gdb_index

/* If there is a .dwz file, read it so we can get its CU list as
well. */
dwz = dwarf2_get_dwz_file (per_bfd);
dwz_file *dwz = per_bfd->get_dwz_file ();
if (dwz != NULL)
{
mapped_gdb_index dwz_map;
Expand Down
12 changes: 4 additions & 8 deletions gdb/dwarf2/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ get_abbrev_section_for_cu (dwarf2_per_cu *this_cu)
dwarf2_per_bfd *per_bfd = this_cu->per_bfd;

if (this_cu->is_dwz)
abbrev = &dwarf2_get_dwz_file (per_bfd, true)->abbrev;
abbrev = &per_bfd->get_dwz_file (true)->abbrev;
else
abbrev = &per_bfd->abbrev;

Expand Down Expand Up @@ -4328,7 +4328,7 @@ create_all_units (dwarf2_per_objfile *per_objfile)
&per_objfile->per_bfd->abbrev, 0, sig_types,
rcuh_kind::TYPE);

dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
dwz_file *dwz = per_objfile->per_bfd->get_dwz_file ();
if (dwz != NULL)
{
read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1,
Expand Down Expand Up @@ -16467,7 +16467,7 @@ read_attribute_value (const struct die_reader_specs *reader,
[[fallthrough]];
case DW_FORM_GNU_strp_alt:
{
dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);
dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);
LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
&bytes_read);

Expand Down Expand Up @@ -17156,11 +17156,7 @@ get_debug_line_section (struct dwarf2_cu *cu)
if (cu->dwo_unit && cu->per_cu->is_debug_types)
section = &cu->dwo_unit->dwo_file->sections.line;
else if (cu->per_cu->is_dwz)
{
dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);

section = &dwz->line;
}
section = &per_objfile->per_bfd->get_dwz_file (true)->line;
else
section = &per_objfile->per_bfd->line;

Expand Down
20 changes: 20 additions & 0 deletions gdb/dwarf2/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,26 @@ struct dwarf2_per_bfd
return this->all_comp_units_index_tus[index];
}

/* Return the separate '.dwz' debug file. If there is no
.gnu_debugaltlink section in the file, then the result depends on
REQUIRE: if REQUIRE is true, error out; if REQUIRE is false,
return nullptr. */
struct dwz_file *get_dwz_file (bool require = false)
{
gdb_assert (!require || this->dwz_file.has_value ());

struct dwz_file *result = nullptr;

if (this->dwz_file.has_value ())
{
result = this->dwz_file->get ();
if (require && result == nullptr)
error (_("could not read '.gnu_debugaltlink' section"));
}

return result;
}

/* A convenience function to allocate a dwarf2_per_cu. The returned object
has its "index" field set properly. The object is allocated on the
dwarf2_per_bfd obstack. */
Expand Down

0 comments on commit 66195fe

Please sign in to comment.