Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>, Simon Marchi <simark@simark.ca>
Subject: [PATCHv2 1/2] gdb: remove sentinel frame check in frame_find_by_id
Date: Mon, 22 Jun 2026 22:33:05 +0100	[thread overview]
Message-ID: <b74c2cb9db61ca16b1caba47b8fc91150b92006d.1782163808.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1782163808.git.aburgess@redhat.com>

While reviewing another patch Simon pointed out that the code in
frame_find_by_id for looking up the sentinel frame is no longer needed
since commit:

  commit 19f988359a62889b00d67fb59ef8c7d6d759fc98
  Date:   Mon Jan 30 15:02:49 2023 -0500

    gdb: give sentinel for user frames distinct IDs, register sentinel frames to the frame cache

Prior to this commit the sentinel_frame was not added to the frame
stash, so we needed a manual check to lookup the sentinel frame.
After this commit the sentinel frame is added to the stash so the
manual check, though perfectly valid, is just unnecessary complexity,
and can be removed.  A frame stash lookup is just a hash lookup, and
is relatively cheap, so switching to this isn't much extra cost.

While I was working in frame_find_by_id I made a couple of additional
changes:

  1. I moved the declarations of frame and prev_frame locals into the
     function body, closer to where they are first defined.

  2. Instead of treating a frame_info_ptr as a bool, I made use of the
     frame_info_ptr::is_null method.

There should be no user visible changes after this commit.
---
 gdb/frame.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/gdb/frame.c b/gdb/frame.c
index f64f5554f8c..c1a7c41dc4a 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -959,17 +959,11 @@ frame_id_inner (struct gdbarch *gdbarch, struct frame_id l, struct frame_id r)
 frame_info_ptr
 frame_find_by_id (struct frame_id id)
 {
-  frame_info_ptr frame, prev_frame;
-
   /* ZERO denotes the null frame, let the caller decide what to do
      about it.  Should it instead return get_current_frame()?  */
   if (!frame_id_p (id))
     return NULL;
 
-  /* Check for the sentinel frame.  */
-  if (id == frame_id_build_sentinel (0, 0))
-    return frame_info_ptr (sentinel_frame);
-
   /* Try using the frame stash first.  Finding it there removes the need
      to perform the search by looping over all frames, which can be very
      CPU-intensive if the number of frames is very high (the loop is O(n)
@@ -978,10 +972,11 @@ frame_find_by_id (struct frame_id id)
      is called from another function (such as value_fetch_lazy, case
      val->lval () == lval_register) which already loops over all frames,
      making the overall behavior O(n^2).  */
-  frame = frame_stash_find (id);
-  if (frame)
+  frame_info_ptr frame = frame_stash_find (id);
+  if (!frame.is_null ())
     return frame;
 
+  frame_info_ptr prev_frame;
   for (frame = get_current_frame (); ; frame = prev_frame)
     {
       struct frame_id self = get_frame_id (frame);
@@ -991,7 +986,7 @@ frame_find_by_id (struct frame_id id)
 	return frame;
 
       prev_frame = get_prev_frame (frame);
-      if (!prev_frame)
+      if (prev_frame.is_null ())
 	return NULL;
 
       /* As a safety net to avoid unnecessary backtracing while trying
-- 
2.25.4


  reply	other threads:[~2026-06-22 21:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18 17:00 [PATCH] gdb: return raw frame_info pointer from create_sentinel_frame Andrew Burgess
2026-06-18 17:25 ` Simon Marchi
2026-06-18 17:27 ` Tom Tromey
2026-06-22 21:33 ` [PATCHv2 0/2] Some sentinel frame related cleanup in frame.c Andrew Burgess
2026-06-22 21:33   ` Andrew Burgess [this message]
2026-06-23  2:18     ` [PATCHv2 1/2] gdb: remove sentinel frame check in frame_find_by_id Simon Marchi
2026-06-23 10:52       ` Andrew Burgess
2026-06-22 21:33   ` [PATCHv2 2/2] gdb: convert sentinel_frame to a frame_info_ptr Andrew Burgess
2026-06-23  2:23     ` Simon Marchi
2026-06-23 10:55       ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b74c2cb9db61ca16b1caba47b8fc91150b92006d.1782163808.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox