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 2322A3858431 for ; Mon, 8 Apr 2024 20:19:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2322A3858431 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2322A3858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712607577; cv=none; b=pXGU28+MtwCedwSJLWPNwrd9y8ZHhdML3W4TJME34eX3QegusRaF94sa/iJiV8t5h3vMX1RfkQIwT+0vS6Do2ltzd6K2KW9cU1CiNorJz0+xl44jcTSojbpwcreOvYULIPSh8F++y7CQiXt1Wo4w2IzuZMvOj5mi2SvzrXa7Gxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712607577; c=relaxed/simple; bh=oSu2T7Dy6R2t4hXW1OkrQs3yNoqqFD/s4zTIvSyDOgs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bm5zLp8looxyfp6+dmdqwqEKOj/WavgTehABZzaUouf1EMmhIO/wvwbP+Cf8ALHVb2mfy90Yn/HEnOcx6Bkm4Ocvr4c/tKB+zzLJ4QoGWaYv2TQVS/Fo9So5/DQkP+KdzUPKwLkTnFwsp5fYpvMcc8Ruu9OFdGrIFS5odl4+tK8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712607572; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pycD2oKtBM2qdwixBUVspQYHF20ITQsxYsXdjVLXP9Q=; b=Ox9Kw5t4GM1E17l8Nz3H0cBG1P/AQccbB4Q6Oqy9NGh/8+wEPDLMNfdVN0Nom3D/g3hpd7 1gohfLJKD+Me7PvVzgmK+E3Cx2ajCCARtdp+23xdl12ASvGmZfiFKDRnW65tmz4z1Oi4AD nVyXFxni8GKgfs9i394CERmKXdOkEgY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-oq5B8585MUSbEXJtsHkELQ-1; Mon, 08 Apr 2024 16:19:31 -0400 X-MC-Unique: oq5B8585MUSbEXJtsHkELQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1B1688032FA for ; Mon, 8 Apr 2024 20:19:31 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.96.134.170]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76F831C0A923; Mon, 8 Apr 2024 20:19:30 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH v2 1/5] gdb: make gdbarch store a vector of frame unwinders Date: Mon, 8 Apr 2024 17:19:11 -0300 Message-ID: <20240408201915.1482831-2-blarsen@redhat.com> In-Reply-To: <20240408201915.1482831-1-blarsen@redhat.com> References: <20240408201915.1482831-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.2 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_H4,RCVD_IN_MSPIKE_WL,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: Before this commit, all frame unwinders would be stored in the obstack of a gdbarch and accessed by using the registry system. This made for unwieldy code, and unnecessarily complex logic in the frame_unwinder implementation, along with making frame_unwind structs be unable to have non-trivial destructors. Seeing as a future patch of this series wants to refactor the frame_unwind struct to use inheritance, and we'd like to not restrict the future derived classes on what destructors are allowed. In preparation for that change, this commit adds an std::vector to gdbarch to store the unwinders in. There should be no user-visible changes. --- gdb/arch-utils.c | 8 ++++ gdb/frame-unwind.c | 111 +++++++++++++++++---------------------------- gdb/gdbarch.c | 3 ++ gdb/gdbarch.h | 5 ++ gdb/gdbarch.py | 3 ++ 5 files changed, 61 insertions(+), 69 deletions(-) diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 456bfe971ff..a63a6115116 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1218,6 +1218,14 @@ obstack *gdbarch_obstack (gdbarch *arch) /* See gdbarch.h. */ +std::vector& +gdbarch_get_unwinder_list (struct gdbarch *arch) +{ + return arch->unwinders; +} + +/* See gdbarch.h. */ + char * gdbarch_obstack_strdup (struct gdbarch *arch, const char *string) { diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c index a80421a9c5a..36c3d81435d 100644 --- a/gdb/frame-unwind.c +++ b/gdb/frame-unwind.c @@ -30,49 +30,16 @@ #include "cli/cli-cmds.h" #include "inferior.h" -struct frame_unwind_table_entry -{ - const struct frame_unwind *unwinder; - struct frame_unwind_table_entry *next; -}; - -struct frame_unwind_table -{ - struct frame_unwind_table_entry *list = nullptr; - /* The head of the OSABI part of the search list. */ - struct frame_unwind_table_entry **osabi_head = nullptr; -}; +/* If an unwinder should be prepended to the list, this is the + index in which it should be inserted. */ +static int osabi_start = -1; -static const registry::key - frame_unwind_data; - -/* A helper function to add an unwinder to a list. LINK says where to - install the new unwinder. The new link is returned. */ - -static struct frame_unwind_table_entry ** -add_unwinder (struct obstack *obstack, const struct frame_unwind *unwinder, - struct frame_unwind_table_entry **link) -{ - *link = OBSTACK_ZALLOC (obstack, struct frame_unwind_table_entry); - (*link)->unwinder = unwinder; - return &(*link)->next; -} - -static struct frame_unwind_table * -get_frame_unwind_table (struct gdbarch *gdbarch) +/* Start the table out with a few default sniffers. OSABI code + can't override this. */ +static void +initialize_frame_unwind_table (std::vector& table) { - struct frame_unwind_table *table = frame_unwind_data.get (gdbarch); - if (table != nullptr) - return table; - - table = new frame_unwind_table; - - /* Start the table out with a few default sniffers. OSABI code - can't override this. */ - struct frame_unwind_table_entry **link = &table->list; - - struct obstack *obstack = gdbarch_obstack (gdbarch); - link = add_unwinder (obstack, &dummy_frame_unwind, link); + table.push_back (&dummy_frame_unwind); /* The DWARF tailcall sniffer must come before the inline sniffer. Otherwise, we can end up in a situation where a DWARF frame finds tailcall information, but then the inline sniffer claims a frame @@ -80,12 +47,22 @@ get_frame_unwind_table (struct gdbarch *gdbarch) safe to do always because the tailcall sniffer can only ever be activated if the newer frame was created using the DWARF unwinder, and it also found tailcall information. */ - link = add_unwinder (obstack, &dwarf2_tailcall_frame_unwind, link); - link = add_unwinder (obstack, &inline_frame_unwind, link); + table.push_back (&dwarf2_tailcall_frame_unwind); + table.push_back (&inline_frame_unwind); /* The insertion point for OSABI sniffers. */ - table->osabi_head = link; - frame_unwind_data.set (gdbarch, table); + osabi_start = table.size (); +} + +/* This function call retrieves the list of frame unwinders available in + GDBARCH. If this list is empty, it is initialized before being + returned. */ +static std::vector& +get_frame_unwind_table (struct gdbarch *gdbarch) +{ + std::vector& table = gdbarch_get_unwinder_list (gdbarch); + if (table.size () == 0) + initialize_frame_unwind_table (table); return table; } @@ -94,27 +71,25 @@ void frame_unwind_prepend_unwinder (struct gdbarch *gdbarch, const struct frame_unwind *unwinder) { - struct frame_unwind_table *table = get_frame_unwind_table (gdbarch); - struct frame_unwind_table_entry *entry; - - /* Insert the new entry at the start of the list. */ - entry = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry); - entry->unwinder = unwinder; - entry->next = (*table->osabi_head); - (*table->osabi_head) = entry; + std::vector& table = get_frame_unwind_table (gdbarch); + + gdb_assert (osabi_start >= 0); + + table.push_back (unwinder); + + /* Bubble the new entry up to where new unwinders are allowed to be + inserterd. */ + for (int i = table.size() - 1; i > osabi_start; i--) + std::swap(table[i], table[i-1]); } void frame_unwind_append_unwinder (struct gdbarch *gdbarch, const struct frame_unwind *unwinder) { - struct frame_unwind_table *table = get_frame_unwind_table (gdbarch); - struct frame_unwind_table_entry **ip; + std::vector& table = get_frame_unwind_table (gdbarch); - /* Find the end of the list and insert the new entry there. */ - for (ip = table->osabi_head; (*ip) != NULL; ip = &(*ip)->next); - (*ip) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry); - (*ip)->unwinder = unwinder; + table.push_back (unwinder); } /* Call SNIFFER from UNWINDER. If it succeeded set UNWINDER for @@ -187,9 +162,6 @@ frame_unwind_find_by_frame (const frame_info_ptr &this_frame, void **this_cache) FRAME_SCOPED_DEBUG_ENTER_EXIT; frame_debug_printf ("this_frame=%d", frame_relative_level (this_frame)); - struct gdbarch *gdbarch = get_frame_arch (this_frame); - struct frame_unwind_table *table = get_frame_unwind_table (gdbarch); - struct frame_unwind_table_entry *entry; const struct frame_unwind *unwinder_from_target; unwinder_from_target = target_get_unwinder (); @@ -204,8 +176,10 @@ frame_unwind_find_by_frame (const frame_info_ptr &this_frame, void **this_cache) unwinder_from_target)) return; - for (entry = table->list; entry != NULL; entry = entry->next) - if (frame_unwind_try_unwinder (this_frame, this_cache, entry->unwinder)) + struct gdbarch *gdbarch = get_frame_arch (this_frame); + std::vector table = get_frame_unwind_table (gdbarch); + for (auto unwinder: table) + if (frame_unwind_try_unwinder (this_frame, this_cache, unwinder)) return; internal_error (_("frame_unwind_find_by_frame failed")); @@ -346,7 +320,7 @@ static void maintenance_info_frame_unwinders (const char *args, int from_tty) { gdbarch *gdbarch = current_inferior ()->arch (); - struct frame_unwind_table *table = get_frame_unwind_table (gdbarch); + std::vector table = get_frame_unwind_table (gdbarch); ui_out *uiout = current_uiout; ui_out_emit_table table_emitter (uiout, 2, -1, "FrameUnwinders"); @@ -354,11 +328,10 @@ maintenance_info_frame_unwinders (const char *args, int from_tty) uiout->table_header (25, ui_left, "type", "Type"); uiout->table_body (); - for (struct frame_unwind_table_entry *entry = table->list; entry != NULL; - entry = entry->next) + for (const struct frame_unwind* unwinder: table) { - const char *name = entry->unwinder->name; - const char *type = frame_type_str (entry->unwinder->type); + const char *name = unwinder->name; + const char *type = frame_type_str (unwinder->type); ui_out_emit_list tuple_emitter (uiout, nullptr); uiout->field_string ("name", name); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 9319571deba..a238d5749b7 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -27,6 +27,7 @@ /* Maintain the struct gdbarch object. */ +#include struct gdbarch { /* Has this architecture been fully initialized? */ @@ -36,6 +37,8 @@ struct gdbarch auto_obstack obstack; /* Registry. */ registry registry_fields; + /* list of frame unwinders. */ + std::vector unwinders; /* basic architectural information. */ const struct bfd_arch_info * bfd_arch_info; diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 77d3406779f..1434d61e600 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -30,6 +30,7 @@ #include "displaced-stepping.h" #include "gdbsupport/gdb-checked-static-cast.h" #include "registry.h" +#include "frame-unwind.h" struct floatformat; struct ui_file; @@ -310,6 +311,10 @@ extern obstack *gdbarch_obstack (gdbarch *arch); #define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) obstack_zalloc (gdbarch_obstack ((GDBARCH))) +/* Return the vector of unwinders stored in a gdbarch object. */ + +std::vector& gdbarch_get_unwinder_list (struct gdbarch *arch); + /* Duplicate STRING, returning an equivalent string that's allocated on the obstack associated with GDBARCH. The string is freed when the corresponding architecture is also freed. */ diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py index 4b4db667ca4..bff66cc39d3 100755 --- a/gdb/gdbarch.py +++ b/gdb/gdbarch.py @@ -125,6 +125,7 @@ with open("gdbarch.c", "w") as f: print(file=f) print("/* Maintain the struct gdbarch object. */", file=f) print(file=f) + print("#include ", file=f) # # The struct definition body. # @@ -137,6 +138,8 @@ with open("gdbarch.c", "w") as f: print(" auto_obstack obstack;", file=f) print(" /* Registry. */", file=f) print(" registry registry_fields;", file=f) + print(" /* list of frame unwinders. */", file=f) + print(" std::vector unwinders;", file=f) print(file=f) print(" /* basic architectural information. */", file=f) for c in filter(info, components): -- 2.44.0