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