]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: fail for 'maint print frame-id LEVEL' of an invalid frame
authorAndrew Burgess <aburgess@redhat.com>
Tue, 20 Jan 2026 15:08:38 +0000 (15:08 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 20 Jan 2026 20:39:15 +0000 (20:39 +0000)
I noticed that 'maint print frame-id LEVEL' will always print a
frame-id, just not always for LEVEL, for example:

  (gdb) bt
  #0  woof () at stack.c:4
  #1  0x000000000040111f in bar () at stack.c:10
  #2  0x000000000040112f in foo () at stack.c:16
  #3  0x000000000040113f in main () at stack.c:22
  (gdb) maintenance print frame-id 4
  frame-id for frame #3: {stack=0x7fffffffa640,code=0x0000000000401131,!special}
  (gdb)

Notice that the request was for the frame-id of #4, which doesn't
exist, but what I got was the frame-id for #3.

Fix this by adding a check to maintenance_print_frame_id (frame.c), so
the new behaviour is:

  (gdb) maintenance print frame-id 4
  No frame at level 4.
  (gdb)

This matches the behaviour of the 'frame' command:

  (gdb) frame 4
  No frame at level 4.
  (gdb)

I've added a new test to cover this case.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/frame.c
gdb/testsuite/gdb.base/maint-print-frame-id.exp

index 7ade9c4459695ae87e32d134e47b2326baa23556..8cb1d0a5c428afdd5a25869980372da3f5d1a943 100644 (file)
@@ -3395,6 +3395,8 @@ maintenance_print_frame_id (const char *args, int from_tty)
     {
       int level = value_as_long (parse_and_eval (args));
       frame = find_relative_frame (get_current_frame (), &level);
+      if (level != 0)
+       error (_("No frame at level %s."), args);
     }
 
   /* Print the frame-id.  */
index ea71de0bf376caaaac7081fcba51ed263921662e..9e1236a973d59e618e68657ccc86cf4b6079127b 100644 (file)
@@ -62,3 +62,10 @@ for { set i 0 } { $i < 4 } { incr i } {
     gdb_test "up" ".*" \
        "move up from frame $i"
 }
+
+# Check that asking for the frame-id of a non-existent frame fails.
+foreach level { -1 5 } {
+    gdb_test "maint print frame-id ${level}" \
+       "^No frame at level ${level}\\." \
+       "no frame at $level"
+}