Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - stack commands. |
28e7fd62 | 2 | Copyright (C) 2000-2013 Free Software Foundation, Inc. |
ab91fdd5 | 3 | Contributed by Cygnus Solutions (a Red Hat company). |
fb40c209 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
fb40c209 AC |
10 | (at your option) any later version. |
11 | ||
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
fb40c209 AC |
19 | |
20 | #include "defs.h" | |
21 | #include "target.h" | |
22 | #include "frame.h" | |
23 | #include "value.h" | |
24 | #include "mi-cmds.h" | |
25 | #include "ui-out.h" | |
e88c90f2 | 26 | #include "symtab.h" |
fe898f56 | 27 | #include "block.h" |
b9362cc7 | 28 | #include "stack.h" |
de4f826b | 29 | #include "dictionary.h" |
f5ec2042 | 30 | #include "gdb_string.h" |
d8ca156b | 31 | #include "language.h" |
79a45b7d | 32 | #include "valprint.h" |
875b4ff5 | 33 | #include "exceptions.h" |
1e611234 PM |
34 | #include "utils.h" |
35 | #include "mi-getopt.h" | |
36 | #include "python/python.h" | |
37 | #include <ctype.h> | |
87967e27 | 38 | #include "mi-parse.h" |
daf3c977 VP |
39 | |
40 | enum what_to_list { locals, arguments, all }; | |
41 | ||
42 | static void list_args_or_locals (enum what_to_list what, | |
bdaf8d4a JK |
43 | enum print_values values, |
44 | struct frame_info *fi); | |
fb40c209 | 45 | |
1e611234 PM |
46 | /* True if we want to allow Python-based frame filters. */ |
47 | static int frame_filters = 0; | |
48 | ||
49 | void | |
50 | mi_cmd_enable_frame_filters (char *command, char **argv, int argc) | |
51 | { | |
52 | if (argc != 0) | |
53 | error (_("-enable-frame-filters: no arguments allowed")); | |
54 | frame_filters = 1; | |
55 | } | |
56 | ||
57 | /* Parse the --no-frame-filters option in commands where we cannot use | |
58 | mi_getopt. */ | |
59 | static int | |
60 | parse_no_frames_option (const char *arg) | |
61 | { | |
62 | if (arg && (strcmp (arg, "--no-frame-filters") == 0)) | |
63 | return 1; | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
2b03b41d | 68 | /* Print a list of the stack frames. Args can be none, in which case |
fb40c209 AC |
69 | we want to print the whole backtrace, or a pair of numbers |
70 | specifying the frame numbers at which to start and stop the | |
2b03b41d SS |
71 | display. If the two numbers are equal, a single frame will be |
72 | displayed. */ | |
73 | ||
ce8f13f8 | 74 | void |
fb40c209 AC |
75 | mi_cmd_stack_list_frames (char *command, char **argv, int argc) |
76 | { | |
77 | int frame_low; | |
78 | int frame_high; | |
79 | int i; | |
6ad4a2cf | 80 | struct cleanup *cleanup_stack; |
fb40c209 | 81 | struct frame_info *fi; |
1e611234 PM |
82 | enum py_bt_status result = PY_BT_ERROR; |
83 | int raw_arg = 0; | |
84 | int oind = 0; | |
85 | enum opt | |
86 | { | |
87 | NO_FRAME_FILTERS | |
88 | }; | |
89 | static const struct mi_opt opts[] = | |
90 | { | |
91 | {"-no-frame-filters", NO_FRAME_FILTERS, 0}, | |
92 | { 0, 0, 0 } | |
93 | }; | |
94 | ||
95 | /* Parse arguments. In this instance we are just looking for | |
96 | --no-frame-filters. */ | |
97 | while (1) | |
98 | { | |
99 | char *oarg; | |
100 | int opt = mi_getopt ("-stack-list-frames", argc, argv, | |
101 | opts, &oind, &oarg); | |
102 | if (opt < 0) | |
103 | break; | |
104 | switch ((enum opt) opt) | |
105 | { | |
106 | case NO_FRAME_FILTERS: | |
107 | raw_arg = oind; | |
108 | break; | |
109 | } | |
110 | } | |
fb40c209 | 111 | |
1e611234 PM |
112 | /* After the last option is parsed, there should either be low - |
113 | high range, or no further arguments. */ | |
114 | if ((argc - oind != 0) && (argc - oind != 2)) | |
115 | error (_("-stack-list-frames: Usage: [--no-frame-filters] [FRAME_LOW FRAME_HIGH]")); | |
fb40c209 | 116 | |
1e611234 PM |
117 | /* If there is a range, set it. */ |
118 | if (argc - oind == 2) | |
fb40c209 | 119 | { |
1e611234 PM |
120 | frame_low = atoi (argv[0 + oind]); |
121 | frame_high = atoi (argv[1 + oind]); | |
fb40c209 AC |
122 | } |
123 | else | |
124 | { | |
125 | /* Called with no arguments, it means we want the whole | |
2b03b41d | 126 | backtrace. */ |
fb40c209 AC |
127 | frame_low = -1; |
128 | frame_high = -1; | |
129 | } | |
130 | ||
131 | /* Let's position fi on the frame at which to start the | |
132 | display. Could be the innermost frame if the whole stack needs | |
2b03b41d | 133 | displaying, or if frame_low is 0. */ |
fb40c209 AC |
134 | for (i = 0, fi = get_current_frame (); |
135 | fi && i < frame_low; | |
136 | i++, fi = get_prev_frame (fi)); | |
137 | ||
138 | if (fi == NULL) | |
1b05df00 | 139 | error (_("-stack-list-frames: Not enough frames in stack.")); |
fb40c209 | 140 | |
79a45e25 | 141 | cleanup_stack = make_cleanup_ui_out_list_begin_end (current_uiout, "stack"); |
fb40c209 | 142 | |
1e611234 | 143 | if (! raw_arg && frame_filters) |
fb40c209 | 144 | { |
1e611234 PM |
145 | int flags = PRINT_LEVEL | PRINT_FRAME_INFO; |
146 | int py_frame_low = frame_low; | |
147 | ||
148 | /* We cannot pass -1 to frame_low, as that would signify a | |
149 | relative backtrace from the tail of the stack. So, in the case | |
150 | of frame_low == -1, assign and increment it. */ | |
151 | if (py_frame_low == -1) | |
152 | py_frame_low++; | |
153 | ||
154 | result = apply_frame_filter (get_current_frame (), flags, | |
155 | NO_VALUES, current_uiout, | |
156 | py_frame_low, frame_high); | |
157 | } | |
158 | ||
159 | /* Run the inbuilt backtrace if there are no filters registered, or | |
160 | if "--no-frame-filters" has been specified from the command. */ | |
161 | if (! frame_filters || raw_arg || result == PY_BT_NO_FILTERS) | |
162 | { | |
163 | /* Now let's print the frames up to frame_high, or until there are | |
164 | frames in the stack. */ | |
165 | for (; | |
166 | fi && (i <= frame_high || frame_high == -1); | |
167 | i++, fi = get_prev_frame (fi)) | |
168 | { | |
169 | QUIT; | |
170 | /* Print the location and the address always, even for level 0. | |
171 | If args is 0, don't print the arguments. */ | |
172 | print_frame_info (fi, 1, LOC_AND_ADDRESS, 0 /* args */ ); | |
173 | } | |
fb40c209 AC |
174 | } |
175 | ||
6ad4a2cf | 176 | do_cleanups (cleanup_stack); |
fb40c209 AC |
177 | } |
178 | ||
ce8f13f8 | 179 | void |
fb40c209 AC |
180 | mi_cmd_stack_info_depth (char *command, char **argv, int argc) |
181 | { | |
182 | int frame_high; | |
183 | int i; | |
184 | struct frame_info *fi; | |
185 | ||
fb40c209 | 186 | if (argc > 1) |
1b05df00 | 187 | error (_("-stack-info-depth: Usage: [MAX_DEPTH]")); |
fb40c209 AC |
188 | |
189 | if (argc == 1) | |
190 | frame_high = atoi (argv[0]); | |
191 | else | |
192 | /* Called with no arguments, it means we want the real depth of | |
2b03b41d | 193 | the stack. */ |
fb40c209 AC |
194 | frame_high = -1; |
195 | ||
196 | for (i = 0, fi = get_current_frame (); | |
197 | fi && (i < frame_high || frame_high == -1); | |
198 | i++, fi = get_prev_frame (fi)) | |
199 | QUIT; | |
200 | ||
79a45e25 | 201 | ui_out_field_int (current_uiout, "depth", i); |
fb40c209 AC |
202 | } |
203 | ||
7a93fb82 | 204 | /* Print a list of the locals for the current frame. With argument of |
fb40c209 | 205 | 0, print only the names, with argument of 1 print also the |
2b03b41d SS |
206 | values. */ |
207 | ||
ce8f13f8 | 208 | void |
fb40c209 AC |
209 | mi_cmd_stack_list_locals (char *command, char **argv, int argc) |
210 | { | |
f5ec2042 | 211 | struct frame_info *frame; |
1e611234 PM |
212 | int raw_arg = 0; |
213 | enum py_bt_status result = PY_BT_ERROR; | |
214 | int print_value; | |
645eab03 | 215 | int oind = 0; |
f5ec2042 | 216 | |
645eab03 YQ |
217 | if (argc > 1) |
218 | { | |
219 | int i; | |
220 | enum opt | |
221 | { | |
222 | NO_FRAME_FILTERS | |
223 | }; | |
224 | static const struct mi_opt opts[] = | |
225 | { | |
226 | {"-no-frame-filters", NO_FRAME_FILTERS, 0}, | |
227 | { 0, 0, 0 } | |
228 | }; | |
229 | ||
230 | while (1) | |
231 | { | |
232 | char *oarg; | |
233 | /* Don't parse 'print-values' as an option. */ | |
234 | int opt = mi_getopt ("-stack-list-locals", argc - 1, argv, | |
235 | opts, &oind, &oarg); | |
236 | ||
237 | if (opt < 0) | |
238 | break; | |
239 | switch ((enum opt) opt) | |
240 | { | |
241 | case NO_FRAME_FILTERS: | |
242 | raw_arg = oind; | |
243 | break; | |
244 | } | |
245 | } | |
246 | } | |
fb40c209 | 247 | |
645eab03 YQ |
248 | /* After the last option is parsed, there should be only |
249 | 'print-values'. */ | |
250 | if (argc - oind != 1) | |
1e611234 | 251 | error (_("-stack-list-locals: Usage: [--no-frame-filters] PRINT_VALUES")); |
f5ec2042 | 252 | |
1e611234 | 253 | frame = get_selected_frame (NULL); |
645eab03 | 254 | print_value = mi_parse_print_values (argv[oind]); |
1e611234 PM |
255 | |
256 | if (! raw_arg && frame_filters) | |
257 | { | |
258 | int flags = PRINT_LEVEL | PRINT_LOCALS; | |
259 | ||
260 | result = apply_frame_filter (frame, flags, print_value, | |
261 | current_uiout, 0, 0); | |
262 | } | |
263 | ||
264 | /* Run the inbuilt backtrace if there are no filters registered, or | |
265 | if "--no-frame-filters" has been specified from the command. */ | |
266 | if (! frame_filters || raw_arg || result == PY_BT_NO_FILTERS) | |
267 | { | |
268 | list_args_or_locals (locals, print_value, frame); | |
269 | } | |
fb40c209 AC |
270 | } |
271 | ||
7a93fb82 | 272 | /* Print a list of the arguments for the current frame. With argument |
fb40c209 | 273 | of 0, print only the names, with argument of 1 print also the |
2b03b41d SS |
274 | values. */ |
275 | ||
ce8f13f8 | 276 | void |
fb40c209 AC |
277 | mi_cmd_stack_list_args (char *command, char **argv, int argc) |
278 | { | |
279 | int frame_low; | |
280 | int frame_high; | |
281 | int i; | |
282 | struct frame_info *fi; | |
6ad4a2cf | 283 | struct cleanup *cleanup_stack_args; |
8b777f02 | 284 | enum print_values print_values; |
79a45e25 | 285 | struct ui_out *uiout = current_uiout; |
1e611234 PM |
286 | int raw_arg = 0; |
287 | enum py_bt_status result = PY_BT_ERROR; | |
fb40c209 | 288 | |
1e611234 PM |
289 | if (argc > 0) |
290 | raw_arg = parse_no_frames_option (argv[0]); | |
fb40c209 | 291 | |
1e611234 PM |
292 | if (argc < 1 || (argc > 3 && ! raw_arg) || (argc == 2 && ! raw_arg)) |
293 | error (_("-stack-list-arguments: Usage: " \ | |
294 | "[--no-frame-filters] PRINT_VALUES [FRAME_LOW FRAME_HIGH]")); | |
295 | ||
296 | if (argc >= 3) | |
fb40c209 | 297 | { |
1e611234 PM |
298 | frame_low = atoi (argv[1 + raw_arg]); |
299 | frame_high = atoi (argv[2 + raw_arg]); | |
fb40c209 AC |
300 | } |
301 | else | |
302 | { | |
303 | /* Called with no arguments, it means we want args for the whole | |
2b03b41d | 304 | backtrace. */ |
fb40c209 AC |
305 | frame_low = -1; |
306 | frame_high = -1; | |
307 | } | |
308 | ||
87967e27 | 309 | print_values = mi_parse_print_values (argv[raw_arg]); |
8b777f02 | 310 | |
fb40c209 AC |
311 | /* Let's position fi on the frame at which to start the |
312 | display. Could be the innermost frame if the whole stack needs | |
2b03b41d | 313 | displaying, or if frame_low is 0. */ |
fb40c209 AC |
314 | for (i = 0, fi = get_current_frame (); |
315 | fi && i < frame_low; | |
316 | i++, fi = get_prev_frame (fi)); | |
317 | ||
318 | if (fi == NULL) | |
1b05df00 | 319 | error (_("-stack-list-arguments: Not enough frames in stack.")); |
fb40c209 | 320 | |
9a2b4c1b MS |
321 | cleanup_stack_args |
322 | = make_cleanup_ui_out_list_begin_end (uiout, "stack-args"); | |
fb40c209 | 323 | |
1e611234 | 324 | if (! raw_arg && frame_filters) |
fb40c209 | 325 | { |
1e611234 PM |
326 | int flags = PRINT_LEVEL | PRINT_ARGS; |
327 | int py_frame_low = frame_low; | |
328 | ||
329 | /* We cannot pass -1 to frame_low, as that would signify a | |
330 | relative backtrace from the tail of the stack. So, in the case | |
331 | of frame_low == -1, assign and increment it. */ | |
332 | if (py_frame_low == -1) | |
333 | py_frame_low++; | |
334 | ||
335 | result = apply_frame_filter (get_current_frame (), flags, | |
336 | print_values, current_uiout, | |
337 | py_frame_low, frame_high); | |
fb40c209 AC |
338 | } |
339 | ||
1e611234 PM |
340 | /* Run the inbuilt backtrace if there are no filters registered, or |
341 | if "--no-frame-filters" has been specified from the command. */ | |
342 | if (! frame_filters || raw_arg || result == PY_BT_NO_FILTERS) | |
343 | { | |
344 | /* Now let's print the frames up to frame_high, or until there are | |
345 | frames in the stack. */ | |
346 | for (; | |
347 | fi && (i <= frame_high || frame_high == -1); | |
348 | i++, fi = get_prev_frame (fi)) | |
349 | { | |
350 | struct cleanup *cleanup_frame; | |
351 | ||
352 | QUIT; | |
353 | cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); | |
354 | ui_out_field_int (uiout, "level", i); | |
355 | list_args_or_locals (arguments, print_values, fi); | |
356 | do_cleanups (cleanup_frame); | |
357 | } | |
358 | } | |
6ad4a2cf | 359 | do_cleanups (cleanup_stack_args); |
fb40c209 AC |
360 | } |
361 | ||
daf3c977 | 362 | /* Print a list of the local variables (including arguments) for the |
7a93fb82 VP |
363 | current frame. ARGC must be 1 and ARGV[0] specify if only the names, |
364 | or both names and values of the variables must be printed. See | |
365 | parse_print_value for possible values. */ | |
2b03b41d | 366 | |
daf3c977 VP |
367 | void |
368 | mi_cmd_stack_list_variables (char *command, char **argv, int argc) | |
369 | { | |
370 | struct frame_info *frame; | |
1e611234 PM |
371 | int raw_arg = 0; |
372 | enum py_bt_status result = PY_BT_ERROR; | |
373 | int print_value; | |
645eab03 | 374 | int oind = 0; |
daf3c977 | 375 | |
645eab03 YQ |
376 | if (argc > 1) |
377 | { | |
378 | int i; | |
379 | enum opt | |
380 | { | |
381 | NO_FRAME_FILTERS | |
382 | }; | |
383 | static const struct mi_opt opts[] = | |
384 | { | |
385 | {"-no-frame-filters", NO_FRAME_FILTERS, 0}, | |
386 | { 0, 0, 0 } | |
387 | }; | |
388 | ||
389 | while (1) | |
390 | { | |
391 | char *oarg; | |
392 | /* Don't parse 'print-values' as an option. */ | |
393 | int opt = mi_getopt ("-stack-list-variables", argc - 1, | |
394 | argv, opts, &oind, &oarg); | |
395 | if (opt < 0) | |
396 | break; | |
397 | switch ((enum opt) opt) | |
398 | { | |
399 | case NO_FRAME_FILTERS: | |
400 | raw_arg = oind; | |
401 | break; | |
402 | } | |
403 | } | |
404 | } | |
daf3c977 | 405 | |
645eab03 YQ |
406 | /* After the last option is parsed, there should be only |
407 | 'print-values'. */ | |
408 | if (argc - oind != 1) | |
1e611234 PM |
409 | error (_("-stack-list-variables: Usage: " \ |
410 | "[--no-frame-filters] PRINT_VALUES")); | |
daf3c977 | 411 | |
1e611234 | 412 | frame = get_selected_frame (NULL); |
645eab03 | 413 | print_value = mi_parse_print_values (argv[oind]); |
1e611234 PM |
414 | |
415 | if (! raw_arg && frame_filters) | |
416 | { | |
417 | int flags = PRINT_LEVEL | PRINT_ARGS | PRINT_LOCALS; | |
418 | ||
419 | result = apply_frame_filter (frame, flags, print_value, | |
420 | current_uiout, 0, 0); | |
421 | } | |
422 | ||
423 | /* Run the inbuilt backtrace if there are no filters registered, or | |
424 | if "--no-frame-filters" has been specified from the command. */ | |
425 | if (! frame_filters || raw_arg || result == PY_BT_NO_FILTERS) | |
426 | { | |
427 | list_args_or_locals (all, print_value, frame); | |
428 | } | |
daf3c977 VP |
429 | } |
430 | ||
2b03b41d SS |
431 | /* Print single local or argument. ARG must be already read in. For |
432 | WHAT and VALUES see list_args_or_locals. | |
93d86cef | 433 | |
2b03b41d SS |
434 | Errors are printed as if they would be the parameter value. Use |
435 | zeroed ARG iff it should not be printed according to VALUES. */ | |
93d86cef JK |
436 | |
437 | static void | |
438 | list_arg_or_local (const struct frame_arg *arg, enum what_to_list what, | |
439 | enum print_values values) | |
440 | { | |
f99d8bf4 | 441 | struct cleanup *old_chain; |
93d86cef | 442 | struct ui_out *uiout = current_uiout; |
f99d8bf4 PA |
443 | struct ui_file *stb; |
444 | ||
445 | stb = mem_fileopen (); | |
446 | old_chain = make_cleanup_ui_file_delete (stb); | |
93d86cef JK |
447 | |
448 | gdb_assert (!arg->val || !arg->error); | |
449 | gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL | |
450 | && arg->error == NULL) | |
451 | || values == PRINT_SIMPLE_VALUES | |
452 | || (values == PRINT_ALL_VALUES | |
453 | && (arg->val != NULL || arg->error != NULL))); | |
e18b2753 JK |
454 | gdb_assert (arg->entry_kind == print_entry_values_no |
455 | || (arg->entry_kind == print_entry_values_only | |
456 | && (arg->val || arg->error))); | |
93d86cef JK |
457 | |
458 | if (values != PRINT_NO_VALUES || what == all) | |
cd82eddc | 459 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); |
93d86cef | 460 | |
f99d8bf4 | 461 | fputs_filtered (SYMBOL_PRINT_NAME (arg->sym), stb); |
e18b2753 | 462 | if (arg->entry_kind == print_entry_values_only) |
f99d8bf4 | 463 | fputs_filtered ("@entry", stb); |
e18b2753 | 464 | ui_out_field_stream (uiout, "name", stb); |
93d86cef JK |
465 | |
466 | if (what == all && SYMBOL_IS_ARGUMENT (arg->sym)) | |
467 | ui_out_field_int (uiout, "arg", 1); | |
468 | ||
469 | if (values == PRINT_SIMPLE_VALUES) | |
470 | { | |
471 | check_typedef (arg->sym->type); | |
f99d8bf4 | 472 | type_print (arg->sym->type, "", stb, -1); |
93d86cef JK |
473 | ui_out_field_stream (uiout, "type", stb); |
474 | } | |
475 | ||
476 | if (arg->val || arg->error) | |
477 | { | |
478 | volatile struct gdb_exception except; | |
479 | ||
480 | if (arg->error) | |
481 | except.message = arg->error; | |
482 | else | |
483 | { | |
484 | /* TRY_CATCH has two statements, wrap it in a block. */ | |
485 | ||
486 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
487 | { | |
488 | struct value_print_options opts; | |
489 | ||
2a998fc0 | 490 | get_no_prettyformat_print_options (&opts); |
93d86cef | 491 | opts.deref_ref = 1; |
f99d8bf4 | 492 | common_val_print (arg->val, stb, 0, &opts, |
93d86cef JK |
493 | language_def (SYMBOL_LANGUAGE (arg->sym))); |
494 | } | |
495 | } | |
496 | if (except.message) | |
f99d8bf4 | 497 | fprintf_filtered (stb, _("<error reading variable: %s>"), |
93d86cef JK |
498 | except.message); |
499 | ui_out_field_stream (uiout, "value", stb); | |
500 | } | |
501 | ||
f99d8bf4 | 502 | do_cleanups (old_chain); |
93d86cef | 503 | } |
daf3c977 | 504 | |
fb40c209 AC |
505 | /* Print a list of the locals or the arguments for the currently |
506 | selected frame. If the argument passed is 0, printonly the names | |
507 | of the variables, if an argument of 1 is passed, print the values | |
2b03b41d SS |
508 | as well. */ |
509 | ||
fb40c209 | 510 | static void |
bdaf8d4a JK |
511 | list_args_or_locals (enum what_to_list what, enum print_values values, |
512 | struct frame_info *fi) | |
fb40c209 AC |
513 | { |
514 | struct block *block; | |
515 | struct symbol *sym; | |
8157b174 | 516 | struct block_iterator iter; |
6ad4a2cf | 517 | struct cleanup *cleanup_list; |
f5ec2042 | 518 | struct type *type; |
daf3c977 | 519 | char *name_of_result; |
79a45e25 | 520 | struct ui_out *uiout = current_uiout; |
fb40c209 | 521 | |
ae767bfb | 522 | block = get_frame_block (fi, 0); |
fb40c209 | 523 | |
daf3c977 VP |
524 | switch (what) |
525 | { | |
526 | case locals: | |
d6fd4674 PA |
527 | name_of_result = "locals"; |
528 | break; | |
daf3c977 | 529 | case arguments: |
d6fd4674 PA |
530 | name_of_result = "args"; |
531 | break; | |
daf3c977 | 532 | case all: |
d6fd4674 PA |
533 | name_of_result = "variables"; |
534 | break; | |
654e7c1f | 535 | default: |
d6fd4674 PA |
536 | internal_error (__FILE__, __LINE__, |
537 | "unexpected what_to_list: %d", (int) what); | |
daf3c977 VP |
538 | } |
539 | ||
540 | cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, name_of_result); | |
fb40c209 AC |
541 | |
542 | while (block != 0) | |
543 | { | |
de4f826b | 544 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
fb40c209 | 545 | { |
39bf4652 JB |
546 | int print_me = 0; |
547 | ||
fb40c209 AC |
548 | switch (SYMBOL_CLASS (sym)) |
549 | { | |
550 | default: | |
551 | case LOC_UNDEF: /* catches errors */ | |
552 | case LOC_CONST: /* constant */ | |
553 | case LOC_TYPEDEF: /* local typedef */ | |
554 | case LOC_LABEL: /* local label */ | |
555 | case LOC_BLOCK: /* local function */ | |
556 | case LOC_CONST_BYTES: /* loc. byte seq. */ | |
557 | case LOC_UNRESOLVED: /* unresolved static */ | |
558 | case LOC_OPTIMIZED_OUT: /* optimized out */ | |
559 | print_me = 0; | |
560 | break; | |
561 | ||
562 | case LOC_ARG: /* argument */ | |
563 | case LOC_REF_ARG: /* reference arg */ | |
fb40c209 | 564 | case LOC_REGPARM_ADDR: /* indirect register arg */ |
fb40c209 | 565 | case LOC_LOCAL: /* stack local */ |
fb40c209 AC |
566 | case LOC_STATIC: /* static */ |
567 | case LOC_REGISTER: /* register */ | |
4cf623b6 | 568 | case LOC_COMPUTED: /* computed location */ |
daf3c977 | 569 | if (what == all) |
fb40c209 | 570 | print_me = 1; |
daf3c977 VP |
571 | else if (what == locals) |
572 | print_me = !SYMBOL_IS_ARGUMENT (sym); | |
573 | else | |
574 | print_me = SYMBOL_IS_ARGUMENT (sym); | |
fb40c209 AC |
575 | break; |
576 | } | |
577 | if (print_me) | |
578 | { | |
6bb0384f | 579 | struct symbol *sym2; |
e18b2753 | 580 | struct frame_arg arg, entryarg; |
fb40c209 | 581 | |
daf3c977 | 582 | if (SYMBOL_IS_ARGUMENT (sym)) |
f7e44f65 | 583 | sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), |
f5ec2042 | 584 | block, VAR_DOMAIN, |
1993b719 | 585 | NULL); |
f5ec2042 | 586 | else |
2a2d4dc3 | 587 | sym2 = sym; |
f7e44f65 | 588 | gdb_assert (sym2 != NULL); |
93d86cef JK |
589 | |
590 | memset (&arg, 0, sizeof (arg)); | |
591 | arg.sym = sym2; | |
e18b2753 JK |
592 | arg.entry_kind = print_entry_values_no; |
593 | memset (&entryarg, 0, sizeof (entryarg)); | |
594 | entryarg.sym = sym2; | |
595 | entryarg.entry_kind = print_entry_values_no; | |
93d86cef | 596 | |
f5ec2042 NR |
597 | switch (values) |
598 | { | |
599 | case PRINT_SIMPLE_VALUES: | |
600 | type = check_typedef (sym2->type); | |
f5ec2042 NR |
601 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY |
602 | && TYPE_CODE (type) != TYPE_CODE_STRUCT | |
603 | && TYPE_CODE (type) != TYPE_CODE_UNION) | |
604 | { | |
f5ec2042 | 605 | case PRINT_ALL_VALUES: |
e18b2753 | 606 | read_frame_arg (sym2, fi, &arg, &entryarg); |
93d86cef | 607 | } |
f5ec2042 | 608 | break; |
fb40c209 | 609 | } |
7a93fb82 | 610 | |
e18b2753 JK |
611 | if (arg.entry_kind != print_entry_values_only) |
612 | list_arg_or_local (&arg, what, values); | |
613 | if (entryarg.entry_kind != print_entry_values_no) | |
614 | list_arg_or_local (&entryarg, what, values); | |
93d86cef | 615 | xfree (arg.error); |
e18b2753 | 616 | xfree (entryarg.error); |
fb40c209 AC |
617 | } |
618 | } | |
2b03b41d | 619 | |
fb40c209 AC |
620 | if (BLOCK_FUNCTION (block)) |
621 | break; | |
622 | else | |
623 | block = BLOCK_SUPERBLOCK (block); | |
624 | } | |
6ad4a2cf | 625 | do_cleanups (cleanup_list); |
fb40c209 AC |
626 | } |
627 | ||
ce8f13f8 | 628 | void |
fb40c209 AC |
629 | mi_cmd_stack_select_frame (char *command, char **argv, int argc) |
630 | { | |
fcf43932 | 631 | if (argc == 0 || argc > 1) |
1b05df00 | 632 | error (_("-stack-select-frame: Usage: FRAME_SPEC")); |
fb40c209 | 633 | |
fcf43932 | 634 | select_frame_command (argv[0], 1 /* not used */ ); |
fb40c209 | 635 | } |
64fd8944 | 636 | |
ce8f13f8 | 637 | void |
64fd8944 NR |
638 | mi_cmd_stack_info_frame (char *command, char **argv, int argc) |
639 | { | |
640 | if (argc > 0) | |
2b03b41d | 641 | error (_("-stack-info-frame: No arguments allowed")); |
ce8f13f8 | 642 | |
64fd8944 | 643 | print_frame_info (get_selected_frame (NULL), 1, LOC_AND_ADDRESS, 0); |
64fd8944 | 644 | } |