Add output styles to gdb
[deliverable/binutils-gdb.git] / gdb / stack.c
CommitLineData
c906108c 1/* Print and select stack frames for GDB, the GNU debugger.
8926118c 2
e2882c85 3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 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/>. */
c906108c 19
c906108c 20#include "defs.h"
c906108c
SS
21#include "value.h"
22#include "symtab.h"
23#include "gdbtypes.h"
24#include "expression.h"
25#include "language.h"
26#include "frame.h"
27#include "gdbcmd.h"
28#include "gdbcore.h"
29#include "target.h"
0378c332 30#include "source.h"
c906108c
SS
31#include "breakpoint.h"
32#include "demangle.h"
33#include "inferior.h"
34#include "annotate.h"
8b93c638 35#include "ui-out.h"
fe898f56 36#include "block.h"
b9362cc7 37#include "stack.h"
de4f826b 38#include "dictionary.h"
898c62f5 39#include "reggroups.h"
fc70c2a0 40#include "regcache.h"
a77053c2 41#include "solib.h"
033a42c2 42#include "valprint.h"
8ea051c5 43#include "gdbthread.h"
3567439c 44#include "cp-support.h"
30c33a9f 45#include "disasm.h"
edb3359d 46#include "inline-frame.h"
f8eba3c6 47#include "linespec.h"
529480d0 48#include "cli/cli-utils.h"
77e371c0 49#include "objfiles.h"
c906108c 50
ccefe4c4 51#include "symfile.h"
6dddc817 52#include "extension.h"
76727919 53#include "observable.h"
0b868b60 54#include "common/def-vector.h"
ccefe4c4 55
2421fe6f 56/* The possible choices of "set print frame-arguments", and the value
88408340
JB
57 of this setting. */
58
40478521 59static const char *const print_frame_arguments_choices[] =
88408340 60 {"all", "scalars", "none", NULL};
476f7b68 61static const char *print_frame_arguments = "scalars";
88408340 62
e7045703
DE
63/* If non-zero, don't invoke pretty-printers for frame arguments. */
64static int print_raw_frame_arguments;
65
e18b2753
JK
66/* The possible choices of "set print entry-values", and the value
67 of this setting. */
68
69const char print_entry_values_no[] = "no";
70const char print_entry_values_only[] = "only";
71const char print_entry_values_preferred[] = "preferred";
72const char print_entry_values_if_needed[] = "if-needed";
73const char print_entry_values_both[] = "both";
74const char print_entry_values_compact[] = "compact";
75const char print_entry_values_default[] = "default";
40478521 76static const char *const print_entry_values_choices[] =
e18b2753
JK
77{
78 print_entry_values_no,
79 print_entry_values_only,
80 print_entry_values_preferred,
81 print_entry_values_if_needed,
82 print_entry_values_both,
83 print_entry_values_compact,
84 print_entry_values_default,
85 NULL
86};
87const char *print_entry_values = print_entry_values_default;
88
c378eb4e 89/* Prototypes for local functions. */
c906108c 90
12615cba
PW
91static void print_frame_local_vars (struct frame_info *frame,
92 bool quiet,
93 const char *regexp, const char *t_regexp,
94 int num_tabs, struct ui_file *stream);
c906108c 95
033a42c2
MK
96static void print_frame (struct frame_info *frame, int print_level,
97 enum print_what print_what, int print_args,
c5394b80
JM
98 struct symtab_and_line sal);
99
1bfeeb0f
JL
100static void set_last_displayed_sal (int valid,
101 struct program_space *pspace,
102 CORE_ADDR addr,
103 struct symtab *symtab,
104 int line);
105
f67ffa6a
AB
106static struct frame_info *find_frame_for_function (const char *);
107static struct frame_info *find_frame_for_address (CORE_ADDR);
108
c906108c
SS
109/* Zero means do things normally; we are interacting directly with the
110 user. One means print the full filename and linenumber when a
111 frame is printed, and do so in a format emacs18/emacs19.22 can
112 parse. Two means print similar annotations, but in many more
113 cases and in a slightly different syntax. */
114
115int annotation_level = 0;
1bfeeb0f
JL
116
117/* These variables hold the last symtab and line we displayed to the user.
118 * This is where we insert a breakpoint or a skiplist entry by default. */
119static int last_displayed_sal_valid = 0;
120static struct program_space *last_displayed_pspace = 0;
121static CORE_ADDR last_displayed_addr = 0;
122static struct symtab *last_displayed_symtab = 0;
123static int last_displayed_line = 0;
c906108c 124\f
c5aa993b 125
edb3359d
DJ
126/* Return 1 if we should display the address in addition to the location,
127 because we are in the middle of a statement. */
128
129static int
130frame_show_address (struct frame_info *frame,
131 struct symtab_and_line sal)
132{
133 /* If there is a line number, but no PC, then there is no location
134 information associated with this sal. The only way that should
135 happen is for the call sites of inlined functions (SAL comes from
136 find_frame_sal). Otherwise, we would have some PC range if the
137 SAL came from a line table. */
138 if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
139 {
140 if (get_next_frame (frame) == NULL)
00431a78 141 gdb_assert (inline_skipped_frames (inferior_thread ()) > 0);
edb3359d
DJ
142 else
143 gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
144 return 0;
145 }
146
147 return get_frame_pc (frame) != sal.pc;
148}
149
4034d0ff
AT
150/* See frame.h. */
151
152void
153print_stack_frame_to_uiout (struct ui_out *uiout, struct frame_info *frame,
154 int print_level, enum print_what print_what,
155 int set_current_sal)
156{
67ad9399 157 scoped_restore save_uiout = make_scoped_restore (&current_uiout, uiout);
4034d0ff
AT
158
159 print_stack_frame (frame, print_level, print_what, set_current_sal);
4034d0ff
AT
160}
161
f9acce4a 162/* Show or print a stack frame FRAME briefly. The output is formatted
d762c46a
AC
163 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
164 relative level, function name, argument list, and file name and
165 line number. If the frame's PC is not at the beginning of the
166 source line, the actual PC is printed at the beginning. */
c906108c
SS
167
168void
033a42c2 169print_stack_frame (struct frame_info *frame, int print_level,
08d72866
PA
170 enum print_what print_what,
171 int set_current_sal)
c906108c 172{
c906108c 173
aaf9e9fd 174 /* For mi, alway print location and address. */
112e8700 175 if (current_uiout->is_mi_like_p ())
311b5970 176 print_what = LOC_AND_ADDRESS;
c906108c 177
492d29ea 178 TRY
311b5970 179 {
08d72866
PA
180 print_frame_info (frame, print_level, print_what, 1 /* print_args */,
181 set_current_sal);
182 if (set_current_sal)
5166082f 183 set_current_sal_from_frame (frame);
311b5970 184 }
492d29ea
PA
185 CATCH (e, RETURN_MASK_ERROR)
186 {
187 }
188 END_CATCH
311b5970 189}
c906108c 190
033a42c2
MK
191/* Print nameless arguments of frame FRAME on STREAM, where START is
192 the offset of the first nameless argument, and NUM is the number of
193 nameless arguments to print. FIRST is nonzero if this is the first
194 argument (not just the first nameless argument). */
8d3b0994
AC
195
196static void
033a42c2 197print_frame_nameless_args (struct frame_info *frame, long start, int num,
8d3b0994
AC
198 int first, struct ui_file *stream)
199{
e17a4113
UW
200 struct gdbarch *gdbarch = get_frame_arch (frame);
201 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
8d3b0994
AC
202 int i;
203 CORE_ADDR argsaddr;
204 long arg_value;
205
206 for (i = 0; i < num; i++)
207 {
208 QUIT;
033a42c2 209 argsaddr = get_frame_args_address (frame);
8d3b0994
AC
210 if (!argsaddr)
211 return;
e17a4113
UW
212 arg_value = read_memory_integer (argsaddr + start,
213 sizeof (int), byte_order);
8d3b0994
AC
214 if (!first)
215 fprintf_filtered (stream, ", ");
216 fprintf_filtered (stream, "%ld", arg_value);
217 first = 0;
218 start += sizeof (int);
219 }
220}
221
93d86cef
JK
222/* Print single argument of inferior function. ARG must be already
223 read in.
224
225 Errors are printed as if they would be the parameter value. Use zeroed ARG
226 iff it should not be printed accoring to user settings. */
227
228static void
229print_frame_arg (const struct frame_arg *arg)
230{
231 struct ui_out *uiout = current_uiout;
492d29ea 232 const char *error_message = NULL;
93d86cef 233
d7e74731 234 string_file stb;
93d86cef
JK
235
236 gdb_assert (!arg->val || !arg->error);
e18b2753
JK
237 gdb_assert (arg->entry_kind == print_entry_values_no
238 || arg->entry_kind == print_entry_values_only
112e8700 239 || (!uiout->is_mi_like_p ()
e18b2753 240 && arg->entry_kind == print_entry_values_compact));
93d86cef 241
46b9c129
TT
242 annotate_arg_emitter arg_emitter;
243 ui_out_emit_tuple tuple_emitter (uiout, NULL);
d7e74731 244 fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
93d86cef 245 SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
e18b2753
JK
246 if (arg->entry_kind == print_entry_values_compact)
247 {
248 /* It is OK to provide invalid MI-like stream as with
249 PRINT_ENTRY_VALUE_COMPACT we never use MI. */
d7e74731 250 stb.puts ("=");
e18b2753 251
d7e74731 252 fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
e18b2753
JK
253 SYMBOL_LANGUAGE (arg->sym),
254 DMGL_PARAMS | DMGL_ANSI);
255 }
256 if (arg->entry_kind == print_entry_values_only
257 || arg->entry_kind == print_entry_values_compact)
d7e74731 258 stb.puts ("@entry");
112e8700 259 uiout->field_stream ("name", stb);
93d86cef 260 annotate_arg_name_end ();
112e8700 261 uiout->text ("=");
93d86cef
JK
262
263 if (!arg->val && !arg->error)
112e8700 264 uiout->text ("...");
93d86cef
JK
265 else
266 {
267 if (arg->error)
492d29ea 268 error_message = arg->error;
93d86cef
JK
269 else
270 {
492d29ea 271 TRY
93d86cef
JK
272 {
273 const struct language_defn *language;
274 struct value_print_options opts;
275
276 /* Avoid value_print because it will deref ref parameters. We
277 just want to print their addresses. Print ??? for args whose
278 address we do not know. We pass 2 as "recurse" to val_print
279 because our standard indentation here is 4 spaces, and
280 val_print indents 2 for each recurse. */
281
282 annotate_arg_value (value_type (arg->val));
283
284 /* Use the appropriate language to display our symbol, unless the
285 user forced the language to a specific language. */
286 if (language_mode == language_mode_auto)
287 language = language_def (SYMBOL_LANGUAGE (arg->sym));
288 else
289 language = current_language;
290
2a998fc0 291 get_no_prettyformat_print_options (&opts);
3343315b 292 opts.deref_ref = 1;
e7045703 293 opts.raw = print_raw_frame_arguments;
93d86cef
JK
294
295 /* True in "summary" mode, false otherwise. */
296 opts.summary = !strcmp (print_frame_arguments, "scalars");
297
d7e74731 298 common_val_print (arg->val, &stb, 2, &opts, language);
93d86cef 299 }
492d29ea
PA
300 CATCH (except, RETURN_MASK_ERROR)
301 {
302 error_message = except.message;
303 }
304 END_CATCH
93d86cef 305 }
492d29ea 306 if (error_message != NULL)
d7e74731 307 stb.printf (_("<error reading variable: %s>"), error_message);
93d86cef
JK
308 }
309
112e8700 310 uiout->field_stream ("value", stb);
93d86cef
JK
311}
312
82a0a75f
YQ
313/* Read in inferior function local SYM at FRAME into ARGP. Caller is
314 responsible for xfree of ARGP->ERROR. This function never throws an
315 exception. */
316
317void
318read_frame_local (struct symbol *sym, struct frame_info *frame,
319 struct frame_arg *argp)
320{
492d29ea
PA
321 argp->sym = sym;
322 argp->val = NULL;
323 argp->error = NULL;
324
325 TRY
82a0a75f 326 {
63e43d3a 327 argp->val = read_var_value (sym, NULL, frame);
82a0a75f 328 }
492d29ea
PA
329 CATCH (except, RETURN_MASK_ERROR)
330 {
331 argp->error = xstrdup (except.message);
332 }
333 END_CATCH
82a0a75f
YQ
334}
335
93d86cef
JK
336/* Read in inferior function parameter SYM at FRAME into ARGP. Caller is
337 responsible for xfree of ARGP->ERROR. This function never throws an
338 exception. */
339
340void
341read_frame_arg (struct symbol *sym, struct frame_info *frame,
e18b2753 342 struct frame_arg *argp, struct frame_arg *entryargp)
93d86cef 343{
e18b2753
JK
344 struct value *val = NULL, *entryval = NULL;
345 char *val_error = NULL, *entryval_error = NULL;
346 int val_equal = 0;
93d86cef 347
e18b2753
JK
348 if (print_entry_values != print_entry_values_only
349 && print_entry_values != print_entry_values_preferred)
350 {
492d29ea 351 TRY
e18b2753 352 {
63e43d3a 353 val = read_var_value (sym, NULL, frame);
e18b2753 354 }
492d29ea 355 CATCH (except, RETURN_MASK_ERROR)
e18b2753 356 {
224c3ddb 357 val_error = (char *) alloca (strlen (except.message) + 1);
e18b2753
JK
358 strcpy (val_error, except.message);
359 }
492d29ea 360 END_CATCH
e18b2753
JK
361 }
362
24d6c2a0
TT
363 if (SYMBOL_COMPUTED_OPS (sym) != NULL
364 && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
e18b2753
JK
365 && print_entry_values != print_entry_values_no
366 && (print_entry_values != print_entry_values_if_needed
367 || !val || value_optimized_out (val)))
368 {
492d29ea 369 TRY
e18b2753
JK
370 {
371 const struct symbol_computed_ops *ops;
372
373 ops = SYMBOL_COMPUTED_OPS (sym);
374 entryval = ops->read_variable_at_entry (sym, frame);
375 }
492d29ea 376 CATCH (except, RETURN_MASK_ERROR)
e18b2753 377 {
492d29ea
PA
378 if (except.error != NO_ENTRY_VALUE_ERROR)
379 {
380 entryval_error = (char *) alloca (strlen (except.message) + 1);
381 strcpy (entryval_error, except.message);
382 }
e18b2753 383 }
492d29ea 384 END_CATCH
e18b2753 385
492d29ea
PA
386 if (entryval != NULL && value_optimized_out (entryval))
387 entryval = NULL;
e18b2753
JK
388
389 if (print_entry_values == print_entry_values_compact
390 || print_entry_values == print_entry_values_default)
391 {
392 /* For MI do not try to use print_entry_values_compact for ARGP. */
393
112e8700 394 if (val && entryval && !current_uiout->is_mi_like_p ())
e18b2753 395 {
744a8059 396 struct type *type = value_type (val);
e18b2753 397
9a0dc9e3
PA
398 if (value_lazy (val))
399 value_fetch_lazy (val);
400 if (value_lazy (entryval))
401 value_fetch_lazy (entryval);
402
403 if (value_contents_eq (val, 0, entryval, 0, TYPE_LENGTH (type)))
e18b2753 404 {
509f0fd9
JK
405 /* Initialize it just to avoid a GCC false warning. */
406 struct value *val_deref = NULL, *entryval_deref;
a471c594 407
216f72a1 408 /* DW_AT_call_value does match with the current
a471c594 409 value. If it is a reference still try to verify if
216f72a1 410 dereferenced DW_AT_call_data_value does not differ. */
a471c594 411
492d29ea 412 TRY
a471c594 413 {
744a8059 414 struct type *type_deref;
a471c594
JK
415
416 val_deref = coerce_ref (val);
417 if (value_lazy (val_deref))
418 value_fetch_lazy (val_deref);
744a8059 419 type_deref = value_type (val_deref);
a471c594
JK
420
421 entryval_deref = coerce_ref (entryval);
422 if (value_lazy (entryval_deref))
423 value_fetch_lazy (entryval_deref);
424
425 /* If the reference addresses match but dereferenced
426 content does not match print them. */
427 if (val != val_deref
9a0dc9e3
PA
428 && value_contents_eq (val_deref, 0,
429 entryval_deref, 0,
430 TYPE_LENGTH (type_deref)))
a471c594
JK
431 val_equal = 1;
432 }
492d29ea
PA
433 CATCH (except, RETURN_MASK_ERROR)
434 {
435 /* If the dereferenced content could not be
436 fetched do not display anything. */
437 if (except.error == NO_ENTRY_VALUE_ERROR)
438 val_equal = 1;
439 else if (except.message != NULL)
440 {
441 entryval_error = (char *) alloca (strlen (except.message) + 1);
442 strcpy (entryval_error, except.message);
443 }
444 }
445 END_CATCH
a471c594
JK
446
447 /* Value was not a reference; and its content matches. */
448 if (val == val_deref)
449 val_equal = 1;
a471c594
JK
450
451 if (val_equal)
452 entryval = NULL;
e18b2753
JK
453 }
454 }
455
456 /* Try to remove possibly duplicate error message for ENTRYARGP even
457 in MI mode. */
458
459 if (val_error && entryval_error
460 && strcmp (val_error, entryval_error) == 0)
461 {
462 entryval_error = NULL;
463
464 /* Do not se VAL_EQUAL as the same error message may be shown for
465 the entry value even if no entry values are present in the
466 inferior. */
467 }
468 }
469 }
470
471 if (entryval == NULL)
93d86cef 472 {
e18b2753
JK
473 if (print_entry_values == print_entry_values_preferred)
474 {
492d29ea
PA
475 gdb_assert (val == NULL);
476
477 TRY
e18b2753 478 {
63e43d3a 479 val = read_var_value (sym, NULL, frame);
e18b2753 480 }
492d29ea 481 CATCH (except, RETURN_MASK_ERROR)
e18b2753 482 {
224c3ddb 483 val_error = (char *) alloca (strlen (except.message) + 1);
e18b2753
JK
484 strcpy (val_error, except.message);
485 }
492d29ea 486 END_CATCH
e18b2753
JK
487 }
488 if (print_entry_values == print_entry_values_only
489 || print_entry_values == print_entry_values_both
490 || (print_entry_values == print_entry_values_preferred
491 && (!val || value_optimized_out (val))))
1ed8d800
YQ
492 {
493 entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
494 entryval_error = NULL;
495 }
93d86cef 496 }
e18b2753
JK
497 if ((print_entry_values == print_entry_values_compact
498 || print_entry_values == print_entry_values_if_needed
499 || print_entry_values == print_entry_values_preferred)
500 && (!val || value_optimized_out (val)) && entryval != NULL)
93d86cef 501 {
e18b2753
JK
502 val = NULL;
503 val_error = NULL;
93d86cef
JK
504 }
505
506 argp->sym = sym;
507 argp->val = val;
508 argp->error = val_error ? xstrdup (val_error) : NULL;
e18b2753
JK
509 if (!val && !val_error)
510 argp->entry_kind = print_entry_values_only;
511 else if ((print_entry_values == print_entry_values_compact
512 || print_entry_values == print_entry_values_default) && val_equal)
513 {
514 argp->entry_kind = print_entry_values_compact;
112e8700 515 gdb_assert (!current_uiout->is_mi_like_p ());
e18b2753
JK
516 }
517 else
518 argp->entry_kind = print_entry_values_no;
519
520 entryargp->sym = sym;
521 entryargp->val = entryval;
522 entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
523 if (!entryval && !entryval_error)
524 entryargp->entry_kind = print_entry_values_no;
525 else
526 entryargp->entry_kind = print_entry_values_only;
93d86cef
JK
527}
528
033a42c2
MK
529/* Print the arguments of frame FRAME on STREAM, given the function
530 FUNC running in that frame (as a symbol), where NUM is the number
531 of arguments according to the stack frame (or -1 if the number of
532 arguments is unknown). */
8d3b0994 533
e3168615 534/* Note that currently the "number of arguments according to the
033a42c2 535 stack frame" is only known on VAX where i refers to the "number of
e3168615 536 ints of arguments according to the stack frame". */
8d3b0994
AC
537
538static void
033a42c2
MK
539print_frame_args (struct symbol *func, struct frame_info *frame,
540 int num, struct ui_file *stream)
8d3b0994 541{
79a45e25 542 struct ui_out *uiout = current_uiout;
8d3b0994 543 int first = 1;
8d3b0994 544 /* Offset of next stack argument beyond the one we have seen that is
033a42c2
MK
545 at the highest offset, or -1 if we haven't come to a stack
546 argument yet. */
8d3b0994 547 long highest_offset = -1;
8d3b0994
AC
548 /* Number of ints of arguments that we have printed so far. */
549 int args_printed = 0;
a6bac58e
TT
550 /* True if we should print arguments, false otherwise. */
551 int print_args = strcmp (print_frame_arguments, "none");
8d3b0994 552
8d3b0994
AC
553 if (func)
554 {
3977b71f 555 const struct block *b = SYMBOL_BLOCK_VALUE (func);
8157b174 556 struct block_iterator iter;
033a42c2 557 struct symbol *sym;
8d3b0994 558
de4f826b 559 ALL_BLOCK_SYMBOLS (b, iter, sym)
8d3b0994 560 {
e18b2753 561 struct frame_arg arg, entryarg;
93d86cef 562
8d3b0994
AC
563 QUIT;
564
565 /* Keep track of the highest stack argument offset seen, and
566 skip over any kinds of symbols we don't care about. */
567
2a2d4dc3
AS
568 if (!SYMBOL_IS_ARGUMENT (sym))
569 continue;
570
8d3b0994
AC
571 switch (SYMBOL_CLASS (sym))
572 {
573 case LOC_ARG:
574 case LOC_REF_ARG:
575 {
576 long current_offset = SYMBOL_VALUE (sym);
033a42c2 577 int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
8d3b0994
AC
578
579 /* Compute address of next argument by adding the size of
580 this argument and rounding to an int boundary. */
581 current_offset =
582 ((current_offset + arg_size + sizeof (int) - 1)
583 & ~(sizeof (int) - 1));
584
033a42c2
MK
585 /* If this is the highest offset seen yet, set
586 highest_offset. */
8d3b0994
AC
587 if (highest_offset == -1
588 || (current_offset > highest_offset))
589 highest_offset = current_offset;
590
033a42c2
MK
591 /* Add the number of ints we're about to print to
592 args_printed. */
8d3b0994
AC
593 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
594 }
595
033a42c2
MK
596 /* We care about types of symbols, but don't need to
597 keep track of stack offsets in them. */
2a2d4dc3 598 case LOC_REGISTER:
8d3b0994 599 case LOC_REGPARM_ADDR:
2a2d4dc3
AS
600 case LOC_COMPUTED:
601 case LOC_OPTIMIZED_OUT:
8d3b0994 602 default:
2a2d4dc3 603 break;
8d3b0994
AC
604 }
605
606 /* We have to look up the symbol because arguments can have
607 two entries (one a parameter, one a local) and the one we
608 want is the local, which lookup_symbol will find for us.
033a42c2 609 This includes gcc1 (not gcc2) on SPARC when passing a
8d3b0994
AC
610 small structure and gcc2 when the argument type is float
611 and it is passed as a double and converted to float by
612 the prologue (in the latter case the type of the LOC_ARG
613 symbol is double and the type of the LOC_LOCAL symbol is
614 float). */
033a42c2
MK
615 /* But if the parameter name is null, don't try it. Null
616 parameter names occur on the RS/6000, for traceback
617 tables. FIXME, should we even print them? */
8d3b0994 618
3567439c 619 if (*SYMBOL_LINKAGE_NAME (sym))
8d3b0994
AC
620 {
621 struct symbol *nsym;
433759f7 622
de63c46b
PA
623 nsym = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym),
624 b, VAR_DOMAIN).symbol;
55765a25 625 gdb_assert (nsym != NULL);
2a2d4dc3
AS
626 if (SYMBOL_CLASS (nsym) == LOC_REGISTER
627 && !SYMBOL_IS_ARGUMENT (nsym))
8d3b0994 628 {
033a42c2
MK
629 /* There is a LOC_ARG/LOC_REGISTER pair. This means
630 that it was passed on the stack and loaded into a
631 register, or passed in a register and stored in a
632 stack slot. GDB 3.x used the LOC_ARG; GDB
633 4.0-4.11 used the LOC_REGISTER.
8d3b0994
AC
634
635 Reasons for using the LOC_ARG:
033a42c2
MK
636
637 (1) Because find_saved_registers may be slow for
638 remote debugging.
639
640 (2) Because registers are often re-used and stack
641 slots rarely (never?) are. Therefore using
642 the stack slot is much less likely to print
643 garbage.
8d3b0994
AC
644
645 Reasons why we might want to use the LOC_REGISTER:
033a42c2
MK
646
647 (1) So that the backtrace prints the same value
648 as "print foo". I see no compelling reason
649 why this needs to be the case; having the
650 backtrace print the value which was passed
651 in, and "print foo" print the value as
652 modified within the called function, makes
653 perfect sense to me.
654
655 Additional note: It might be nice if "info args"
656 displayed both values.
657
658 One more note: There is a case with SPARC
659 structure passing where we need to use the
660 LOC_REGISTER, but this is dealt with by creating
661 a single LOC_REGPARM in symbol reading. */
8d3b0994
AC
662
663 /* Leave sym (the LOC_ARG) alone. */
664 ;
665 }
666 else
667 sym = nsym;
668 }
669
670 /* Print the current arg. */
671 if (!first)
112e8700
SM
672 uiout->text (", ");
673 uiout->wrap_hint (" ");
8d3b0994 674
93d86cef
JK
675 if (!print_args)
676 {
677 memset (&arg, 0, sizeof (arg));
678 arg.sym = sym;
e18b2753
JK
679 arg.entry_kind = print_entry_values_no;
680 memset (&entryarg, 0, sizeof (entryarg));
681 entryarg.sym = sym;
682 entryarg.entry_kind = print_entry_values_no;
93d86cef
JK
683 }
684 else
e18b2753 685 read_frame_arg (sym, frame, &arg, &entryarg);
8d3b0994 686
e18b2753
JK
687 if (arg.entry_kind != print_entry_values_only)
688 print_frame_arg (&arg);
689
690 if (entryarg.entry_kind != print_entry_values_no)
691 {
692 if (arg.entry_kind != print_entry_values_only)
693 {
112e8700
SM
694 uiout->text (", ");
695 uiout->wrap_hint (" ");
e18b2753
JK
696 }
697
698 print_frame_arg (&entryarg);
699 }
8d3b0994 700
93d86cef 701 xfree (arg.error);
e18b2753 702 xfree (entryarg.error);
8d3b0994
AC
703
704 first = 0;
705 }
706 }
707
708 /* Don't print nameless args in situations where we don't know
709 enough about the stack to find them. */
710 if (num != -1)
711 {
712 long start;
713
714 if (highest_offset == -1)
7500260a 715 start = gdbarch_frame_args_skip (get_frame_arch (frame));
8d3b0994
AC
716 else
717 start = highest_offset;
718
033a42c2 719 print_frame_nameless_args (frame, start, num - args_printed,
8d3b0994
AC
720 first, stream);
721 }
8d3b0994
AC
722}
723
033a42c2
MK
724/* Set the current source and line to the location given by frame
725 FRAME, if possible. When CENTER is true, adjust so the relevant
726 line is in the center of the next 'list'. */
c789492a 727
7abfe014 728void
5166082f 729set_current_sal_from_frame (struct frame_info *frame)
c789492a 730{
51abb421 731 symtab_and_line sal = find_frame_sal (frame);
5166082f 732 if (sal.symtab != NULL)
51abb421 733 set_current_source_symtab_and_line (sal);
c789492a
FL
734}
735
30c33a9f
HZ
736/* If ON, GDB will display disassembly of the next source line when
737 execution of the program being debugged stops.
481df73e
HZ
738 If AUTO (which is the default), or there's no line info to determine
739 the source line of the next instruction, display disassembly of next
740 instruction instead. */
30c33a9f
HZ
741
742static enum auto_boolean disassemble_next_line;
743
744static void
745show_disassemble_next_line (struct ui_file *file, int from_tty,
746 struct cmd_list_element *c,
747 const char *value)
748{
3e43a32a
MS
749 fprintf_filtered (file,
750 _("Debugger's willingness to use "
751 "disassemble-next-line is %s.\n"),
30c33a9f
HZ
752 value);
753}
754
30c33a9f
HZ
755/* Use TRY_CATCH to catch the exception from the gdb_disassembly
756 because it will be broken by filter sometime. */
757
758static void
13274fc3
UW
759do_gdb_disassembly (struct gdbarch *gdbarch,
760 int how_many, CORE_ADDR low, CORE_ADDR high)
30c33a9f 761{
30c33a9f 762
492d29ea 763 TRY
30c33a9f 764 {
7a8eb317 765 gdb_disassembly (gdbarch, current_uiout,
79a45e25
PA
766 DISASSEMBLY_RAW_INSN, how_many,
767 low, high);
30c33a9f 768 }
492d29ea 769 CATCH (exception, RETURN_MASK_ERROR)
b1d288d3
JK
770 {
771 /* If an exception was thrown while doing the disassembly, print
772 the error message, to give the user a clue of what happened. */
773 exception_print (gdb_stderr, exception);
774 }
492d29ea 775 END_CATCH
30c33a9f
HZ
776}
777
033a42c2 778/* Print information about frame FRAME. The output is format according
65aa373f 779 to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. The meaning of
033a42c2
MK
780 PRINT_WHAT is:
781
782 SRC_LINE: Print only source line.
783 LOCATION: Print only location.
50c65c2d 784 SRC_AND_LOC: Print location and source line.
033a42c2
MK
785
786 Used in "where" output, and to emit breakpoint or step
787 messages. */
c906108c 788
7789c6f5 789void
033a42c2 790print_frame_info (struct frame_info *frame, int print_level,
08d72866
PA
791 enum print_what print_what, int print_args,
792 int set_current_sal)
c906108c 793{
5af949e3 794 struct gdbarch *gdbarch = get_frame_arch (frame);
c5394b80
JM
795 int source_print;
796 int location_print;
79a45e25 797 struct ui_out *uiout = current_uiout;
c906108c 798
033a42c2 799 if (get_frame_type (frame) == DUMMY_FRAME
36f15f55
UW
800 || get_frame_type (frame) == SIGTRAMP_FRAME
801 || get_frame_type (frame) == ARCH_FRAME)
c906108c 802 {
2e783024 803 ui_out_emit_tuple tuple_emitter (uiout, "frame");
c906108c 804
033a42c2 805 annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
5af949e3 806 gdbarch, get_frame_pc (frame));
6a3fe0a4 807
c906108c 808 /* Do this regardless of SOURCE because we don't have any source
c5aa993b 809 to list for this frame. */
0faf0076 810 if (print_level)
52c6a6ac 811 {
112e8700
SM
812 uiout->text ("#");
813 uiout->field_fmt_int (2, ui_left, "level",
033a42c2 814 frame_relative_level (frame));
52c6a6ac 815 }
112e8700 816 if (uiout->is_mi_like_p ())
52c6a6ac 817 {
075559bc 818 annotate_frame_address ();
112e8700 819 uiout->field_core_addr ("addr",
5af949e3 820 gdbarch, get_frame_pc (frame));
075559bc 821 annotate_frame_address_end ();
52c6a6ac 822 }
6a3fe0a4 823
033a42c2 824 if (get_frame_type (frame) == DUMMY_FRAME)
075559bc
AC
825 {
826 annotate_function_call ();
cbe56571
TT
827 uiout->field_string ("func", "<function called from gdb>",
828 ui_out_style_kind::FUNCTION);
075559bc 829 }
033a42c2 830 else if (get_frame_type (frame) == SIGTRAMP_FRAME)
075559bc
AC
831 {
832 annotate_signal_handler_caller ();
cbe56571
TT
833 uiout->field_string ("func", "<signal handler called>",
834 ui_out_style_kind::FUNCTION);
075559bc 835 }
36f15f55
UW
836 else if (get_frame_type (frame) == ARCH_FRAME)
837 {
cbe56571
TT
838 uiout->field_string ("func", "<cross-architecture call>",
839 ui_out_style_kind::FUNCTION);
36f15f55 840 }
112e8700 841 uiout->text ("\n");
c906108c 842 annotate_frame_end ();
075559bc 843
433e77fa
HZ
844 /* If disassemble-next-line is set to auto or on output the next
845 instruction. */
846 if (disassemble_next_line == AUTO_BOOLEAN_AUTO
847 || disassemble_next_line == AUTO_BOOLEAN_TRUE)
848 do_gdb_disassembly (get_frame_arch (frame), 1,
849 get_frame_pc (frame), get_frame_pc (frame) + 1);
850
c906108c
SS
851 return;
852 }
853
033a42c2
MK
854 /* If FRAME is not the innermost frame, that normally means that
855 FRAME->pc points to *after* the call instruction, and we want to
856 get the line containing the call, never the next line. But if
857 the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
858 next frame was not entered as the result of a call, and we want
859 to get the line containing FRAME->pc. */
51abb421 860 symtab_and_line sal = find_frame_sal (frame);
c906108c 861
0faf0076
AC
862 location_print = (print_what == LOCATION
863 || print_what == LOC_AND_ADDRESS
864 || print_what == SRC_AND_LOC);
c5394b80
JM
865
866 if (location_print || !sal.symtab)
033a42c2 867 print_frame (frame, print_level, print_what, print_args, sal);
c5394b80 868
0faf0076 869 source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
0378c332 870
30c33a9f
HZ
871 /* If disassemble-next-line is set to auto or on and doesn't have
872 the line debug messages for $pc, output the next instruction. */
873 if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
874 || disassemble_next_line == AUTO_BOOLEAN_TRUE)
875 && source_print && !sal.symtab)
13274fc3
UW
876 do_gdb_disassembly (get_frame_arch (frame), 1,
877 get_frame_pc (frame), get_frame_pc (frame) + 1);
30c33a9f 878
c5394b80
JM
879 if (source_print && sal.symtab)
880 {
881 int done = 0;
0faf0076 882 int mid_statement = ((print_what == SRC_LINE)
edb3359d 883 && frame_show_address (frame, sal));
c5394b80
JM
884
885 if (annotation_level)
886 done = identify_source_line (sal.symtab, sal.line, mid_statement,
033a42c2 887 get_frame_pc (frame));
c5394b80
JM
888 if (!done)
889 {
9a4105ab 890 if (deprecated_print_frame_info_listing_hook)
cbd3c883
MS
891 deprecated_print_frame_info_listing_hook (sal.symtab,
892 sal.line,
893 sal.line + 1, 0);
ba4bbdcb 894 else
c5394b80 895 {
79a45b7d 896 struct value_print_options opts;
433759f7 897
79a45b7d 898 get_user_print_options (&opts);
ba4bbdcb 899 /* We used to do this earlier, but that is clearly
c378eb4e 900 wrong. This function is used by many different
ba4bbdcb
KS
901 parts of gdb, including normal_stop in infrun.c,
902 which uses this to print out the current PC
903 when we stepi/nexti into the middle of a source
c378eb4e
MS
904 line. Only the command line really wants this
905 behavior. Other UIs probably would like the
cbd3c883 906 ability to decide for themselves if it is desired. */
79a45b7d 907 if (opts.addressprint && mid_statement)
ba4bbdcb 908 {
112e8700 909 uiout->field_core_addr ("addr",
5af949e3 910 gdbarch, get_frame_pc (frame));
112e8700 911 uiout->text ("\t");
ba4bbdcb
KS
912 }
913
914 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
c5394b80 915 }
c5394b80 916 }
30c33a9f
HZ
917
918 /* If disassemble-next-line is set to on and there is line debug
919 messages, output assembly codes for next line. */
920 if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
2b28d209 921 do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
c5394b80
JM
922 }
923
08d72866 924 if (set_current_sal)
e3eebbd7
PA
925 {
926 CORE_ADDR pc;
927
928 if (get_frame_pc_if_available (frame, &pc))
1bfeeb0f 929 set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
e3eebbd7 930 else
1bfeeb0f 931 set_last_displayed_sal (0, 0, 0, 0, 0);
e3eebbd7 932 }
c5394b80
JM
933
934 annotate_frame_end ();
935
936 gdb_flush (gdb_stdout);
937}
938
1bfeeb0f
JL
939/* Remember the last symtab and line we displayed, which we use e.g.
940 * as the place to put a breakpoint when the `break' command is
941 * invoked with no arguments. */
942
943static void
944set_last_displayed_sal (int valid, struct program_space *pspace,
945 CORE_ADDR addr, struct symtab *symtab,
946 int line)
947{
948 last_displayed_sal_valid = valid;
949 last_displayed_pspace = pspace;
950 last_displayed_addr = addr;
951 last_displayed_symtab = symtab;
952 last_displayed_line = line;
4cb6da1c
AR
953 if (valid && pspace == NULL)
954 {
4cb6da1c 955 clear_last_displayed_sal ();
e36930bb
PA
956 internal_error (__FILE__, __LINE__,
957 _("Trying to set NULL pspace."));
4cb6da1c 958 }
1bfeeb0f
JL
959}
960
961/* Forget the last sal we displayed. */
962
963void
964clear_last_displayed_sal (void)
965{
966 last_displayed_sal_valid = 0;
967 last_displayed_pspace = 0;
968 last_displayed_addr = 0;
969 last_displayed_symtab = 0;
970 last_displayed_line = 0;
971}
972
973/* Is our record of the last sal we displayed valid? If not,
974 * the get_last_displayed_* functions will return NULL or 0, as
975 * appropriate. */
976
977int
978last_displayed_sal_is_valid (void)
979{
980 return last_displayed_sal_valid;
981}
982
983/* Get the pspace of the last sal we displayed, if it's valid. */
984
985struct program_space *
986get_last_displayed_pspace (void)
987{
988 if (last_displayed_sal_valid)
989 return last_displayed_pspace;
990 return 0;
991}
992
993/* Get the address of the last sal we displayed, if it's valid. */
994
995CORE_ADDR
996get_last_displayed_addr (void)
997{
998 if (last_displayed_sal_valid)
999 return last_displayed_addr;
1000 return 0;
1001}
1002
1003/* Get the symtab of the last sal we displayed, if it's valid. */
1004
1005struct symtab*
1006get_last_displayed_symtab (void)
1007{
1008 if (last_displayed_sal_valid)
1009 return last_displayed_symtab;
1010 return 0;
1011}
1012
1013/* Get the line of the last sal we displayed, if it's valid. */
1014
1015int
1016get_last_displayed_line (void)
1017{
1018 if (last_displayed_sal_valid)
1019 return last_displayed_line;
1020 return 0;
1021}
1022
1023/* Get the last sal we displayed, if it's valid. */
1024
51abb421
PA
1025symtab_and_line
1026get_last_displayed_sal ()
1bfeeb0f 1027{
51abb421
PA
1028 symtab_and_line sal;
1029
1bfeeb0f
JL
1030 if (last_displayed_sal_valid)
1031 {
51abb421
PA
1032 sal.pspace = last_displayed_pspace;
1033 sal.pc = last_displayed_addr;
1034 sal.symtab = last_displayed_symtab;
1035 sal.line = last_displayed_line;
1bfeeb0f 1036 }
51abb421
PA
1037
1038 return sal;
1bfeeb0f
JL
1039}
1040
1041
c6dc63a1
TT
1042/* Attempt to obtain the name, FUNLANG and optionally FUNCP of the function
1043 corresponding to FRAME. */
e9e07ba6 1044
c6dc63a1
TT
1045gdb::unique_xmalloc_ptr<char>
1046find_frame_funname (struct frame_info *frame, enum language *funlang,
1047 struct symbol **funcp)
c5394b80
JM
1048{
1049 struct symbol *func;
c6dc63a1 1050 gdb::unique_xmalloc_ptr<char> funname;
8b93c638 1051
f8f6f20b 1052 *funlang = language_unknown;
e9e07ba6
JK
1053 if (funcp)
1054 *funcp = NULL;
c5394b80 1055
edb3359d 1056 func = get_frame_function (frame);
c906108c
SS
1057 if (func)
1058 {
1059 /* In certain pathological cases, the symtabs give the wrong
c5aa993b
JM
1060 function (when we are in the first function in a file which
1061 is compiled without debugging symbols, the previous function
1062 is compiled with debugging symbols, and the "foo.o" symbol
033a42c2
MK
1063 that is supposed to tell us where the file with debugging
1064 symbols ends has been truncated by ar because it is longer
1065 than 15 characters). This also occurs if the user uses asm()
1066 to create a function but not stabs for it (in a file compiled
1067 with -g).
c5aa993b
JM
1068
1069 So look in the minimal symbol tables as well, and if it comes
1070 up with a larger address for the function use that instead.
033a42c2
MK
1071 I don't think this can ever cause any problems; there
1072 shouldn't be any minimal symbols in the middle of a function;
1073 if this is ever changed many parts of GDB will need to be
1074 changed (and we'll create a find_pc_minimal_function or some
1075 such). */
1076
7cbd4a93 1077 struct bound_minimal_symbol msymbol;
edb3359d
DJ
1078
1079 /* Don't attempt to do this for inlined functions, which do not
1080 have a corresponding minimal symbol. */
1081 if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
1082 msymbol
1083 = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
7cbd4a93
TT
1084 else
1085 memset (&msymbol, 0, sizeof (msymbol));
c906108c 1086
7cbd4a93 1087 if (msymbol.minsym != NULL
77e371c0 1088 && (BMSYMBOL_VALUE_ADDRESS (msymbol)
2b1ffcfd 1089 > BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func))))
c906108c 1090 {
c906108c
SS
1091 /* We also don't know anything about the function besides
1092 its address and name. */
1093 func = 0;
c6dc63a1 1094 funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)));
efd66ac6 1095 *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
c906108c
SS
1096 }
1097 else
1098 {
d10153cf
TT
1099 const char *print_name = SYMBOL_PRINT_NAME (func);
1100
f8f6f20b 1101 *funlang = SYMBOL_LANGUAGE (func);
e9e07ba6
JK
1102 if (funcp)
1103 *funcp = func;
f8f6f20b 1104 if (*funlang == language_cplus)
c5aa993b 1105 {
033a42c2
MK
1106 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
1107 to display the demangled name that we already have
1108 stored in the symbol table, but we stored a version
1109 with DMGL_PARAMS turned on, and here we don't want to
3567439c 1110 display parameters. So remove the parameters. */
109483d9 1111 funname = cp_remove_params (print_name);
c5aa993b 1112 }
d10153cf 1113
c6dc63a1
TT
1114 /* If we didn't hit the C++ case above, set *funname
1115 here. */
1116 if (funname == NULL)
1117 funname.reset (xstrdup (print_name));
c906108c
SS
1118 }
1119 }
1120 else
1121 {
7cbd4a93 1122 struct bound_minimal_symbol msymbol;
e3eebbd7 1123 CORE_ADDR pc;
033a42c2 1124
e3eebbd7 1125 if (!get_frame_address_in_block_if_available (frame, &pc))
c6dc63a1 1126 return funname;
e3eebbd7
PA
1127
1128 msymbol = lookup_minimal_symbol_by_pc (pc);
7cbd4a93 1129 if (msymbol.minsym != NULL)
c906108c 1130 {
c6dc63a1 1131 funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)));
efd66ac6 1132 *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
c906108c
SS
1133 }
1134 }
c6dc63a1
TT
1135
1136 return funname;
f8f6f20b
TJB
1137}
1138
1139static void
1140print_frame (struct frame_info *frame, int print_level,
1141 enum print_what print_what, int print_args,
1142 struct symtab_and_line sal)
1143{
5af949e3 1144 struct gdbarch *gdbarch = get_frame_arch (frame);
79a45e25 1145 struct ui_out *uiout = current_uiout;
f8f6f20b 1146 enum language funlang = language_unknown;
f8f6f20b 1147 struct value_print_options opts;
e9e07ba6 1148 struct symbol *func;
e3eebbd7
PA
1149 CORE_ADDR pc = 0;
1150 int pc_p;
1151
1152 pc_p = get_frame_pc_if_available (frame, &pc);
f8f6f20b 1153
c6dc63a1
TT
1154 gdb::unique_xmalloc_ptr<char> funname
1155 = find_frame_funname (frame, &funlang, &func);
c906108c 1156
033a42c2 1157 annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
e3eebbd7 1158 gdbarch, pc);
c5394b80 1159
76f9c9cf
TT
1160 {
1161 ui_out_emit_tuple tuple_emitter (uiout, "frame");
c5394b80 1162
76f9c9cf 1163 if (print_level)
c5394b80 1164 {
76f9c9cf
TT
1165 uiout->text ("#");
1166 uiout->field_fmt_int (2, ui_left, "level",
1167 frame_relative_level (frame));
c5394b80 1168 }
76f9c9cf
TT
1169 get_user_print_options (&opts);
1170 if (opts.addressprint)
1171 if (!sal.symtab
1172 || frame_show_address (frame, sal)
1173 || print_what == LOC_AND_ADDRESS)
311b5970 1174 {
76f9c9cf
TT
1175 annotate_frame_address ();
1176 if (pc_p)
1177 uiout->field_core_addr ("addr", gdbarch, pc);
1178 else
1179 uiout->field_string ("addr", "<unavailable>");
1180 annotate_frame_address_end ();
1181 uiout->text (" in ");
311b5970 1182 }
76f9c9cf
TT
1183 annotate_frame_function_name ();
1184
1185 string_file stb;
c6dc63a1 1186 fprintf_symbol_filtered (&stb, funname ? funname.get () : "??",
76f9c9cf 1187 funlang, DMGL_ANSI);
cbe56571 1188 uiout->field_stream ("func", stb, ui_out_style_kind::FUNCTION);
76f9c9cf
TT
1189 uiout->wrap_hint (" ");
1190 annotate_frame_args ();
cbe56571 1191
76f9c9cf
TT
1192 uiout->text (" (");
1193 if (print_args)
10f489e5 1194 {
76f9c9cf
TT
1195 int numargs;
1196
1197 if (gdbarch_frame_num_args_p (gdbarch))
10f489e5 1198 {
76f9c9cf
TT
1199 numargs = gdbarch_frame_num_args (gdbarch, frame);
1200 gdb_assert (numargs >= 0);
10f489e5 1201 }
76f9c9cf
TT
1202 else
1203 numargs = -1;
1204
1205 {
1206 ui_out_emit_list list_emitter (uiout, "args");
1207 TRY
1208 {
1209 print_frame_args (func, frame, numargs, gdb_stdout);
1210 }
1211 CATCH (e, RETURN_MASK_ERROR)
1212 {
1213 }
1214 END_CATCH
10f489e5 1215
76f9c9cf
TT
1216 /* FIXME: ARGS must be a list. If one argument is a string it
1217 will have " that will not be properly escaped. */
1218 }
1219 QUIT;
10f489e5 1220 }
76f9c9cf
TT
1221 uiout->text (")");
1222 if (sal.symtab)
1223 {
1224 const char *filename_display;
1b56eb55 1225
76f9c9cf
TT
1226 filename_display = symtab_to_filename_for_display (sal.symtab);
1227 annotate_frame_source_begin ();
1228 uiout->wrap_hint (" ");
1229 uiout->text (" at ");
1230 annotate_frame_source_file ();
cbe56571 1231 uiout->field_string ("file", filename_display, ui_out_style_kind::FILE);
76f9c9cf
TT
1232 if (uiout->is_mi_like_p ())
1233 {
1234 const char *fullname = symtab_to_fullname (sal.symtab);
433759f7 1235
76f9c9cf
TT
1236 uiout->field_string ("fullname", fullname);
1237 }
1238 annotate_frame_source_file_end ();
1239 uiout->text (":");
1240 annotate_frame_source_line ();
1241 uiout->field_int ("line", sal.line);
1242 annotate_frame_source_end ();
1243 }
c906108c 1244
76f9c9cf
TT
1245 if (pc_p && (funname == NULL || sal.symtab == NULL))
1246 {
1247 char *lib = solib_name_from_address (get_frame_program_space (frame),
1248 get_frame_pc (frame));
4d1eb6b4 1249
76f9c9cf
TT
1250 if (lib)
1251 {
1252 annotate_frame_where ();
1253 uiout->wrap_hint (" ");
1254 uiout->text (" from ");
1255 uiout->field_string ("from", lib);
1256 }
1257 }
6d52907e
JV
1258 if (uiout->is_mi_like_p ())
1259 uiout->field_string ("arch",
1260 (gdbarch_bfd_arch_info (gdbarch))->printable_name);
76f9c9cf 1261 }
e514a9d6 1262
112e8700 1263 uiout->text ("\n");
c906108c
SS
1264}
1265\f
c5aa993b 1266
f67ffa6a
AB
1267/* Completion function for "frame function", "info frame function", and
1268 "select-frame function" commands. */
c906108c 1269
f67ffa6a
AB
1270void
1271frame_selection_by_function_completer (struct cmd_list_element *ignore,
1272 completion_tracker &tracker,
1273 const char *text, const char *word)
c906108c 1274{
f67ffa6a
AB
1275 /* This is used to complete function names within a stack. It would be
1276 nice if we only offered functions that were actually in the stack.
1277 However, this would mean unwinding the stack to completion, which
1278 could take too long, or on a corrupted stack, possibly not end.
1279 Instead, we offer all symbol names as a safer choice. */
1280 collect_symbol_completion_matches (tracker,
1281 complete_symbol_mode::EXPRESSION,
1282 symbol_name_match_type::EXPRESSION,
1283 text, word);
1c8831c5
AC
1284}
1285
f67ffa6a
AB
1286/* Core of all the "info frame" sub-commands. Print information about a
1287 frame FI. If SELECTED_FRAME_P is true then the user didn't provide a
1288 frame specification, they just entered 'info frame'. If the user did
1289 provide a frame specification (for example 'info frame 0', 'info frame
1290 level 1') then SELECTED_FRAME_P will be false. */
c906108c
SS
1291
1292static void
f67ffa6a 1293info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
c906108c 1294{
c906108c
SS
1295 struct symbol *func;
1296 struct symtab *s;
1297 struct frame_info *calling_frame_info;
167e4384 1298 int numregs;
0d5cff50 1299 const char *funname = 0;
c906108c 1300 enum language funlang = language_unknown;
82de1e5b 1301 const char *pc_regname;
7500260a 1302 struct gdbarch *gdbarch;
008f8f2e
PA
1303 CORE_ADDR frame_pc;
1304 int frame_pc_p;
e5e6f788
YQ
1305 /* Initialize it to avoid "may be used uninitialized" warning. */
1306 CORE_ADDR caller_pc = 0;
492d29ea 1307 int caller_pc_p = 0;
c906108c 1308
12368003 1309 gdbarch = get_frame_arch (fi);
c906108c 1310
82de1e5b
AC
1311 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
1312 is not a good name. */
12368003 1313 if (gdbarch_pc_regnum (gdbarch) >= 0)
3e8c568d 1314 /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can
82de1e5b
AC
1315 easily not match that of the internal value returned by
1316 get_frame_pc(). */
12368003 1317 pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch));
82de1e5b 1318 else
3e8c568d 1319 /* But then, this is weird to. Even without gdbarch_pc_regnum, an
82de1e5b
AC
1320 architectures will often have a hardware register called "pc",
1321 and that register's value, again, can easily not match
1322 get_frame_pc(). */
1323 pc_regname = "pc";
1324
008f8f2e 1325 frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
c906108c 1326 func = get_frame_function (fi);
51abb421 1327 symtab_and_line sal = find_frame_sal (fi);
008f8f2e 1328 s = sal.symtab;
2003f3d8 1329 gdb::unique_xmalloc_ptr<char> func_only;
c906108c
SS
1330 if (func)
1331 {
3567439c 1332 funname = SYMBOL_PRINT_NAME (func);
c5aa993b
JM
1333 funlang = SYMBOL_LANGUAGE (func);
1334 if (funlang == language_cplus)
1335 {
3567439c
DJ
1336 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
1337 to display the demangled name that we already have
1338 stored in the symbol table, but we stored a version
1339 with DMGL_PARAMS turned on, and here we don't want to
1340 display parameters. So remove the parameters. */
109483d9 1341 func_only = cp_remove_params (funname);
433759f7 1342
3567439c 1343 if (func_only)
2003f3d8 1344 funname = func_only.get ();
c5aa993b 1345 }
c906108c 1346 }
008f8f2e 1347 else if (frame_pc_p)
c906108c 1348 {
7cbd4a93 1349 struct bound_minimal_symbol msymbol;
033a42c2 1350
008f8f2e 1351 msymbol = lookup_minimal_symbol_by_pc (frame_pc);
7cbd4a93 1352 if (msymbol.minsym != NULL)
c906108c 1353 {
efd66ac6
TT
1354 funname = MSYMBOL_PRINT_NAME (msymbol.minsym);
1355 funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
c906108c
SS
1356 }
1357 }
1358 calling_frame_info = get_prev_frame (fi);
1359
1c8831c5 1360 if (selected_frame_p && frame_relative_level (fi) >= 0)
c906108c 1361 {
a3f17187 1362 printf_filtered (_("Stack level %d, frame at "),
1c8831c5 1363 frame_relative_level (fi));
c906108c
SS
1364 }
1365 else
1366 {
a3f17187 1367 printf_filtered (_("Stack frame at "));
c906108c 1368 }
5af949e3 1369 fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
9c833c82 1370 printf_filtered (":\n");
82de1e5b 1371 printf_filtered (" %s = ", pc_regname);
008f8f2e
PA
1372 if (frame_pc_p)
1373 fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
1374 else
1375 fputs_filtered ("<unavailable>", gdb_stdout);
c906108c
SS
1376
1377 wrap_here (" ");
1378 if (funname)
1379 {
1380 printf_filtered (" in ");
1381 fprintf_symbol_filtered (gdb_stdout, funname, funlang,
1382 DMGL_ANSI | DMGL_PARAMS);
1383 }
1384 wrap_here (" ");
1385 if (sal.symtab)
05cba821
JK
1386 printf_filtered (" (%s:%d)", symtab_to_filename_for_display (sal.symtab),
1387 sal.line);
c906108c
SS
1388 puts_filtered ("; ");
1389 wrap_here (" ");
782d47df
PA
1390 printf_filtered ("saved %s = ", pc_regname);
1391
a038fa3e 1392 if (!frame_id_p (frame_unwind_caller_id (fi)))
c620c3e4 1393 val_print_not_saved (gdb_stdout);
a038fa3e 1394 else
782d47df 1395 {
a038fa3e 1396 TRY
782d47df 1397 {
a038fa3e
MM
1398 caller_pc = frame_unwind_caller_pc (fi);
1399 caller_pc_p = 1;
782d47df 1400 }
a038fa3e
MM
1401 CATCH (ex, RETURN_MASK_ERROR)
1402 {
1403 switch (ex.error)
1404 {
1405 case NOT_AVAILABLE_ERROR:
1406 val_print_unavailable (gdb_stdout);
1407 break;
1408 case OPTIMIZED_OUT_ERROR:
1409 val_print_not_saved (gdb_stdout);
1410 break;
1411 default:
1412 fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
1413 break;
1414 }
1415 }
1416 END_CATCH
782d47df 1417 }
492d29ea
PA
1418
1419 if (caller_pc_p)
782d47df 1420 fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
c906108c
SS
1421 printf_filtered ("\n");
1422
55feb689
DJ
1423 if (calling_frame_info == NULL)
1424 {
1425 enum unwind_stop_reason reason;
1426
1427 reason = get_frame_unwind_stop_reason (fi);
1428 if (reason != UNWIND_NO_REASON)
1429 printf_filtered (_(" Outermost frame: %s\n"),
53e8a631 1430 frame_stop_reason_string (fi));
55feb689 1431 }
111c6489
JK
1432 else if (get_frame_type (fi) == TAILCALL_FRAME)
1433 puts_filtered (" tail call frame");
edb3359d
DJ
1434 else if (get_frame_type (fi) == INLINE_FRAME)
1435 printf_filtered (" inlined into frame %d",
1436 frame_relative_level (get_prev_frame (fi)));
1437 else
c906108c
SS
1438 {
1439 printf_filtered (" called by frame at ");
5af949e3 1440 fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)),
ed49a04f 1441 gdb_stdout);
c906108c 1442 }
75e3c1f9 1443 if (get_next_frame (fi) && calling_frame_info)
c906108c
SS
1444 puts_filtered (",");
1445 wrap_here (" ");
75e3c1f9 1446 if (get_next_frame (fi))
c906108c
SS
1447 {
1448 printf_filtered (" caller of frame at ");
5af949e3 1449 fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))),
ed49a04f 1450 gdb_stdout);
c906108c 1451 }
75e3c1f9 1452 if (get_next_frame (fi) || calling_frame_info)
c906108c 1453 puts_filtered ("\n");
55feb689 1454
c906108c 1455 if (s)
1058bca7
AC
1456 printf_filtered (" source language %s.\n",
1457 language_str (s->language));
c906108c 1458
c906108c
SS
1459 {
1460 /* Address of the argument list for this frame, or 0. */
da62e633 1461 CORE_ADDR arg_list = get_frame_args_address (fi);
c906108c
SS
1462 /* Number of args for this frame, or -1 if unknown. */
1463 int numargs;
1464
1465 if (arg_list == 0)
1466 printf_filtered (" Arglist at unknown address.\n");
1467 else
1468 {
1469 printf_filtered (" Arglist at ");
5af949e3 1470 fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
c906108c
SS
1471 printf_filtered (",");
1472
7500260a 1473 if (!gdbarch_frame_num_args_p (gdbarch))
983a287a
AC
1474 {
1475 numargs = -1;
1476 puts_filtered (" args: ");
1477 }
c906108c 1478 else
983a287a 1479 {
7500260a 1480 numargs = gdbarch_frame_num_args (gdbarch, fi);
983a287a
AC
1481 gdb_assert (numargs >= 0);
1482 if (numargs == 0)
1483 puts_filtered (" no args.");
1484 else if (numargs == 1)
1485 puts_filtered (" 1 arg: ");
1486 else
1487 printf_filtered (" %d args: ", numargs);
1488 }
c906108c
SS
1489 print_frame_args (func, fi, numargs, gdb_stdout);
1490 puts_filtered ("\n");
1491 }
1492 }
1493 {
1494 /* Address of the local variables for this frame, or 0. */
da62e633 1495 CORE_ADDR arg_list = get_frame_locals_address (fi);
c906108c
SS
1496
1497 if (arg_list == 0)
1498 printf_filtered (" Locals at unknown address,");
1499 else
1500 {
1501 printf_filtered (" Locals at ");
5af949e3 1502 fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
c906108c
SS
1503 printf_filtered (",");
1504 }
1505 }
1506
4f460812
AC
1507 /* Print as much information as possible on the location of all the
1508 registers. */
1509 {
4f460812
AC
1510 int count;
1511 int i;
1512 int need_nl = 1;
b0e4b369 1513 int sp_regnum = gdbarch_sp_regnum (gdbarch);
4f460812
AC
1514
1515 /* The sp is special; what's displayed isn't the save address, but
1516 the value of the previous frame's sp. This is a legacy thing,
1517 at one stage the frame cached the previous frame's SP instead
1518 of its address, hence it was easiest to just display the cached
1519 value. */
b0e4b369 1520 if (sp_regnum >= 0)
4f460812 1521 {
b0e4b369
AH
1522 struct value *value = frame_unwind_register_value (fi, sp_regnum);
1523 gdb_assert (value != NULL);
1524
1525 if (!value_optimized_out (value) && value_entirely_available (value))
4f460812 1526 {
b0e4b369
AH
1527 if (VALUE_LVAL (value) == not_lval)
1528 {
1529 CORE_ADDR sp;
1530 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1531 int sp_size = register_size (gdbarch, sp_regnum);
1532
1533 sp = extract_unsigned_integer (value_contents_all (value),
1534 sp_size, byte_order);
1535
1536 printf_filtered (" Previous frame's sp is ");
1537 fputs_filtered (paddress (gdbarch, sp), gdb_stdout);
1538 printf_filtered ("\n");
1539 }
1540 else if (VALUE_LVAL (value) == lval_memory)
1541 {
1542 printf_filtered (" Previous frame's sp at ");
1543 fputs_filtered (paddress (gdbarch, value_address (value)),
1544 gdb_stdout);
1545 printf_filtered ("\n");
1546 }
1547 else if (VALUE_LVAL (value) == lval_register)
1548 {
1549 printf_filtered (" Previous frame's sp in %s\n",
1550 gdbarch_register_name (gdbarch,
1551 VALUE_REGNUM (value)));
1552 }
1553
1554 release_value (value);
4f460812
AC
1555 need_nl = 0;
1556 }
1557 /* else keep quiet. */
1558 }
1559
1560 count = 0;
f6efe3f8 1561 numregs = gdbarch_num_cooked_regs (gdbarch);
4f460812 1562 for (i = 0; i < numregs; i++)
b0e4b369 1563 if (i != sp_regnum
7500260a 1564 && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
4f460812 1565 {
b0e4b369
AH
1566 enum lval_type lval;
1567 int optimized;
1568 int unavailable;
1569 CORE_ADDR addr;
1570 int realnum;
1571
4f460812
AC
1572 /* Find out the location of the saved register without
1573 fetching the corresponding value. */
0fdb4f18
PA
1574 frame_register_unwind (fi, i, &optimized, &unavailable,
1575 &lval, &addr, &realnum, NULL);
4f460812
AC
1576 /* For moment, only display registers that were saved on the
1577 stack. */
0fdb4f18 1578 if (!optimized && !unavailable && lval == lval_memory)
4f460812
AC
1579 {
1580 if (count == 0)
1581 puts_filtered (" Saved registers:\n ");
1582 else
1583 puts_filtered (",");
1584 wrap_here (" ");
c9f4d572 1585 printf_filtered (" %s at ",
7500260a 1586 gdbarch_register_name (gdbarch, i));
5af949e3 1587 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
4f460812
AC
1588 count++;
1589 }
1590 }
1591 if (count || need_nl)
c906108c 1592 puts_filtered ("\n");
4f460812 1593 }
c906108c
SS
1594}
1595
6a70eb7d
PW
1596/* Return the innermost frame at level LEVEL. */
1597
1598static struct frame_info *
1599leading_innermost_frame (int level)
1600{
1601 struct frame_info *leading;
1602
1603 leading = get_current_frame ();
1604
1605 gdb_assert (level >= 0);
1606
1607 while (leading != nullptr && level)
1608 {
1609 QUIT;
1610 leading = get_prev_frame (leading);
1611 level--;
1612 }
1613
1614 return leading;
1615}
1616
1617/* Return the starting frame needed to handle COUNT outermost frames. */
1618
1619static struct frame_info *
1620trailing_outermost_frame (int count)
1621{
1622 struct frame_info *current;
1623 struct frame_info *trailing;
1624
1625 trailing = get_current_frame ();
1626
1627 gdb_assert (count > 0);
1628
1629 current = trailing;
1630 while (current != nullptr && count--)
1631 {
1632 QUIT;
1633 current = get_prev_frame (current);
1634 }
1635
1636 /* Will stop when CURRENT reaches the top of the stack.
1637 TRAILING will be COUNT below it. */
1638 while (current != nullptr)
1639 {
1640 QUIT;
1641 trailing = get_prev_frame (trailing);
1642 current = get_prev_frame (current);
1643 }
1644
1645 return trailing;
1646}
1647
f67ffa6a
AB
1648/* The core of all the "select-frame" sub-commands. Just wraps a call to
1649 SELECT_FRAME. */
1650
1651static void
1652select_frame_command_core (struct frame_info *fi, bool ignored)
1653{
1654 struct frame_info *prev_frame = get_selected_frame_if_set ();
1655 select_frame (fi);
1656 if (get_selected_frame_if_set () != prev_frame)
1657 gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
1658}
1659
1660/* See stack.h. */
1661
1662void
1663select_frame_for_mi (struct frame_info *fi)
1664{
1665 select_frame_command_core (fi, FALSE /* Ignored. */);
1666}
1667
1668/* The core of all the "frame" sub-commands. Select frame FI, and if this
1669 means we change frame send out a change notification (otherwise, just
1670 reprint the current frame summary). */
1671
1672static void
1673frame_command_core (struct frame_info *fi, bool ignored)
1674{
1675 struct frame_info *prev_frame = get_selected_frame_if_set ();
1676
1677 select_frame (fi);
1678 if (get_selected_frame_if_set () != prev_frame)
1679 gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
1680 else
1681 print_selected_thread_frame (current_uiout, USER_SELECTED_FRAME);
1682}
1683
1684/* The three commands 'frame', 'select-frame', and 'info frame' all have a
1685 common set of sub-commands that allow a specific frame to be selected.
1686 All of the sub-command functions are static methods within this class
1687 template which is then instantiated below. The template parameter is a
1688 callback used to implement the functionality of the base command
1689 ('frame', 'select-frame', or 'info frame').
1690
1691 In the template parameter FI is the frame being selected. The
1692 SELECTED_FRAME_P flag is true if the frame being selected was done by
1693 default, which happens when the user uses the base command with no
1694 arguments. For example the commands 'info frame', 'select-frame',
1695 'frame' will all cause SELECTED_FRAME_P to be true. In all other cases
1696 SELECTED_FRAME_P is false. */
1697
1698template <void (*FPTR) (struct frame_info *fi, bool selected_frame_p)>
1699class frame_command_helper
1700{
1701public:
1702
1703 /* The "frame level" family of commands. The ARG is an integer that is
1704 the frame's level in the stack. */
1705 static void
1706 level (const char *arg, int from_tty)
1707 {
1708 int level = value_as_long (parse_and_eval (arg));
1709 struct frame_info *fid
1710 = find_relative_frame (get_current_frame (), &level);
1711 if (level != 0)
1712 error (_("No frame at level %s."), arg);
1713 FPTR (fid, false);
1714 }
1715
1716 /* The "frame address" family of commands. ARG is a stack-pointer
1717 address for an existing frame. This command does not allow new
1718 frames to be created. */
1719
1720 static void
1721 address (const char *arg, int from_tty)
1722 {
1723 CORE_ADDR addr = value_as_address (parse_and_eval (arg));
1724 struct frame_info *fid = find_frame_for_address (addr);
1725 if (fid == NULL)
1726 error (_("No frame at address %s."), arg);
1727 FPTR (fid, false);
1728 }
1729
1730 /* The "frame view" family of commands. ARG is one or two addresses and
1731 is used to view a frame that might be outside the current backtrace.
1732 The addresses are stack-pointer address, and (optional) pc-address. */
1733
1734 static void
1735 view (const char *args, int from_tty)
1736 {
1737 struct frame_info *fid;
1738
1739 if (args == NULL)
1740 error (_("Missing address argument to view a frame"));
1741
1742 gdb_argv argv (args);
1743
1744 if (argv.count () == 2)
1745 {
1746 CORE_ADDR addr[2];
1747
1748 addr [0] = value_as_address (parse_and_eval (argv[0]));
1749 addr [1] = value_as_address (parse_and_eval (argv[1]));
1750 fid = create_new_frame (addr[0], addr[1]);
1751 }
1752 else
1753 {
1754 CORE_ADDR addr = value_as_address (parse_and_eval (argv[0]));
1755 fid = create_new_frame (addr, false);
1756 }
1757 FPTR (fid, false);
1758 }
1759
1760 /* The "frame function" family of commands. ARG is the name of a
1761 function within the stack, the first function (searching from frame
1762 0) with that name will be selected. */
1763
1764 static void
1765 function (const char *arg, int from_tty)
1766 {
1767 if (arg == NULL)
1768 error (_("Missing function name argument"));
1769 struct frame_info *fid = find_frame_for_function (arg);
1770 if (fid == NULL)
1771 error (_("No frame for function \"%s\"."), arg);
1772 FPTR (fid, false);
1773 }
1774
1775 /* The "frame" base command, that is, when no sub-command is specified.
1776 If one argument is provided then we assume that this is a frame's
1777 level as historically, this was the supported command syntax that was
1778 used most often.
1779
1780 If no argument is provided, then the current frame is selected. */
1781
1782 static void
1783 base_command (const char *arg, int from_tty)
1784 {
1785 if (arg == NULL)
1786 FPTR (get_selected_frame (_("No stack.")), true);
1787 else
1788 level (arg, from_tty);
1789 }
1790};
1791
1792/* Instantiate three FRAME_COMMAND_HELPER instances to implement the
1793 sub-commands for 'info frame', 'frame', and 'select-frame' commands. */
1794
1795static frame_command_helper <info_frame_command_core> info_frame_cmd;
1796static frame_command_helper <frame_command_core> frame_cmd;
1797static frame_command_helper <select_frame_command_core> select_frame_cmd;
1798
033a42c2
MK
1799/* Print briefly all stack frames or just the innermost COUNT_EXP
1800 frames. */
c906108c
SS
1801
1802static void
1cf7e640
TT
1803backtrace_command_1 (const char *count_exp, frame_filter_flags flags,
1804 int no_filters, int from_tty)
c906108c
SS
1805{
1806 struct frame_info *fi;
52f0bd74 1807 int count;
fb7eb8b5 1808 int py_start = 0, py_end = 0;
6dddc817 1809 enum ext_lang_bt_status result = EXT_LANG_BT_ERROR;
c906108c
SS
1810
1811 if (!target_has_stack)
8a3fe4f8 1812 error (_("No stack."));
c906108c 1813
c906108c
SS
1814 if (count_exp)
1815 {
bb518678 1816 count = parse_and_eval_long (count_exp);
c906108c 1817 if (count < 0)
fb7eb8b5 1818 py_start = count;
1e611234
PM
1819 else
1820 {
1821 py_start = 0;
6893c19a
TT
1822 /* The argument to apply_ext_lang_frame_filter is the number
1823 of the final frame to print, and frames start at 0. */
1824 py_end = count - 1;
1e611234 1825 }
c906108c
SS
1826 }
1827 else
1e611234
PM
1828 {
1829 py_end = -1;
1830 count = -1;
1831 }
c906108c 1832
1e611234 1833 if (! no_filters)
c906108c 1834 {
6dddc817 1835 enum ext_lang_frame_args arg_type;
c906108c 1836
1cf7e640 1837 flags |= PRINT_LEVEL | PRINT_FRAME_INFO | PRINT_ARGS;
6893c19a
TT
1838 if (from_tty)
1839 flags |= PRINT_MORE_FRAMES;
1e611234
PM
1840
1841 if (!strcmp (print_frame_arguments, "scalars"))
1842 arg_type = CLI_SCALAR_VALUES;
1843 else if (!strcmp (print_frame_arguments, "all"))
1844 arg_type = CLI_ALL_VALUES;
1845 else
1846 arg_type = NO_VALUES;
1847
6dddc817
DE
1848 result = apply_ext_lang_frame_filter (get_current_frame (), flags,
1849 arg_type, current_uiout,
1850 py_start, py_end);
1e611234 1851 }
6dddc817 1852
1e611234
PM
1853 /* Run the inbuilt backtrace if there are no filters registered, or
1854 "no-filters" has been specified from the command. */
6dddc817 1855 if (no_filters || result == EXT_LANG_BT_NO_FILTERS)
1e611234 1856 {
fb7eb8b5
TT
1857 struct frame_info *trailing;
1858
1859 /* The following code must do two things. First, it must set the
1860 variable TRAILING to the frame from which we should start
1861 printing. Second, it must set the variable count to the number
1862 of frames which we should print, or -1 if all of them. */
fb7eb8b5
TT
1863
1864 if (count_exp != NULL && count < 0)
1865 {
6a70eb7d 1866 trailing = trailing_outermost_frame (-count);
fb7eb8b5
TT
1867 count = -1;
1868 }
6a70eb7d
PW
1869 else
1870 trailing = get_current_frame ();
fb7eb8b5 1871
59f66be3 1872 for (fi = trailing; fi && count--; fi = get_prev_frame (fi))
1e611234
PM
1873 {
1874 QUIT;
1875
1876 /* Don't use print_stack_frame; if an error() occurs it probably
1877 means further attempts to backtrace would fail (on the other
1878 hand, perhaps the code does or could be fixed to make sure
1879 the frame->prev field gets set to NULL in that case). */
1880
08d72866 1881 print_frame_info (fi, 1, LOCATION, 1, 0);
1cf7e640 1882 if ((flags & PRINT_LOCALS) != 0)
d0548fa2
PM
1883 {
1884 struct frame_id frame_id = get_frame_id (fi);
8f043999 1885
12615cba 1886 print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout);
8f043999 1887
d0548fa2
PM
1888 /* print_frame_local_vars invalidates FI. */
1889 fi = frame_find_by_id (frame_id);
1890 if (fi == NULL)
1891 {
1892 trailing = NULL;
1893 warning (_("Unable to restore previously selected frame."));
1894 break;
1895 }
8f043999 1896 }
55feb689 1897
1e611234
PM
1898 /* Save the last frame to check for error conditions. */
1899 trailing = fi;
1900 }
c906108c 1901
1e611234
PM
1902 /* If we've stopped before the end, mention that. */
1903 if (fi && from_tty)
1904 printf_filtered (_("(More stack frames follow...)\n"));
55feb689 1905
1e611234
PM
1906 /* If we've run out of frames, and the reason appears to be an error
1907 condition, print it. */
1908 if (fi == NULL && trailing != NULL)
1909 {
1910 enum unwind_stop_reason reason;
55feb689 1911
1e611234
PM
1912 reason = get_frame_unwind_stop_reason (trailing);
1913 if (reason >= UNWIND_FIRST_ERROR)
1914 printf_filtered (_("Backtrace stopped: %s\n"),
53e8a631 1915 frame_stop_reason_string (trailing));
1e611234 1916 }
55feb689 1917 }
c906108c
SS
1918}
1919
1920static void
0b39b52e 1921backtrace_command (const char *arg, int from_tty)
c906108c 1922{
ea3b0687 1923 bool filters = true;
1cf7e640 1924 frame_filter_flags flags = 0;
c906108c 1925
033a42c2 1926 if (arg)
c906108c 1927 {
ea3b0687 1928 bool done = false;
c906108c 1929
ea3b0687 1930 while (!done)
c5aa993b 1931 {
ea3b0687
TT
1932 const char *save_arg = arg;
1933 std::string this_arg = extract_arg (&arg);
c5aa993b 1934
ea3b0687
TT
1935 if (this_arg.empty ())
1936 break;
c5aa993b 1937
ea3b0687
TT
1938 if (subset_compare (this_arg.c_str (), "no-filters"))
1939 filters = false;
1940 else if (subset_compare (this_arg.c_str (), "full"))
1cf7e640 1941 flags |= PRINT_LOCALS;
978d6c75
TT
1942 else if (subset_compare (this_arg.c_str (), "hide"))
1943 flags |= PRINT_HIDE;
c5aa993b
JM
1944 else
1945 {
ea3b0687
TT
1946 /* Not a recognized argument, so stop. */
1947 arg = save_arg;
1948 done = true;
c5aa993b 1949 }
c5aa993b 1950 }
ea3b0687
TT
1951
1952 if (*arg == '\0')
1953 arg = NULL;
c906108c
SS
1954 }
1955
1cf7e640 1956 backtrace_command_1 (arg, flags, !filters /* no frame-filters */, from_tty);
c906108c
SS
1957}
1958
2c58c0a9
PA
1959/* Iterate over the local variables of a block B, calling CB with
1960 CB_DATA. */
c906108c 1961
2c58c0a9 1962static void
3977b71f 1963iterate_over_block_locals (const struct block *b,
2c58c0a9
PA
1964 iterate_over_block_arg_local_vars_cb cb,
1965 void *cb_data)
c906108c 1966{
8157b174 1967 struct block_iterator iter;
de4f826b 1968 struct symbol *sym;
c906108c 1969
de4f826b 1970 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c 1971 {
c906108c
SS
1972 switch (SYMBOL_CLASS (sym))
1973 {
1974 case LOC_LOCAL:
1975 case LOC_REGISTER:
1976 case LOC_STATIC:
4c2df51b 1977 case LOC_COMPUTED:
41bd68f5 1978 case LOC_OPTIMIZED_OUT:
2a2d4dc3
AS
1979 if (SYMBOL_IS_ARGUMENT (sym))
1980 break;
4357ac6c
TT
1981 if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
1982 break;
2c58c0a9 1983 (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
c906108c
SS
1984 break;
1985
1986 default:
1987 /* Ignore symbols which are not locals. */
1988 break;
1989 }
1990 }
c906108c
SS
1991}
1992
65c06092 1993
c906108c
SS
1994/* Same, but print labels. */
1995
65c06092
JB
1996#if 0
1997/* Commented out, as the code using this function has also been
1998 commented out. FIXME:brobecker/2009-01-13: Find out why the code
1999 was commented out in the first place. The discussion introducing
2000 this change (2007-12-04: Support lexical blocks and function bodies
2001 that occupy non-contiguous address ranges) did not explain why
2002 this change was made. */
c906108c 2003static int
5af949e3
UW
2004print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
2005 int *have_default, struct ui_file *stream)
c906108c 2006{
8157b174 2007 struct block_iterator iter;
52f0bd74
AC
2008 struct symbol *sym;
2009 int values_printed = 0;
c906108c 2010
de4f826b 2011 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c 2012 {
3567439c 2013 if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0)
c906108c
SS
2014 {
2015 if (*have_default)
2016 continue;
2017 *have_default = 1;
2018 }
2019 if (SYMBOL_CLASS (sym) == LOC_LABEL)
2020 {
2021 struct symtab_and_line sal;
79a45b7d 2022 struct value_print_options opts;
433759f7 2023
c906108c
SS
2024 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
2025 values_printed = 1;
de5ad195 2026 fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
79a45b7d
TT
2027 get_user_print_options (&opts);
2028 if (opts.addressprint)
c906108c
SS
2029 {
2030 fprintf_filtered (stream, " ");
5af949e3
UW
2031 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)),
2032 stream);
c906108c
SS
2033 }
2034 fprintf_filtered (stream, " in file %s, line %d\n",
2035 sal.symtab->filename, sal.line);
2036 }
2037 }
033a42c2 2038
c906108c
SS
2039 return values_printed;
2040}
65c06092 2041#endif
c906108c 2042
2c58c0a9
PA
2043/* Iterate over all the local variables in block B, including all its
2044 superblocks, stopping when the top-level block is reached. */
2045
2046void
3977b71f 2047iterate_over_block_local_vars (const struct block *block,
2c58c0a9
PA
2048 iterate_over_block_arg_local_vars_cb cb,
2049 void *cb_data)
2050{
2051 while (block)
2052 {
2053 iterate_over_block_locals (block, cb, cb_data);
2054 /* After handling the function's top-level block, stop. Don't
2055 continue to its superblock, the block of per-file
2056 symbols. */
2057 if (BLOCK_FUNCTION (block))
2058 break;
2059 block = BLOCK_SUPERBLOCK (block);
2060 }
2061}
2062
2063/* Data to be passed around in the calls to the locals and args
2064 iterators. */
c906108c 2065
2c58c0a9
PA
2066struct print_variable_and_value_data
2067{
12615cba
PW
2068 gdb::optional<compiled_regex> preg;
2069 gdb::optional<compiled_regex> treg;
8f043999 2070 struct frame_id frame_id;
2c58c0a9
PA
2071 int num_tabs;
2072 struct ui_file *stream;
2073 int values_printed;
2074};
2075
c378eb4e 2076/* The callback for the locals and args iterators. */
2c58c0a9
PA
2077
2078static void
2079do_print_variable_and_value (const char *print_name,
2080 struct symbol *sym,
2081 void *cb_data)
2082{
19ba03f4
SM
2083 struct print_variable_and_value_data *p
2084 = (struct print_variable_and_value_data *) cb_data;
8f043999
JK
2085 struct frame_info *frame;
2086
12615cba
PW
2087 if (p->preg.has_value ()
2088 && p->preg->exec (SYMBOL_NATURAL_NAME (sym), 0,
2089 NULL, 0) != 0)
2090 return;
2091 if (p->treg.has_value ()
2092 && !treg_matches_sym_type_name (*p->treg, sym))
2093 return;
2094
8f043999
JK
2095 frame = frame_find_by_id (p->frame_id);
2096 if (frame == NULL)
2097 {
2098 warning (_("Unable to restore previously selected frame."));
2099 return;
2100 }
2101
2102 print_variable_and_value (print_name, sym, frame, p->stream, p->num_tabs);
2103
2104 /* print_variable_and_value invalidates FRAME. */
2105 frame = NULL;
2c58c0a9 2106
2c58c0a9
PA
2107 p->values_printed = 1;
2108}
c906108c 2109
12615cba
PW
2110/* Prepares the regular expression REG from REGEXP.
2111 If REGEXP is NULL, it results in an empty regular expression. */
2112
2113static void
2114prepare_reg (const char *regexp, gdb::optional<compiled_regex> *reg)
2115{
2116 if (regexp != NULL)
2117 {
2118 int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off
2119 ? REG_ICASE : 0);
2120 reg->emplace (regexp, cflags, _("Invalid regexp"));
2121 }
2122 else
2123 reg->reset ();
2124}
2125
8f043999
JK
2126/* Print all variables from the innermost up to the function block of FRAME.
2127 Print them with values to STREAM indented by NUM_TABS.
12615cba
PW
2128 If REGEXP is not NULL, only print local variables whose name
2129 matches REGEXP.
2130 If T_REGEXP is not NULL, only print local variables whose type
2131 matches T_REGEXP.
2132 If no local variables have been printed and !QUIET, prints a message
2133 explaining why no local variables could be printed.
8f043999
JK
2134
2135 This function will invalidate FRAME. */
2136
c906108c 2137static void
12615cba
PW
2138print_frame_local_vars (struct frame_info *frame,
2139 bool quiet,
2140 const char *regexp, const char *t_regexp,
2141 int num_tabs, struct ui_file *stream)
c906108c 2142{
2c58c0a9 2143 struct print_variable_and_value_data cb_data;
3977b71f 2144 const struct block *block;
1d4f5741
PA
2145 CORE_ADDR pc;
2146
2147 if (!get_frame_pc_if_available (frame, &pc))
2148 {
12615cba
PW
2149 if (!quiet)
2150 fprintf_filtered (stream,
2151 _("PC unavailable, cannot determine locals.\n"));
1d4f5741
PA
2152 return;
2153 }
c906108c 2154
2c58c0a9 2155 block = get_frame_block (frame, 0);
c906108c
SS
2156 if (block == 0)
2157 {
12615cba
PW
2158 if (!quiet)
2159 fprintf_filtered (stream, "No symbol table info available.\n");
c906108c
SS
2160 return;
2161 }
c5aa993b 2162
12615cba
PW
2163 prepare_reg (regexp, &cb_data.preg);
2164 prepare_reg (t_regexp, &cb_data.treg);
8f043999 2165 cb_data.frame_id = get_frame_id (frame);
2c58c0a9
PA
2166 cb_data.num_tabs = 4 * num_tabs;
2167 cb_data.stream = stream;
2168 cb_data.values_printed = 0;
2169
16c3b12f
JB
2170 /* Temporarily change the selected frame to the given FRAME.
2171 This allows routines that rely on the selected frame instead
2172 of being given a frame as parameter to use the correct frame. */
45f25d6c 2173 scoped_restore_selected_frame restore_selected_frame;
16c3b12f
JB
2174 select_frame (frame);
2175
45f25d6c
AB
2176 iterate_over_block_local_vars (block,
2177 do_print_variable_and_value,
2178 &cb_data);
8f043999 2179
12615cba
PW
2180 if (!cb_data.values_printed && !quiet)
2181 {
2182 if (regexp == NULL && t_regexp == NULL)
2183 fprintf_filtered (stream, _("No locals.\n"));
2184 else
2185 fprintf_filtered (stream, _("No matching locals.\n"));
2186 }
c906108c
SS
2187}
2188
c906108c 2189void
1d12d88f 2190info_locals_command (const char *args, int from_tty)
c906108c 2191{
12615cba
PW
2192 std::string regexp;
2193 std::string t_regexp;
2194 bool quiet = false;
2195
2196 while (args != NULL
2197 && extract_info_print_args (&args, &quiet, &regexp, &t_regexp))
2198 ;
2199
2200 if (args != NULL)
2201 report_unrecognized_option_error ("info locals", args);
2202
033a42c2 2203 print_frame_local_vars (get_selected_frame (_("No frame selected.")),
12615cba
PW
2204 quiet,
2205 regexp.empty () ? NULL : regexp.c_str (),
2206 t_regexp.empty () ? NULL : t_regexp.c_str (),
b04f3ab4 2207 0, gdb_stdout);
c906108c
SS
2208}
2209
d392224a 2210/* Iterate over all the argument variables in block B. */
2c58c0a9
PA
2211
2212void
3977b71f 2213iterate_over_block_arg_vars (const struct block *b,
2c58c0a9
PA
2214 iterate_over_block_arg_local_vars_cb cb,
2215 void *cb_data)
c906108c 2216{
8157b174 2217 struct block_iterator iter;
52f0bd74 2218 struct symbol *sym, *sym2;
c906108c 2219
de4f826b 2220 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c 2221 {
2a2d4dc3
AS
2222 /* Don't worry about things which aren't arguments. */
2223 if (SYMBOL_IS_ARGUMENT (sym))
c906108c 2224 {
c906108c
SS
2225 /* We have to look up the symbol because arguments can have
2226 two entries (one a parameter, one a local) and the one we
2227 want is the local, which lookup_symbol will find for us.
2228 This includes gcc1 (not gcc2) on the sparc when passing a
2229 small structure and gcc2 when the argument type is float
2230 and it is passed as a double and converted to float by
2231 the prologue (in the latter case the type of the LOC_ARG
2232 symbol is double and the type of the LOC_LOCAL symbol is
2233 float). There are also LOC_ARG/LOC_REGISTER pairs which
2234 are not combined in symbol-reading. */
2235
de63c46b
PA
2236 sym2 = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym),
2237 b, VAR_DOMAIN).symbol;
2c58c0a9 2238 (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
c906108c
SS
2239 }
2240 }
2c58c0a9
PA
2241}
2242
8f043999
JK
2243/* Print all argument variables of the function of FRAME.
2244 Print them with values to STREAM.
12615cba
PW
2245 If REGEXP is not NULL, only print argument variables whose name
2246 matches REGEXP.
2247 If T_REGEXP is not NULL, only print argument variables whose type
2248 matches T_REGEXP.
2249 If no argument variables have been printed and !QUIET, prints a message
2250 explaining why no argument variables could be printed.
8f043999
JK
2251
2252 This function will invalidate FRAME. */
2253
2c58c0a9 2254static void
12615cba
PW
2255print_frame_arg_vars (struct frame_info *frame,
2256 bool quiet,
2257 const char *regexp, const char *t_regexp,
2258 struct ui_file *stream)
2c58c0a9
PA
2259{
2260 struct print_variable_and_value_data cb_data;
2261 struct symbol *func;
1d4f5741 2262 CORE_ADDR pc;
12615cba
PW
2263 gdb::optional<compiled_regex> preg;
2264 gdb::optional<compiled_regex> treg;
1d4f5741
PA
2265
2266 if (!get_frame_pc_if_available (frame, &pc))
2267 {
12615cba
PW
2268 if (!quiet)
2269 fprintf_filtered (stream,
2270 _("PC unavailable, cannot determine args.\n"));
1d4f5741
PA
2271 return;
2272 }
2c58c0a9
PA
2273
2274 func = get_frame_function (frame);
2275 if (func == NULL)
2276 {
12615cba
PW
2277 if (!quiet)
2278 fprintf_filtered (stream, _("No symbol table info available.\n"));
2c58c0a9
PA
2279 return;
2280 }
2281
12615cba
PW
2282 prepare_reg (regexp, &cb_data.preg);
2283 prepare_reg (t_regexp, &cb_data.treg);
8f043999 2284 cb_data.frame_id = get_frame_id (frame);
2c58c0a9 2285 cb_data.num_tabs = 0;
d392224a 2286 cb_data.stream = stream;
2c58c0a9
PA
2287 cb_data.values_printed = 0;
2288
2289 iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func),
2290 do_print_variable_and_value, &cb_data);
033a42c2 2291
8f043999
JK
2292 /* do_print_variable_and_value invalidates FRAME. */
2293 frame = NULL;
2294
12615cba
PW
2295 if (!cb_data.values_printed && !quiet)
2296 {
2297 if (regexp == NULL && t_regexp == NULL)
2298 fprintf_filtered (stream, _("No arguments.\n"));
2299 else
2300 fprintf_filtered (stream, _("No matching arguments.\n"));
2301 }
c906108c
SS
2302}
2303
2304void
12615cba 2305info_args_command (const char *args, int from_tty)
c906108c 2306{
12615cba
PW
2307 std::string regexp;
2308 std::string t_regexp;
d54cfd76 2309 bool quiet = false;
12615cba
PW
2310
2311 while (args != NULL
2312 && extract_info_print_args (&args, &quiet, &regexp, &t_regexp))
2313 ;
2314
2315 if (args != NULL)
2316 report_unrecognized_option_error ("info args", args);
2317
2318
033a42c2 2319 print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
12615cba
PW
2320 quiet,
2321 regexp.empty () ? NULL : regexp.c_str (),
2322 t_regexp.empty () ? NULL : t_regexp.c_str (),
b04f3ab4 2323 gdb_stdout);
c906108c 2324}
c906108c 2325\f
c906108c 2326/* Return the symbol-block in which the selected frame is executing.
ae767bfb
JB
2327 Can return zero under various legitimate circumstances.
2328
2329 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
2330 code address within the block returned. We use this to decide
2331 which macros are in scope. */
c906108c 2332
3977b71f 2333const struct block *
ae767bfb 2334get_selected_block (CORE_ADDR *addr_in_block)
c906108c 2335{
d729566a 2336 if (!has_stack_frames ())
8ea051c5
PA
2337 return 0;
2338
206415a3 2339 return get_frame_block (get_selected_frame (NULL), addr_in_block);
c906108c
SS
2340}
2341
2342/* Find a frame a certain number of levels away from FRAME.
2343 LEVEL_OFFSET_PTR points to an int containing the number of levels.
2344 Positive means go to earlier frames (up); negative, the reverse.
2345 The int that contains the number of levels is counted toward
2346 zero as the frames for those levels are found.
2347 If the top or bottom frame is reached, that frame is returned,
2348 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
2349 how much farther the original request asked to go. */
2350
2351struct frame_info *
033a42c2 2352find_relative_frame (struct frame_info *frame, int *level_offset_ptr)
c906108c 2353{
033a42c2
MK
2354 /* Going up is simple: just call get_prev_frame enough times or
2355 until the initial frame is reached. */
c906108c
SS
2356 while (*level_offset_ptr > 0)
2357 {
033a42c2 2358 struct frame_info *prev = get_prev_frame (frame);
433759f7 2359
033a42c2 2360 if (!prev)
c906108c
SS
2361 break;
2362 (*level_offset_ptr)--;
2363 frame = prev;
2364 }
033a42c2 2365
c906108c 2366 /* Going down is just as simple. */
033a42c2 2367 while (*level_offset_ptr < 0)
c906108c 2368 {
033a42c2 2369 struct frame_info *next = get_next_frame (frame);
433759f7 2370
033a42c2
MK
2371 if (!next)
2372 break;
2373 (*level_offset_ptr)++;
2374 frame = next;
c906108c 2375 }
033a42c2 2376
c906108c
SS
2377 return frame;
2378}
2379
033a42c2
MK
2380/* Select the frame up one or COUNT_EXP stack levels from the
2381 previously selected frame, and print it briefly. */
c906108c 2382
c906108c 2383static void
d3d3328b 2384up_silently_base (const char *count_exp)
c906108c 2385{
033a42c2
MK
2386 struct frame_info *frame;
2387 int count = 1;
2388
c906108c 2389 if (count_exp)
bb518678 2390 count = parse_and_eval_long (count_exp);
c5aa993b 2391
033a42c2
MK
2392 frame = find_relative_frame (get_selected_frame ("No stack."), &count);
2393 if (count != 0 && count_exp == NULL)
8a3fe4f8 2394 error (_("Initial frame selected; you cannot go up."));
033a42c2 2395 select_frame (frame);
c906108c
SS
2396}
2397
2398static void
0b39b52e 2399up_silently_command (const char *count_exp, int from_tty)
c906108c 2400{
c5aa993b 2401 up_silently_base (count_exp);
c906108c
SS
2402}
2403
2404static void
0b39b52e 2405up_command (const char *count_exp, int from_tty)
c906108c
SS
2406{
2407 up_silently_base (count_exp);
76727919 2408 gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
c906108c
SS
2409}
2410
033a42c2
MK
2411/* Select the frame down one or COUNT_EXP stack levels from the previously
2412 selected frame, and print it briefly. */
c906108c 2413
c906108c 2414static void
d3d3328b 2415down_silently_base (const char *count_exp)
c906108c 2416{
52f0bd74 2417 struct frame_info *frame;
033a42c2 2418 int count = -1;
f89b749f 2419
c906108c 2420 if (count_exp)
bb518678 2421 count = -parse_and_eval_long (count_exp);
c5aa993b 2422
033a42c2
MK
2423 frame = find_relative_frame (get_selected_frame ("No stack."), &count);
2424 if (count != 0 && count_exp == NULL)
c906108c 2425 {
033a42c2
MK
2426 /* We only do this if COUNT_EXP is not specified. That way
2427 "down" means to really go down (and let me know if that is
2428 impossible), but "down 9999" can be used to mean go all the
2429 way down without getting an error. */
c906108c 2430
033a42c2 2431 error (_("Bottom (innermost) frame selected; you cannot go down."));
c906108c
SS
2432 }
2433
0f7d239c 2434 select_frame (frame);
c906108c
SS
2435}
2436
c906108c 2437static void
0b39b52e 2438down_silently_command (const char *count_exp, int from_tty)
c906108c
SS
2439{
2440 down_silently_base (count_exp);
c906108c
SS
2441}
2442
2443static void
0b39b52e 2444down_command (const char *count_exp, int from_tty)
c906108c
SS
2445{
2446 down_silently_base (count_exp);
76727919 2447 gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
c906108c 2448}
033a42c2 2449
8b93c638 2450void
0b39b52e 2451return_command (const char *retval_exp, int from_tty)
c906108c 2452{
901900c4
MGD
2453 /* Initialize it just to avoid a GCC false warning. */
2454 enum return_value_convention rv_conv = RETURN_VALUE_STRUCT_CONVENTION;
5ed92fa8 2455 struct frame_info *thisframe;
d80b854b 2456 struct gdbarch *gdbarch;
c906108c 2457 struct symbol *thisfun;
3d6d86c6 2458 struct value *return_value = NULL;
6a3a010b 2459 struct value *function = NULL;
fc70c2a0 2460 const char *query_prefix = "";
c906108c 2461
5ed92fa8
UW
2462 thisframe = get_selected_frame ("No selected frame.");
2463 thisfun = get_frame_function (thisframe);
d80b854b 2464 gdbarch = get_frame_arch (thisframe);
c906108c 2465
edb3359d
DJ
2466 if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
2467 error (_("Can not force return from an inlined function."));
2468
fc70c2a0
AC
2469 /* Compute the return value. If the computation triggers an error,
2470 let it bail. If the return type can't be handled, set
2471 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
2472 message. */
c906108c
SS
2473 if (retval_exp)
2474 {
4d01a485 2475 expression_up retval_expr = parse_expression (retval_exp);
c906108c
SS
2476 struct type *return_type = NULL;
2477
fc70c2a0
AC
2478 /* Compute the return value. Should the computation fail, this
2479 call throws an error. */
4d01a485 2480 return_value = evaluate_expression (retval_expr.get ());
c906108c 2481
fc70c2a0
AC
2482 /* Cast return value to the return type of the function. Should
2483 the cast fail, this call throws an error. */
c906108c
SS
2484 if (thisfun != NULL)
2485 return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
2486 if (return_type == NULL)
61ff14c6 2487 {
9eaf6705
TT
2488 if (retval_expr->elts[0].opcode != UNOP_CAST
2489 && retval_expr->elts[0].opcode != UNOP_CAST_TYPE)
61ff14c6
JK
2490 error (_("Return value type not available for selected "
2491 "stack frame.\n"
2492 "Please use an explicit cast of the value to return."));
2493 return_type = value_type (return_value);
2494 }
f168693b 2495 return_type = check_typedef (return_type);
c906108c
SS
2496 return_value = value_cast (return_type, return_value);
2497
fc70c2a0
AC
2498 /* Make sure the value is fully evaluated. It may live in the
2499 stack frame we're about to pop. */
d69fe07e 2500 if (value_lazy (return_value))
c906108c 2501 value_fetch_lazy (return_value);
c906108c 2502
6a3a010b 2503 if (thisfun != NULL)
63e43d3a 2504 function = read_var_value (thisfun, NULL, thisframe);
6a3a010b 2505
bbfdfe1c 2506 rv_conv = RETURN_VALUE_REGISTER_CONVENTION;
667e784f
AC
2507 if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
2508 /* If the return-type is "void", don't try to find the
2509 return-value's location. However, do still evaluate the
2510 return expression so that, even when the expression result
2511 is discarded, side effects such as "return i++" still
033a42c2 2512 occur. */
667e784f 2513 return_value = NULL;
bbfdfe1c 2514 else if (thisfun != NULL)
fc70c2a0 2515 {
bbfdfe1c
DM
2516 rv_conv = struct_return_convention (gdbarch, function, return_type);
2517 if (rv_conv == RETURN_VALUE_STRUCT_CONVENTION
2518 || rv_conv == RETURN_VALUE_ABI_RETURNS_ADDRESS)
2519 {
2520 query_prefix = "The location at which to store the "
2521 "function's return value is unknown.\n"
2522 "If you continue, the return value "
2523 "that you specified will be ignored.\n";
2524 return_value = NULL;
2525 }
fc70c2a0 2526 }
c906108c
SS
2527 }
2528
fc70c2a0
AC
2529 /* Does an interactive user really want to do this? Include
2530 information, such as how well GDB can handle the return value, in
2531 the query message. */
2532 if (from_tty)
2533 {
2534 int confirmed;
433759f7 2535
fc70c2a0 2536 if (thisfun == NULL)
e2e0b3e5 2537 confirmed = query (_("%sMake selected stack frame return now? "),
fc70c2a0
AC
2538 query_prefix);
2539 else
743649fd
MW
2540 {
2541 if (TYPE_NO_RETURN (thisfun->type))
d35b90fb 2542 warning (_("Function does not return normally to caller."));
743649fd
MW
2543 confirmed = query (_("%sMake %s return now? "), query_prefix,
2544 SYMBOL_PRINT_NAME (thisfun));
2545 }
fc70c2a0 2546 if (!confirmed)
8a3fe4f8 2547 error (_("Not confirmed"));
fc70c2a0 2548 }
c906108c 2549
a45ae3ed
UW
2550 /* Discard the selected frame and all frames inner-to it. */
2551 frame_pop (get_selected_frame (NULL));
c906108c 2552
a1f5b845 2553 /* Store RETURN_VALUE in the just-returned register set. */
fc70c2a0
AC
2554 if (return_value != NULL)
2555 {
df407dfe 2556 struct type *return_type = value_type (return_value);
b926417a 2557 struct gdbarch *cache_arch = get_current_regcache ()->arch ();
42e2132c 2558
bbfdfe1c
DM
2559 gdb_assert (rv_conv != RETURN_VALUE_STRUCT_CONVENTION
2560 && rv_conv != RETURN_VALUE_ABI_RETURNS_ADDRESS);
b926417a 2561 gdbarch_return_value (cache_arch, function, return_type,
594f7785 2562 get_current_regcache (), NULL /*read*/,
0fd88904 2563 value_contents (return_value) /*write*/);
fc70c2a0 2564 }
1a2aab69 2565
fc70c2a0
AC
2566 /* If we are at the end of a call dummy now, pop the dummy frame
2567 too. */
e8bcf01f
AC
2568 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
2569 frame_pop (get_current_frame ());
1a2aab69 2570
edbbff4a 2571 select_frame (get_current_frame ());
c906108c 2572 /* If interactive, print the frame that is now current. */
c906108c 2573 if (from_tty)
edbbff4a 2574 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
c906108c
SS
2575}
2576
39f0c204
AB
2577/* Find the most inner frame in the current stack for a function called
2578 FUNCTION_NAME. If no matching frame is found return NULL. */
c906108c 2579
39f0c204
AB
2580static struct frame_info *
2581find_frame_for_function (const char *function_name)
c906108c 2582{
39f0c204
AB
2583 /* Used to hold the lower and upper addresses for each of the
2584 SYMTAB_AND_LINEs found for functions matching FUNCTION_NAME. */
2585 struct function_bounds
2586 {
2587 CORE_ADDR low, high;
2588 };
033a42c2 2589 struct frame_info *frame;
39f0c204 2590 bool found = false;
c906108c 2591 int level = 1;
c906108c 2592
39f0c204 2593 gdb_assert (function_name != NULL);
c906108c 2594
edbbff4a 2595 frame = get_current_frame ();
6c5b2ebe 2596 std::vector<symtab_and_line> sals
39f0c204
AB
2597 = decode_line_with_current_source (function_name,
2598 DECODE_LINE_FUNFIRSTLINE);
0b868b60 2599 gdb::def_vector<function_bounds> func_bounds (sals.size ());
39f0c204 2600 for (size_t i = 0; i < sals.size (); i++)
c906108c 2601 {
6c5b2ebe 2602 if (sals[i].pspace != current_program_space)
f8eba3c6 2603 func_bounds[i].low = func_bounds[i].high = 0;
6c5b2ebe
PA
2604 else if (sals[i].pc == 0
2605 || find_pc_partial_function (sals[i].pc, NULL,
f8eba3c6
TT
2606 &func_bounds[i].low,
2607 &func_bounds[i].high) == 0)
39f0c204 2608 func_bounds[i].low = func_bounds[i].high = 0;
c906108c
SS
2609 }
2610
2611 do
2612 {
6c5b2ebe 2613 for (size_t i = 0; (i < sals.size () && !found); i++)
033a42c2
MK
2614 found = (get_frame_pc (frame) >= func_bounds[i].low
2615 && get_frame_pc (frame) < func_bounds[i].high);
c906108c
SS
2616 if (!found)
2617 {
2618 level = 1;
033a42c2 2619 frame = find_relative_frame (frame, &level);
c906108c
SS
2620 }
2621 }
2622 while (!found && level == 0);
2623
c906108c 2624 if (!found)
39f0c204
AB
2625 frame = NULL;
2626
2627 return frame;
2628}
2629
2630/* Implements the dbx 'func' command. */
2631
2632static void
2633func_command (const char *arg, int from_tty)
2634{
2635 if (arg == NULL)
2636 return;
2637
2638 struct frame_info *frame = find_frame_for_function (arg);
2639 if (frame == NULL)
61367c61 2640 error (_("'%s' not within current stack frame."), arg);
39f0c204
AB
2641 if (frame != get_selected_frame (NULL))
2642 {
2643 select_frame (frame);
2644 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2645 }
c906108c 2646}
033a42c2 2647
6a70eb7d
PW
2648/* Apply a GDB command to all stack frames, or a set of identified frames,
2649 or innermost COUNT frames.
2650 With a negative COUNT, apply command on outermost -COUNT frames.
2651
2652 frame apply 3 info frame Apply 'info frame' to frames 0, 1, 2
2653 frame apply -3 info frame Apply 'info frame' to outermost 3 frames.
2654 frame apply all x/i $pc Apply 'x/i $pc' cmd to all frames.
2655 frame apply all -s p local_var_no_idea_in_which_frame
2656 If a frame has a local variable called
2657 local_var_no_idea_in_which_frame, print frame
2658 and value of local_var_no_idea_in_which_frame.
2659 frame apply all -s -q p local_var_no_idea_in_which_frame
2660 Same as before, but only print the variable value.
2661 frame apply level 2-5 0 4-7 -s p i = i + 1
2662 Adds 1 to the variable i in the specified frames.
2663 Note that i will be incremented twice in
2664 frames 4 and 5. */
2665
2666/* Apply a GDB command to COUNT stack frames, starting at TRAILING.
2667 CMD starts with 0 or more qcs flags followed by the GDB command to apply.
2668 COUNT -1 means all frames starting at TRAILING. WHICH_COMMAND is used
2669 for error messages. */
2670
2671static void
2672frame_apply_command_count (const char *which_command,
2673 const char *cmd, int from_tty,
2674 struct frame_info *trailing, int count)
2675{
2676 qcs_flags flags;
2677 struct frame_info *fi;
2678
2679 while (cmd != NULL && parse_flags_qcs (which_command, &cmd, &flags))
2680 ;
2681
2682 if (cmd == NULL || *cmd == '\0')
2683 error (_("Please specify a command to apply on the selected frames"));
2684
2685 /* The below will restore the current inferior/thread/frame.
2686 Usually, only the frame is effectively to be restored.
2687 But in case CMD switches of inferior/thread, better restore
2688 these also. */
2689 scoped_restore_current_thread restore_thread;
2690
2691 for (fi = trailing; fi && count--; fi = get_prev_frame (fi))
2692 {
2693 QUIT;
2694
2695 select_frame (fi);
2696 TRY
2697 {
2698 std::string cmd_result;
2699 {
2700 /* In case CMD switches of inferior/thread/frame, the below
2701 restores the inferior/thread/frame. FI can then be
2702 set to the selected frame. */
2703 scoped_restore_current_thread restore_fi_current_frame;
2704
2705 cmd_result = execute_command_to_string (cmd, from_tty);
2706 }
2707 fi = get_selected_frame (_("frame apply "
2708 "unable to get selected frame."));
2709 if (!flags.silent || cmd_result.length () > 0)
2710 {
2711 if (!flags.quiet)
2712 print_stack_frame (fi, 1, LOCATION, 0);
2713 printf_filtered ("%s", cmd_result.c_str ());
2714 }
2715 }
2716 CATCH (ex, RETURN_MASK_ERROR)
2717 {
2718 fi = get_selected_frame (_("frame apply "
2719 "unable to get selected frame."));
2720 if (!flags.silent)
2721 {
2722 if (!flags.quiet)
2723 print_stack_frame (fi, 1, LOCATION, 0);
2724 if (flags.cont)
2725 printf_filtered ("%s\n", ex.message);
2726 else
2727 throw_exception (ex);
2728 }
2729 }
2730 END_CATCH;
2731 }
2732}
2733
2734/* Implementation of the "frame apply level" command. */
2735
2736static void
2737frame_apply_level_command (const char *cmd, int from_tty)
2738{
2739 if (!target_has_stack)
2740 error (_("No stack."));
2741
2742 bool level_found = false;
2743 const char *levels_str = cmd;
2744 number_or_range_parser levels (levels_str);
2745
2746 /* Skip the LEVEL list to find the flags and command args. */
2747 while (!levels.finished ())
2748 {
8d49165d
TT
2749 /* Call for effect. */
2750 levels.get_number ();
6a70eb7d
PW
2751
2752 level_found = true;
2753 if (levels.in_range ())
2754 levels.skip_range ();
2755 }
2756
2757 if (!level_found)
2758 error (_("Missing or invalid LEVEL... argument"));
2759
2760 cmd = levels.cur_tok ();
2761
2762 /* Redo the LEVELS parsing, but applying COMMAND. */
2763 levels.init (levels_str);
2764 while (!levels.finished ())
2765 {
2766 const int level_beg = levels.get_number ();
2767 int n_frames;
2768
2769 if (levels.in_range ())
2770 {
2771 n_frames = levels.end_value () - level_beg + 1;
2772 levels.skip_range ();
2773 }
2774 else
2775 n_frames = 1;
2776
2777 frame_apply_command_count ("frame apply level", cmd, from_tty,
2778 leading_innermost_frame (level_beg), n_frames);
2779 }
2780}
2781
2782/* Implementation of the "frame apply all" command. */
2783
2784static void
2785frame_apply_all_command (const char *cmd, int from_tty)
2786{
2787 if (!target_has_stack)
2788 error (_("No stack."));
2789
2790 frame_apply_command_count ("frame apply all", cmd, from_tty,
2791 get_current_frame (), INT_MAX);
2792}
2793
2794/* Implementation of the "frame apply" command. */
2795
2796static void
2797frame_apply_command (const char* cmd, int from_tty)
2798{
2799 int count;
2800 struct frame_info *trailing;
2801
2802 if (!target_has_stack)
2803 error (_("No stack."));
2804
2805 if (cmd == NULL)
2806 error (_("Missing COUNT argument."));
2807 count = get_number_trailer (&cmd, 0);
2808 if (count == 0)
2809 error (_("Invalid COUNT argument."));
2810
2811 if (count < 0)
2812 {
2813 trailing = trailing_outermost_frame (-count);
2814 count = -1;
2815 }
2816 else
2817 trailing = get_current_frame ();
2818
2819 frame_apply_command_count ("frame apply", cmd, from_tty,
2820 trailing, count);
2821}
2822
2823/* Implementation of the "faas" command. */
2824
2825static void
2826faas_command (const char *cmd, int from_tty)
2827{
2828 std::string expanded = std::string ("frame apply all -s ") + cmd;
2829 execute_command (expanded.c_str (), from_tty);
2830}
2831
2832
f67ffa6a
AB
2833/* Find inner-mode frame with frame address ADDRESS. Return NULL if no
2834 matching frame can be found. */
2835
2836static struct frame_info *
2837find_frame_for_address (CORE_ADDR address)
2838{
2839 struct frame_id id;
2840 struct frame_info *fid;
2841
2842 id = frame_id_build_wild (address);
2843
2844 /* If (s)he specifies the frame with an address, he deserves
2845 what (s)he gets. Still, give the highest one that matches.
2846 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
2847 know). */
2848 for (fid = get_current_frame ();
2849 fid != NULL;
2850 fid = get_prev_frame (fid))
2851 {
2852 if (frame_id_eq (id, get_frame_id (fid)))
2853 {
2854 struct frame_info *prev_frame;
2855
2856 while (1)
2857 {
2858 prev_frame = get_prev_frame (fid);
2859 if (!prev_frame
2860 || !frame_id_eq (id, get_frame_id (prev_frame)))
2861 break;
2862 fid = prev_frame;
2863 }
2864 return fid;
2865 }
2866 }
2867 return NULL;
2868}
2869
2870\f
2871
2872/* Commands with a prefix of `frame apply'. */
2873static struct cmd_list_element *frame_apply_cmd_list = NULL;
2874
6a70eb7d 2875/* Commands with a prefix of `frame'. */
f67ffa6a
AB
2876static struct cmd_list_element *frame_cmd_list = NULL;
2877
2878/* Commands with a prefix of `select frame'. */
2879static struct cmd_list_element *select_frame_cmd_list = NULL;
2880
2881/* Commands with a prefix of `info frame'. */
2882static struct cmd_list_element *info_frame_cmd_list = NULL;
6a70eb7d 2883
c906108c 2884void
fba45db2 2885_initialize_stack (void)
c906108c 2886{
f67ffa6a 2887 struct cmd_list_element *cmd;
6a70eb7d 2888
1bedd215
AC
2889 add_com ("return", class_stack, return_command, _("\
2890Make selected stack frame return to its caller.\n\
c906108c
SS
2891Control remains in the debugger, but when you continue\n\
2892execution will resume in the frame above the one now selected.\n\
1bedd215
AC
2893If an argument is given, it is an expression for the value to return."));
2894
2895 add_com ("up", class_stack, up_command, _("\
2896Select and print stack frame that called this one.\n\
2897An argument says how many frames up to go."));
2898 add_com ("up-silently", class_support, up_silently_command, _("\
2899Same as the `up' command, but does not print anything.\n\
2900This is useful in command scripts."));
2901
2902 add_com ("down", class_stack, down_command, _("\
2903Select and print stack frame called by this one.\n\
2904An argument says how many frames down to go."));
c906108c
SS
2905 add_com_alias ("do", "down", class_stack, 1);
2906 add_com_alias ("dow", "down", class_stack, 1);
1bedd215
AC
2907 add_com ("down-silently", class_support, down_silently_command, _("\
2908Same as the `down' command, but does not print anything.\n\
2909This is useful in command scripts."));
c906108c 2910
f67ffa6a
AB
2911 add_prefix_cmd ("frame", class_stack,
2912 &frame_cmd.base_command, _("\
2913Select and print a stack frame.\n\
2914With no argument, print the selected stack frame. (See also \"info frame\").\n\
2915A single numerical argument specifies the frame to select."),
2916 &frame_cmd_list, "frame ", 1, &cmdlist);
c906108c
SS
2917
2918 add_com_alias ("f", "frame", class_stack, 1);
2919
6a70eb7d
PW
2920#define FRAME_APPLY_FLAGS_HELP "\
2921Prints the frame location information followed by COMMAND output.\n\
2922FLAG arguments are -q (quiet), -c (continue), -s (silent).\n\
2923Flag -q disables printing the frame location information.\n\
2924By default, if a COMMAND raises an error, frame apply is aborted.\n\
2925Flag -c indicates to print the error and continue.\n\
2926Flag -s indicates to silently ignore a COMMAND that raises an error\n\
2927or produces no output."
2928
2929 add_prefix_cmd ("apply", class_stack, frame_apply_command,
2930 _("Apply a command to a number of frames.\n\
2931Usage: frame apply COUNT [FLAG]... COMMAND\n\
2932With a negative COUNT argument, applies the command on outermost -COUNT frames.\n"
2933FRAME_APPLY_FLAGS_HELP),
f67ffa6a 2934 &frame_apply_cmd_list, "frame apply ", 1, &frame_cmd_list);
6a70eb7d
PW
2935
2936 add_cmd ("all", class_stack, frame_apply_all_command,
2937 _("\
2938Apply a command to all frames.\n\
2939\n\
2940Usage: frame apply all [FLAG]... COMMAND\n"
2941FRAME_APPLY_FLAGS_HELP),
f67ffa6a 2942 &frame_apply_cmd_list);
6a70eb7d
PW
2943
2944 add_cmd ("level", class_stack, frame_apply_level_command,
2945 _("\
2946Apply a command to a list of frames.\n\
2947\n\
2948Usage: frame apply level LEVEL... [FLAG]... COMMAND\n\
2949ID is a space-separated list of LEVELs of frames to apply COMMAND on.\n"
2950FRAME_APPLY_FLAGS_HELP),
f67ffa6a 2951 &frame_apply_cmd_list);
6a70eb7d
PW
2952
2953 add_com ("faas", class_stack, faas_command, _("\
2954Apply a command to all frames (ignoring errors and empty output).\n\
2955Usage: faas COMMAND\n\
2956shortcut for 'frame apply all -s COMMAND'"));
2957
f67ffa6a
AB
2958
2959 add_prefix_cmd ("frame", class_stack,
2960 &frame_cmd.base_command, _("\
2961Select and print a stack frame.\n\
2962With no argument, print the selected stack frame. (See also \"info frame\").\n\
2963A single numerical argument specifies the frame to select."),
2964 &frame_cmd_list, "frame ", 1, &cmdlist);
2965 add_com_alias ("f", "frame", class_stack, 1);
2966
2967 add_cmd ("address", class_stack, &frame_cmd.address,
2968 _("\
2969Select and print a stack frame by stack address\n\
2970\n\
2971Usage: frame address STACK-ADDRESS"),
2972 &frame_cmd_list);
2973
2974 add_cmd ("view", class_stack, &frame_cmd.view,
2975 _("\
2976View a stack frame that might be outside the current backtrace.\n\
2977\n\
2978Usage: frame view STACK-ADDRESS\n\
2979 frame view STACK-ADDRESS PC-ADDRESS"),
2980 &frame_cmd_list);
2981
2982 cmd = add_cmd ("function", class_stack, &frame_cmd.function,
2983 _("\
2984Select and print a stack frame by function name.\n\
2985\n\
2986Usage: frame function NAME\n\
2987\n\
2988The innermost frame that visited function NAME is selected."),
2989 &frame_cmd_list);
2990 set_cmd_completer (cmd, frame_selection_by_function_completer);
2991
2992
2993 add_cmd ("level", class_stack, &frame_cmd.level,
2994 _("\
2995Select and print a stack frame by level.\n\
2996\n\
2997Usage: frame level LEVEL"),
2998 &frame_cmd_list);
2999
3000 cmd = add_prefix_cmd_suppress_notification ("select-frame", class_stack,
3001 &select_frame_cmd.base_command, _("\
1bedd215 3002Select a stack frame without printing anything.\n\
f67ffa6a
AB
3003A single numerical argument specifies the frame to select."),
3004 &select_frame_cmd_list, "select-frame ", 1, &cmdlist,
3005 &cli_suppress_notification.user_selected_context);
3006
3007 add_cmd_suppress_notification ("address", class_stack,
3008 &select_frame_cmd.address, _("\
3009Select a stack frame by stack address.\n\
3010\n\
3011Usage: select-frame address STACK-ADDRESS"),
3012 &select_frame_cmd_list,
3013 &cli_suppress_notification.user_selected_context);
3014
3015
3016 add_cmd_suppress_notification ("view", class_stack,
3017 &select_frame_cmd.view, _("\
3018Select a stack frame that might be outside the current backtrace.\n\
3019\n\
3020Usage: select-frame view STACK-ADDRESS\n\
3021 select-frame view STACK-ADDRESS PC-ADDRESS"),
3022 &select_frame_cmd_list,
4034d0ff 3023 &cli_suppress_notification.user_selected_context);
c906108c 3024
f67ffa6a
AB
3025 cmd = add_cmd_suppress_notification ("function", class_stack,
3026 &select_frame_cmd.function, _("\
3027Select a stack frame by function name.\n\
3028\n\
3029Usage: select-frame function NAME"),
3030 &select_frame_cmd_list,
3031 &cli_suppress_notification.user_selected_context);
3032 set_cmd_completer (cmd, frame_selection_by_function_completer);
3033
3034 add_cmd_suppress_notification ("level", class_stack,
3035 &select_frame_cmd.level, _("\
3036Select a stack frame by level.\n\
3037\n\
3038Usage: select-frame level LEVEL"),
3039 &select_frame_cmd_list,
3040 &cli_suppress_notification.user_selected_context);
3041
1bedd215
AC
3042 add_com ("backtrace", class_stack, backtrace_command, _("\
3043Print backtrace of all stack frames, or innermost COUNT frames.\n\
9507b29c
TT
3044Usage: backtrace [QUALIFIERS]... [COUNT]\n\
3045With a negative argument, print outermost -COUNT frames.\n\
3046Use of the 'full' qualifier also prints the values of the local variables.\n\
1e611234 3047Use of the 'no-filters' qualifier prohibits frame filters from executing\n\
9507b29c 3048on this backtrace."));
c906108c 3049 add_com_alias ("bt", "backtrace", class_stack, 0);
c906108c
SS
3050
3051 add_com_alias ("where", "backtrace", class_alias, 0);
3052 add_info ("stack", backtrace_command,
1bedd215 3053 _("Backtrace of the stack, or innermost COUNT frames."));
c906108c 3054 add_info_alias ("s", "stack", 1);
f67ffa6a
AB
3055
3056 add_prefix_cmd ("frame", class_info, &info_frame_cmd.base_command,
3057 _("All about the selected stack frame.\n\
3058With no arguments, displays information about the currently selected stack\n\
3059frame. Alternatively a frame specification may be provided (See \"frame\")\n\
3060the information is then printed about the specified frame."),
3061 &info_frame_cmd_list, "info frame ", 1, &infolist);
c906108c 3062 add_info_alias ("f", "frame", 1);
f67ffa6a
AB
3063
3064 add_cmd ("address", class_stack, &info_frame_cmd.address,
3065 _("\
3066Print information about a stack frame selected by stack address.\n\
3067\n\
3068Usage: info frame address STACK-ADDRESS"),
3069 &info_frame_cmd_list);
3070
3071 add_cmd ("view", class_stack, &info_frame_cmd.view,
3072 _("\
3073Print information about a stack frame outside the current backtrace.\n\
3074\n\
3075Usage: info frame view STACK-ADDRESS\n\
3076 info frame view STACK-ADDRESS PC-ADDRESS"),
3077 &info_frame_cmd_list);
3078
3079 cmd = add_cmd ("function", class_stack, &info_frame_cmd.function,
3080 _("\
3081Print information about a stack frame selected by function name.\n\
3082\n\
3083Usage: info frame function NAME"),
3084 &info_frame_cmd_list);
3085 set_cmd_completer (cmd, frame_selection_by_function_completer);
3086
3087 add_cmd ("level", class_stack, &info_frame_cmd.level,
3088 _("\
3089Print information about a stack frame selected by level.\n\
3090\n\
3091Usage: info frame level LEVEL"),
3092 &info_frame_cmd_list);
3093
11db9430 3094 add_info ("locals", info_locals_command,
12615cba
PW
3095 info_print_args_help (_("\
3096All local variables of current stack frame or those matching REGEXPs.\n\
3097Usage: info locals [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
3098Prints the local variables of the current stack frame.\n"),
3099 _("local variables")));
11db9430 3100 add_info ("args", info_args_command,
12615cba
PW
3101 info_print_args_help (_("\
3102All argument variables of current stack frame or those matching REGEXPs.\n\
3103Usage: info args [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
3104Prints the argument variables of the current stack frame.\n"),
3105 _("argument variables")));
c906108c
SS
3106
3107 if (dbx_commands)
1bedd215 3108 add_com ("func", class_stack, func_command, _("\
41827fc3
TT
3109Select the stack frame that contains NAME.\n\
3110Usage: func NAME"));
c906108c 3111
88408340
JB
3112 add_setshow_enum_cmd ("frame-arguments", class_stack,
3113 print_frame_arguments_choices, &print_frame_arguments,
3114 _("Set printing of non-scalar frame arguments"),
3115 _("Show printing of non-scalar frame arguments"),
3116 NULL, NULL, NULL, &setprintlist, &showprintlist);
3117
e7045703
DE
3118 add_setshow_boolean_cmd ("frame-arguments", no_class,
3119 &print_raw_frame_arguments, _("\
3120Set whether to print frame arguments in raw form."), _("\
3121Show whether to print frame arguments in raw form."), _("\
3122If set, frame arguments are printed in raw form, bypassing any\n\
3123pretty-printers for that value."),
3124 NULL, NULL,
3125 &setprintrawlist, &showprintrawlist);
3126
30c33a9f
HZ
3127 add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
3128 &disassemble_next_line, _("\
3e43a32a
MS
3129Set whether to disassemble next source line or insn when execution stops."),
3130 _("\
3131Show whether to disassemble next source line or insn when execution stops."),
3132 _("\
80a0ea0f
EZ
3133If ON, GDB will display disassembly of the next source line, in addition\n\
3134to displaying the source line itself. If the next source line cannot\n\
3135be displayed (e.g., source is unavailable or there's no line info), GDB\n\
3136will display disassembly of next instruction instead of showing the\n\
3137source line.\n\
3138If AUTO, display disassembly of next instruction only if the source line\n\
3139cannot be displayed.\n\
3140If OFF (which is the default), never display the disassembly of the next\n\
3141source line."),
30c33a9f
HZ
3142 NULL,
3143 show_disassemble_next_line,
3144 &setlist, &showlist);
a362e3d3 3145 disassemble_next_line = AUTO_BOOLEAN_FALSE;
e18b2753
JK
3146
3147 add_setshow_enum_cmd ("entry-values", class_stack,
3148 print_entry_values_choices, &print_entry_values,
3149 _("Set printing of function arguments at function "
3150 "entry"),
3151 _("Show printing of function arguments at function "
3152 "entry"),
3153 _("\
3154GDB can sometimes determine the values of function arguments at entry,\n\
3155in addition to their current values. This option tells GDB whether\n\
3156to print the current value, the value at entry (marked as val@entry),\n\
3157or both. Note that one or both of these values may be <optimized out>."),
3158 NULL, NULL, &setprintlist, &showprintlist);
c906108c 3159}
This page took 2.162868 seconds and 4 git commands to generate.