Skip to content

Commit 8422833

Browse files
committed
gdb/dwarf: move loops into locate_dw{o,z}_sections
For a subsequent patch, it would be easier if the loop over sections inside locate_dwo_sections (I want to maintain some state for the duration of the loop). Move the for loop in there. And because locate_dwz_sections is very similar, modify that one too, to keep both in sync. Change-Id: I90b3d44184910cc2d86af265bb4b41828a5d2c2e Approved-By: Tom Tromey <[email protected]>
1 parent b33b677 commit 8422833

File tree

3 files changed

+69
-69
lines changed

3 files changed

+69
-69
lines changed

gdb/dwarf2/dwz.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,37 @@ dwz_file::read_string (struct objfile *objfile, LONGEST str_offset)
5656
/* A helper function to find the sections for a .dwz file. */
5757

5858
static void
59-
locate_dwz_sections (struct objfile *objfile, bfd *abfd, asection *sectp,
60-
dwz_file *dwz_file)
59+
locate_dwz_sections (objfile *objfile, dwz_file &dwz_file)
6160
{
62-
dwarf2_section_info *sect = nullptr;
61+
for (asection *sec : gdb_bfd_sections (dwz_file.dwz_bfd))
62+
{
63+
dwarf2_section_info *sect = nullptr;
6364

64-
/* Note that we only support the standard ELF names, because .dwz
65+
/* Note that we only support the standard ELF names, because .dwz
6566
is ELF-only (at the time of writing). */
66-
if (dwarf2_elf_names.abbrev.matches (sectp->name))
67-
sect = &dwz_file->abbrev;
68-
else if (dwarf2_elf_names.info.matches (sectp->name))
69-
sect = &dwz_file->info;
70-
else if (dwarf2_elf_names.str.matches (sectp->name))
71-
sect = &dwz_file->str;
72-
else if (dwarf2_elf_names.line.matches (sectp->name))
73-
sect = &dwz_file->line;
74-
else if (dwarf2_elf_names.macro.matches (sectp->name))
75-
sect = &dwz_file->macro;
76-
else if (dwarf2_elf_names.gdb_index.matches (sectp->name))
77-
sect = &dwz_file->gdb_index;
78-
else if (dwarf2_elf_names.debug_names.matches (sectp->name))
79-
sect = &dwz_file->debug_names;
80-
else if (dwarf2_elf_names.types.matches (sectp->name))
81-
sect = &dwz_file->types;
82-
83-
if (sect != nullptr)
84-
{
85-
sect->s.section = sectp;
86-
sect->size = bfd_section_size (sectp);
87-
sect->read (objfile);
67+
if (dwarf2_elf_names.abbrev.matches (sec->name))
68+
sect = &dwz_file.abbrev;
69+
else if (dwarf2_elf_names.info.matches (sec->name))
70+
sect = &dwz_file.info;
71+
else if (dwarf2_elf_names.str.matches (sec->name))
72+
sect = &dwz_file.str;
73+
else if (dwarf2_elf_names.line.matches (sec->name))
74+
sect = &dwz_file.line;
75+
else if (dwarf2_elf_names.macro.matches (sec->name))
76+
sect = &dwz_file.macro;
77+
else if (dwarf2_elf_names.gdb_index.matches (sec->name))
78+
sect = &dwz_file.gdb_index;
79+
else if (dwarf2_elf_names.debug_names.matches (sec->name))
80+
sect = &dwz_file.debug_names;
81+
else if (dwarf2_elf_names.types.matches (sec->name))
82+
sect = &dwz_file.types;
83+
84+
if (sect != nullptr)
85+
{
86+
sect->s.section = sec;
87+
sect->size = bfd_section_size (sec);
88+
sect->read (objfile);
89+
}
8890
}
8991
}
9092

@@ -392,9 +394,7 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile)
392394

393395
dwz_file_up result (new dwz_file (std::move (dwz_bfd)));
394396

395-
for (asection *sec : gdb_bfd_sections (result->dwz_bfd))
396-
locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (),
397-
sec, result.get ());
397+
locate_dwz_sections (per_objfile->objfile, *result);
398398

399399
gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ());
400400
bfd_cache_close (result->dwz_bfd.get ());

gdb/dwarf2/read.c

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7512,45 +7512,48 @@ cutu_reader::open_dwo_file (dwarf2_per_bfd *per_bfd, const char *file_name,
75127512
size of each of the DWO debugging sections we are interested in. */
75137513

75147514
void
7515-
cutu_reader::locate_dwo_sections (struct objfile *objfile, bfd *abfd,
7516-
asection *sectp, dwo_sections *dwo_sections)
7515+
cutu_reader::locate_dwo_sections (objfile *objfile, dwo_file &dwo_file)
75177516
{
75187517
const struct dwop_section_names *names = &dwop_section_names;
7519-
7520-
struct dwarf2_section_info *dw_sect = nullptr;
7521-
7522-
if (names->abbrev_dwo.matches (sectp->name))
7523-
dw_sect = &dwo_sections->abbrev;
7524-
else if (names->info_dwo.matches (sectp->name))
7525-
dw_sect = &dwo_sections->infos.emplace_back (dwarf2_section_info {});
7526-
else if (names->line_dwo.matches (sectp->name))
7527-
dw_sect = &dwo_sections->line;
7528-
else if (names->loc_dwo.matches (sectp->name))
7529-
dw_sect = &dwo_sections->loc;
7530-
else if (names->loclists_dwo.matches (sectp->name))
7531-
dw_sect = &dwo_sections->loclists;
7532-
else if (names->macinfo_dwo.matches (sectp->name))
7533-
dw_sect = &dwo_sections->macinfo;
7534-
else if (names->macro_dwo.matches (sectp->name))
7535-
dw_sect = &dwo_sections->macro;
7536-
else if (names->rnglists_dwo.matches (sectp->name))
7537-
dw_sect = &dwo_sections->rnglists;
7538-
else if (names->str_dwo.matches (sectp->name))
7539-
dw_sect = &dwo_sections->str;
7540-
else if (names->str_offsets_dwo.matches (sectp->name))
7541-
dw_sect = &dwo_sections->str_offsets;
7542-
else if (names->types_dwo.matches (sectp->name))
7543-
dw_sect = &dwo_sections->types.emplace_back (dwarf2_section_info {});
7544-
7545-
if (dw_sect != nullptr)
7546-
{
7547-
/* Make sure we don't overwrite a section info that has been filled in
7518+
dwo_sections &dwo_sections = dwo_file.sections;
7519+
7520+
for (asection *sec : gdb_bfd_sections (dwo_file.dbfd))
7521+
{
7522+
struct dwarf2_section_info *dw_sect = nullptr;
7523+
7524+
if (names->abbrev_dwo.matches (sec->name))
7525+
dw_sect = &dwo_sections.abbrev;
7526+
else if (names->info_dwo.matches (sec->name))
7527+
dw_sect = &dwo_sections.infos.emplace_back (dwarf2_section_info {});
7528+
else if (names->line_dwo.matches (sec->name))
7529+
dw_sect = &dwo_sections.line;
7530+
else if (names->loc_dwo.matches (sec->name))
7531+
dw_sect = &dwo_sections.loc;
7532+
else if (names->loclists_dwo.matches (sec->name))
7533+
dw_sect = &dwo_sections.loclists;
7534+
else if (names->macinfo_dwo.matches (sec->name))
7535+
dw_sect = &dwo_sections.macinfo;
7536+
else if (names->macro_dwo.matches (sec->name))
7537+
dw_sect = &dwo_sections.macro;
7538+
else if (names->rnglists_dwo.matches (sec->name))
7539+
dw_sect = &dwo_sections.rnglists;
7540+
else if (names->str_dwo.matches (sec->name))
7541+
dw_sect = &dwo_sections.str;
7542+
else if (names->str_offsets_dwo.matches (sec->name))
7543+
dw_sect = &dwo_sections.str_offsets;
7544+
else if (names->types_dwo.matches (sec->name))
7545+
dw_sect = &dwo_sections.types.emplace_back (dwarf2_section_info {});
7546+
7547+
if (dw_sect != nullptr)
7548+
{
7549+
/* Make sure we don't overwrite a section info that has been filled in
75487550
already. */
7549-
gdb_assert (!dw_sect->readin);
7551+
gdb_assert (!dw_sect->readin);
75507552

7551-
dw_sect->s.section = sectp;
7552-
dw_sect->size = bfd_section_size (sectp);
7553-
dw_sect->read (objfile);
7553+
dw_sect->s.section = sec;
7554+
dw_sect->size = bfd_section_size (sec);
7555+
dw_sect->read (objfile);
7556+
}
75547557
}
75557558
}
75567559

@@ -7578,9 +7581,7 @@ cutu_reader::open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
75787581
dwo_file->comp_dir = comp_dir;
75797582
dwo_file->dbfd = std::move (dbfd);
75807583

7581-
for (asection *sec : gdb_bfd_sections (dwo_file->dbfd))
7582-
this->locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (), sec,
7583-
&dwo_file->sections);
7584+
this->locate_dwo_sections (per_objfile->objfile, *dwo_file);
75847585

75857586
/* There is normally just one .debug_info.dwo section in a DWO file. But when
75867587
building with -fdebug-types-section, gcc produces multiple .debug_info.dwo

gdb/dwarf2/read.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,7 @@ class cutu_reader
10291029
dwo_file_up open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
10301030
const char *comp_dir);
10311031

1032-
void locate_dwo_sections (struct objfile *objfile, bfd *abfd, asection *sectp,
1033-
struct dwo_sections *dwo_sections);
1032+
void locate_dwo_sections (objfile *objfile, dwo_file &dwo_file);
10341033

10351034
void create_dwo_unit_hash_tables (dwo_file &dwo_file, dwarf2_cu &skeleton_cu,
10361035
dwarf2_section_info &section,

0 commit comments

Comments
 (0)