1 /* MI Command Set - stack commands.
2 Copyright 2000, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 static void list_args_or_locals (int locals, int values, struct frame_info *fi);
34 /* Print a list of the stack frames. Args can be none, in which case
35 we want to print the whole backtrace, or a pair of numbers
36 specifying the frame numbers at which to start and stop the
37 display. If the two numbers are equal, a single frame will be
40 mi_cmd_stack_list_frames (char *command, char **argv, int argc)
45 struct cleanup *cleanup_stack;
46 struct frame_info *fi;
48 if (!target_has_stack)
49 error ("mi_cmd_stack_list_frames: No stack.");
51 if (argc > 2 || argc == 1)
52 error ("mi_cmd_stack_list_frames: Usage: [FRAME_LOW FRAME_HIGH]");
56 frame_low = atoi (argv[0]);
57 frame_high = atoi (argv[1]);
61 /* Called with no arguments, it means we want the whole
67 /* Let's position fi on the frame at which to start the
68 display. Could be the innermost frame if the whole stack needs
69 displaying, or if frame_low is 0. */
70 for (i = 0, fi = get_current_frame ();
72 i++, fi = get_prev_frame (fi));
75 error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
77 cleanup_stack = make_cleanup_ui_out_list_begin_end (uiout, "stack");
79 /* Now let;s print the frames up to frame_high, or until there are
80 frames in the stack. */
82 fi && (i <= frame_high || frame_high == -1);
83 i++, fi = get_prev_frame (fi))
86 /* level == i: always print the level 'i'
87 source == LOC_AND_ADDRESS: print the location and the address
88 always, even for level 0.
89 args == 0: don't print the arguments. */
90 print_frame_info (fi /* frame info */ ,
92 LOC_AND_ADDRESS /* source */ ,
96 do_cleanups (cleanup_stack);
98 error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
104 mi_cmd_stack_info_depth (char *command, char **argv, int argc)
108 struct frame_info *fi;
110 if (!target_has_stack)
111 error ("mi_cmd_stack_info_depth: No stack.");
114 error ("mi_cmd_stack_info_depth: Usage: [MAX_DEPTH]");
117 frame_high = atoi (argv[0]);
119 /* Called with no arguments, it means we want the real depth of
123 for (i = 0, fi = get_current_frame ();
124 fi && (i < frame_high || frame_high == -1);
125 i++, fi = get_prev_frame (fi))
128 ui_out_field_int (uiout, "depth", i);
133 /* Print a list of the locals for the current frame. With argument of
134 0, print only the names, with argument of 1 print also the
137 mi_cmd_stack_list_locals (char *command, char **argv, int argc)
140 error ("mi_cmd_stack_list_locals: Usage: PRINT_VALUES");
142 list_args_or_locals (1, atoi (argv[0]), deprecated_selected_frame);
146 /* Print a list of the arguments for the current frame. With argument
147 of 0, print only the names, with argument of 1 print also the
150 mi_cmd_stack_list_args (char *command, char **argv, int argc)
155 struct frame_info *fi;
156 struct cleanup *cleanup_stack_args;
158 if (argc < 1 || argc > 3 || argc == 2)
159 error ("mi_cmd_stack_list_args: Usage: PRINT_VALUES [FRAME_LOW FRAME_HIGH]");
163 frame_low = atoi (argv[1]);
164 frame_high = atoi (argv[2]);
168 /* Called with no arguments, it means we want args for the whole
174 /* Let's position fi on the frame at which to start the
175 display. Could be the innermost frame if the whole stack needs
176 displaying, or if frame_low is 0. */
177 for (i = 0, fi = get_current_frame ();
179 i++, fi = get_prev_frame (fi));
182 error ("mi_cmd_stack_list_args: Not enough frames in stack.");
184 cleanup_stack_args = make_cleanup_ui_out_list_begin_end (uiout, "stack-args");
186 /* Now let's print the frames up to frame_high, or until there are
187 frames in the stack. */
189 fi && (i <= frame_high || frame_high == -1);
190 i++, fi = get_prev_frame (fi))
192 struct cleanup *cleanup_frame;
194 cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
195 ui_out_field_int (uiout, "level", i);
196 list_args_or_locals (0, atoi (argv[0]), fi);
197 do_cleanups (cleanup_frame);
200 do_cleanups (cleanup_stack_args);
202 error ("mi_cmd_stack_list_args: Not enough frames in stack.");
207 /* Print a list of the locals or the arguments for the currently
208 selected frame. If the argument passed is 0, printonly the names
209 of the variables, if an argument of 1 is passed, print the values
212 list_args_or_locals (int locals, int values, struct frame_info *fi)
217 struct cleanup *cleanup_list;
218 static struct ui_stream *stb = NULL;
220 stb = ui_out_stream_new (uiout);
222 block = get_frame_block (fi, 0);
224 cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, locals ? "locals" : "args");
228 ALL_BLOCK_SYMBOLS (block, i, sym)
232 switch (SYMBOL_CLASS (sym))
235 case LOC_UNDEF: /* catches errors */
236 case LOC_CONST: /* constant */
237 case LOC_TYPEDEF: /* local typedef */
238 case LOC_LABEL: /* local label */
239 case LOC_BLOCK: /* local function */
240 case LOC_CONST_BYTES: /* loc. byte seq. */
241 case LOC_UNRESOLVED: /* unresolved static */
242 case LOC_OPTIMIZED_OUT: /* optimized out */
246 case LOC_ARG: /* argument */
247 case LOC_REF_ARG: /* reference arg */
248 case LOC_REGPARM: /* register arg */
249 case LOC_REGPARM_ADDR: /* indirect register arg */
250 case LOC_LOCAL_ARG: /* stack arg */
251 case LOC_BASEREG_ARG: /* basereg arg */
252 case LOC_COMPUTED_ARG: /* arg with computed location */
257 case LOC_LOCAL: /* stack local */
258 case LOC_BASEREG: /* basereg local */
259 case LOC_STATIC: /* static */
260 case LOC_REGISTER: /* register */
261 case LOC_COMPUTED: /* computed location */
268 struct cleanup *cleanup_tuple = NULL;
271 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
272 ui_out_field_string (uiout, "name", DEPRECATED_SYMBOL_NAME (sym));
278 sym2 = lookup_symbol (DEPRECATED_SYMBOL_NAME (sym),
281 (struct symtab **) NULL);
284 print_variable_value (sym2, fi, stb->stream);
285 ui_out_field_stream (uiout, "value", stb);
286 do_cleanups (cleanup_tuple);
290 if (BLOCK_FUNCTION (block))
293 block = BLOCK_SUPERBLOCK (block);
295 do_cleanups (cleanup_list);
296 ui_out_stream_delete (stb);
300 mi_cmd_stack_select_frame (char *command, char **argv, int argc)
302 if (!target_has_stack)
303 error ("mi_cmd_stack_select_frame: No stack.");
306 error ("mi_cmd_stack_select_frame: Usage: [FRAME_SPEC]");
308 /* with no args, don't change frame */
310 select_frame_command (0, 1 /* not used */ );
312 select_frame_command (argv[0], 1 /* not used */ );