From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id CE0F83858C54; Tue, 12 Apr 2022 15:41:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE0F83858C54 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Pre-read DWARF section data X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: da6322977928bc23b0d6a3a88af8c935fb334f3e X-Git-Newrev: c748b24c47d2f94d2282ffa31d7484a732c18cfd Message-Id: <20220412154101.CE0F83858C54@sourceware.org> Date: Tue, 12 Apr 2022 15:41:01 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 15:41:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc748b24c47d2= f94d2282ffa31d7484a732c18cfd commit c748b24c47d2f94d2282ffa31d7484a732c18cfd Author: Tom Tromey Date: Sun Jun 27 18:44:29 2021 -0600 Pre-read DWARF section data =20 Because BFD is not thread-safe, we need to be sure that any section data that is needed is read before trying to do any DWARF indexing in the background. =20 This patch takes a simple approach to this -- it pre-reads the "info"-related sections. This is done for the main file, but also any auxiliary files as well, such as the DWO file. =20 This patch could be perhaps enhanced by removing some now-redundant calls to dwarf2_section_info::read. Diff: --- gdb/dwarf2/read.c | 221 ++++++++++++++++++++++++--------------------------= ---- gdb/dwarf2/read.h | 4 + 2 files changed, 103 insertions(+), 122 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1887089121f..5998b7ffca7 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2039,6 +2039,25 @@ dwarf2_get_section_info (struct objfile *objfile, *sizep =3D info->size; } =20 +/* See dwarf2/read.h. */ + +void +dwarf2_per_bfd::map_info_sections (struct objfile *objfile) +{ + info.read (objfile); + abbrev.read (objfile); + line.read (objfile); + str.read (objfile); + str_offsets.read (objfile); + line_str.read (objfile); + ranges.read (objfile); + rnglists.read (objfile); + addr.read (objfile); + + for (auto §ion : types) + section.read (objfile); +} + =0C /* DWARF quick_symbol_functions support. */ =20 @@ -7831,7 +7850,7 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_o= bjfile) scoped_restore restore_reading_psyms =3D make_scoped_restore (&per_bfd->reading_partial_symbols, true); =20 - per_bfd->info.read (objfile); + per_bfd->map_info_sections (objfile); =20 /* Any cached compilation units will be linked by the per-objfile read_in_chain. Make sure to free them when we're done. */ @@ -8018,8 +8037,16 @@ create_all_comp_units (dwarf2_per_objfile *per_objfi= le) =20 dwz_file *dwz =3D dwarf2_get_dwz_file (per_objfile->per_bfd); if (dwz !=3D NULL) - read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1, - types_htab, rcuh_kind::COMPILE); + { + /* Pre-read the sections we'll need to construct an index. */ + struct objfile *objfile =3D per_objfile->objfile; + dwz->abbrev.read (objfile); + dwz->info.read (objfile); + dwz->str.read (objfile); + dwz->line.read (objfile); + read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev,= 1, + types_htab, rcuh_kind::COMPILE); + } =20 per_objfile->per_bfd->signatured_types =3D std::move (types_htab); } @@ -12635,69 +12662,47 @@ open_dwo_file (dwarf2_per_objfile *per_objfile, size of each of the DWO debugging sections we are interested in. */ =20 static void -dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, - dwo_sections *dwo_sections) +dwarf2_locate_dwo_sections (struct objfile *objfile, bfd *abfd, + asection *sectp, dwo_sections *dwo_sections) { const struct dwop_section_names *names =3D &dwop_section_names; =20 + struct dwarf2_section_info *dw_sect =3D nullptr; + if (names->abbrev_dwo.matches (sectp->name)) - { - dwo_sections->abbrev.s.section =3D sectp; - dwo_sections->abbrev.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->abbrev; else if (names->info_dwo.matches (sectp->name)) - { - dwo_sections->info.s.section =3D sectp; - dwo_sections->info.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->info; else if (names->line_dwo.matches (sectp->name)) - { - dwo_sections->line.s.section =3D sectp; - dwo_sections->line.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->line; else if (names->loc_dwo.matches (sectp->name)) - { - dwo_sections->loc.s.section =3D sectp; - dwo_sections->loc.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->loc; else if (names->loclists_dwo.matches (sectp->name)) - { - dwo_sections->loclists.s.section =3D sectp; - dwo_sections->loclists.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->loclists; else if (names->macinfo_dwo.matches (sectp->name)) - { - dwo_sections->macinfo.s.section =3D sectp; - dwo_sections->macinfo.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->macinfo; else if (names->macro_dwo.matches (sectp->name)) - { - dwo_sections->macro.s.section =3D sectp; - dwo_sections->macro.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->macro; else if (names->rnglists_dwo.matches (sectp->name)) - { - dwo_sections->rnglists.s.section =3D sectp; - dwo_sections->rnglists.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->rnglists; else if (names->str_dwo.matches (sectp->name)) - { - dwo_sections->str.s.section =3D sectp; - dwo_sections->str.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->str; else if (names->str_offsets_dwo.matches (sectp->name)) - { - dwo_sections->str_offsets.s.section =3D sectp; - dwo_sections->str_offsets.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwo_sections->str_offsets; else if (names->types_dwo.matches (sectp->name)) { struct dwarf2_section_info type_section; =20 memset (&type_section, 0, sizeof (type_section)); - type_section.s.section =3D sectp; - type_section.size =3D bfd_section_size (sectp); dwo_sections->types.push_back (type_section); + dw_sect =3D &dwo_sections->types.back (); + } + + if (dw_sect !=3D nullptr) + { + dw_sect->s.section =3D sectp; + dw_sect->size =3D bfd_section_size (sectp); + dw_sect->read (objfile); } } =20 @@ -12725,8 +12730,8 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *= dwo_name, dwo_file->dbfd =3D std::move (dbfd); =20 for (asection *sec : gdb_bfd_sections (dwo_file->dbfd)) - dwarf2_locate_dwo_sections (dwo_file->dbfd.get (), sec, - &dwo_file->sections); + dwarf2_locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (= ), + sec, &dwo_file->sections); =20 create_cus_hash_table (per_objfile, cu, *dwo_file, dwo_file->sections.in= fo, dwo_file->cus); @@ -12753,8 +12758,8 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *= dwo_name, we are interested in. */ =20 static void -dwarf2_locate_common_dwp_sections (bfd *abfd, asection *sectp, - dwp_file *dwp_file) +dwarf2_locate_common_dwp_sections (struct objfile *objfile, bfd *abfd, + asection *sectp, dwp_file *dwp_file) { const struct dwop_section_names *names =3D &dwop_section_names; unsigned int elf_section_nr =3D elf_section_data (sectp)->this_idx; @@ -12765,20 +12770,19 @@ dwarf2_locate_common_dwp_sections (bfd *abfd, ase= ction *sectp, dwp_file->elf_sections[elf_section_nr] =3D sectp; =20 /* Look for specific sections that we need. */ + struct dwarf2_section_info *dw_sect =3D nullptr; if (names->str_dwo.matches (sectp->name)) - { - dwp_file->sections.str.s.section =3D sectp; - dwp_file->sections.str.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.str; else if (names->cu_index.matches (sectp->name)) - { - dwp_file->sections.cu_index.s.section =3D sectp; - dwp_file->sections.cu_index.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.cu_index; else if (names->tu_index.matches (sectp->name)) + dw_sect =3D &dwp_file->sections.tu_index; + + if (dw_sect !=3D nullptr) { - dwp_file->sections.tu_index.s.section =3D sectp; - dwp_file->sections.tu_index.size =3D bfd_section_size (sectp); + dw_sect->s.section =3D sectp; + dw_sect->size =3D bfd_section_size (sectp); + dw_sect->read (objfile); } } =20 @@ -12788,7 +12792,8 @@ dwarf2_locate_common_dwp_sections (bfd *abfd, asect= ion *sectp, have version 1 or 2 or 5 until we parse the cu_index/tu_index sections.= */ =20 static void -dwarf2_locate_v2_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_= ptr) +dwarf2_locate_v2_dwp_sections (struct objfile *objfile, bfd *abfd, + asection *sectp, void *dwp_file_ptr) { struct dwp_file *dwp_file =3D (struct dwp_file *) dwp_file_ptr; const struct dwop_section_names *names =3D &dwop_section_names; @@ -12800,45 +12805,29 @@ dwarf2_locate_v2_dwp_sections (bfd *abfd, asectio= n *sectp, void *dwp_file_ptr) dwp_file->elf_sections[elf_section_nr] =3D sectp; =20 /* Look for specific sections that we need. */ + struct dwarf2_section_info *dw_sect =3D nullptr; if (names->abbrev_dwo.matches (sectp->name)) - { - dwp_file->sections.abbrev.s.section =3D sectp; - dwp_file->sections.abbrev.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.abbrev; else if (names->info_dwo.matches (sectp->name)) - { - dwp_file->sections.info.s.section =3D sectp; - dwp_file->sections.info.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.info; else if (names->line_dwo.matches (sectp->name)) - { - dwp_file->sections.line.s.section =3D sectp; - dwp_file->sections.line.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.line; else if (names->loc_dwo.matches (sectp->name)) - { - dwp_file->sections.loc.s.section =3D sectp; - dwp_file->sections.loc.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.loc; else if (names->macinfo_dwo.matches (sectp->name)) - { - dwp_file->sections.macinfo.s.section =3D sectp; - dwp_file->sections.macinfo.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.macinfo; else if (names->macro_dwo.matches (sectp->name)) - { - dwp_file->sections.macro.s.section =3D sectp; - dwp_file->sections.macro.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.macro; else if (names->str_offsets_dwo.matches (sectp->name)) - { - dwp_file->sections.str_offsets.s.section =3D sectp; - dwp_file->sections.str_offsets.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.str_offsets; else if (names->types_dwo.matches (sectp->name)) + dw_sect =3D &dwp_file->sections.types; + + if (dw_sect !=3D nullptr) { - dwp_file->sections.types.s.section =3D sectp; - dwp_file->sections.types.size =3D bfd_section_size (sectp); + dw_sect->s.section =3D sectp; + dw_sect->size =3D bfd_section_size (sectp); + dw_sect->read (objfile); } } =20 @@ -12848,7 +12837,8 @@ dwarf2_locate_v2_dwp_sections (bfd *abfd, asection = *sectp, void *dwp_file_ptr) have version 1 or 2 or 5 until we parse the cu_index/tu_index sections.= */ =20 static void -dwarf2_locate_v5_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_= ptr) +dwarf2_locate_v5_dwp_sections (struct objfile *objfile, bfd *abfd, + asection *sectp, void *dwp_file_ptr) { struct dwp_file *dwp_file =3D (struct dwp_file *) dwp_file_ptr; const struct dwop_section_names *names =3D &dwop_section_names; @@ -12860,40 +12850,27 @@ dwarf2_locate_v5_dwp_sections (bfd *abfd, asectio= n *sectp, void *dwp_file_ptr) dwp_file->elf_sections[elf_section_nr] =3D sectp; =20 /* Look for specific sections that we need. */ + struct dwarf2_section_info *dw_sect =3D nullptr; if (names->abbrev_dwo.matches (sectp->name)) - { - dwp_file->sections.abbrev.s.section =3D sectp; - dwp_file->sections.abbrev.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.abbrev; else if (names->info_dwo.matches (sectp->name)) - { - dwp_file->sections.info.s.section =3D sectp; - dwp_file->sections.info.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.info; else if (names->line_dwo.matches (sectp->name)) - { - dwp_file->sections.line.s.section =3D sectp; - dwp_file->sections.line.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.line; else if (names->loclists_dwo.matches (sectp->name)) - { - dwp_file->sections.loclists.s.section =3D sectp; - dwp_file->sections.loclists.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.loclists; else if (names->macro_dwo.matches (sectp->name)) - { - dwp_file->sections.macro.s.section =3D sectp; - dwp_file->sections.macro.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.macro; else if (names->rnglists_dwo.matches (sectp->name)) - { - dwp_file->sections.rnglists.s.section =3D sectp; - dwp_file->sections.rnglists.size =3D bfd_section_size (sectp); - } + dw_sect =3D &dwp_file->sections.rnglists; else if (names->str_offsets_dwo.matches (sectp->name)) + dw_sect =3D &dwp_file->sections.str_offsets; + + if (dw_sect !=3D nullptr) { - dwp_file->sections.str_offsets.s.section =3D sectp; - dwp_file->sections.str_offsets.size =3D bfd_section_size (sectp); + dw_sect->s.section =3D sectp; + dw_sect->size =3D bfd_section_size (sectp); + dw_sect->read (objfile); } } =20 @@ -13020,7 +12997,7 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_obj= file) dwp_file->num_sections, asection *); =20 for (asection *sec : gdb_bfd_sections (dwp_file->dbfd)) - dwarf2_locate_common_dwp_sections (dwp_file->dbfd.get (), sec, + dwarf2_locate_common_dwp_sections (objfile, dwp_file->dbfd.get (), sec, dwp_file.get ()); =20 dwp_file->cus =3D create_dwp_hash_table (per_objfile, dwp_file.get (), 0= ); @@ -13050,10 +13027,10 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_o= bjfile) for (asection *sec : gdb_bfd_sections (dwp_file->dbfd)) { if (dwp_file->version =3D=3D 2) - dwarf2_locate_v2_dwp_sections (dwp_file->dbfd.get (), sec, + dwarf2_locate_v2_dwp_sections (objfile, dwp_file->dbfd.get (), sec, dwp_file.get ()); else - dwarf2_locate_v5_dwp_sections (dwp_file->dbfd.get (), sec, + dwarf2_locate_v5_dwp_sections (objfile, dwp_file->dbfd.get (), sec, dwp_file.get ()); } =20 diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 4158a06e2bc..4ee7de98c50 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -368,6 +368,10 @@ struct dwarf2_per_bfd is allocated on the dwarf2_per_bfd obstack. */ signatured_type_up allocate_signatured_type (ULONGEST signature); =20 + /* Map all the DWARF section data needed when scanning + .debug_info. */ + void map_info_sections (struct objfile *objfile); + private: /* This function is mapped across the sections and remembers the offset and size of each of the debugging sections we are