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