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