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