From patchwork Fri Dec 2 18:00:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 61380 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F361E385842E for ; Fri, 2 Dec 2022 18:10:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F361E385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670004632; bh=xFLiofK0Ld7aTalme/xz+zKQrABtN+dGbZSdpPYzGjI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=MRhWgSaB8zZxjaKb6cf7BH+CsENq/0Z87LnUIpemZ6+4zOPjrXp7ZozJOqg4JZAev OUwkmxko4Yd0Sq3AoGLfw+fOm36skOpXkhPo+YoFQsJmwXjbjOZt03VKCnRlvNq8Vq 7A23E/0jUpprHN7FdbFr9kFaD854OTBUKXQEEOqA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 63D593858C52 for ; Fri, 2 Dec 2022 18:09:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 63D593858C52 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2B2I9U52028481 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 2 Dec 2022 13:09:35 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2B2I9U52028481 Received: from simark.localdomain (unknown [217.28.27.60]) (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 simark.ca (Postfix) with ESMTPSA id 482271E12A; Fri, 2 Dec 2022 13:00:55 -0500 (EST) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 6/6] gdb: make frame_info_ptr auto-reinflatable Date: Fri, 2 Dec 2022 13:00:52 -0500 Message-Id: <20221202180052.212745-7-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221202180052.212745-1-simon.marchi@polymtl.ca> References: <20221202180052.212745-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 2 Dec 2022 18:09:30 +0000 X-Spam-Status: No, score=-3189.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This is the second step of making frame_info_ptr automatic, reinflate on demand whenever trying to obtain the wrapper frame_info pointer, either through the get method or operator->. Make the reinflate method private, it is used as a convenience method in those two. Add an "is_null" method, because it is often needed to know whether the frame_info_ptr wraps an frame_info or is empty. Make m_ptr mutable, so that it's possible to reinflate const frame_info_ptr objects. Whether m_ptr is nullptr or not does not change the logical state of the object, because we re-create it on demand. I believe this is the right use case for mutable. Change-Id: Icb0552d0035e227f81eb3c121d8a9bb2f9d25794 --- gdb/frame-info.c | 8 ++++---- gdb/frame-info.h | 45 ++++++++++++++++++++++++++++++------------- gdb/infcmd.c | 1 - gdb/mi/mi-cmd-stack.c | 1 - gdb/stack.c | 6 ------ 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/gdb/frame-info.c b/gdb/frame-info.c index 8ab5f54f8202..9010774c2b9f 100644 --- a/gdb/frame-info.c +++ b/gdb/frame-info.c @@ -48,8 +48,8 @@ frame_info_ptr::frame_info_ptr (struct frame_info *ptr) /* See frame-info-ptr.h. */ -void -frame_info_ptr::reinflate () +frame_info * +frame_info_ptr::reinflate () const { /* Ensure we have a valid frame level (sentinel frame or above), indicating prepare_reinflate was called. */ @@ -58,7 +58,7 @@ frame_info_ptr::reinflate () if (m_ptr != nullptr) { /* The frame_info wasn't invalidated, no need to reinflate. */ - return; + return m_ptr; } /* Frame #0 needs special handling, see comment in select_frame. */ @@ -77,6 +77,7 @@ frame_info_ptr::reinflate () } gdb_assert (m_ptr != nullptr); + return m_ptr; } #if GDB_SELF_TEST @@ -97,7 +98,6 @@ test_user_created_frame () SELF_CHECK (id.code_addr == 0x5678); reinit_frame_cache (); - frame.reinflate (); id = get_frame_id (frame); SELF_CHECK (id.stack_status == FID_STACK_VALID); diff --git a/gdb/frame-info.h b/gdb/frame-info.h index 224a553ac040..abba3cb35e73 100644 --- a/gdb/frame-info.h +++ b/gdb/frame-info.h @@ -107,29 +107,38 @@ class frame_info_ptr : public intrusive_list_node } frame_info *operator-> () const - { - return m_ptr; - } + { return this->reinflate (); } /* Fetch the underlying pointer. Note that new code should generally not use this -- avoid it if at all possible. */ frame_info *get () const { - return m_ptr; + if (this->is_null ()) + return nullptr; + + return this->reinflate (); } + /* Return true if this object is empty (does not wrap a frame_info + object). */ + + bool is_null () const + { + return m_cached_level == this->invalid_level; + }; + /* This exists for compatibility with pre-existing code that checked a "frame_info *" using "!". */ bool operator! () const { - return m_ptr == nullptr; + return this->is_null (); } /* This exists for compatibility with pre-existing code that checked a "frame_info *" like "if (ptr)". */ explicit operator bool () const { - return m_ptr != nullptr; + return !this->is_null (); } /* Invalidate this pointer. */ @@ -138,17 +147,18 @@ class frame_info_ptr : public intrusive_list_node m_ptr = nullptr; } - /* Use the cached frame_id to reinflate the pointer. */ - void reinflate (); - private: /* We sometimes need to construct frame_info_ptr objects around the sentinel_frame, which has level -1. Therefore, make the invalid frame level value -2. */ static constexpr int invalid_level = -2; + /* Use the cached frame level and id to reinflate the pointer, and return + it. */ + frame_info *reinflate () const; + /* The underlying pointer. */ - frame_info *m_ptr = nullptr; + mutable frame_info *m_ptr = nullptr; /* The frame_id of the underlying pointer. @@ -173,37 +183,46 @@ class frame_info_ptr : public intrusive_list_node static inline bool operator== (const frame_info *self, const frame_info_ptr &other) { + if (self == nullptr || other.is_null ()) + return self == nullptr && other.is_null (); + return self == other.get (); } static inline bool operator== (const frame_info_ptr &self, const frame_info_ptr &other) { + if (self.is_null () || other.is_null ()) + return self.is_null () && other.is_null (); + return self.get () == other.get (); } static inline bool operator== (const frame_info_ptr &self, const frame_info *other) { + if (self.is_null () || other == nullptr) + return self.is_null () && other == nullptr; + return self.get () == other; } static inline bool operator!= (const frame_info *self, const frame_info_ptr &other) { - return self != other.get (); + return !(self == other); } static inline bool operator!= (const frame_info_ptr &self, const frame_info_ptr &other) { - return self.get () != other.get (); + return !(self == other); } static inline bool operator!= (const frame_info_ptr &self, const frame_info *other) { - return self.get () != other; + return !(self == other); } #endif /* GDB_FRAME_INFO_H */ diff --git a/gdb/infcmd.c b/gdb/infcmd.c index ee3d97b585dd..d1f634f86b1d 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1917,7 +1917,6 @@ finish_command (const char *arg, int from_tty) print_stack_frame (callee_frame, 1, LOCATION, 0); } - frame.reinflate (); if (execution_direction == EXEC_REVERSE) finish_backward (sm); diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index 186d53156730..16be1938c033 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -180,7 +180,6 @@ mi_cmd_stack_list_frames (const char *command, char **argv, int argc) If args is 0, don't print the arguments. */ print_frame_info (user_frame_print_options, fi, 1, LOC_AND_ADDRESS, 0 /* args */, 0); - fi.reinflate (); } } } diff --git a/gdb/stack.c b/gdb/stack.c index 126ce0b8cc2a..5bc5b2d26cfe 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -367,7 +367,6 @@ print_stack_frame (frame_info_ptr frame, int print_level, print_frame_info (user_frame_print_options, frame, print_level, print_what, 1 /* print_args */, set_current_sal); - frame.reinflate (); if (set_current_sal) set_current_sal_from_frame (frame); } @@ -903,7 +902,6 @@ print_frame_args (const frame_print_options &fp_opts, } first = 0; - frame.reinflate (); } } @@ -1173,7 +1171,6 @@ print_frame_info (const frame_print_options &fp_opts, print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); } - frame.reinflate (); /* If disassemble-next-line is set to on and there is line debug messages, output assembly codes for next line. */ @@ -1676,8 +1673,6 @@ info_frame_command_core (frame_info_ptr fi, bool selected_frame_p) print_frame_args (user_frame_print_options, func, fi, numargs, gdb_stdout); - fi.reinflate (); - gdb_puts ("\n"); } } @@ -2077,7 +2072,6 @@ backtrace_command_1 (const frame_print_options &fp_opts, print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout); /* Save the last frame to check for error conditions. */ - fi.reinflate (); trailing = fi; }