From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 9D2E338582B2; Thu, 22 Sep 2022 12:50:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D2E338582B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663851036; bh=ZpoxLsantLptrmgkFzc5deLGGY9psdU2tKJsPHNpoRg=; h=From:To:Subject:Date:From; b=LANXidwzTjvHJ9LFfvojxFusRf7oWUTWahlF9DyH7K0HQ748koj6JAzdlhxWbHcos baVvmCrB39umvLVwWdEsXOo24h/gVbbkt2wamULdBHQMkpXrE4ArcMAh3Ae/978Y2n DjwKubnpfcy9t7ybleWsMU0RwgSUmbXY7ZyKFXjY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Add all_comp_units/all_type_units views on all_units X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 93547a56dcbec5c3c3d8707dba4e55545000766a X-Git-Newrev: aaf3f3f3bb38a59125ea34afa0ef7e0e14c2e916 Message-Id: <20220922125036.9D2E338582B2@sourceware.org> Date: Thu, 22 Sep 2022 12:50:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Daaf3f3f3bb38= a59125ea34afa0ef7e0e14c2e916 commit aaf3f3f3bb38a59125ea34afa0ef7e0e14c2e916 Author: Tom de Vries Date: Thu Sep 22 14:50:27 2022 +0200 [gdb/symtab] Add all_comp_units/all_type_units views on all_units =20 Add all_comp_units/all_type_units views on all_units. =20 Having the views allows us to: - easily get the number of CUs or TUs in all_units, and - easily access the nth CU or TU. =20 This minimizes the use of tu_stats.nr_tus. =20 Tested on x86_64-linux. Diff: --- gdb/dwarf2/index-write.c | 5 ++--- gdb/dwarf2/read.c | 33 +++++++++++++++++++++++++-------- gdb/dwarf2/read.h | 5 +++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 09f14953bf8..4cc0ee53070 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1286,9 +1286,8 @@ write_debug_names (dwarf2_per_objfile *per_objfile, } =20 /* Verify that all units are represented. */ - gdb_assert (counter =3D=3D (per_objfile->per_bfd->all_units.size () - - per_objfile->per_bfd->tu_stats.nr_tus)); - gdb_assert (types_counter =3D=3D per_objfile->per_bfd->tu_stats.nr_tus); + gdb_assert (counter =3D=3D per_objfile->per_bfd->all_comp_units.size ()); + gdb_assert (types_counter =3D=3D per_objfile->per_bfd->all_type_units.si= ze ()); =20 for (const cooked_index_entry *entry : table->all_entries ()) nametable.insert (entry); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8697fba55ea..35cce9396ae 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2631,6 +2631,8 @@ to use the section anyway."), return 1; } =20 +static void finalize_all_units (dwarf2_per_bfd *per_bfd); + /* Callback types for dwarf2_read_gdb_index. */ =20 typedef gdb::function_view @@ -2722,6 +2724,8 @@ dwarf2_read_gdb_index types_list_elements); } =20 + finalize_all_units (per_bfd); + create_addrmap_from_index (per_objfile, map.get ()); =20 per_bfd->index_table =3D std::move (map); @@ -4754,6 +4758,8 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objf= ile) (per_objfile, *map, section, &per_bfd->abbrev); } =20 + finalize_all_units (per_bfd); + create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges); =20 per_bfd->index_table =3D std::move (map); @@ -5017,9 +5023,7 @@ dw2_debug_names_iterator::next () case DW_IDX_compile_unit: { /* Don't crash on bad data. */ - int nr_cus =3D (per_bfd->all_units.size () - - per_bfd->tu_stats.nr_tus); - if (ull >=3D nr_cus) + if (ull >=3D per_bfd->all_comp_units.size ()) { complaint (_(".debug_names entry has bad CU index %s" " [in module %s]"), @@ -5032,7 +5036,7 @@ dw2_debug_names_iterator::next () break; case DW_IDX_type_unit: /* Don't crash on bad data. */ - if (ull >=3D per_bfd->tu_stats.nr_tus) + if (ull >=3D per_bfd->all_type_units.size ()) { complaint (_(".debug_names entry has bad TU index %s" " [in module %s]"), @@ -5041,8 +5045,7 @@ dw2_debug_names_iterator::next () continue; } { - int nr_cus =3D (per_bfd->all_units.size () - - per_bfd->tu_stats.nr_tus); + int nr_cus =3D per_bfd->all_comp_units.size (); per_cu =3D per_bfd->get_cu (nr_cus + ull); } break; @@ -6918,7 +6921,7 @@ build_type_psymtabs (dwarf2_per_objfile *per_objfile, /* It's up to the caller to not call us multiple times. */ gdb_assert (per_objfile->per_bfd->type_unit_groups =3D=3D NULL); =20 - if (per_objfile->per_bfd->tu_stats.nr_tus =3D=3D 0) + if (per_objfile->per_bfd->all_type_units.size () =3D=3D 0) return; =20 /* TUs typically share abbrev tables, and there can be way more TUs than @@ -6945,7 +6948,7 @@ build_type_psymtabs (dwarf2_per_objfile *per_objfile, /* Sort in a separate table to maintain the order of all_units for .gdb_index: TU indices directly index all_type_units. */ std::vector sorted_by_abbrev; - sorted_by_abbrev.reserve (per_objfile->per_bfd->tu_stats.nr_tus); + sorted_by_abbrev.reserve (per_objfile->per_bfd->all_type_units.size ()); =20 for (const auto &cu : per_objfile->per_bfd->all_units) { @@ -7259,6 +7262,18 @@ read_comp_units_from_section (dwarf2_per_objfile *pe= r_objfile, } } =20 +/* Initialize the views on all_units. */ + +static void +finalize_all_units (dwarf2_per_bfd *per_bfd) +{ + size_t nr_tus =3D per_bfd->tu_stats.nr_tus; + size_t nr_cus =3D per_bfd->all_units.size () - nr_tus; + gdb::array_view tmp =3D per_bfd->all_units; + per_bfd->all_comp_units =3D tmp.slice (0, nr_cus); + per_bfd->all_type_units =3D tmp.slice (nr_cus, nr_tus); +} + /* Create a list of all compilation units in OBJFILE. This is only done for -readnow and building partial symtabs. */ =20 @@ -7290,6 +7305,8 @@ create_all_units (dwarf2_per_objfile *per_objfile) } =20 per_objfile->per_bfd->signatured_types =3D std::move (types_htab); + + finalize_all_units (per_objfile->per_bfd); } =20 /* Return the initial uleb128 in the die at INFO_PTR. */ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index ce4fe52f4a2..5f01fbc1025 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -491,6 +491,11 @@ public: the target compilation unit of a particular reference. */ std::vector all_units; =20 + /* The all_units vector contains both CUs and TUs. Provide views on the + vector that are limited to either the CU part or the TU part. */ + gdb::array_view all_comp_units; + gdb::array_view all_type_units; + /* Table of struct type_unit_group objects. The hash key is the DW_AT_stmt_list value. */ htab_up type_unit_groups;