]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove sentinel frame check in frame_find_by_id
authorAndrew Burgess <aburgess@redhat.com>
Sat, 20 Jun 2026 10:40:57 +0000 (11:40 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 24 Jun 2026 08:34:21 +0000 (09:34 +0100)
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 <simon.marchi@efficios.com>
gdb/frame.c

index f64f5554f8c2cd3d74a6a1586edf4a4976d76ef7..5487a3e638919f4b77d8b391b36cb7cd485087b0 100644 (file)
@@ -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