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