From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id CA6213858D33 for ; Fri, 8 Mar 2024 17:07:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA6213858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CA6213858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709917631; cv=none; b=MF7E+/5DwEywqldluZFcGhOzmxRlcHnn3QIIxjbmAv7xZbek+993L1YrMUXQnJI9DmkybTHDGb8LJpal91IdDpXDsvI6XnrQPnBiwUKKVd/32aPdBDy7M9AqmBgiVNdaITw+umRRQq+o6BHuQybniKocEozBhrv8wTgbQB8hT60= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709917631; c=relaxed/simple; bh=sF5JUawd0QhLpL8xbG73nw6YmF8kBqlLg2dIO23vhCw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tkgBGF9WhghMOU8FHrS2sV2sdt5/GX7trz2+vNRw01DLdPq/V5oTzYHt0xIfni6r1YNTjcag3isNpLntUF2zvty5GFwvgJIc42Dk7hVmrG8ZVYsmF016S79B/EJ8RRFSBGihoGtlS0j097dvCpNrfrS5Zv25SFCGz3rnoLUQh7A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5001a.ext.cloudfilter.net ([10.0.29.139]) by cmsmtp with ESMTPS id ib8Wrlz4ls4yTidgar3YJK; Fri, 08 Mar 2024 17:07:08 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id idgYrGmMBPuJeidgZr3nbG; Fri, 08 Mar 2024 17:07:07 +0000 X-Authority-Analysis: v=2.4 cv=YscJRZYX c=1 sm=1 tr=0 ts=65eb45bb a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=K6JAEmCyrfEA:10 a=Qbun_eYptAEA:10 a=20KFwNOVAAAA:8 a=oRyP15szwZflBotwJk4A:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=q2wo6JJ1Cn2jOIABcW5aah/qPCvf0tjUF+IdpjpHmzU=; b=kQRT8vMJrgPznDlOsDLcAo2gee zGiN8xNISrkFXmRNsYL01ze8hjcOhO1dDOk1rWBp1FGSAydUnGxgtCQsPO+SHrGFaSLCwffPjo+To JV7Kbme8xfl1MRpuppmULO9H0; Received: from 97-122-82-115.hlrn.qwest.net ([97.122.82.115]:42710 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ridgY-004D4r-1x; Fri, 08 Mar 2024 10:07:06 -0700 From: Tom Tromey To: Guinevere Larsen Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/4] gdb: Migrate frame unwinders to use C++ classes References: <20240306125135.766567-1-blarsen@redhat.com> <20240306125135.766567-4-blarsen@redhat.com> X-Attribution: Tom Date: Fri, 08 Mar 2024 10:07:05 -0700 In-Reply-To: <20240306125135.766567-4-blarsen@redhat.com> (Guinevere Larsen's message of "Wed, 6 Mar 2024 13:51:34 +0100") Message-ID: <87plw4r6ti.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.82.115 X-Source-L: No X-Exim-ID: 1ridgY-004D4r-1x X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-82-115.hlrn.qwest.net (murgatroyd) [97.122.82.115]:42710 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfJBbIbhARKm9VFdzkyG2DV0N9ryFE6Jmy0ff+iMVeasbOtGCYzIFRqAF6RhgmYk9VP/bQnt9y8uN9CBCBwiIoigYK8IgvMOdnYKN/10vVCjF6cimx3ye BQw7RiZhQtO5dEGyqHYbqnBIFBLUoaYxxXSOAGswVTg82zwtFAUJm9J7tCeP8D6L9uVuaPclvjuYmgO4Bc0SyGxmqa3L4KoHZTM= X-Spam-Status: No, score=-3015.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: >>>>> Guinevere Larsen writes: > Frame unwinders have historically been a structure populated with > callback pointers, so that architectures (or other specific unwinders) > could install their own way to handle the inferior. However, since > moving to c++, we could use polymorphism to get the same functionality > in a more readable way. Polymorphism also makes it simpler to add new > functionality to all frame unwinders, since all that's required is > adding it to the base class. > As part of the changes to add support to disabling frame unwinders, > this commit makes the first baby step in using polymorphism for the > frame unwinders, by making frame_unwind a virtual class, and adds a > couple of new classes. The main class added is frame_unwind_legacy, > which works the same as the previous structs, using function pointers > as callbacks. This class was added to allow the transition to happen > piecemeal. New unwinders should instead follow the lead of the other > classes implemented. > 2 of the others, frame_unwind_python and frame_unwind_trampoline, were added > because it seemed simpler at the moment to do that instead of reworking > the dynamic allocation to work with the legacy class, and can be used as > an example to future implementations. > /* AArch64 prologue unwinder. */ > -static frame_unwind aarch64_prologue_unwind = > -{ > +static frame_unwind_legacy aarch64_prologue_unwind ( Some of these should probably be 'const'... not really your problem but the patch points it out. > +/* See frame-unwind.h. */ > + > +enum unwind_stop_reason > +frame_unwind::stop_reason (const frame_info_ptr &this_frame, > + void **this_prologue_cache) const > +{ > + return default_frame_unwind_stop_reason (this_frame, this_prologue_cache); > +} > + It looks like all of these methods here could just be inline in the header. > -struct frame_unwind > +class frame_unwind > { > - const char *name; > +private: class defaults to private. > + frame_unwind (const char *n, frame_type t, frame_unwind_class c, > + const struct frame_data *d) > + : m_name (n), m_type (t), m_unwinder_class (c), m_unwind_data (d) { } This looks weird. > + /* Calculate the ID of the given frame using this unwinder. */ > + virtual void this_id (const frame_info_ptr &this_frame, > + void **this_prologue_cache, > + struct frame_id *id) const > + { > + error (_("No method this_id implemented for unwinder %s"), m_name); > + } Why not pure virtual? > + frame_unwind_legacy (const char *n, frame_type t, frame_unwind_class c, > + frame_unwind_stop_reason_ftype *sr, > + frame_this_id_ftype *ti, > + frame_prev_register_ftype *pr, > + const struct frame_data *ud, > + frame_sniffer_ftype *s, > + frame_dealloc_cache_ftype *dc = nullptr, > + frame_prev_arch_ftype *pa = nullptr) > + : frame_unwind (n, t, c, ud), stop_reason_p (sr), > + this_id_p (ti), prev_register_p (pr), sniffer_p (s), > + dealloc_cache_p (dc), prev_arch_p (pa) { } I wonder if making this constexpr would help avoid running a ton of constructors at startup time. Alternatively maybe an approach would be to overload frame_unwind_append_unwinder to automatically instantiate the frame_unwind_legacy object given the C-style struct. I think this would delay running the constructor until the gdbarch is initialized, which in many cases would be never. > + = obstack_new > + (gdbarch_obstack(newarch), (const struct frame_data *) newarch); > + I think it's better to derive from allocate_on_obstack instead. This helps prevent errors. Also a missing space. Tom