From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0B6313858C60 for ; Fri, 27 Jan 2023 10:34:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B6313858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674815650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mdj63dR4QlV4hSD00h1/eq3qMICl03yF+JGcPjgiM3M=; b=ht5/SK/Zw+mbzh8un3iKyys7luJFNRgcZ87Ek4CJ2DhdEhOW+uhj92Aj5ChPKib0BTdCCc xNOHFAB4zcFvUos8yBg5IAXR3jO3cqugFH+ePDdU5mjseGhjHOTY4Q+bBqLL5HG6B+UHKo kvveJG9zvVVxbBe9P5Y6zkLSJhlaERc= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-599-oHZPfEJOP_2WKnnBrpry0A-1; Fri, 27 Jan 2023 05:34:09 -0500 X-MC-Unique: oHZPfEJOP_2WKnnBrpry0A-1 Received: by mail-qk1-f197.google.com with SMTP id a3-20020a05620a438300b007069b068069so2754183qkp.2 for ; Fri, 27 Jan 2023 02:34:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mdj63dR4QlV4hSD00h1/eq3qMICl03yF+JGcPjgiM3M=; b=O38SFkiSmoacecIAF87DlGTEECLXIverfSR4M6RbHXzKM4+TSSZAL+AIvoKh7TWt/7 VEDmcQTuLT/qlWO8jNmAuu0R2QvFe3wzjOLXCliP2tICwRg0cfpohpnQpIeFvFZ3cIYJ e988CJsDau7oOdcwVMMUo5iKLkZFMEL0g4sP7ntnP5ipCS6L7VCpTNO3tsGCaZFarNaX n9vC642/BUGEoTwFy0w+gtIjQw0pCc5uTVTZ8Of58HehQRLBZQAcOC7YWMwnokNsIpHn X1oLIinkiXrmCgn65pXFkHRKdSY0AwwEb+Wn7jZ0OPniRigviTvdZUAZjWqqT6HhtMBJ so5A== X-Gm-Message-State: AO0yUKXSQ4+vutZ/giFl3mU5E3WMU23P8070LEyKlJNNidjXHZaT1AL/ 3KBUDw7Nk240koU8P5IkSy08s5INL8lMNcg7EbPq7Wn2BFeNjyPSI/WSa9as6CINS75bv9laHcV XSheYykfIGV9El616qAbOJA== X-Received: by 2002:a05:622a:28d:b0:3b6:980e:87e7 with SMTP id z13-20020a05622a028d00b003b6980e87e7mr15562143qtw.24.1674815648664; Fri, 27 Jan 2023 02:34:08 -0800 (PST) X-Google-Smtp-Source: AK7set9VteVSDgyTMikhcrOijA13xMeESRPhVGGj1QcS49gpTlMjIaeHFJBdtLtnJ0AHmiQCppTQag== X-Received: by 2002:a05:622a:28d:b0:3b6:980e:87e7 with SMTP id z13-20020a05622a028d00b003b6980e87e7mr15562130qtw.24.1674815648331; Fri, 27 Jan 2023 02:34:08 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id 139-20020a370891000000b006feea093006sm2559292qki.124.2023.01.27.02.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 02:34:07 -0800 (PST) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Cc: Simon Marchi Subject: Re: [PATCH] gdb/dwarf: dump cooked index contents in cooked_index_functions::dump In-Reply-To: <20230127051317.700077-1-simon.marchi@polymtl.ca> References: <20230127051317.700077-1-simon.marchi@polymtl.ca> Date: Fri, 27 Jan 2023 10:34:06 +0000 Message-ID: <87tu0cuuzl.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Simon Marchi via Gdb-patches writes: > From: Simon Marchi > > 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. > > 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. > > The dump function first dumps all cooked index entries, like this: > > [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] > > Then the information about the main symbol: > > main: ((cooked_index_entry *) 0x621000123b40) [main] > > And finally the address map contents: > > [1] ((addrmap *) 0x6210000f7910) > > [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) > > The display of address maps above could probably be improved, to show it > more as ranges, but I think this is a reasonable start. > > 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. > > [1] https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-8-pedro@palves.net/ Tested this. The output looks good to me. Patch LGTM too. Thanks, Andrew > > Change-Id: Ida13e479fd4c8d21102ddd732241778bc3b6904a > --- > gdb/dwarf2/cooked-index.c | 16 +++++++++ > gdb/dwarf2/cooked-index.h | 4 +++ > gdb/dwarf2/read.c | 74 ++++++++++++++++++++++++++++++++++++++- > 3 files changed, 93 insertions(+), 1 deletion(-) > > diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c > index 09b3fd70b262..0dc1c6e2516c 100644 > --- a/gdb/dwarf2/cooked-index.c > +++ b/gdb/dwarf2/cooked-index.c > @@ -30,6 +30,22 @@ > > /* See cooked-index.h. */ > > +std::string > +to_string (cooked_index_flag flags) > +{ > + static constexpr cooked_index_flag::string_mapping mapping[] = { > + 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. */ > + > bool > cooked_index_entry::compare (const char *stra, const char *strb, > bool completing) > diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h > index 55eaf9955ab7..7a2e85ecf699 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); > > +/* 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. > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index cd937f24ee74..73aafbed80b4 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -93,6 +93,7 @@ > #include "split-name.h" > #include "gdbsupport/parallel-for.h" > #include "gdbsupport/thread-pool.h" > +#include "inferior.h" > > /* When == 1, print basic high level tracing messages. > When > 1, be more verbose. > @@ -18588,7 +18589,78 @@ struct cooked_index_functions : public dwarf2_base_index_functions > > 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 = get_dwarf2_per_objfile (objfile); > + > + cooked_index_vector *table > + = (gdb::checked_static_cast > + (per_objfile->per_bfd->index_table.get ())); > + > + gdb_printf (" entries:\n"); > + gdb_printf ("\n"); > + > + size_t i = 0; > + for (const cooked_index_entry *entry : table->all_entries ()) > + { > + 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 != 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 = table->get_main (); > + if (main_entry != 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 = table->get_addrmaps (); > + for (i = 0; i < addrmaps.size (); ++i) > + { > + addrmap &addrmap = *addrmaps[i]; > + > + gdb_printf (" [%zu] ((addrmap *) %p)\n", i, &addrmap); > + gdb_printf ("\n"); > + > + addrmap.foreach ([] (CORE_ADDR start_addr, void *obj) > + { > + const char *start_addr_str > + = paddress (current_inferior ()->gdbarch, start_addr); > + > + if (obj != nullptr) > + { > + const dwarf2_per_cu_data *per_cu > + = (const dwarf2_per_cu_data *) 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 expand_matching_symbols > > base-commit: 48afe8b710712bf131fadbfa3278e512a7034483 > -- > 2.39.0