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 EA2AC3858D1E for ; Mon, 30 Jan 2023 21:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA2AC3858D1E 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=1675114543; 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=ngyE5+AFk/m7WRkI8CfRuDMwYG9YksJee15qiNxH3yc=; b=QgfmymemmlBFfcCb7zh7Z3BSsn7C/thvjcvdnSpAU15y6ff+xrXiaF9gZNC+LNHzkBJOBP xHcnan8zupmWrr7FB1a8XgFvCjdfaJKQbZjlw5HIw437RegmS+r22x/qJBXdXuWJXz7Lv/ tNkLmywxfUDSeI0/5LbB3k4Y8g9xGmM= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-125-GJX-UHq-MAGIBrw9OcZO-A-1; Mon, 30 Jan 2023 16:35:40 -0500 X-MC-Unique: GJX-UHq-MAGIBrw9OcZO-A-1 Received: by mail-qk1-f199.google.com with SMTP id s7-20020a05620a0bc700b006e08208eb31so7834470qki.3 for ; Mon, 30 Jan 2023 13:35:40 -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=ngyE5+AFk/m7WRkI8CfRuDMwYG9YksJee15qiNxH3yc=; b=UPLNR1NICX1xlXAy4OWwOP/NXwGIG4wmXrG7ui+N0k9pumKseUhrDUVxoDFts5SeiG WIYq8ymQFU30FFxP9BO0eKWW70NUHI8SvPJMtIB9COC/5a2dknqo/yFQsdLWpZi05LhQ QfKsL+KKOjfOhwWQv4tUh5bFwLtA9Huh+4EnN1WzeEZzInUZOoT59DtEkSen7zhFrD90 kOfIWjhCcz+Rdo1QQ8jXdvtezWP9mxSwtp8Mlg5CQeE45o2TmutmRUSQ7VL0kGVnjuFR 0py3M9ZifUqZJlQ4HW4Lpfa9waajSsOmJcgH6SzYmbpKhZYy51TfmENo7Nc+No6vD9Zn Kijw== X-Gm-Message-State: AO0yUKWFctJ1jqy3aJj+cpa2uLzfdP5eONWB50SG38t90e52Y8id6buP sseDr/7IQAImYd9/jAHdn4w5hsApk1DPQuCwqu4HTA+hQ+GFemkouRCskw+mnUB9slgW91V5lF1 /IxzhFdbmQpkENmQTVVRHLg== X-Received: by 2002:ac8:7c53:0:b0:3b9:971d:4e2c with SMTP id o19-20020ac87c53000000b003b9971d4e2cmr4243382qtv.45.1675114539680; Mon, 30 Jan 2023 13:35:39 -0800 (PST) X-Google-Smtp-Source: AK7set93StFcfqVhx4vEK2dlX/Qa/KRdOPi/LtswDI6EuHHt0k08DR7CJUTqTVvIwaRD4KxWmLszJQ== X-Received: by 2002:ac8:7c53:0:b0:3b9:971d:4e2c with SMTP id o19-20020ac87c53000000b003b9971d4e2cmr4243352qtv.45.1675114539351; Mon, 30 Jan 2023 13:35:39 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id c16-20020ac80090000000b003b323387c1asm8665623qtg.18.2023.01.30.13.35.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 13:35:39 -0800 (PST) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Cc: Simon Marchi Subject: Re: [PATCH v2] gdb/dwarf: dump cooked index contents in cooked_index_functions::dump In-Reply-To: <20230130160337.55890-1-simon.marchi@efficios.com> References: <20230130160337.55890-1-simon.marchi@efficios.com> Date: Mon, 30 Jan 2023 21:35:37 +0000 Message-ID: <87a61zvh7a.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,WEIRD_PORT 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 > > New in v2: > > - move the implementation to the cooked_index_vector class > - use the gdbarch from the objfile > - add some QUIT macro calls > - add call to wait, to ensure the index is finished > > 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/ > > Change-Id: Ida13e479fd4c8d21102ddd732241778bc3b6904a > --- > 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 646bc76575cd..0ee7afb7b978 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 @@ > > /* 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) > @@ -442,6 +459,82 @@ cooked_index_vector::get_main () const > return result; > } > > +/* 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 = 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 != 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 = this->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 = this->get_addrmaps (); > + for (i = 0; i < addrmaps.size (); ++i) > + { > + const addrmap &addrmap = *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 = paddress (arch, start_addr); > + > + if (obj != nullptr) > + { > + const dwarf2_per_cu_data *per_cu > + = 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 7299a4f77b44..9d9be517c3a9 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. > @@ -373,6 +377,9 @@ class cooked_index_vector : public dwarf_scanner_base > > quick_symbol_functions_up make_quick_functions () const override; > > + /* Dump a human-readable form of the contents of the index. */ > + void dump (gdbarch *arch) const; > + > private: > > /* The vector of cooked_index objects. This is stored because the > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 9d8952a4eb8d..16559133a3d0 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -18589,7 +18589,15 @@ 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 *index > + = (gdb::checked_static_cast > + (per_objfile->per_bfd->index_table.get ())); > + With this patch I'm seeing this failure: (gdb) PASS: gdb.dwarf2/dw2-error.exp: file dw2-error maint print objfiles /tmp/build/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error Object file /tmp/build/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error: Objfile at 0x40dada0, bfd at 0x426bf70, 50 minsyms Cooked index in use: ../../src/gdb/../gdbsupport/gdb-checked-static-cast.h:58: internal-error: checked_static_cast: Assertion `result != nullptr' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- FAIL: gdb.dwarf2/dw2-error.exp: maint print objfiles /tmp/build/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error (GDB internal error) PATH: gdb.dwarf2/dw2-error.exp: maint print objfiles /tmp/build/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error (GDB internal error) Resyncing due to internal error. 0x5ff81a gdb_internal_backtrace_1 ../../src/gdb/bt-utils.c:122 0x5ff8bd _Z22gdb_internal_backtracev ../../src/gdb/bt-utils.c:168 0xf4f770 internal_vproblem ../../src/gdb/utils.c:401 0xf4fb3f _Z15internal_verrorPKciS0_P13__va_list_tag ../../src/gdb/utils.c:481 0x1701002 _Z18internal_error_locPKciS0_z ../../src/gdbsupport/errors.cc:58 0x835778 ??? 0x82a86d ??? 0xdc63a9 _ZN7objfile4dumpEv ../../src/gdb/symfile-debug.c:317 0xdea35f dump_objfile ../../src/gdb/symmisc.c:122 0xdec5e9 maintenance_print_objfiles ../../src/gdb/symmisc.c:728 0x67c1fc do_simple_func ../../src/gdb/cli/cli-decode.c:95 0x681318 _Z8cmd_funcP16cmd_list_elementPKci ../../src/gdb/cli/cli-decode.c:2737 0xe72b87 _Z15execute_commandPKci ../../src/gdb/top.c:688 0x897cb5 _Z15command_handlerPKc ../../src/gdb/event-top.c:620 0x8981bb _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE ../../src/gdb/event-top.c:856 ...etc... Thanks, Andrew