[Patch] add implementation of stack-info-frame MI command

Mo DeJong
2002-07-25T21:38:18Z

Hello.

While using the MI, I noticed that there is a real problem trying to find
the current stack level. One could get the stack and look at the level
value of the first frame or parse the results of a cli frame command,
but these both seem ugly. What is needed is a stack-info-frame that
returns the current stack level to complement the stack-select-frame
which selects a stack level.

Here is what I propose:

-stack-info-frame
^done,level="0"
(gdb)
-stack-select-frame 5
^done
(gdb)
-stack-info-frame
^done,level="5"
(gdb)

The stack-info-frame command is currently unimplemented
even though it appears in the documentation, so there is
no way this patch could break anything. The only objection
I could think of was that folks might want the command
to return all the info about the current frame, like the
stack-list-frames method. That is actually not needed since
one could always run stack-list-frames and then select
a stack level out of the returned frames. In real code,
it is better to query the whole stack as opposed to changing
the stack, doing a query of the current frame, changing the
stack, then doing a query, and so on.

I forgot to mention in my last patch that I sent in my FSF
copyright paperwork, so that should not stand in the way
of incorporating my patches any longer.

cheers
Mo

2002-07-25 Mo DeJong <supermo@bayarea.net>

* mi-stack.exp: Add test for stack-info-frame
command that returns the current stack level.

Index: mi-stack.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-stack.exp,v
retrieving revision 1.8
diff -u -r1.8 mi-stack.exp
--- mi-stack.exp 19 Aug 2001 01:23:43 -0000 1.8
+++ mi-stack.exp 25 Jul 2002 21:06:38 -0000
@@ -192,6 +192,10 @@
"232\\^done" \
"stack select frame 1"

+ mi_gdb_test "232-stack-info-frame" \
+ "232\\^done,level=\"1\"" \
+ "stack info frame"
+
mi_gdb_test "232-stack-list-locals 1" \
"232\\^done,locals=\\\[\\\]" \
"stack locals listing for new frame"

2002-07-25 Mo DeJong <supermo@bayarea.net>

* gdbmi.texinfo (stack-info-frame): Document
return of current stack level by stack-info-frame.
* mi-cmd-stack.c (mi_cmd_stack_info_frame):
Implement stack-info-frame command.
* mi-cmds.c: Add mi_cmd_stack_info_frame to
mi command lookup table.
* mi-cmds.h: Add mi_cmd_stack_info_frame decl.

Index: gdbmi.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/mi/gdbmi.texinfo,v
retrieving revision 1.26
diff -u -r1.26 gdbmi.texinfo
--- gdbmi.texinfo 25 Feb 2002 02:13:09 -0000 1.26
+++ gdbmi.texinfo 25 Jul 2002 21:11:34 -0000
@@ -2558,12 +2558,18 @@
-stack-info-frame
@end example

-Get info on the current frame.
+Get the stack level of the current frame.
+
+@smallexample
+(@value{GDBP})
+-stack-info-frame
+^done,level="0"
+(@value{GDBP})
+@end smallexample

@subsubheading @value{GDBN} Command

-The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
-(without arguments).
+There's no equivalent @value{GDBN} command.

@subsubheading Example
N.A.
Index: mi-cmd-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v
retrieving revision 1.10
diff -u -r1.10 mi-cmd-stack.c
--- mi-cmd-stack.c 5 Feb 2002 19:28:36 -0000 1.10
+++ mi-cmd-stack.c 25 Jul 2002 21:11:35 -0000
@@ -307,3 +307,16 @@
select_frame_command_wrapper (argv[0], 1 /* not used */ );
return MI_CMD_DONE;
}
+
+enum mi_cmd_result
+mi_cmd_stack_info_frame (char *command, char **argv, int argc)
+{
+ if (!target_has_stack)
+ error ("mi_cmd_stack_info_frame: No stack.");
+
+ if (argc > 0)
+ error ("mi_cmd_stack_info_frame: Command accepts no arguments");
+
+ ui_out_field_fmt (uiout, "level", "%d", selected_frame_level);
+ return MI_CMD_DONE;
+}
Index: mi-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
retrieving revision 1.8
diff -u -r1.8 mi-cmds.c
--- mi-cmds.c 6 Mar 2001 08:21:45 -0000 1.8
+++ mi-cmds.c 25 Jul 2002 21:11:35 -0000
@@ -103,7 +103,7 @@
{"signal-list-handle-actions", 0, 0},
{"signal-list-signal-types", 0, 0},
{"stack-info-depth", 0, 0, mi_cmd_stack_info_depth},
- {"stack-info-frame", 0, 0},
+ {"stack-info-frame", 0, 0, mi_cmd_stack_info_frame},
{"stack-list-arguments", 0, 0, mi_cmd_stack_list_args},
{"stack-list-exception-handlers", 0, 0},
{"stack-list-frames", 0, 0, mi_cmd_stack_list_frames},
Index: mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.5
diff -u -r1.5 mi-cmds.h
--- mi-cmds.h 6 Mar 2001 08:21:45 -0000 1.5
+++ mi-cmds.h 25 Jul 2002 21:11:35 -0000
@@ -76,6 +76,7 @@
extern mi_cmd_args_ftype mi_cmd_exec_interrupt;
extern mi_cmd_argv_ftype mi_cmd_gdb_exit;
extern mi_cmd_argv_ftype mi_cmd_stack_info_depth;
+extern mi_cmd_argv_ftype mi_cmd_stack_info_frame;
extern mi_cmd_argv_ftype mi_cmd_stack_list_args;
extern mi_cmd_argv_ftype mi_cmd_stack_list_frames;
extern mi_cmd_argv_ftype mi_cmd_stack_list_locals;