[binutils-gdb] gdb: remove sentinel frame check in frame_find_by_id

Andrew Burgess via Gdb-cvs <[email protected]> Wed, 24 Jun 2026 08:34:55 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e82c9feb26b7940f498a29de9d064377b7632039

commit e82c9feb26b7940f498a29de9d064377b7632039
Author: Andrew Burgess <[email protected]>
Date:   Sat Jun 20 11:40:57 2026 +0100

    gdb: remove sentinel frame check in frame_find_by_id
    
    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 use a
         comparison against nullptr, which is inline with GDB's policy of
         not treating pointers as bools.
    
    There should be no user visible changes after this commit.
    
    Approved-By: Simon Marchi <[email protected]>

Diff:
---
 gdb/frame.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/gdb/frame.c b/gdb/frame.c
index f64f5554f8c..5487a3e6389 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 != nullptr)
     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 == nullptr)
 	return NULL;
 
       /* As a safety net to avoid unnecessary backtracing while trying