From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id D7E63385B534; Mon, 30 Jan 2023 20:06:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7E63385B534 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675109201; bh=thU3fqt6VaL/iAA4X0nmpJPIiSdrndVdfEQdFeog92Y=; h=From:To:Subject:Date:From; b=QQNuupIu2+j1LcfY4QT+95siUbipeND5Pm/iK9gcq1iOWu8wM7t1oV3PgDRdoRYoB pujB+wRHqu+3xWY3NSQ1CHdGq7Fr49o+eUFnqwHXf1fflBV1hHzduR5oIx9eFVfR00 QRqDnI2aW7hZQjDl9e5oePphZEdpSioQT0GQzs5Y= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/dwarf: dump cooked index contents in cooked_index_functions::dump X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 8c4f70ffe7980fe8654660d84592807da2e6f8bc X-Git-Newrev: 7d82b08e9e0a7a22943b843972cd1b8ae1328884 Message-Id: <20230130200641.D7E63385B534@sourceware.org> Date: Mon, 30 Jan 2023 20:06:41 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7d82b08e9e0a= 7a22943b843972cd1b8ae1328884 commit 7d82b08e9e0a7a22943b843972cd1b8ae1328884 Author: Simon Marchi Date: Mon Jan 30 11:03:37 2023 -0500 gdb/dwarf: dump cooked index contents in cooked_index_functions::dump =20 As I am investigating a crash I see with the cooked index, I thought it would be useful to have a way to dump the index contents. For those not too familiar with it (that includes me), it can help get a feel of what it contains and how it is structured. =20 The cooked_index_functions::dump function is called as part of the "maintenance print objfiles" command. I tried to make the output well structured and indented to help readability, as this prints a lot of text. =20 The dump function first dumps all cooked index entries, like this: =20 [25] ((cooked_index_entry *) 0x621000121220) name: __ioinit canonical: __ioinit DWARF tag: DW_TAG_variable flags: 0x2 [IS_STATIC] DIE offset: 0x21a4 parent: ((cooked_index_entry *) 0x6210000f9610) [std] =20 Then the information about the main symbol: =20 main: ((cooked_index_entry *) 0x621000123b40) [main] =20 And finally the address map contents: =20 [1] ((addrmap *) 0x6210000f7910) =20 [0x0] ((dwarf2_per_cu_data *) 0) [0x118a] ((dwarf2_per_cu_data *) 0x60c000007f00) [0x1cc7] ((dwarf2_per_cu_data *) 0) [0x1cc8] ((dwarf2_per_cu_data *) 0x60c000007f00) [0x1cdf] ((dwarf2_per_cu_data *) 0) [0x1ce0] ((dwarf2_per_cu_data *) 0x60c000007f00) =20 The display of address maps above could probably be improved, to show it more as ranges, but I think this is a reasonable start. =20 Note that this patch depends on Pedro Alves' patch "enum_flags to_string" [1]. If my patch is to be merged before Pedro's series, I will cherry-pick this patch from his series and merge it before mine. =20 [1] https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-8-p= edro@palves.net/ =20 Change-Id: Ida13e479fd4c8d21102ddd732241778bc3b6904a Diff: --- gdb/dwarf2/cooked-index.c | 93 +++++++++++++++++++++++++++++++++++++++++++= ++++ gdb/dwarf2/cooked-index.h | 7 ++++ gdb/dwarf2/read.c | 10 ++++- 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 09d76523419..9dbb844cade 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -20,6 +20,7 @@ #include "defs.h" #include "dwarf2/cooked-index.h" #include "dwarf2/read.h" +#include "dwarf2/stringify.h" #include "cp-support.h" #include "c-lang.h" #include "ada-lang.h" @@ -30,6 +31,22 @@ =20 /* See cooked-index.h. */ =20 +std::string +to_string (cooked_index_flag flags) +{ + static constexpr cooked_index_flag::string_mapping mapping[] =3D { + MAP_ENUM_FLAG (IS_MAIN), + MAP_ENUM_FLAG (IS_STATIC), + MAP_ENUM_FLAG (IS_ENUM_CLASS), + MAP_ENUM_FLAG (IS_LINKAGE), + MAP_ENUM_FLAG (IS_TYPE_DECLARATION), + }; + + return flags.to_string (mapping); +} + +/* See cooked-index.h. */ + int cooked_index_entry::compare (const char *stra, const char *strb, comparison_mode mode) @@ -451,6 +468,82 @@ cooked_index_vector::get_main () const return result; } =20 +/* See cooked-index.h. */ + +void +cooked_index_vector::dump (gdbarch *arch) const +{ + /* Ensure the index is done building. */ + this->wait (); + + gdb_printf (" entries:\n"); + gdb_printf ("\n"); + + size_t i =3D 0; + for (const cooked_index_entry *entry : this->all_entries ()) + { + QUIT; + + gdb_printf (" [%zu] ((cooked_index_entry *) %p)\n", i++, entry); + gdb_printf (" name: %s\n", entry->name); + gdb_printf (" canonical: %s\n", entry->canonical); + gdb_printf (" DWARF tag: %s\n", dwarf_tag_name (entry->tag)); + gdb_printf (" flags: %s\n", to_string (entry->flags).c_str (= )); + gdb_printf (" DIE offset: 0x%lx\n", + to_underlying (entry->die_offset)); + + if (entry->parent_entry !=3D nullptr) + gdb_printf (" parent: ((cooked_index_entry *) %p) [%s]\n", + entry->parent_entry, entry->parent_entry->name); + else + gdb_printf (" parent: ((cooked_index_entry *) 0)\n"); + + gdb_printf ("\n"); + } + + const cooked_index_entry *main_entry =3D this->get_main (); + if (main_entry !=3D nullptr) + gdb_printf (" main: ((cooked_index_entry *) %p) [%s]\n", main_entry, + main_entry->name); + else + gdb_printf (" main: ((cooked_index_entry *) 0)\n"); + + gdb_printf ("\n"); + gdb_printf (" address maps:\n"); + gdb_printf ("\n"); + + std::vector addrmaps =3D this->get_addrmaps (); + for (i =3D 0; i < addrmaps.size (); ++i) + { + const addrmap &addrmap =3D *addrmaps[i]; + + gdb_printf (" [%zu] ((addrmap *) %p)\n", i, &addrmap); + gdb_printf ("\n"); + + addrmap.foreach ([arch] (CORE_ADDR start_addr, const void *obj) + { + QUIT; + + const char *start_addr_str =3D paddress (arch, start_addr); + + if (obj !=3D nullptr) + { + const dwarf2_per_cu_data *per_cu + =3D static_cast (obj); + gdb_printf (" [%s] ((dwarf2_per_cu_data *) %p)\n", + start_addr_str, per_cu); + } + else + gdb_printf (" [%s] ((dwarf2_per_cu_data *) 0)\n", + start_addr_str); + + return 0; + }); + + gdb_printf ("\n"); + } +} + void _initialize_cooked_index (); void _initialize_cooked_index () diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 891659f56e0..fa7d8840d16 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -54,6 +54,10 @@ enum cooked_index_flag_enum : unsigned char }; DEF_ENUM_FLAGS_TYPE (enum cooked_index_flag_enum, cooked_index_flag); =20 +/* Return a string representation of FLAGS. */ + +std::string to_string (cooked_index_flag flags); + /* A cooked_index_entry represents a single item in the index. Note that two entries can be created for the same DIE -- one using the name, and another one using the linkage name, if any. @@ -411,6 +415,9 @@ public: =20 quick_symbol_functions_up make_quick_functions () const override; =20 + /* Dump a human-readable form of the contents of the index. */ + void dump (gdbarch *arch) const; + private: =20 /* The vector of cooked_index objects. This is stored because the diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3a1728e9ff9..e8a3e359ada 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18589,7 +18589,15 @@ struct cooked_index_functions : public dwarf2_base= _index_functions =20 void dump (struct objfile *objfile) override { - gdb_printf ("Cooked index in use\n"); + gdb_printf ("Cooked index in use:\n"); + gdb_printf ("\n"); + + dwarf2_per_objfile *per_objfile =3D get_dwarf2_per_objfile (objfile); + cooked_index_vector *index + =3D (gdb::checked_static_cast + (per_objfile->per_bfd->index_table.get ())); + + index->dump (objfile->arch ()); } =20 void expand_matching_symbols