From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id BA2D03858C50; Fri, 20 Jan 2023 19:53:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA2D03858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674244392; bh=3WK9mpD8T6l7cI1utRxesXluqLgEEGdkQioBFYSx0Wg=; h=From:To:Subject:Date:From; b=mmxRVhyaLnN+q/EmuZpAHRdbj694LMriyDpIUTmwUTw02IbAWFNQV2CzPNMqryajr heYc6NGVkl/YoALQjZHBgdJ1OJM2BwjMSZvOzvT4Gb3B9a80icpo21zBN08AqQQcM0 Um40QSvpKch3sotrkKMYRSBnIYCtuvuBrKqsIUK4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: make frame_info_ptr auto-reinflatable X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 93e39555dd0fcd222ce68fc7162f511056361bc7 X-Git-Newrev: 908de5e67156068f3da74c60dea6f360246a3d0b Message-Id: <20230120195312.BA2D03858C50@sourceware.org> Date: Fri, 20 Jan 2023 19:53:12 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D908de5e67156= 068f3da74c60dea6f360246a3d0b commit 908de5e67156068f3da74c60dea6f360246a3d0b Author: Simon Marchi Date: Tue Dec 13 22:34:41 2022 -0500 gdb: make frame_info_ptr auto-reinflatable =20 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. =20 Add an "is_null" method, because it is often needed to know whether the frame_info_ptr wraps an frame_info or is empty. =20 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. =20 Change-Id: Icb0552d0035e227f81eb3c121d8a9bb2f9d25794 Reviewed-By: Bruno Larsen Diff: --- gdb/frame.c | 7 ++--- gdb/frame.h | 45 +++++++++++++++++++++++-----= ---- gdb/infcall.c | 2 -- gdb/infcmd.c | 1 - gdb/mi/mi-cmd-stack.c | 1 - gdb/stack.c | 6 ----- gdb/unittests/frame_info_ptr-selftests.c | 2 -- 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/gdb/frame.c b/gdb/frame.c index c4b0f0166d6..a08a8f47ebc 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -3224,8 +3224,8 @@ frame_info_ptr::frame_info_ptr (struct frame_info *pt= r) =20 /* See frame-info-ptr.h. */ =20 -void -frame_info_ptr::reinflate () +frame_info * +frame_info_ptr::reinflate () const { /* Ensure we have a valid frame level (sentinel frame or above). */ gdb_assert (m_cached_level >=3D -1); @@ -3233,7 +3233,7 @@ frame_info_ptr::reinflate () if (m_ptr !=3D nullptr) { /* The frame_info wasn't invalidated, no need to reinflate. */ - return; + return m_ptr; } =20 if (m_cached_id.user_created_p) @@ -3255,6 +3255,7 @@ frame_info_ptr::reinflate () } =20 gdb_assert (m_ptr !=3D nullptr); + return m_ptr; } =20 void _initialize_frame (); diff --git a/gdb/frame.h b/gdb/frame.h index 105b9fb92a8..c4f7c121391 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -275,29 +275,38 @@ public: } =20 frame_info *operator-> () const - { - return m_ptr; - } + { return this->reinflate (); } =20 /* 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 (); } =20 + /* Return true if this object is empty (does not wrap a frame_info + object). */ + + bool is_null () const + { + return m_cached_level =3D=3D this->invalid_level; + }; + /* This exists for compatibility with pre-existing code that checked a "frame_info *" using "!". */ bool operator! () const { - return m_ptr =3D=3D nullptr; + return this->is_null (); } =20 /* This exists for compatibility with pre-existing code that checked a "frame_info *" like "if (ptr)". */ explicit operator bool () const { - return m_ptr !=3D nullptr; + return !this->is_null (); } =20 /* Invalidate this pointer. */ @@ -306,17 +315,18 @@ public: m_ptr =3D nullptr; } =20 - /* 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 =3D -2; =20 + /* 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 =3D nullptr; + mutable frame_info *m_ptr =3D nullptr; =20 /* The frame_id of the underlying pointer. =20 @@ -341,37 +351,46 @@ private: static inline bool operator=3D=3D (const frame_info *self, const frame_info_ptr &other) { + if (self =3D=3D nullptr || other.is_null ()) + return self =3D=3D nullptr && other.is_null (); + return self =3D=3D other.get (); } =20 static inline bool operator=3D=3D (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 () =3D=3D other.get (); } =20 static inline bool operator=3D=3D (const frame_info_ptr &self, const frame_info *other) { + if (self.is_null () || other =3D=3D nullptr) + return self.is_null () && other =3D=3D nullptr; + return self.get () =3D=3D other; } =20 static inline bool operator!=3D (const frame_info *self, const frame_info_ptr &other) { - return self !=3D other.get (); + return !(self =3D=3D other); } =20 static inline bool operator!=3D (const frame_info_ptr &self, const frame_info_ptr &other) { - return self.get () !=3D other.get (); + return !(self =3D=3D other); } =20 static inline bool operator!=3D (const frame_info_ptr &self, const frame_info *other) { - return self.get () !=3D other; + return !(self =3D=3D other); } =20 /* For every stopped thread, GDB tracks two frames: current and diff --git a/gdb/infcall.c b/gdb/infcall.c index a60cca47c33..4c2a4e4f400 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -857,8 +857,6 @@ call_function_by_hand_dummy (struct value *function, "target calling convention."), get_function_name (funaddr, name_buf, sizeof (name_buf))); =20 - frame.reinflate (); - if (values_type =3D=3D NULL || values_type->is_stub ()) values_type =3D default_return_type; if (values_type =3D=3D NULL) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 15dca8c4604..fd88b8ca328 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1915,7 +1915,6 @@ finish_command (const char *arg, int from_tty) =20 print_stack_frame (callee_frame, 1, LOCATION, 0); } - frame.reinflate (); =20 if (execution_direction =3D=3D EXEC_REVERSE) finish_backward (sm); diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index 9582fa24507..00e61e04b67 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 **a= rgv, 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 4250383d9eb..c36f144f093 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -367,7 +367,6 @@ print_stack_frame (frame_info_ptr frame, int print_leve= l, 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, } =20 first =3D 0; - frame.reinflate (); } } =20 @@ -1173,7 +1171,6 @@ print_frame_info (const frame_print_options &fp_opts, =20 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); } - frame.reinflate (); =20 /* 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 sele= cted_frame_p) =20 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_op= ts, print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout); =20 /* Save the last frame to check for error conditions. */ - fi.reinflate (); trailing =3D fi; } =20 diff --git a/gdb/unittests/frame_info_ptr-selftests.c b/gdb/unittests/frame= _info_ptr-selftests.c index 47306113c7a..fe1e7be35da 100644 --- a/gdb/unittests/frame_info_ptr-selftests.c +++ b/gdb/unittests/frame_info_ptr-selftests.c @@ -41,7 +41,6 @@ user_created_frame_callee (frame_info_ptr frame) validate_user_created_frame (get_frame_id (frame)); =20 reinit_frame_cache (); - frame.reinflate (); =20 validate_user_created_frame (get_frame_id (frame)); =20 @@ -61,7 +60,6 @@ test_user_created_frame () validate that the reinflation in both the callee and caller restore t= he same frame_info object. */ frame_info_ptr callees_frame_info =3D user_created_frame_callee (frame); - frame.reinflate (); =20 validate_user_created_frame (get_frame_id (frame)); SELF_CHECK (frame.get () =3D=3D callees_frame_info.get ());