1 /* MI Command Set - stack commands.
2 Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions (a Red Hat company).
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 #include "dictionary.h"
31 #include "gdb_string.h"
33 static void list_args_or_locals (int locals
, int values
, struct frame_info
*fi
);
35 /* Print a list of the stack frames. Args can be none, in which case
36 we want to print the whole backtrace, or a pair of numbers
37 specifying the frame numbers at which to start and stop the
38 display. If the two numbers are equal, a single frame will be
41 mi_cmd_stack_list_frames (char *command
, char **argv
, int argc
)
46 struct cleanup
*cleanup_stack
;
47 struct frame_info
*fi
;
49 if (argc
> 2 || argc
== 1)
50 error (_("mi_cmd_stack_list_frames: Usage: [FRAME_LOW FRAME_HIGH]"));
54 frame_low
= atoi (argv
[0]);
55 frame_high
= atoi (argv
[1]);
59 /* Called with no arguments, it means we want the whole
65 /* Let's position fi on the frame at which to start the
66 display. Could be the innermost frame if the whole stack needs
67 displaying, or if frame_low is 0. */
68 for (i
= 0, fi
= get_current_frame ();
70 i
++, fi
= get_prev_frame (fi
));
73 error (_("mi_cmd_stack_list_frames: Not enough frames in stack."));
75 cleanup_stack
= make_cleanup_ui_out_list_begin_end (uiout
, "stack");
77 /* Now let;s print the frames up to frame_high, or until there are
78 frames in the stack. */
80 fi
&& (i
<= frame_high
|| frame_high
== -1);
81 i
++, fi
= get_prev_frame (fi
))
84 /* Print the location and the address always, even for level 0.
85 args == 0: don't print the arguments. */
86 print_frame_info (fi
, 1, LOC_AND_ADDRESS
, 0 /* args */ );
89 do_cleanups (cleanup_stack
);
95 mi_cmd_stack_info_depth (char *command
, char **argv
, int argc
)
99 struct frame_info
*fi
;
102 error (_("mi_cmd_stack_info_depth: Usage: [MAX_DEPTH]"));
105 frame_high
= atoi (argv
[0]);
107 /* Called with no arguments, it means we want the real depth of
111 for (i
= 0, fi
= get_current_frame ();
112 fi
&& (i
< frame_high
|| frame_high
== -1);
113 i
++, fi
= get_prev_frame (fi
))
116 ui_out_field_int (uiout
, "depth", i
);
121 /* Print a list of the locals for the current frame. With argument of
122 0, print only the names, with argument of 1 print also the
125 mi_cmd_stack_list_locals (char *command
, char **argv
, int argc
)
127 struct frame_info
*frame
;
128 enum print_values print_values
;
131 error (_("mi_cmd_stack_list_locals: Usage: PRINT_VALUES"));
133 frame
= get_selected_frame (NULL
);
135 if (strcmp (argv
[0], "0") == 0
136 || strcmp (argv
[0], mi_no_values
) == 0)
137 print_values
= PRINT_NO_VALUES
;
138 else if (strcmp (argv
[0], "1") == 0
139 || strcmp (argv
[0], mi_all_values
) == 0)
140 print_values
= PRINT_ALL_VALUES
;
141 else if (strcmp (argv
[0], "2") == 0
142 || strcmp (argv
[0], mi_simple_values
) == 0)
143 print_values
= PRINT_SIMPLE_VALUES
;
145 error (_("Unknown value for PRINT_VALUES: must be: \
146 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
147 mi_no_values
, mi_all_values
, mi_simple_values
);
148 list_args_or_locals (1, print_values
, frame
);
152 /* Print a list of the arguments for the current frame. With argument
153 of 0, print only the names, with argument of 1 print also the
156 mi_cmd_stack_list_args (char *command
, char **argv
, int argc
)
161 struct frame_info
*fi
;
162 struct cleanup
*cleanup_stack_args
;
164 if (argc
< 1 || argc
> 3 || argc
== 2)
165 error (_("mi_cmd_stack_list_args: Usage: PRINT_VALUES [FRAME_LOW FRAME_HIGH]"));
169 frame_low
= atoi (argv
[1]);
170 frame_high
= atoi (argv
[2]);
174 /* Called with no arguments, it means we want args for the whole
180 /* Let's position fi on the frame at which to start the
181 display. Could be the innermost frame if the whole stack needs
182 displaying, or if frame_low is 0. */
183 for (i
= 0, fi
= get_current_frame ();
185 i
++, fi
= get_prev_frame (fi
));
188 error (_("mi_cmd_stack_list_args: Not enough frames in stack."));
190 cleanup_stack_args
= make_cleanup_ui_out_list_begin_end (uiout
, "stack-args");
192 /* Now let's print the frames up to frame_high, or until there are
193 frames in the stack. */
195 fi
&& (i
<= frame_high
|| frame_high
== -1);
196 i
++, fi
= get_prev_frame (fi
))
198 struct cleanup
*cleanup_frame
;
200 cleanup_frame
= make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
201 ui_out_field_int (uiout
, "level", i
);
202 list_args_or_locals (0, atoi (argv
[0]), fi
);
203 do_cleanups (cleanup_frame
);
206 do_cleanups (cleanup_stack_args
);
211 /* Print a list of the locals or the arguments for the currently
212 selected frame. If the argument passed is 0, printonly the names
213 of the variables, if an argument of 1 is passed, print the values
216 list_args_or_locals (int locals
, int values
, struct frame_info
*fi
)
220 struct dict_iterator iter
;
222 struct cleanup
*cleanup_list
;
223 static struct ui_stream
*stb
= NULL
;
226 stb
= ui_out_stream_new (uiout
);
228 block
= get_frame_block (fi
, 0);
230 cleanup_list
= make_cleanup_ui_out_list_begin_end (uiout
, locals
? "locals" : "args");
234 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
238 switch (SYMBOL_CLASS (sym
))
241 case LOC_UNDEF
: /* catches errors */
242 case LOC_CONST
: /* constant */
243 case LOC_TYPEDEF
: /* local typedef */
244 case LOC_LABEL
: /* local label */
245 case LOC_BLOCK
: /* local function */
246 case LOC_CONST_BYTES
: /* loc. byte seq. */
247 case LOC_UNRESOLVED
: /* unresolved static */
248 case LOC_OPTIMIZED_OUT
: /* optimized out */
252 case LOC_ARG
: /* argument */
253 case LOC_REF_ARG
: /* reference arg */
254 case LOC_REGPARM
: /* register arg */
255 case LOC_REGPARM_ADDR
: /* indirect register arg */
256 case LOC_LOCAL_ARG
: /* stack arg */
257 case LOC_BASEREG_ARG
: /* basereg arg */
258 case LOC_COMPUTED_ARG
: /* arg with computed location */
263 case LOC_LOCAL
: /* stack local */
264 case LOC_BASEREG
: /* basereg local */
265 case LOC_STATIC
: /* static */
266 case LOC_REGISTER
: /* register */
267 case LOC_COMPUTED
: /* computed location */
274 struct cleanup
*cleanup_tuple
= NULL
;
277 if (values
!= PRINT_NO_VALUES
)
279 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
280 ui_out_field_string (uiout
, "name", SYMBOL_PRINT_NAME (sym
));
283 sym2
= lookup_symbol (SYMBOL_NATURAL_NAME (sym
),
286 (struct symtab
**) NULL
);
291 case PRINT_SIMPLE_VALUES
:
292 type
= check_typedef (sym2
->type
);
293 type_print (sym2
->type
, "", stb
->stream
, -1);
294 ui_out_field_stream (uiout
, "type", stb
);
295 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
296 && TYPE_CODE (type
) != TYPE_CODE_STRUCT
297 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
299 val
= read_var_value (sym2
, fi
);
301 (val
, stb
->stream
, 0, 1, 0, Val_no_prettyprint
);
302 ui_out_field_stream (uiout
, "value", stb
);
304 do_cleanups (cleanup_tuple
);
306 case PRINT_ALL_VALUES
:
307 val
= read_var_value (sym2
, fi
);
309 (val
, stb
->stream
, 0, 1, 0, Val_no_prettyprint
);
310 ui_out_field_stream (uiout
, "value", stb
);
311 do_cleanups (cleanup_tuple
);
316 if (BLOCK_FUNCTION (block
))
319 block
= BLOCK_SUPERBLOCK (block
);
321 do_cleanups (cleanup_list
);
322 ui_out_stream_delete (stb
);
326 mi_cmd_stack_select_frame (char *command
, char **argv
, int argc
)
328 if (argc
== 0 || argc
> 1)
329 error (_("mi_cmd_stack_select_frame: Usage: FRAME_SPEC"));
331 select_frame_command (argv
[0], 1 /* not used */ );
336 mi_cmd_stack_info_frame (char *command
, char **argv
, int argc
)
339 error (_("mi_cmd_stack_info_frame: No arguments required"));
341 print_frame_info (get_selected_frame (NULL
), 1, LOC_AND_ADDRESS
, 0);