* configure.ac (mips*-*-*linux*, mips*-*-gnu*): Use mt-mips-gnu.
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-stack.c
CommitLineData
fb40c209 1/* MI Command Set - stack commands.
9b254dd1 2 Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008
6aba47ca 3 Free Software Foundation, Inc.
ab91fdd5 4 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
5
6 This file is part of GDB.
7
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
fb40c209
AC
11 (at your option) any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb40c209
AC
20
21#include "defs.h"
22#include "target.h"
23#include "frame.h"
24#include "value.h"
25#include "mi-cmds.h"
26#include "ui-out.h"
e88c90f2 27#include "symtab.h"
fe898f56 28#include "block.h"
b9362cc7 29#include "stack.h"
de4f826b 30#include "dictionary.h"
f5ec2042 31#include "gdb_string.h"
d8ca156b 32#include "language.h"
fb40c209
AC
33
34static void list_args_or_locals (int locals, int values, struct frame_info *fi);
35
36/* Print a list of the stack frames. Args can be none, in which case
37 we want to print the whole backtrace, or a pair of numbers
38 specifying the frame numbers at which to start and stop the
39 display. If the two numbers are equal, a single frame will be
40 displayed. */
ce8f13f8 41void
fb40c209
AC
42mi_cmd_stack_list_frames (char *command, char **argv, int argc)
43{
44 int frame_low;
45 int frame_high;
46 int i;
6ad4a2cf 47 struct cleanup *cleanup_stack;
fb40c209
AC
48 struct frame_info *fi;
49
fb40c209 50 if (argc > 2 || argc == 1)
8a3fe4f8 51 error (_("mi_cmd_stack_list_frames: Usage: [FRAME_LOW FRAME_HIGH]"));
fb40c209
AC
52
53 if (argc == 2)
54 {
55 frame_low = atoi (argv[0]);
56 frame_high = atoi (argv[1]);
57 }
58 else
59 {
60 /* Called with no arguments, it means we want the whole
61 backtrace. */
62 frame_low = -1;
63 frame_high = -1;
64 }
65
66 /* Let's position fi on the frame at which to start the
67 display. Could be the innermost frame if the whole stack needs
68 displaying, or if frame_low is 0. */
69 for (i = 0, fi = get_current_frame ();
70 fi && i < frame_low;
71 i++, fi = get_prev_frame (fi));
72
73 if (fi == NULL)
8a3fe4f8 74 error (_("mi_cmd_stack_list_frames: Not enough frames in stack."));
fb40c209 75
6ad4a2cf 76 cleanup_stack = make_cleanup_ui_out_list_begin_end (uiout, "stack");
fb40c209
AC
77
78 /* Now let;s print the frames up to frame_high, or until there are
79 frames in the stack. */
80 for (;
81 fi && (i <= frame_high || frame_high == -1);
82 i++, fi = get_prev_frame (fi))
83 {
84 QUIT;
0faf0076 85 /* Print the location and the address always, even for level 0.
fb40c209 86 args == 0: don't print the arguments. */
0faf0076 87 print_frame_info (fi, 1, LOC_AND_ADDRESS, 0 /* args */ );
fb40c209
AC
88 }
89
6ad4a2cf 90 do_cleanups (cleanup_stack);
fb40c209
AC
91}
92
ce8f13f8 93void
fb40c209
AC
94mi_cmd_stack_info_depth (char *command, char **argv, int argc)
95{
96 int frame_high;
97 int i;
98 struct frame_info *fi;
99
fb40c209 100 if (argc > 1)
8a3fe4f8 101 error (_("mi_cmd_stack_info_depth: Usage: [MAX_DEPTH]"));
fb40c209
AC
102
103 if (argc == 1)
104 frame_high = atoi (argv[0]);
105 else
106 /* Called with no arguments, it means we want the real depth of
107 the stack. */
108 frame_high = -1;
109
110 for (i = 0, fi = get_current_frame ();
111 fi && (i < frame_high || frame_high == -1);
112 i++, fi = get_prev_frame (fi))
113 QUIT;
114
115 ui_out_field_int (uiout, "depth", i);
fb40c209
AC
116}
117
118/* Print a list of the locals for the current frame. With argument of
119 0, print only the names, with argument of 1 print also the
120 values. */
ce8f13f8 121void
fb40c209
AC
122mi_cmd_stack_list_locals (char *command, char **argv, int argc)
123{
f5ec2042
NR
124 struct frame_info *frame;
125 enum print_values print_values;
126
fb40c209 127 if (argc != 1)
8a3fe4f8 128 error (_("mi_cmd_stack_list_locals: Usage: PRINT_VALUES"));
fb40c209 129
b04f3ab4 130 frame = get_selected_frame (NULL);
f5ec2042
NR
131
132 if (strcmp (argv[0], "0") == 0
1ecb4ee0 133 || strcmp (argv[0], mi_no_values) == 0)
f5ec2042
NR
134 print_values = PRINT_NO_VALUES;
135 else if (strcmp (argv[0], "1") == 0
1ecb4ee0 136 || strcmp (argv[0], mi_all_values) == 0)
f5ec2042
NR
137 print_values = PRINT_ALL_VALUES;
138 else if (strcmp (argv[0], "2") == 0
1ecb4ee0 139 || strcmp (argv[0], mi_simple_values) == 0)
f5ec2042
NR
140 print_values = PRINT_SIMPLE_VALUES;
141 else
1ecb4ee0
DJ
142 error (_("Unknown value for PRINT_VALUES: must be: \
1430 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
144 mi_no_values, mi_all_values, mi_simple_values);
f5ec2042 145 list_args_or_locals (1, print_values, frame);
fb40c209
AC
146}
147
148/* Print a list of the arguments for the current frame. With argument
149 of 0, print only the names, with argument of 1 print also the
150 values. */
ce8f13f8 151void
fb40c209
AC
152mi_cmd_stack_list_args (char *command, char **argv, int argc)
153{
154 int frame_low;
155 int frame_high;
156 int i;
157 struct frame_info *fi;
6ad4a2cf 158 struct cleanup *cleanup_stack_args;
fb40c209
AC
159
160 if (argc < 1 || argc > 3 || argc == 2)
8a3fe4f8 161 error (_("mi_cmd_stack_list_args: Usage: PRINT_VALUES [FRAME_LOW FRAME_HIGH]"));
fb40c209
AC
162
163 if (argc == 3)
164 {
165 frame_low = atoi (argv[1]);
166 frame_high = atoi (argv[2]);
167 }
168 else
169 {
170 /* Called with no arguments, it means we want args for the whole
171 backtrace. */
172 frame_low = -1;
173 frame_high = -1;
174 }
175
176 /* Let's position fi on the frame at which to start the
177 display. Could be the innermost frame if the whole stack needs
178 displaying, or if frame_low is 0. */
179 for (i = 0, fi = get_current_frame ();
180 fi && i < frame_low;
181 i++, fi = get_prev_frame (fi));
182
183 if (fi == NULL)
8a3fe4f8 184 error (_("mi_cmd_stack_list_args: Not enough frames in stack."));
fb40c209 185
6ad4a2cf 186 cleanup_stack_args = make_cleanup_ui_out_list_begin_end (uiout, "stack-args");
fb40c209
AC
187
188 /* Now let's print the frames up to frame_high, or until there are
189 frames in the stack. */
190 for (;
191 fi && (i <= frame_high || frame_high == -1);
192 i++, fi = get_prev_frame (fi))
193 {
6ad4a2cf 194 struct cleanup *cleanup_frame;
fb40c209 195 QUIT;
6ad4a2cf 196 cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
fb40c209
AC
197 ui_out_field_int (uiout, "level", i);
198 list_args_or_locals (0, atoi (argv[0]), fi);
6ad4a2cf 199 do_cleanups (cleanup_frame);
fb40c209
AC
200 }
201
6ad4a2cf 202 do_cleanups (cleanup_stack_args);
fb40c209
AC
203}
204
205/* Print a list of the locals or the arguments for the currently
206 selected frame. If the argument passed is 0, printonly the names
207 of the variables, if an argument of 1 is passed, print the values
208 as well. */
209static void
210list_args_or_locals (int locals, int values, struct frame_info *fi)
211{
212 struct block *block;
213 struct symbol *sym;
de4f826b
DC
214 struct dict_iterator iter;
215 int nsyms;
6ad4a2cf 216 struct cleanup *cleanup_list;
fb40c209 217 static struct ui_stream *stb = NULL;
f5ec2042 218 struct type *type;
fb40c209
AC
219
220 stb = ui_out_stream_new (uiout);
221
ae767bfb 222 block = get_frame_block (fi, 0);
fb40c209 223
6ad4a2cf 224 cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, locals ? "locals" : "args");
fb40c209
AC
225
226 while (block != 0)
227 {
de4f826b 228 ALL_BLOCK_SYMBOLS (block, iter, sym)
fb40c209 229 {
39bf4652
JB
230 int print_me = 0;
231
fb40c209
AC
232 switch (SYMBOL_CLASS (sym))
233 {
234 default:
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 */
243 print_me = 0;
244 break;
245
246 case LOC_ARG: /* argument */
247 case LOC_REF_ARG: /* reference arg */
fb40c209 248 case LOC_REGPARM_ADDR: /* indirect register arg */
fb40c209 249 case LOC_LOCAL: /* stack local */
fb40c209
AC
250 case LOC_STATIC: /* static */
251 case LOC_REGISTER: /* register */
4cf623b6 252 case LOC_COMPUTED: /* computed location */
2a2d4dc3 253 if (SYMBOL_IS_ARGUMENT (sym) ? !locals : locals)
fb40c209
AC
254 print_me = 1;
255 break;
256 }
257 if (print_me)
258 {
6ad4a2cf 259 struct cleanup *cleanup_tuple = NULL;
6bb0384f 260 struct symbol *sym2;
9fbcbb40 261 struct value *val;
f5ec2042
NR
262 if (values != PRINT_NO_VALUES)
263 cleanup_tuple =
6ad4a2cf 264 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
f5ec2042 265 ui_out_field_string (uiout, "name", SYMBOL_PRINT_NAME (sym));
fb40c209 266
f5ec2042
NR
267 if (!locals)
268 sym2 = lookup_symbol (SYMBOL_NATURAL_NAME (sym),
269 block, VAR_DOMAIN,
2570f2b7 270 (int *) NULL);
f5ec2042 271 else
2a2d4dc3 272 sym2 = sym;
f5ec2042
NR
273 switch (values)
274 {
275 case PRINT_SIMPLE_VALUES:
276 type = check_typedef (sym2->type);
277 type_print (sym2->type, "", stb->stream, -1);
278 ui_out_field_stream (uiout, "type", stb);
279 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
280 && TYPE_CODE (type) != TYPE_CODE_STRUCT
281 && TYPE_CODE (type) != TYPE_CODE_UNION)
282 {
9fbcbb40
NR
283 val = read_var_value (sym2, fi);
284 common_val_print
d8ca156b
JB
285 (val, stb->stream, 0, 1, 0, Val_no_prettyprint,
286 language_def (SYMBOL_LANGUAGE (sym2)));
f5ec2042
NR
287 ui_out_field_stream (uiout, "value", stb);
288 }
289 do_cleanups (cleanup_tuple);
290 break;
291 case PRINT_ALL_VALUES:
9fbcbb40
NR
292 val = read_var_value (sym2, fi);
293 common_val_print
d8ca156b
JB
294 (val, stb->stream, 0, 1, 0, Val_no_prettyprint,
295 language_def (SYMBOL_LANGUAGE (sym2)));
fb40c209 296 ui_out_field_stream (uiout, "value", stb);
6ad4a2cf 297 do_cleanups (cleanup_tuple);
f5ec2042 298 break;
fb40c209
AC
299 }
300 }
301 }
302 if (BLOCK_FUNCTION (block))
303 break;
304 else
305 block = BLOCK_SUPERBLOCK (block);
306 }
6ad4a2cf 307 do_cleanups (cleanup_list);
fb40c209
AC
308 ui_out_stream_delete (stb);
309}
310
ce8f13f8 311void
fb40c209
AC
312mi_cmd_stack_select_frame (char *command, char **argv, int argc)
313{
fcf43932
NR
314 if (argc == 0 || argc > 1)
315 error (_("mi_cmd_stack_select_frame: Usage: FRAME_SPEC"));
fb40c209 316
fcf43932 317 select_frame_command (argv[0], 1 /* not used */ );
fb40c209 318}
64fd8944 319
ce8f13f8 320void
64fd8944
NR
321mi_cmd_stack_info_frame (char *command, char **argv, int argc)
322{
323 if (argc > 0)
324 error (_("mi_cmd_stack_info_frame: No arguments required"));
ce8f13f8 325
64fd8944 326 print_frame_info (get_selected_frame (NULL), 1, LOC_AND_ADDRESS, 0);
64fd8944 327}
This page took 0.870243 seconds and 4 git commands to generate.