From 70175292616118bad315296ba6180f375326bb6c Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 16 Aug 2022 16:48:01 +0100 Subject: gdb: new 'maint print frame-id' command When debugging a certain class of GDB bug, I often end up wanting to know what GDB thinks the frame-id is in a particular frame. It's not too hard to pull this from some debug output, but I thought it might be nice if there was a maintenance command that could tell us. This commit adds 'maint print frame-id' which prints the frame-id of the currently selected frame. You can also pass a frame level number to find the frame-id for a specific frame. There's a new test too. --- gdb/frame.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gdb/frame.c') diff --git a/gdb/frame.c b/gdb/frame.c index ae45e22..e6bebf5 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -3116,6 +3116,30 @@ the rest of the stack trace."), }, }; +/* Implement the 'maintenance print frame-id' command. */ + +static void +maintenance_print_frame_id (const char *args, int from_tty) +{ + struct frame_info *frame; + + /* Use the currently selected frame, or select a frame based on the level + number passed by the user. */ + if (args == nullptr) + frame = get_selected_frame ("No frame selected"); + else + { + int level = value_as_long (parse_and_eval (args)); + frame = find_relative_frame (get_current_frame (), &level); + } + + /* Print the frame-id. */ + gdb_assert (frame != nullptr); + gdb_printf ("frame-id for frame #%d: %s\n", + frame_relative_level (frame), + get_frame_id (frame).to_string ().c_str ()); +} + void _initialize_frame (); void _initialize_frame () @@ -3160,4 +3184,8 @@ When non-zero, frame specific internal debugging is enabled."), NULL, show_frame_debug, &setdebuglist, &showdebuglist); + + add_cmd ("frame-id", class_maintenance, maintenance_print_frame_id, + _("Print the current frame-id."), + &maintenanceprintlist); } -- cgit v1.1