1 /* Print and select stack frames for GDB, the GNU debugger.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
31 #include "breakpoint.h"
38 #include "dictionary.h"
39 #include "reggroups.h"
43 #include "gdbthread.h"
44 #include "cp-support.h"
46 #include "inline-frame.h"
48 #include "cli/cli-utils.h"
52 #include "extension.h"
53 #include "observable.h"
54 #include "common/def-vector.h"
55 #include "cli/cli-option.h"
57 /* The possible choices of "set print frame-arguments", and the value
60 const char print_frame_arguments_all
[] = "all";
61 const char print_frame_arguments_scalars
[] = "scalars";
62 const char print_frame_arguments_none
[] = "none";
64 static const char *const print_frame_arguments_choices
[] =
66 print_frame_arguments_all
,
67 print_frame_arguments_scalars
,
68 print_frame_arguments_none
,
72 /* The possible choices of "set print entry-values", and the value
75 const char print_entry_values_no
[] = "no";
76 const char print_entry_values_only
[] = "only";
77 const char print_entry_values_preferred
[] = "preferred";
78 const char print_entry_values_if_needed
[] = "if-needed";
79 const char print_entry_values_both
[] = "both";
80 const char print_entry_values_compact
[] = "compact";
81 const char print_entry_values_default
[] = "default";
82 static const char *const print_entry_values_choices
[] =
84 print_entry_values_no
,
85 print_entry_values_only
,
86 print_entry_values_preferred
,
87 print_entry_values_if_needed
,
88 print_entry_values_both
,
89 print_entry_values_compact
,
90 print_entry_values_default
,
95 frame_print_options user_frame_print_options
;
97 /* Option definitions for some frame-related "set print ..."
100 using boolean_option_def
101 = gdb::option::boolean_option_def
<frame_print_options
>;
102 using enum_option_def
103 = gdb::option::enum_option_def
<frame_print_options
>;
105 static const gdb::option::option_def frame_print_option_defs
[] = {
109 print_entry_values_choices
,
110 [] (frame_print_options
*opt
) { return &opt
->print_entry_values
; },
111 NULL
, /* show_cmd_cb */
112 N_("Set printing of function arguments at function entry"),
113 N_("Show printing of function arguments at function entry"),
114 N_("GDB can sometimes determine the values of function arguments at entry,\n\
115 in addition to their current values. This option tells GDB whether\n\
116 to print the current value, the value at entry (marked as val@entry),\n\
117 or both. Note that one or both of these values may be <optimized out>."),
122 print_frame_arguments_choices
,
123 [] (frame_print_options
*opt
) { return &opt
->print_frame_arguments
; },
124 NULL
, /* show_cmd_cb */
125 N_("Set printing of non-scalar frame arguments"),
126 N_("Show printing of non-scalar frame arguments"),
131 "raw-frame-arguments",
132 [] (frame_print_options
*opt
) { return &opt
->print_raw_frame_arguments
; },
133 NULL
, /* show_cmd_cb */
134 N_("Set whether to print frame arguments in raw form."),
135 N_("Show whether to print frame arguments in raw form."),
136 N_("If set, frame arguments are printed in raw form, bypassing any\n\
137 pretty-printers for that value.")
141 /* Options for the "backtrace" command. */
143 struct backtrace_cmd_options
150 using bt_flag_option_def
151 = gdb::option::flag_option_def
<backtrace_cmd_options
>;
153 static const gdb::option::option_def backtrace_command_option_defs
[] = {
156 [] (backtrace_cmd_options
*opt
) { return &opt
->full
; },
157 N_("Print values of local variables.")
162 [] (backtrace_cmd_options
*opt
) { return &opt
->no_filters
; },
163 N_("Prohibit frame filters from executing on a backtrace."),
168 [] (backtrace_cmd_options
*opt
) { return &opt
->hide
; },
169 N_("Causes Python frame filter elided frames to not be printed."),
173 /* Prototypes for local functions. */
175 static void print_frame_local_vars (struct frame_info
*frame
,
177 const char *regexp
, const char *t_regexp
,
178 int num_tabs
, struct ui_file
*stream
);
180 static void print_frame (const frame_print_options
&opts
,
181 frame_info
*frame
, int print_level
,
182 enum print_what print_what
, int print_args
,
183 struct symtab_and_line sal
);
185 static void set_last_displayed_sal (int valid
,
186 struct program_space
*pspace
,
188 struct symtab
*symtab
,
191 static struct frame_info
*find_frame_for_function (const char *);
192 static struct frame_info
*find_frame_for_address (CORE_ADDR
);
194 /* Zero means do things normally; we are interacting directly with the
195 user. One means print the full filename and linenumber when a
196 frame is printed, and do so in a format emacs18/emacs19.22 can
197 parse. Two means print similar annotations, but in many more
198 cases and in a slightly different syntax. */
200 int annotation_level
= 0;
202 /* These variables hold the last symtab and line we displayed to the user.
203 * This is where we insert a breakpoint or a skiplist entry by default. */
204 static int last_displayed_sal_valid
= 0;
205 static struct program_space
*last_displayed_pspace
= 0;
206 static CORE_ADDR last_displayed_addr
= 0;
207 static struct symtab
*last_displayed_symtab
= 0;
208 static int last_displayed_line
= 0;
211 /* Return 1 if we should display the address in addition to the location,
212 because we are in the middle of a statement. */
215 frame_show_address (struct frame_info
*frame
,
216 struct symtab_and_line sal
)
218 /* If there is a line number, but no PC, then there is no location
219 information associated with this sal. The only way that should
220 happen is for the call sites of inlined functions (SAL comes from
221 find_frame_sal). Otherwise, we would have some PC range if the
222 SAL came from a line table. */
223 if (sal
.line
!= 0 && sal
.pc
== 0 && sal
.end
== 0)
225 if (get_next_frame (frame
) == NULL
)
226 gdb_assert (inline_skipped_frames (inferior_thread ()) > 0);
228 gdb_assert (get_frame_type (get_next_frame (frame
)) == INLINE_FRAME
);
232 return get_frame_pc (frame
) != sal
.pc
;
238 print_stack_frame_to_uiout (struct ui_out
*uiout
, struct frame_info
*frame
,
239 int print_level
, enum print_what print_what
,
242 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
244 print_stack_frame (frame
, print_level
, print_what
, set_current_sal
);
247 /* Show or print a stack frame FRAME briefly. The output is formatted
248 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
249 relative level, function name, argument list, and file name and
250 line number. If the frame's PC is not at the beginning of the
251 source line, the actual PC is printed at the beginning. */
254 print_stack_frame (struct frame_info
*frame
, int print_level
,
255 enum print_what print_what
,
259 /* For mi, alway print location and address. */
260 if (current_uiout
->is_mi_like_p ())
261 print_what
= LOC_AND_ADDRESS
;
265 print_frame_info (user_frame_print_options
,
266 frame
, print_level
, print_what
, 1 /* print_args */,
269 set_current_sal_from_frame (frame
);
271 catch (const gdb_exception_error
&e
)
276 /* Print nameless arguments of frame FRAME on STREAM, where START is
277 the offset of the first nameless argument, and NUM is the number of
278 nameless arguments to print. FIRST is nonzero if this is the first
279 argument (not just the first nameless argument). */
282 print_frame_nameless_args (struct frame_info
*frame
, long start
, int num
,
283 int first
, struct ui_file
*stream
)
285 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
286 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
291 for (i
= 0; i
< num
; i
++)
294 argsaddr
= get_frame_args_address (frame
);
297 arg_value
= read_memory_integer (argsaddr
+ start
,
298 sizeof (int), byte_order
);
300 fprintf_filtered (stream
, ", ");
301 fprintf_filtered (stream
, "%ld", arg_value
);
303 start
+= sizeof (int);
307 /* Print single argument of inferior function. ARG must be already
310 Errors are printed as if they would be the parameter value. Use zeroed ARG
311 iff it should not be printed accoring to user settings. */
314 print_frame_arg (const frame_print_options
&fp_opts
,
315 const struct frame_arg
*arg
)
317 struct ui_out
*uiout
= current_uiout
;
321 gdb_assert (!arg
->val
|| !arg
->error
);
322 gdb_assert (arg
->entry_kind
== print_entry_values_no
323 || arg
->entry_kind
== print_entry_values_only
324 || (!uiout
->is_mi_like_p ()
325 && arg
->entry_kind
== print_entry_values_compact
));
327 annotate_arg_emitter arg_emitter
;
328 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
329 fprintf_symbol_filtered (&stb
, SYMBOL_PRINT_NAME (arg
->sym
),
330 SYMBOL_LANGUAGE (arg
->sym
), DMGL_PARAMS
| DMGL_ANSI
);
331 if (arg
->entry_kind
== print_entry_values_compact
)
333 /* It is OK to provide invalid MI-like stream as with
334 PRINT_ENTRY_VALUE_COMPACT we never use MI. */
337 fprintf_symbol_filtered (&stb
, SYMBOL_PRINT_NAME (arg
->sym
),
338 SYMBOL_LANGUAGE (arg
->sym
),
339 DMGL_PARAMS
| DMGL_ANSI
);
341 if (arg
->entry_kind
== print_entry_values_only
342 || arg
->entry_kind
== print_entry_values_compact
)
344 uiout
->field_stream ("name", stb
, ui_out_style_kind::VARIABLE
);
345 annotate_arg_name_end ();
348 if (!arg
->val
&& !arg
->error
)
353 stb
.printf (_("<error reading variable: %s>"), arg
->error
);
358 const struct language_defn
*language
;
359 struct value_print_options vp_opts
;
361 /* Avoid value_print because it will deref ref parameters. We
362 just want to print their addresses. Print ??? for args whose
363 address we do not know. We pass 2 as "recurse" to val_print
364 because our standard indentation here is 4 spaces, and
365 val_print indents 2 for each recurse. */
367 annotate_arg_value (value_type (arg
->val
));
369 /* Use the appropriate language to display our symbol, unless the
370 user forced the language to a specific language. */
371 if (language_mode
== language_mode_auto
)
372 language
= language_def (SYMBOL_LANGUAGE (arg
->sym
));
374 language
= current_language
;
376 get_no_prettyformat_print_options (&vp_opts
);
377 vp_opts
.deref_ref
= 1;
378 vp_opts
.raw
= fp_opts
.print_raw_frame_arguments
;
380 /* True in "summary" mode, false otherwise. */
382 = fp_opts
.print_frame_arguments
== print_frame_arguments_scalars
;
384 common_val_print (arg
->val
, &stb
, 2, &vp_opts
, language
);
386 catch (const gdb_exception_error
&except
)
388 stb
.printf (_("<error reading variable: %s>"),
394 uiout
->field_stream ("value", stb
);
397 /* Read in inferior function local SYM at FRAME into ARGP. Caller is
398 responsible for xfree of ARGP->ERROR. This function never throws an
402 read_frame_local (struct symbol
*sym
, struct frame_info
*frame
,
403 struct frame_arg
*argp
)
411 argp
->val
= read_var_value (sym
, NULL
, frame
);
413 catch (const gdb_exception_error
&except
)
415 argp
->error
= xstrdup (except
.what ());
419 /* Read in inferior function parameter SYM at FRAME into ARGP. Caller is
420 responsible for xfree of ARGP->ERROR. This function never throws an
424 read_frame_arg (const frame_print_options
&fp_opts
,
425 symbol
*sym
, frame_info
*frame
,
426 struct frame_arg
*argp
, struct frame_arg
*entryargp
)
428 struct value
*val
= NULL
, *entryval
= NULL
;
429 char *val_error
= NULL
, *entryval_error
= NULL
;
432 if (fp_opts
.print_entry_values
!= print_entry_values_only
433 && fp_opts
.print_entry_values
!= print_entry_values_preferred
)
437 val
= read_var_value (sym
, NULL
, frame
);
439 catch (const gdb_exception_error
&except
)
441 val_error
= (char *) alloca (except
.message
->size () + 1);
442 strcpy (val_error
, except
.what ());
446 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
447 && SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
!= NULL
448 && fp_opts
.print_entry_values
!= print_entry_values_no
449 && (fp_opts
.print_entry_values
!= print_entry_values_if_needed
450 || !val
|| value_optimized_out (val
)))
454 const struct symbol_computed_ops
*ops
;
456 ops
= SYMBOL_COMPUTED_OPS (sym
);
457 entryval
= ops
->read_variable_at_entry (sym
, frame
);
459 catch (const gdb_exception_error
&except
)
461 if (except
.error
!= NO_ENTRY_VALUE_ERROR
)
463 entryval_error
= (char *) alloca (except
.message
->size () + 1);
464 strcpy (entryval_error
, except
.what ());
468 if (entryval
!= NULL
&& value_optimized_out (entryval
))
471 if (fp_opts
.print_entry_values
== print_entry_values_compact
472 || fp_opts
.print_entry_values
== print_entry_values_default
)
474 /* For MI do not try to use print_entry_values_compact for ARGP. */
476 if (val
&& entryval
&& !current_uiout
->is_mi_like_p ())
478 struct type
*type
= value_type (val
);
480 if (value_lazy (val
))
481 value_fetch_lazy (val
);
482 if (value_lazy (entryval
))
483 value_fetch_lazy (entryval
);
485 if (value_contents_eq (val
, 0, entryval
, 0, TYPE_LENGTH (type
)))
487 /* Initialize it just to avoid a GCC false warning. */
488 struct value
*val_deref
= NULL
, *entryval_deref
;
490 /* DW_AT_call_value does match with the current
491 value. If it is a reference still try to verify if
492 dereferenced DW_AT_call_data_value does not differ. */
496 struct type
*type_deref
;
498 val_deref
= coerce_ref (val
);
499 if (value_lazy (val_deref
))
500 value_fetch_lazy (val_deref
);
501 type_deref
= value_type (val_deref
);
503 entryval_deref
= coerce_ref (entryval
);
504 if (value_lazy (entryval_deref
))
505 value_fetch_lazy (entryval_deref
);
507 /* If the reference addresses match but dereferenced
508 content does not match print them. */
510 && value_contents_eq (val_deref
, 0,
512 TYPE_LENGTH (type_deref
)))
515 catch (const gdb_exception_error
&except
)
517 /* If the dereferenced content could not be
518 fetched do not display anything. */
519 if (except
.error
== NO_ENTRY_VALUE_ERROR
)
521 else if (except
.message
!= NULL
)
524 = (char *) alloca (except
.message
->size () + 1);
525 strcpy (entryval_error
, except
.what ());
529 /* Value was not a reference; and its content matches. */
530 if (val
== val_deref
)
538 /* Try to remove possibly duplicate error message for ENTRYARGP even
541 if (val_error
&& entryval_error
542 && strcmp (val_error
, entryval_error
) == 0)
544 entryval_error
= NULL
;
546 /* Do not se VAL_EQUAL as the same error message may be shown for
547 the entry value even if no entry values are present in the
553 if (entryval
== NULL
)
555 if (fp_opts
.print_entry_values
== print_entry_values_preferred
)
557 gdb_assert (val
== NULL
);
561 val
= read_var_value (sym
, NULL
, frame
);
563 catch (const gdb_exception_error
&except
)
565 val_error
= (char *) alloca (except
.message
->size () + 1);
566 strcpy (val_error
, except
.what ());
569 if (fp_opts
.print_entry_values
== print_entry_values_only
570 || fp_opts
.print_entry_values
== print_entry_values_both
571 || (fp_opts
.print_entry_values
== print_entry_values_preferred
572 && (!val
|| value_optimized_out (val
))))
574 entryval
= allocate_optimized_out_value (SYMBOL_TYPE (sym
));
575 entryval_error
= NULL
;
578 if ((fp_opts
.print_entry_values
== print_entry_values_compact
579 || fp_opts
.print_entry_values
== print_entry_values_if_needed
580 || fp_opts
.print_entry_values
== print_entry_values_preferred
)
581 && (!val
|| value_optimized_out (val
)) && entryval
!= NULL
)
589 argp
->error
= val_error
? xstrdup (val_error
) : NULL
;
590 if (!val
&& !val_error
)
591 argp
->entry_kind
= print_entry_values_only
;
592 else if ((fp_opts
.print_entry_values
== print_entry_values_compact
593 || fp_opts
.print_entry_values
== print_entry_values_default
)
596 argp
->entry_kind
= print_entry_values_compact
;
597 gdb_assert (!current_uiout
->is_mi_like_p ());
600 argp
->entry_kind
= print_entry_values_no
;
602 entryargp
->sym
= sym
;
603 entryargp
->val
= entryval
;
604 entryargp
->error
= entryval_error
? xstrdup (entryval_error
) : NULL
;
605 if (!entryval
&& !entryval_error
)
606 entryargp
->entry_kind
= print_entry_values_no
;
608 entryargp
->entry_kind
= print_entry_values_only
;
611 /* Print the arguments of frame FRAME on STREAM, given the function
612 FUNC running in that frame (as a symbol), where NUM is the number
613 of arguments according to the stack frame (or -1 if the number of
614 arguments is unknown). */
616 /* Note that currently the "number of arguments according to the
617 stack frame" is only known on VAX where i refers to the "number of
618 ints of arguments according to the stack frame". */
621 print_frame_args (const frame_print_options
&fp_opts
,
622 struct symbol
*func
, struct frame_info
*frame
,
623 int num
, struct ui_file
*stream
)
625 struct ui_out
*uiout
= current_uiout
;
627 /* Offset of next stack argument beyond the one we have seen that is
628 at the highest offset, or -1 if we haven't come to a stack
630 long highest_offset
= -1;
631 /* Number of ints of arguments that we have printed so far. */
632 int args_printed
= 0;
633 /* True if we should print arguments, false otherwise. */
635 = fp_opts
.print_frame_arguments
!= print_frame_arguments_none
;
639 const struct block
*b
= SYMBOL_BLOCK_VALUE (func
);
640 struct block_iterator iter
;
643 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
645 struct frame_arg arg
, entryarg
;
649 /* Keep track of the highest stack argument offset seen, and
650 skip over any kinds of symbols we don't care about. */
652 if (!SYMBOL_IS_ARGUMENT (sym
))
655 switch (SYMBOL_CLASS (sym
))
660 long current_offset
= SYMBOL_VALUE (sym
);
661 int arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
663 /* Compute address of next argument by adding the size of
664 this argument and rounding to an int boundary. */
666 ((current_offset
+ arg_size
+ sizeof (int) - 1)
667 & ~(sizeof (int) - 1));
669 /* If this is the highest offset seen yet, set
671 if (highest_offset
== -1
672 || (current_offset
> highest_offset
))
673 highest_offset
= current_offset
;
675 /* Add the number of ints we're about to print to
677 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
680 /* We care about types of symbols, but don't need to
681 keep track of stack offsets in them. */
683 case LOC_REGPARM_ADDR
:
685 case LOC_OPTIMIZED_OUT
:
690 /* We have to look up the symbol because arguments can have
691 two entries (one a parameter, one a local) and the one we
692 want is the local, which lookup_symbol will find for us.
693 This includes gcc1 (not gcc2) on SPARC when passing a
694 small structure and gcc2 when the argument type is float
695 and it is passed as a double and converted to float by
696 the prologue (in the latter case the type of the LOC_ARG
697 symbol is double and the type of the LOC_LOCAL symbol is
699 /* But if the parameter name is null, don't try it. Null
700 parameter names occur on the RS/6000, for traceback
701 tables. FIXME, should we even print them? */
703 if (*SYMBOL_LINKAGE_NAME (sym
))
707 nsym
= lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym
),
708 b
, VAR_DOMAIN
).symbol
;
709 gdb_assert (nsym
!= NULL
);
710 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
711 && !SYMBOL_IS_ARGUMENT (nsym
))
713 /* There is a LOC_ARG/LOC_REGISTER pair. This means
714 that it was passed on the stack and loaded into a
715 register, or passed in a register and stored in a
716 stack slot. GDB 3.x used the LOC_ARG; GDB
717 4.0-4.11 used the LOC_REGISTER.
719 Reasons for using the LOC_ARG:
721 (1) Because find_saved_registers may be slow for
724 (2) Because registers are often re-used and stack
725 slots rarely (never?) are. Therefore using
726 the stack slot is much less likely to print
729 Reasons why we might want to use the LOC_REGISTER:
731 (1) So that the backtrace prints the same value
732 as "print foo". I see no compelling reason
733 why this needs to be the case; having the
734 backtrace print the value which was passed
735 in, and "print foo" print the value as
736 modified within the called function, makes
739 Additional note: It might be nice if "info args"
740 displayed both values.
742 One more note: There is a case with SPARC
743 structure passing where we need to use the
744 LOC_REGISTER, but this is dealt with by creating
745 a single LOC_REGPARM in symbol reading. */
747 /* Leave sym (the LOC_ARG) alone. */
754 /* Print the current arg. */
757 uiout
->wrap_hint (" ");
761 memset (&arg
, 0, sizeof (arg
));
763 arg
.entry_kind
= print_entry_values_no
;
764 memset (&entryarg
, 0, sizeof (entryarg
));
766 entryarg
.entry_kind
= print_entry_values_no
;
769 read_frame_arg (fp_opts
, sym
, frame
, &arg
, &entryarg
);
771 if (arg
.entry_kind
!= print_entry_values_only
)
772 print_frame_arg (fp_opts
, &arg
);
774 if (entryarg
.entry_kind
!= print_entry_values_no
)
776 if (arg
.entry_kind
!= print_entry_values_only
)
779 uiout
->wrap_hint (" ");
782 print_frame_arg (fp_opts
, &entryarg
);
786 xfree (entryarg
.error
);
792 /* Don't print nameless args in situations where we don't know
793 enough about the stack to find them. */
798 if (highest_offset
== -1)
799 start
= gdbarch_frame_args_skip (get_frame_arch (frame
));
801 start
= highest_offset
;
803 print_frame_nameless_args (frame
, start
, num
- args_printed
,
808 /* Set the current source and line to the location given by frame
809 FRAME, if possible. When CENTER is true, adjust so the relevant
810 line is in the center of the next 'list'. */
813 set_current_sal_from_frame (struct frame_info
*frame
)
815 symtab_and_line sal
= find_frame_sal (frame
);
816 if (sal
.symtab
!= NULL
)
817 set_current_source_symtab_and_line (sal
);
820 /* If ON, GDB will display disassembly of the next source line when
821 execution of the program being debugged stops.
822 If AUTO (which is the default), or there's no line info to determine
823 the source line of the next instruction, display disassembly of next
824 instruction instead. */
826 static enum auto_boolean disassemble_next_line
;
829 show_disassemble_next_line (struct ui_file
*file
, int from_tty
,
830 struct cmd_list_element
*c
,
833 fprintf_filtered (file
,
834 _("Debugger's willingness to use "
835 "disassemble-next-line is %s.\n"),
839 /* Use TRY_CATCH to catch the exception from the gdb_disassembly
840 because it will be broken by filter sometime. */
843 do_gdb_disassembly (struct gdbarch
*gdbarch
,
844 int how_many
, CORE_ADDR low
, CORE_ADDR high
)
849 gdb_disassembly (gdbarch
, current_uiout
,
850 DISASSEMBLY_RAW_INSN
, how_many
,
853 catch (const gdb_exception_error
&exception
)
855 /* If an exception was thrown while doing the disassembly, print
856 the error message, to give the user a clue of what happened. */
857 exception_print (gdb_stderr
, exception
);
861 /* Print information about frame FRAME. The output is format according
862 to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. The meaning of
865 SRC_LINE: Print only source line.
866 LOCATION: Print only location.
867 SRC_AND_LOC: Print location and source line.
869 Used in "where" output, and to emit breakpoint or step
873 print_frame_info (const frame_print_options
&fp_opts
,
874 frame_info
*frame
, int print_level
,
875 enum print_what print_what
, int print_args
,
878 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
881 struct ui_out
*uiout
= current_uiout
;
883 if (get_frame_type (frame
) == DUMMY_FRAME
884 || get_frame_type (frame
) == SIGTRAMP_FRAME
885 || get_frame_type (frame
) == ARCH_FRAME
)
887 ui_out_emit_tuple
tuple_emitter (uiout
, "frame");
889 annotate_frame_begin (print_level
? frame_relative_level (frame
) : 0,
890 gdbarch
, get_frame_pc (frame
));
892 /* Do this regardless of SOURCE because we don't have any source
893 to list for this frame. */
897 uiout
->field_fmt_int (2, ui_left
, "level",
898 frame_relative_level (frame
));
900 if (uiout
->is_mi_like_p ())
902 annotate_frame_address ();
903 uiout
->field_core_addr ("addr",
904 gdbarch
, get_frame_pc (frame
));
905 annotate_frame_address_end ();
908 if (get_frame_type (frame
) == DUMMY_FRAME
)
910 annotate_function_call ();
911 uiout
->field_string ("func", "<function called from gdb>",
912 ui_out_style_kind::FUNCTION
);
914 else if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
916 annotate_signal_handler_caller ();
917 uiout
->field_string ("func", "<signal handler called>",
918 ui_out_style_kind::FUNCTION
);
920 else if (get_frame_type (frame
) == ARCH_FRAME
)
922 uiout
->field_string ("func", "<cross-architecture call>",
923 ui_out_style_kind::FUNCTION
);
926 annotate_frame_end ();
928 /* If disassemble-next-line is set to auto or on output the next
930 if (disassemble_next_line
== AUTO_BOOLEAN_AUTO
931 || disassemble_next_line
== AUTO_BOOLEAN_TRUE
)
932 do_gdb_disassembly (get_frame_arch (frame
), 1,
933 get_frame_pc (frame
), get_frame_pc (frame
) + 1);
938 /* If FRAME is not the innermost frame, that normally means that
939 FRAME->pc points to *after* the call instruction, and we want to
940 get the line containing the call, never the next line. But if
941 the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
942 next frame was not entered as the result of a call, and we want
943 to get the line containing FRAME->pc. */
944 symtab_and_line sal
= find_frame_sal (frame
);
946 location_print
= (print_what
== LOCATION
947 || print_what
== LOC_AND_ADDRESS
948 || print_what
== SRC_AND_LOC
);
950 if (location_print
|| !sal
.symtab
)
951 print_frame (fp_opts
, frame
, print_level
, print_what
, print_args
, sal
);
953 source_print
= (print_what
== SRC_LINE
|| print_what
== SRC_AND_LOC
);
955 /* If disassemble-next-line is set to auto or on and doesn't have
956 the line debug messages for $pc, output the next instruction. */
957 if ((disassemble_next_line
== AUTO_BOOLEAN_AUTO
958 || disassemble_next_line
== AUTO_BOOLEAN_TRUE
)
959 && source_print
&& !sal
.symtab
)
960 do_gdb_disassembly (get_frame_arch (frame
), 1,
961 get_frame_pc (frame
), get_frame_pc (frame
) + 1);
963 if (source_print
&& sal
.symtab
)
966 int mid_statement
= ((print_what
== SRC_LINE
)
967 && frame_show_address (frame
, sal
));
969 if (annotation_level
)
970 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
971 get_frame_pc (frame
));
974 if (deprecated_print_frame_info_listing_hook
)
975 deprecated_print_frame_info_listing_hook (sal
.symtab
,
980 struct value_print_options opts
;
982 get_user_print_options (&opts
);
983 /* We used to do this earlier, but that is clearly
984 wrong. This function is used by many different
985 parts of gdb, including normal_stop in infrun.c,
986 which uses this to print out the current PC
987 when we stepi/nexti into the middle of a source
988 line. Only the command line really wants this
989 behavior. Other UIs probably would like the
990 ability to decide for themselves if it is desired. */
991 if (opts
.addressprint
&& mid_statement
)
993 uiout
->field_core_addr ("addr",
994 gdbarch
, get_frame_pc (frame
));
998 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
1002 /* If disassemble-next-line is set to on and there is line debug
1003 messages, output assembly codes for next line. */
1004 if (disassemble_next_line
== AUTO_BOOLEAN_TRUE
)
1005 do_gdb_disassembly (get_frame_arch (frame
), -1, sal
.pc
, sal
.end
);
1008 if (set_current_sal
)
1012 if (get_frame_pc_if_available (frame
, &pc
))
1013 set_last_displayed_sal (1, sal
.pspace
, pc
, sal
.symtab
, sal
.line
);
1015 set_last_displayed_sal (0, 0, 0, 0, 0);
1018 annotate_frame_end ();
1020 gdb_flush (gdb_stdout
);
1023 /* Remember the last symtab and line we displayed, which we use e.g.
1024 * as the place to put a breakpoint when the `break' command is
1025 * invoked with no arguments. */
1028 set_last_displayed_sal (int valid
, struct program_space
*pspace
,
1029 CORE_ADDR addr
, struct symtab
*symtab
,
1032 last_displayed_sal_valid
= valid
;
1033 last_displayed_pspace
= pspace
;
1034 last_displayed_addr
= addr
;
1035 last_displayed_symtab
= symtab
;
1036 last_displayed_line
= line
;
1037 if (valid
&& pspace
== NULL
)
1039 clear_last_displayed_sal ();
1040 internal_error (__FILE__
, __LINE__
,
1041 _("Trying to set NULL pspace."));
1045 /* Forget the last sal we displayed. */
1048 clear_last_displayed_sal (void)
1050 last_displayed_sal_valid
= 0;
1051 last_displayed_pspace
= 0;
1052 last_displayed_addr
= 0;
1053 last_displayed_symtab
= 0;
1054 last_displayed_line
= 0;
1057 /* Is our record of the last sal we displayed valid? If not,
1058 * the get_last_displayed_* functions will return NULL or 0, as
1062 last_displayed_sal_is_valid (void)
1064 return last_displayed_sal_valid
;
1067 /* Get the pspace of the last sal we displayed, if it's valid. */
1069 struct program_space
*
1070 get_last_displayed_pspace (void)
1072 if (last_displayed_sal_valid
)
1073 return last_displayed_pspace
;
1077 /* Get the address of the last sal we displayed, if it's valid. */
1080 get_last_displayed_addr (void)
1082 if (last_displayed_sal_valid
)
1083 return last_displayed_addr
;
1087 /* Get the symtab of the last sal we displayed, if it's valid. */
1090 get_last_displayed_symtab (void)
1092 if (last_displayed_sal_valid
)
1093 return last_displayed_symtab
;
1097 /* Get the line of the last sal we displayed, if it's valid. */
1100 get_last_displayed_line (void)
1102 if (last_displayed_sal_valid
)
1103 return last_displayed_line
;
1107 /* Get the last sal we displayed, if it's valid. */
1110 get_last_displayed_sal ()
1112 symtab_and_line sal
;
1114 if (last_displayed_sal_valid
)
1116 sal
.pspace
= last_displayed_pspace
;
1117 sal
.pc
= last_displayed_addr
;
1118 sal
.symtab
= last_displayed_symtab
;
1119 sal
.line
= last_displayed_line
;
1126 /* Attempt to obtain the name, FUNLANG and optionally FUNCP of the function
1127 corresponding to FRAME. */
1129 gdb::unique_xmalloc_ptr
<char>
1130 find_frame_funname (struct frame_info
*frame
, enum language
*funlang
,
1131 struct symbol
**funcp
)
1133 struct symbol
*func
;
1134 gdb::unique_xmalloc_ptr
<char> funname
;
1136 *funlang
= language_unknown
;
1140 func
= get_frame_function (frame
);
1143 /* In certain pathological cases, the symtabs give the wrong
1144 function (when we are in the first function in a file which
1145 is compiled without debugging symbols, the previous function
1146 is compiled with debugging symbols, and the "foo.o" symbol
1147 that is supposed to tell us where the file with debugging
1148 symbols ends has been truncated by ar because it is longer
1149 than 15 characters). This also occurs if the user uses asm()
1150 to create a function but not stabs for it (in a file compiled
1153 So look in the minimal symbol tables as well, and if it comes
1154 up with a larger address for the function use that instead.
1155 I don't think this can ever cause any problems; there
1156 shouldn't be any minimal symbols in the middle of a function;
1157 if this is ever changed many parts of GDB will need to be
1158 changed (and we'll create a find_pc_minimal_function or some
1161 struct bound_minimal_symbol msymbol
;
1163 /* Don't attempt to do this for inlined functions, which do not
1164 have a corresponding minimal symbol. */
1165 if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func
)))
1167 = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame
));
1169 memset (&msymbol
, 0, sizeof (msymbol
));
1171 if (msymbol
.minsym
!= NULL
1172 && (BMSYMBOL_VALUE_ADDRESS (msymbol
)
1173 > BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func
))))
1175 /* We also don't know anything about the function besides
1176 its address and name. */
1178 funname
.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol
.minsym
)));
1179 *funlang
= MSYMBOL_LANGUAGE (msymbol
.minsym
);
1183 const char *print_name
= SYMBOL_PRINT_NAME (func
);
1185 *funlang
= SYMBOL_LANGUAGE (func
);
1188 if (*funlang
== language_cplus
)
1190 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
1191 to display the demangled name that we already have
1192 stored in the symbol table, but we stored a version
1193 with DMGL_PARAMS turned on, and here we don't want to
1194 display parameters. So remove the parameters. */
1195 funname
= cp_remove_params (print_name
);
1198 /* If we didn't hit the C++ case above, set *funname
1200 if (funname
== NULL
)
1201 funname
.reset (xstrdup (print_name
));
1206 struct bound_minimal_symbol msymbol
;
1209 if (!get_frame_address_in_block_if_available (frame
, &pc
))
1212 msymbol
= lookup_minimal_symbol_by_pc (pc
);
1213 if (msymbol
.minsym
!= NULL
)
1215 funname
.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol
.minsym
)));
1216 *funlang
= MSYMBOL_LANGUAGE (msymbol
.minsym
);
1224 print_frame (const frame_print_options
&fp_opts
,
1225 frame_info
*frame
, int print_level
,
1226 enum print_what print_what
, int print_args
,
1227 struct symtab_and_line sal
)
1229 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1230 struct ui_out
*uiout
= current_uiout
;
1231 enum language funlang
= language_unknown
;
1232 struct value_print_options opts
;
1233 struct symbol
*func
;
1237 pc_p
= get_frame_pc_if_available (frame
, &pc
);
1239 gdb::unique_xmalloc_ptr
<char> funname
1240 = find_frame_funname (frame
, &funlang
, &func
);
1242 annotate_frame_begin (print_level
? frame_relative_level (frame
) : 0,
1246 ui_out_emit_tuple
tuple_emitter (uiout
, "frame");
1251 uiout
->field_fmt_int (2, ui_left
, "level",
1252 frame_relative_level (frame
));
1254 get_user_print_options (&opts
);
1255 if (opts
.addressprint
)
1257 || frame_show_address (frame
, sal
)
1258 || print_what
== LOC_AND_ADDRESS
)
1260 annotate_frame_address ();
1262 uiout
->field_core_addr ("addr", gdbarch
, pc
);
1264 uiout
->field_string ("addr", "<unavailable>",
1265 ui_out_style_kind::ADDRESS
);
1266 annotate_frame_address_end ();
1267 uiout
->text (" in ");
1269 annotate_frame_function_name ();
1272 fprintf_symbol_filtered (&stb
, funname
? funname
.get () : "??",
1273 funlang
, DMGL_ANSI
);
1274 uiout
->field_stream ("func", stb
, ui_out_style_kind::FUNCTION
);
1275 uiout
->wrap_hint (" ");
1276 annotate_frame_args ();
1283 if (gdbarch_frame_num_args_p (gdbarch
))
1285 numargs
= gdbarch_frame_num_args (gdbarch
, frame
);
1286 gdb_assert (numargs
>= 0);
1292 ui_out_emit_list
list_emitter (uiout
, "args");
1295 print_frame_args (fp_opts
, func
, frame
, numargs
, gdb_stdout
);
1297 catch (const gdb_exception_error
&e
)
1301 /* FIXME: ARGS must be a list. If one argument is a string it
1302 will have " that will not be properly escaped. */
1309 const char *filename_display
;
1311 filename_display
= symtab_to_filename_for_display (sal
.symtab
);
1312 annotate_frame_source_begin ();
1313 uiout
->wrap_hint (" ");
1314 uiout
->text (" at ");
1315 annotate_frame_source_file ();
1316 uiout
->field_string ("file", filename_display
, ui_out_style_kind::FILE);
1317 if (uiout
->is_mi_like_p ())
1319 const char *fullname
= symtab_to_fullname (sal
.symtab
);
1321 uiout
->field_string ("fullname", fullname
);
1323 annotate_frame_source_file_end ();
1325 annotate_frame_source_line ();
1326 uiout
->field_int ("line", sal
.line
);
1327 annotate_frame_source_end ();
1330 if (pc_p
&& (funname
== NULL
|| sal
.symtab
== NULL
))
1332 char *lib
= solib_name_from_address (get_frame_program_space (frame
),
1333 get_frame_pc (frame
));
1337 annotate_frame_where ();
1338 uiout
->wrap_hint (" ");
1339 uiout
->text (" from ");
1340 uiout
->field_string ("from", lib
);
1343 if (uiout
->is_mi_like_p ())
1344 uiout
->field_string ("arch",
1345 (gdbarch_bfd_arch_info (gdbarch
))->printable_name
);
1352 /* Completion function for "frame function", "info frame function", and
1353 "select-frame function" commands. */
1356 frame_selection_by_function_completer (struct cmd_list_element
*ignore
,
1357 completion_tracker
&tracker
,
1358 const char *text
, const char *word
)
1360 /* This is used to complete function names within a stack. It would be
1361 nice if we only offered functions that were actually in the stack.
1362 However, this would mean unwinding the stack to completion, which
1363 could take too long, or on a corrupted stack, possibly not end.
1364 Instead, we offer all symbol names as a safer choice. */
1365 collect_symbol_completion_matches (tracker
,
1366 complete_symbol_mode::EXPRESSION
,
1367 symbol_name_match_type::EXPRESSION
,
1371 /* Core of all the "info frame" sub-commands. Print information about a
1372 frame FI. If SELECTED_FRAME_P is true then the user didn't provide a
1373 frame specification, they just entered 'info frame'. If the user did
1374 provide a frame specification (for example 'info frame 0', 'info frame
1375 level 1') then SELECTED_FRAME_P will be false. */
1378 info_frame_command_core (struct frame_info
*fi
, bool selected_frame_p
)
1380 struct symbol
*func
;
1382 struct frame_info
*calling_frame_info
;
1384 const char *funname
= 0;
1385 enum language funlang
= language_unknown
;
1386 const char *pc_regname
;
1387 struct gdbarch
*gdbarch
;
1390 /* Initialize it to avoid "may be used uninitialized" warning. */
1391 CORE_ADDR caller_pc
= 0;
1392 int caller_pc_p
= 0;
1394 gdbarch
= get_frame_arch (fi
);
1396 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
1397 is not a good name. */
1398 if (gdbarch_pc_regnum (gdbarch
) >= 0)
1399 /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can
1400 easily not match that of the internal value returned by
1402 pc_regname
= gdbarch_register_name (gdbarch
, gdbarch_pc_regnum (gdbarch
));
1404 /* But then, this is weird to. Even without gdbarch_pc_regnum, an
1405 architectures will often have a hardware register called "pc",
1406 and that register's value, again, can easily not match
1410 frame_pc_p
= get_frame_pc_if_available (fi
, &frame_pc
);
1411 func
= get_frame_function (fi
);
1412 symtab_and_line sal
= find_frame_sal (fi
);
1414 gdb::unique_xmalloc_ptr
<char> func_only
;
1417 funname
= SYMBOL_PRINT_NAME (func
);
1418 funlang
= SYMBOL_LANGUAGE (func
);
1419 if (funlang
== language_cplus
)
1421 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
1422 to display the demangled name that we already have
1423 stored in the symbol table, but we stored a version
1424 with DMGL_PARAMS turned on, and here we don't want to
1425 display parameters. So remove the parameters. */
1426 func_only
= cp_remove_params (funname
);
1429 funname
= func_only
.get ();
1432 else if (frame_pc_p
)
1434 struct bound_minimal_symbol msymbol
;
1436 msymbol
= lookup_minimal_symbol_by_pc (frame_pc
);
1437 if (msymbol
.minsym
!= NULL
)
1439 funname
= MSYMBOL_PRINT_NAME (msymbol
.minsym
);
1440 funlang
= MSYMBOL_LANGUAGE (msymbol
.minsym
);
1443 calling_frame_info
= get_prev_frame (fi
);
1445 if (selected_frame_p
&& frame_relative_level (fi
) >= 0)
1447 printf_filtered (_("Stack level %d, frame at "),
1448 frame_relative_level (fi
));
1452 printf_filtered (_("Stack frame at "));
1454 fputs_filtered (paddress (gdbarch
, get_frame_base (fi
)), gdb_stdout
);
1455 printf_filtered (":\n");
1456 printf_filtered (" %s = ", pc_regname
);
1458 fputs_filtered (paddress (gdbarch
, get_frame_pc (fi
)), gdb_stdout
);
1460 fputs_filtered ("<unavailable>", gdb_stdout
);
1465 printf_filtered (" in ");
1466 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
1467 DMGL_ANSI
| DMGL_PARAMS
);
1471 printf_filtered (" (%s:%d)", symtab_to_filename_for_display (sal
.symtab
),
1473 puts_filtered ("; ");
1475 printf_filtered ("saved %s = ", pc_regname
);
1477 if (!frame_id_p (frame_unwind_caller_id (fi
)))
1478 val_print_not_saved (gdb_stdout
);
1483 caller_pc
= frame_unwind_caller_pc (fi
);
1486 catch (const gdb_exception_error
&ex
)
1490 case NOT_AVAILABLE_ERROR
:
1491 val_print_unavailable (gdb_stdout
);
1493 case OPTIMIZED_OUT_ERROR
:
1494 val_print_not_saved (gdb_stdout
);
1497 fprintf_filtered (gdb_stdout
, _("<error: %s>"),
1505 fputs_filtered (paddress (gdbarch
, caller_pc
), gdb_stdout
);
1506 printf_filtered ("\n");
1508 if (calling_frame_info
== NULL
)
1510 enum unwind_stop_reason reason
;
1512 reason
= get_frame_unwind_stop_reason (fi
);
1513 if (reason
!= UNWIND_NO_REASON
)
1514 printf_filtered (_(" Outermost frame: %s\n"),
1515 frame_stop_reason_string (fi
));
1517 else if (get_frame_type (fi
) == TAILCALL_FRAME
)
1518 puts_filtered (" tail call frame");
1519 else if (get_frame_type (fi
) == INLINE_FRAME
)
1520 printf_filtered (" inlined into frame %d",
1521 frame_relative_level (get_prev_frame (fi
)));
1524 printf_filtered (" called by frame at ");
1525 fputs_filtered (paddress (gdbarch
, get_frame_base (calling_frame_info
)),
1528 if (get_next_frame (fi
) && calling_frame_info
)
1529 puts_filtered (",");
1531 if (get_next_frame (fi
))
1533 printf_filtered (" caller of frame at ");
1534 fputs_filtered (paddress (gdbarch
, get_frame_base (get_next_frame (fi
))),
1537 if (get_next_frame (fi
) || calling_frame_info
)
1538 puts_filtered ("\n");
1541 printf_filtered (" source language %s.\n",
1542 language_str (s
->language
));
1545 /* Address of the argument list for this frame, or 0. */
1546 CORE_ADDR arg_list
= get_frame_args_address (fi
);
1547 /* Number of args for this frame, or -1 if unknown. */
1551 printf_filtered (" Arglist at unknown address.\n");
1554 printf_filtered (" Arglist at ");
1555 fputs_filtered (paddress (gdbarch
, arg_list
), gdb_stdout
);
1556 printf_filtered (",");
1558 if (!gdbarch_frame_num_args_p (gdbarch
))
1561 puts_filtered (" args: ");
1565 numargs
= gdbarch_frame_num_args (gdbarch
, fi
);
1566 gdb_assert (numargs
>= 0);
1568 puts_filtered (" no args.");
1569 else if (numargs
== 1)
1570 puts_filtered (" 1 arg: ");
1572 printf_filtered (" %d args: ", numargs
);
1574 print_frame_args (user_frame_print_options
,
1575 func
, fi
, numargs
, gdb_stdout
);
1576 puts_filtered ("\n");
1580 /* Address of the local variables for this frame, or 0. */
1581 CORE_ADDR arg_list
= get_frame_locals_address (fi
);
1584 printf_filtered (" Locals at unknown address,");
1587 printf_filtered (" Locals at ");
1588 fputs_filtered (paddress (gdbarch
, arg_list
), gdb_stdout
);
1589 printf_filtered (",");
1593 /* Print as much information as possible on the location of all the
1599 int sp_regnum
= gdbarch_sp_regnum (gdbarch
);
1601 /* The sp is special; what's displayed isn't the save address, but
1602 the value of the previous frame's sp. This is a legacy thing,
1603 at one stage the frame cached the previous frame's SP instead
1604 of its address, hence it was easiest to just display the cached
1608 struct value
*value
= frame_unwind_register_value (fi
, sp_regnum
);
1609 gdb_assert (value
!= NULL
);
1611 if (!value_optimized_out (value
) && value_entirely_available (value
))
1613 if (VALUE_LVAL (value
) == not_lval
)
1616 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1617 int sp_size
= register_size (gdbarch
, sp_regnum
);
1619 sp
= extract_unsigned_integer (value_contents_all (value
),
1620 sp_size
, byte_order
);
1622 printf_filtered (" Previous frame's sp is ");
1623 fputs_filtered (paddress (gdbarch
, sp
), gdb_stdout
);
1624 printf_filtered ("\n");
1626 else if (VALUE_LVAL (value
) == lval_memory
)
1628 printf_filtered (" Previous frame's sp at ");
1629 fputs_filtered (paddress (gdbarch
, value_address (value
)),
1631 printf_filtered ("\n");
1633 else if (VALUE_LVAL (value
) == lval_register
)
1635 printf_filtered (" Previous frame's sp in %s\n",
1636 gdbarch_register_name (gdbarch
,
1637 VALUE_REGNUM (value
)));
1640 release_value (value
);
1643 /* else keep quiet. */
1647 numregs
= gdbarch_num_cooked_regs (gdbarch
);
1648 for (i
= 0; i
< numregs
; i
++)
1650 && gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1652 enum lval_type lval
;
1658 /* Find out the location of the saved register without
1659 fetching the corresponding value. */
1660 frame_register_unwind (fi
, i
, &optimized
, &unavailable
,
1661 &lval
, &addr
, &realnum
, NULL
);
1662 /* For moment, only display registers that were saved on the
1664 if (!optimized
&& !unavailable
&& lval
== lval_memory
)
1667 puts_filtered (" Saved registers:\n ");
1669 puts_filtered (",");
1671 printf_filtered (" %s at ",
1672 gdbarch_register_name (gdbarch
, i
));
1673 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1677 if (count
|| need_nl
)
1678 puts_filtered ("\n");
1682 /* Return the innermost frame at level LEVEL. */
1684 static struct frame_info
*
1685 leading_innermost_frame (int level
)
1687 struct frame_info
*leading
;
1689 leading
= get_current_frame ();
1691 gdb_assert (level
>= 0);
1693 while (leading
!= nullptr && level
)
1696 leading
= get_prev_frame (leading
);
1703 /* Return the starting frame needed to handle COUNT outermost frames. */
1705 static struct frame_info
*
1706 trailing_outermost_frame (int count
)
1708 struct frame_info
*current
;
1709 struct frame_info
*trailing
;
1711 trailing
= get_current_frame ();
1713 gdb_assert (count
> 0);
1716 while (current
!= nullptr && count
--)
1719 current
= get_prev_frame (current
);
1722 /* Will stop when CURRENT reaches the top of the stack.
1723 TRAILING will be COUNT below it. */
1724 while (current
!= nullptr)
1727 trailing
= get_prev_frame (trailing
);
1728 current
= get_prev_frame (current
);
1734 /* The core of all the "select-frame" sub-commands. Just wraps a call to
1738 select_frame_command_core (struct frame_info
*fi
, bool ignored
)
1740 struct frame_info
*prev_frame
= get_selected_frame_if_set ();
1742 if (get_selected_frame_if_set () != prev_frame
)
1743 gdb::observers::user_selected_context_changed
.notify (USER_SELECTED_FRAME
);
1749 select_frame_for_mi (struct frame_info
*fi
)
1751 select_frame_command_core (fi
, false /* Ignored. */);
1754 /* The core of all the "frame" sub-commands. Select frame FI, and if this
1755 means we change frame send out a change notification (otherwise, just
1756 reprint the current frame summary). */
1759 frame_command_core (struct frame_info
*fi
, bool ignored
)
1761 struct frame_info
*prev_frame
= get_selected_frame_if_set ();
1764 if (get_selected_frame_if_set () != prev_frame
)
1765 gdb::observers::user_selected_context_changed
.notify (USER_SELECTED_FRAME
);
1767 print_selected_thread_frame (current_uiout
, USER_SELECTED_FRAME
);
1770 /* The three commands 'frame', 'select-frame', and 'info frame' all have a
1771 common set of sub-commands that allow a specific frame to be selected.
1772 All of the sub-command functions are static methods within this class
1773 template which is then instantiated below. The template parameter is a
1774 callback used to implement the functionality of the base command
1775 ('frame', 'select-frame', or 'info frame').
1777 In the template parameter FI is the frame being selected. The
1778 SELECTED_FRAME_P flag is true if the frame being selected was done by
1779 default, which happens when the user uses the base command with no
1780 arguments. For example the commands 'info frame', 'select-frame',
1781 'frame' will all cause SELECTED_FRAME_P to be true. In all other cases
1782 SELECTED_FRAME_P is false. */
1784 template <void (*FPTR
) (struct frame_info
*fi
, bool selected_frame_p
)>
1785 class frame_command_helper
1789 /* The "frame level" family of commands. The ARG is an integer that is
1790 the frame's level in the stack. */
1792 level (const char *arg
, int from_tty
)
1794 int level
= value_as_long (parse_and_eval (arg
));
1795 struct frame_info
*fid
1796 = find_relative_frame (get_current_frame (), &level
);
1798 error (_("No frame at level %s."), arg
);
1802 /* The "frame address" family of commands. ARG is a stack-pointer
1803 address for an existing frame. This command does not allow new
1804 frames to be created. */
1807 address (const char *arg
, int from_tty
)
1809 CORE_ADDR addr
= value_as_address (parse_and_eval (arg
));
1810 struct frame_info
*fid
= find_frame_for_address (addr
);
1812 error (_("No frame at address %s."), arg
);
1816 /* The "frame view" family of commands. ARG is one or two addresses and
1817 is used to view a frame that might be outside the current backtrace.
1818 The addresses are stack-pointer address, and (optional) pc-address. */
1821 view (const char *args
, int from_tty
)
1823 struct frame_info
*fid
;
1826 error (_("Missing address argument to view a frame"));
1828 gdb_argv
argv (args
);
1830 if (argv
.count () == 2)
1834 addr
[0] = value_as_address (parse_and_eval (argv
[0]));
1835 addr
[1] = value_as_address (parse_and_eval (argv
[1]));
1836 fid
= create_new_frame (addr
[0], addr
[1]);
1840 CORE_ADDR addr
= value_as_address (parse_and_eval (argv
[0]));
1841 fid
= create_new_frame (addr
, false);
1846 /* The "frame function" family of commands. ARG is the name of a
1847 function within the stack, the first function (searching from frame
1848 0) with that name will be selected. */
1851 function (const char *arg
, int from_tty
)
1854 error (_("Missing function name argument"));
1855 struct frame_info
*fid
= find_frame_for_function (arg
);
1857 error (_("No frame for function \"%s\"."), arg
);
1861 /* The "frame" base command, that is, when no sub-command is specified.
1862 If one argument is provided then we assume that this is a frame's
1863 level as historically, this was the supported command syntax that was
1866 If no argument is provided, then the current frame is selected. */
1869 base_command (const char *arg
, int from_tty
)
1872 FPTR (get_selected_frame (_("No stack.")), true);
1874 level (arg
, from_tty
);
1878 /* Instantiate three FRAME_COMMAND_HELPER instances to implement the
1879 sub-commands for 'info frame', 'frame', and 'select-frame' commands. */
1881 static frame_command_helper
<info_frame_command_core
> info_frame_cmd
;
1882 static frame_command_helper
<frame_command_core
> frame_cmd
;
1883 static frame_command_helper
<select_frame_command_core
> select_frame_cmd
;
1885 /* Print briefly all stack frames or just the innermost COUNT_EXP
1889 backtrace_command_1 (const frame_print_options
&fp_opts
,
1890 const backtrace_cmd_options
&bt_opts
,
1891 const char *count_exp
, int from_tty
)
1894 struct frame_info
*fi
;
1896 int py_start
= 0, py_end
= 0;
1897 enum ext_lang_bt_status result
= EXT_LANG_BT_ERROR
;
1899 if (!target_has_stack
)
1900 error (_("No stack."));
1904 count
= parse_and_eval_long (count_exp
);
1910 /* The argument to apply_ext_lang_frame_filter is the number
1911 of the final frame to print, and frames start at 0. */
1921 frame_filter_flags flags
= 0;
1924 flags
|= PRINT_LOCALS
;
1926 flags
|= PRINT_HIDE
;
1928 if (!bt_opts
.no_filters
)
1930 enum ext_lang_frame_args arg_type
;
1932 flags
|= PRINT_LEVEL
| PRINT_FRAME_INFO
| PRINT_ARGS
;
1934 flags
|= PRINT_MORE_FRAMES
;
1936 if (fp_opts
.print_frame_arguments
== print_frame_arguments_scalars
)
1937 arg_type
= CLI_SCALAR_VALUES
;
1938 else if (fp_opts
.print_frame_arguments
== print_frame_arguments_all
)
1939 arg_type
= CLI_ALL_VALUES
;
1941 arg_type
= NO_VALUES
;
1943 result
= apply_ext_lang_frame_filter (get_current_frame (), flags
,
1944 arg_type
, current_uiout
,
1948 /* Run the inbuilt backtrace if there are no filters registered, or
1949 "-no-filters" has been specified from the command. */
1950 if (bt_opts
.no_filters
|| result
== EXT_LANG_BT_NO_FILTERS
)
1952 struct frame_info
*trailing
;
1954 /* The following code must do two things. First, it must set the
1955 variable TRAILING to the frame from which we should start
1956 printing. Second, it must set the variable count to the number
1957 of frames which we should print, or -1 if all of them. */
1959 if (count_exp
!= NULL
&& count
< 0)
1961 trailing
= trailing_outermost_frame (-count
);
1965 trailing
= get_current_frame ();
1967 for (fi
= trailing
; fi
&& count
--; fi
= get_prev_frame (fi
))
1971 /* Don't use print_stack_frame; if an error() occurs it probably
1972 means further attempts to backtrace would fail (on the other
1973 hand, perhaps the code does or could be fixed to make sure
1974 the frame->prev field gets set to NULL in that case). */
1976 print_frame_info (fp_opts
, fi
, 1, LOCATION
, 1, 0);
1977 if ((flags
& PRINT_LOCALS
) != 0)
1979 struct frame_id frame_id
= get_frame_id (fi
);
1981 print_frame_local_vars (fi
, false, NULL
, NULL
, 1, gdb_stdout
);
1983 /* print_frame_local_vars invalidates FI. */
1984 fi
= frame_find_by_id (frame_id
);
1988 warning (_("Unable to restore previously selected frame."));
1993 /* Save the last frame to check for error conditions. */
1997 /* If we've stopped before the end, mention that. */
1999 printf_filtered (_("(More stack frames follow...)\n"));
2001 /* If we've run out of frames, and the reason appears to be an error
2002 condition, print it. */
2003 if (fi
== NULL
&& trailing
!= NULL
)
2005 enum unwind_stop_reason reason
;
2007 reason
= get_frame_unwind_stop_reason (trailing
);
2008 if (reason
>= UNWIND_FIRST_ERROR
)
2009 printf_filtered (_("Backtrace stopped: %s\n"),
2010 frame_stop_reason_string (trailing
));
2015 /* Create an option_def_group array grouping all the "backtrace"
2016 options, with FP_OPTS, BT_CMD_OPT, SET_BT_OPTS as contexts. */
2018 static inline std::array
<gdb::option::option_def_group
, 3>
2019 make_backtrace_options_def_group (frame_print_options
*fp_opts
,
2020 backtrace_cmd_options
*bt_cmd_opts
,
2021 set_backtrace_options
*set_bt_opts
)
2024 { {frame_print_option_defs
}, fp_opts
},
2025 { {set_backtrace_option_defs
}, set_bt_opts
},
2026 { {backtrace_command_option_defs
}, bt_cmd_opts
}
2030 /* Parse the backtrace command's qualifiers. Returns ARG advanced
2031 past the qualifiers, if any. BT_CMD_OPTS, if not null, is used to
2032 store the parsed qualifiers. */
2035 parse_backtrace_qualifiers (const char *arg
,
2036 backtrace_cmd_options
*bt_cmd_opts
= nullptr)
2040 const char *save_arg
= arg
;
2041 std::string this_arg
= extract_arg (&arg
);
2043 if (this_arg
.empty ())
2046 if (subset_compare (this_arg
.c_str (), "no-filters"))
2048 if (bt_cmd_opts
!= nullptr)
2049 bt_cmd_opts
->no_filters
= true;
2051 else if (subset_compare (this_arg
.c_str (), "full"))
2053 if (bt_cmd_opts
!= nullptr)
2054 bt_cmd_opts
->full
= true;
2056 else if (subset_compare (this_arg
.c_str (), "hide"))
2058 if (bt_cmd_opts
!= nullptr)
2059 bt_cmd_opts
->hide
= true;
2063 /* Not a recognized qualifier, so stop. */
2070 backtrace_command (const char *arg
, int from_tty
)
2072 frame_print_options fp_opts
= user_frame_print_options
;
2073 backtrace_cmd_options bt_cmd_opts
;
2074 set_backtrace_options set_bt_opts
= user_set_backtrace_options
;
2077 = make_backtrace_options_def_group (&fp_opts
, &bt_cmd_opts
, &set_bt_opts
);
2078 gdb::option::process_options
2079 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
2081 /* Parse non-'-'-prefixed qualifiers, for backwards
2085 arg
= parse_backtrace_qualifiers (arg
, &bt_cmd_opts
);
2090 /* These options are handled quite deep in the unwind machinery, so
2091 we get to pass them down by swapping globals. */
2092 scoped_restore restore_set_backtrace_options
2093 = make_scoped_restore (&user_set_backtrace_options
, set_bt_opts
);
2095 backtrace_command_1 (fp_opts
, bt_cmd_opts
, arg
, from_tty
);
2098 /* Completer for the "backtrace" command. */
2101 backtrace_command_completer (struct cmd_list_element
*ignore
,
2102 completion_tracker
&tracker
,
2103 const char *text
, const char */
*word*/
)
2106 = make_backtrace_options_def_group (nullptr, nullptr, nullptr);
2107 if (gdb::option::complete_options
2108 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
2113 const char *p
= skip_to_space (text
);
2116 static const char *const backtrace_cmd_qualifier_choices
[] = {
2117 "full", "no-filters", "hide", nullptr,
2119 complete_on_enum (tracker
, backtrace_cmd_qualifier_choices
,
2122 if (tracker
.have_completions ())
2127 const char *cmd
= parse_backtrace_qualifiers (text
);
2128 tracker
.advance_custom_word_point_by (cmd
- text
);
2133 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
2134 expression_completer (ignore
, tracker
, text
, word
);
2137 /* Iterate over the local variables of a block B, calling CB with
2141 iterate_over_block_locals (const struct block
*b
,
2142 iterate_over_block_arg_local_vars_cb cb
,
2145 struct block_iterator iter
;
2148 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
2150 switch (SYMBOL_CLASS (sym
))
2156 case LOC_OPTIMIZED_OUT
:
2157 if (SYMBOL_IS_ARGUMENT (sym
))
2159 if (SYMBOL_DOMAIN (sym
) == COMMON_BLOCK_DOMAIN
)
2161 (*cb
) (SYMBOL_PRINT_NAME (sym
), sym
, cb_data
);
2165 /* Ignore symbols which are not locals. */
2172 /* Same, but print labels. */
2175 /* Commented out, as the code using this function has also been
2176 commented out. FIXME:brobecker/2009-01-13: Find out why the code
2177 was commented out in the first place. The discussion introducing
2178 this change (2007-12-04: Support lexical blocks and function bodies
2179 that occupy non-contiguous address ranges) did not explain why
2180 this change was made. */
2182 print_block_frame_labels (struct gdbarch
*gdbarch
, struct block
*b
,
2183 int *have_default
, struct ui_file
*stream
)
2185 struct block_iterator iter
;
2187 int values_printed
= 0;
2189 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
2191 if (strcmp (SYMBOL_LINKAGE_NAME (sym
), "default") == 0)
2197 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
2199 struct symtab_and_line sal
;
2200 struct value_print_options opts
;
2202 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
2204 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
2205 get_user_print_options (&opts
);
2206 if (opts
.addressprint
)
2208 fprintf_filtered (stream
, " ");
2209 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (sym
)),
2212 fprintf_filtered (stream
, " in file %s, line %d\n",
2213 sal
.symtab
->filename
, sal
.line
);
2217 return values_printed
;
2221 /* Iterate over all the local variables in block B, including all its
2222 superblocks, stopping when the top-level block is reached. */
2225 iterate_over_block_local_vars (const struct block
*block
,
2226 iterate_over_block_arg_local_vars_cb cb
,
2231 iterate_over_block_locals (block
, cb
, cb_data
);
2232 /* After handling the function's top-level block, stop. Don't
2233 continue to its superblock, the block of per-file
2235 if (BLOCK_FUNCTION (block
))
2237 block
= BLOCK_SUPERBLOCK (block
);
2241 /* Data to be passed around in the calls to the locals and args
2244 struct print_variable_and_value_data
2246 gdb::optional
<compiled_regex
> preg
;
2247 gdb::optional
<compiled_regex
> treg
;
2248 struct frame_id frame_id
;
2250 struct ui_file
*stream
;
2254 /* The callback for the locals and args iterators. */
2257 do_print_variable_and_value (const char *print_name
,
2261 struct print_variable_and_value_data
*p
2262 = (struct print_variable_and_value_data
*) cb_data
;
2263 struct frame_info
*frame
;
2265 if (p
->preg
.has_value ()
2266 && p
->preg
->exec (SYMBOL_NATURAL_NAME (sym
), 0,
2269 if (p
->treg
.has_value ()
2270 && !treg_matches_sym_type_name (*p
->treg
, sym
))
2273 frame
= frame_find_by_id (p
->frame_id
);
2276 warning (_("Unable to restore previously selected frame."));
2280 print_variable_and_value (print_name
, sym
, frame
, p
->stream
, p
->num_tabs
);
2282 /* print_variable_and_value invalidates FRAME. */
2285 p
->values_printed
= 1;
2288 /* Prepares the regular expression REG from REGEXP.
2289 If REGEXP is NULL, it results in an empty regular expression. */
2292 prepare_reg (const char *regexp
, gdb::optional
<compiled_regex
> *reg
)
2296 int cflags
= REG_NOSUB
| (case_sensitivity
== case_sensitive_off
2298 reg
->emplace (regexp
, cflags
, _("Invalid regexp"));
2304 /* Print all variables from the innermost up to the function block of FRAME.
2305 Print them with values to STREAM indented by NUM_TABS.
2306 If REGEXP is not NULL, only print local variables whose name
2308 If T_REGEXP is not NULL, only print local variables whose type
2310 If no local variables have been printed and !QUIET, prints a message
2311 explaining why no local variables could be printed.
2313 This function will invalidate FRAME. */
2316 print_frame_local_vars (struct frame_info
*frame
,
2318 const char *regexp
, const char *t_regexp
,
2319 int num_tabs
, struct ui_file
*stream
)
2321 struct print_variable_and_value_data cb_data
;
2322 const struct block
*block
;
2325 if (!get_frame_pc_if_available (frame
, &pc
))
2328 fprintf_filtered (stream
,
2329 _("PC unavailable, cannot determine locals.\n"));
2333 block
= get_frame_block (frame
, 0);
2337 fprintf_filtered (stream
, "No symbol table info available.\n");
2341 prepare_reg (regexp
, &cb_data
.preg
);
2342 prepare_reg (t_regexp
, &cb_data
.treg
);
2343 cb_data
.frame_id
= get_frame_id (frame
);
2344 cb_data
.num_tabs
= 4 * num_tabs
;
2345 cb_data
.stream
= stream
;
2346 cb_data
.values_printed
= 0;
2348 /* Temporarily change the selected frame to the given FRAME.
2349 This allows routines that rely on the selected frame instead
2350 of being given a frame as parameter to use the correct frame. */
2351 scoped_restore_selected_frame restore_selected_frame
;
2352 select_frame (frame
);
2354 iterate_over_block_local_vars (block
,
2355 do_print_variable_and_value
,
2358 if (!cb_data
.values_printed
&& !quiet
)
2360 if (regexp
== NULL
&& t_regexp
== NULL
)
2361 fprintf_filtered (stream
, _("No locals.\n"));
2363 fprintf_filtered (stream
, _("No matching locals.\n"));
2368 info_locals_command (const char *args
, int from_tty
)
2371 std::string t_regexp
;
2375 && extract_info_print_args (&args
, &quiet
, ®exp
, &t_regexp
))
2379 report_unrecognized_option_error ("info locals", args
);
2381 print_frame_local_vars (get_selected_frame (_("No frame selected.")),
2383 regexp
.empty () ? NULL
: regexp
.c_str (),
2384 t_regexp
.empty () ? NULL
: t_regexp
.c_str (),
2388 /* Iterate over all the argument variables in block B. */
2391 iterate_over_block_arg_vars (const struct block
*b
,
2392 iterate_over_block_arg_local_vars_cb cb
,
2395 struct block_iterator iter
;
2396 struct symbol
*sym
, *sym2
;
2398 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
2400 /* Don't worry about things which aren't arguments. */
2401 if (SYMBOL_IS_ARGUMENT (sym
))
2403 /* We have to look up the symbol because arguments can have
2404 two entries (one a parameter, one a local) and the one we
2405 want is the local, which lookup_symbol will find for us.
2406 This includes gcc1 (not gcc2) on the sparc when passing a
2407 small structure and gcc2 when the argument type is float
2408 and it is passed as a double and converted to float by
2409 the prologue (in the latter case the type of the LOC_ARG
2410 symbol is double and the type of the LOC_LOCAL symbol is
2411 float). There are also LOC_ARG/LOC_REGISTER pairs which
2412 are not combined in symbol-reading. */
2414 sym2
= lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym
),
2415 b
, VAR_DOMAIN
).symbol
;
2416 (*cb
) (SYMBOL_PRINT_NAME (sym
), sym2
, cb_data
);
2421 /* Print all argument variables of the function of FRAME.
2422 Print them with values to STREAM.
2423 If REGEXP is not NULL, only print argument variables whose name
2425 If T_REGEXP is not NULL, only print argument variables whose type
2427 If no argument variables have been printed and !QUIET, prints a message
2428 explaining why no argument variables could be printed.
2430 This function will invalidate FRAME. */
2433 print_frame_arg_vars (struct frame_info
*frame
,
2435 const char *regexp
, const char *t_regexp
,
2436 struct ui_file
*stream
)
2438 struct print_variable_and_value_data cb_data
;
2439 struct symbol
*func
;
2441 gdb::optional
<compiled_regex
> preg
;
2442 gdb::optional
<compiled_regex
> treg
;
2444 if (!get_frame_pc_if_available (frame
, &pc
))
2447 fprintf_filtered (stream
,
2448 _("PC unavailable, cannot determine args.\n"));
2452 func
= get_frame_function (frame
);
2456 fprintf_filtered (stream
, _("No symbol table info available.\n"));
2460 prepare_reg (regexp
, &cb_data
.preg
);
2461 prepare_reg (t_regexp
, &cb_data
.treg
);
2462 cb_data
.frame_id
= get_frame_id (frame
);
2463 cb_data
.num_tabs
= 0;
2464 cb_data
.stream
= stream
;
2465 cb_data
.values_printed
= 0;
2467 iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func
),
2468 do_print_variable_and_value
, &cb_data
);
2470 /* do_print_variable_and_value invalidates FRAME. */
2473 if (!cb_data
.values_printed
&& !quiet
)
2475 if (regexp
== NULL
&& t_regexp
== NULL
)
2476 fprintf_filtered (stream
, _("No arguments.\n"));
2478 fprintf_filtered (stream
, _("No matching arguments.\n"));
2483 info_args_command (const char *args
, int from_tty
)
2486 std::string t_regexp
;
2490 && extract_info_print_args (&args
, &quiet
, ®exp
, &t_regexp
))
2494 report_unrecognized_option_error ("info args", args
);
2497 print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
2499 regexp
.empty () ? NULL
: regexp
.c_str (),
2500 t_regexp
.empty () ? NULL
: t_regexp
.c_str (),
2504 /* Return the symbol-block in which the selected frame is executing.
2505 Can return zero under various legitimate circumstances.
2507 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
2508 code address within the block returned. We use this to decide
2509 which macros are in scope. */
2511 const struct block
*
2512 get_selected_block (CORE_ADDR
*addr_in_block
)
2514 if (!has_stack_frames ())
2517 return get_frame_block (get_selected_frame (NULL
), addr_in_block
);
2520 /* Find a frame a certain number of levels away from FRAME.
2521 LEVEL_OFFSET_PTR points to an int containing the number of levels.
2522 Positive means go to earlier frames (up); negative, the reverse.
2523 The int that contains the number of levels is counted toward
2524 zero as the frames for those levels are found.
2525 If the top or bottom frame is reached, that frame is returned,
2526 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
2527 how much farther the original request asked to go. */
2530 find_relative_frame (struct frame_info
*frame
, int *level_offset_ptr
)
2532 /* Going up is simple: just call get_prev_frame enough times or
2533 until the initial frame is reached. */
2534 while (*level_offset_ptr
> 0)
2536 struct frame_info
*prev
= get_prev_frame (frame
);
2540 (*level_offset_ptr
)--;
2544 /* Going down is just as simple. */
2545 while (*level_offset_ptr
< 0)
2547 struct frame_info
*next
= get_next_frame (frame
);
2551 (*level_offset_ptr
)++;
2558 /* Select the frame up one or COUNT_EXP stack levels from the
2559 previously selected frame, and print it briefly. */
2562 up_silently_base (const char *count_exp
)
2564 struct frame_info
*frame
;
2568 count
= parse_and_eval_long (count_exp
);
2570 frame
= find_relative_frame (get_selected_frame ("No stack."), &count
);
2571 if (count
!= 0 && count_exp
== NULL
)
2572 error (_("Initial frame selected; you cannot go up."));
2573 select_frame (frame
);
2577 up_silently_command (const char *count_exp
, int from_tty
)
2579 up_silently_base (count_exp
);
2583 up_command (const char *count_exp
, int from_tty
)
2585 up_silently_base (count_exp
);
2586 gdb::observers::user_selected_context_changed
.notify (USER_SELECTED_FRAME
);
2589 /* Select the frame down one or COUNT_EXP stack levels from the previously
2590 selected frame, and print it briefly. */
2593 down_silently_base (const char *count_exp
)
2595 struct frame_info
*frame
;
2599 count
= -parse_and_eval_long (count_exp
);
2601 frame
= find_relative_frame (get_selected_frame ("No stack."), &count
);
2602 if (count
!= 0 && count_exp
== NULL
)
2604 /* We only do this if COUNT_EXP is not specified. That way
2605 "down" means to really go down (and let me know if that is
2606 impossible), but "down 9999" can be used to mean go all the
2607 way down without getting an error. */
2609 error (_("Bottom (innermost) frame selected; you cannot go down."));
2612 select_frame (frame
);
2616 down_silently_command (const char *count_exp
, int from_tty
)
2618 down_silently_base (count_exp
);
2622 down_command (const char *count_exp
, int from_tty
)
2624 down_silently_base (count_exp
);
2625 gdb::observers::user_selected_context_changed
.notify (USER_SELECTED_FRAME
);
2629 return_command (const char *retval_exp
, int from_tty
)
2631 /* Initialize it just to avoid a GCC false warning. */
2632 enum return_value_convention rv_conv
= RETURN_VALUE_STRUCT_CONVENTION
;
2633 struct frame_info
*thisframe
;
2634 struct gdbarch
*gdbarch
;
2635 struct symbol
*thisfun
;
2636 struct value
*return_value
= NULL
;
2637 struct value
*function
= NULL
;
2638 const char *query_prefix
= "";
2640 thisframe
= get_selected_frame ("No selected frame.");
2641 thisfun
= get_frame_function (thisframe
);
2642 gdbarch
= get_frame_arch (thisframe
);
2644 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
)
2645 error (_("Can not force return from an inlined function."));
2647 /* Compute the return value. If the computation triggers an error,
2648 let it bail. If the return type can't be handled, set
2649 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
2653 expression_up retval_expr
= parse_expression (retval_exp
);
2654 struct type
*return_type
= NULL
;
2656 /* Compute the return value. Should the computation fail, this
2657 call throws an error. */
2658 return_value
= evaluate_expression (retval_expr
.get ());
2660 /* Cast return value to the return type of the function. Should
2661 the cast fail, this call throws an error. */
2662 if (thisfun
!= NULL
)
2663 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
2664 if (return_type
== NULL
)
2666 if (retval_expr
->elts
[0].opcode
!= UNOP_CAST
2667 && retval_expr
->elts
[0].opcode
!= UNOP_CAST_TYPE
)
2668 error (_("Return value type not available for selected "
2670 "Please use an explicit cast of the value to return."));
2671 return_type
= value_type (return_value
);
2673 return_type
= check_typedef (return_type
);
2674 return_value
= value_cast (return_type
, return_value
);
2676 /* Make sure the value is fully evaluated. It may live in the
2677 stack frame we're about to pop. */
2678 if (value_lazy (return_value
))
2679 value_fetch_lazy (return_value
);
2681 if (thisfun
!= NULL
)
2682 function
= read_var_value (thisfun
, NULL
, thisframe
);
2684 rv_conv
= RETURN_VALUE_REGISTER_CONVENTION
;
2685 if (TYPE_CODE (return_type
) == TYPE_CODE_VOID
)
2686 /* If the return-type is "void", don't try to find the
2687 return-value's location. However, do still evaluate the
2688 return expression so that, even when the expression result
2689 is discarded, side effects such as "return i++" still
2691 return_value
= NULL
;
2692 else if (thisfun
!= NULL
)
2694 rv_conv
= struct_return_convention (gdbarch
, function
, return_type
);
2695 if (rv_conv
== RETURN_VALUE_STRUCT_CONVENTION
2696 || rv_conv
== RETURN_VALUE_ABI_RETURNS_ADDRESS
)
2698 query_prefix
= "The location at which to store the "
2699 "function's return value is unknown.\n"
2700 "If you continue, the return value "
2701 "that you specified will be ignored.\n";
2702 return_value
= NULL
;
2707 /* Does an interactive user really want to do this? Include
2708 information, such as how well GDB can handle the return value, in
2709 the query message. */
2714 if (thisfun
== NULL
)
2715 confirmed
= query (_("%sMake selected stack frame return now? "),
2719 if (TYPE_NO_RETURN (thisfun
->type
))
2720 warning (_("Function does not return normally to caller."));
2721 confirmed
= query (_("%sMake %s return now? "), query_prefix
,
2722 SYMBOL_PRINT_NAME (thisfun
));
2725 error (_("Not confirmed"));
2728 /* Discard the selected frame and all frames inner-to it. */
2729 frame_pop (get_selected_frame (NULL
));
2731 /* Store RETURN_VALUE in the just-returned register set. */
2732 if (return_value
!= NULL
)
2734 struct type
*return_type
= value_type (return_value
);
2735 struct gdbarch
*cache_arch
= get_current_regcache ()->arch ();
2737 gdb_assert (rv_conv
!= RETURN_VALUE_STRUCT_CONVENTION
2738 && rv_conv
!= RETURN_VALUE_ABI_RETURNS_ADDRESS
);
2739 gdbarch_return_value (cache_arch
, function
, return_type
,
2740 get_current_regcache (), NULL
/*read*/,
2741 value_contents (return_value
) /*write*/);
2744 /* If we are at the end of a call dummy now, pop the dummy frame
2746 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME
)
2747 frame_pop (get_current_frame ());
2749 select_frame (get_current_frame ());
2750 /* If interactive, print the frame that is now current. */
2752 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2755 /* Find the most inner frame in the current stack for a function called
2756 FUNCTION_NAME. If no matching frame is found return NULL. */
2758 static struct frame_info
*
2759 find_frame_for_function (const char *function_name
)
2761 /* Used to hold the lower and upper addresses for each of the
2762 SYMTAB_AND_LINEs found for functions matching FUNCTION_NAME. */
2763 struct function_bounds
2765 CORE_ADDR low
, high
;
2767 struct frame_info
*frame
;
2771 gdb_assert (function_name
!= NULL
);
2773 frame
= get_current_frame ();
2774 std::vector
<symtab_and_line
> sals
2775 = decode_line_with_current_source (function_name
,
2776 DECODE_LINE_FUNFIRSTLINE
);
2777 gdb::def_vector
<function_bounds
> func_bounds (sals
.size ());
2778 for (size_t i
= 0; i
< sals
.size (); i
++)
2780 if (sals
[i
].pspace
!= current_program_space
)
2781 func_bounds
[i
].low
= func_bounds
[i
].high
= 0;
2782 else if (sals
[i
].pc
== 0
2783 || find_pc_partial_function (sals
[i
].pc
, NULL
,
2784 &func_bounds
[i
].low
,
2785 &func_bounds
[i
].high
) == 0)
2786 func_bounds
[i
].low
= func_bounds
[i
].high
= 0;
2791 for (size_t i
= 0; (i
< sals
.size () && !found
); i
++)
2792 found
= (get_frame_pc (frame
) >= func_bounds
[i
].low
2793 && get_frame_pc (frame
) < func_bounds
[i
].high
);
2797 frame
= find_relative_frame (frame
, &level
);
2800 while (!found
&& level
== 0);
2808 /* Implements the dbx 'func' command. */
2811 func_command (const char *arg
, int from_tty
)
2816 struct frame_info
*frame
= find_frame_for_function (arg
);
2818 error (_("'%s' not within current stack frame."), arg
);
2819 if (frame
!= get_selected_frame (NULL
))
2821 select_frame (frame
);
2822 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2826 /* The qcs command line flags for the "frame apply" commands. Keep
2827 this in sync with the "thread apply" commands. */
2829 using qcs_flag_option_def
2830 = gdb::option::flag_option_def
<qcs_flags
>;
2832 static const gdb::option::option_def fr_qcs_flags_option_defs
[] = {
2833 qcs_flag_option_def
{
2834 "q", [] (qcs_flags
*opt
) { return &opt
->quiet
; },
2835 N_("Disables printing the frame location information."),
2838 qcs_flag_option_def
{
2839 "c", [] (qcs_flags
*opt
) { return &opt
->cont
; },
2840 N_("Print any error raised by COMMAND and continue."),
2843 qcs_flag_option_def
{
2844 "s", [] (qcs_flags
*opt
) { return &opt
->silent
; },
2845 N_("Silently ignore any errors or empty output produced by COMMAND."),
2849 /* Create an option_def_group array for all the "frame apply" options,
2850 with FLAGS and SET_BT_OPTS as context. */
2852 static inline std::array
<gdb::option::option_def_group
, 2>
2853 make_frame_apply_options_def_group (qcs_flags
*flags
,
2854 set_backtrace_options
*set_bt_opts
)
2857 { {fr_qcs_flags_option_defs
}, flags
},
2858 { {set_backtrace_option_defs
}, set_bt_opts
},
2862 /* Apply a GDB command to all stack frames, or a set of identified frames,
2863 or innermost COUNT frames.
2864 With a negative COUNT, apply command on outermost -COUNT frames.
2866 frame apply 3 info frame Apply 'info frame' to frames 0, 1, 2
2867 frame apply -3 info frame Apply 'info frame' to outermost 3 frames.
2868 frame apply all x/i $pc Apply 'x/i $pc' cmd to all frames.
2869 frame apply all -s p local_var_no_idea_in_which_frame
2870 If a frame has a local variable called
2871 local_var_no_idea_in_which_frame, print frame
2872 and value of local_var_no_idea_in_which_frame.
2873 frame apply all -s -q p local_var_no_idea_in_which_frame
2874 Same as before, but only print the variable value.
2875 frame apply level 2-5 0 4-7 -s p i = i + 1
2876 Adds 1 to the variable i in the specified frames.
2877 Note that i will be incremented twice in
2880 /* Apply a GDB command to COUNT stack frames, starting at TRAILING.
2881 CMD starts with 0 or more qcs flags followed by the GDB command to apply.
2882 COUNT -1 means all frames starting at TRAILING. WHICH_COMMAND is used
2883 for error messages. */
2886 frame_apply_command_count (const char *which_command
,
2887 const char *cmd
, int from_tty
,
2888 struct frame_info
*trailing
, int count
)
2891 set_backtrace_options set_bt_opts
= user_set_backtrace_options
;
2893 auto group
= make_frame_apply_options_def_group (&flags
, &set_bt_opts
);
2894 gdb::option::process_options
2895 (&cmd
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
);
2897 validate_flags_qcs (which_command
, &flags
);
2899 if (cmd
== NULL
|| *cmd
== '\0')
2900 error (_("Please specify a command to apply on the selected frames"));
2902 /* The below will restore the current inferior/thread/frame.
2903 Usually, only the frame is effectively to be restored.
2904 But in case CMD switches of inferior/thread, better restore
2906 scoped_restore_current_thread restore_thread
;
2908 /* These options are handled quite deep in the unwind machinery, so
2909 we get to pass them down by swapping globals. */
2910 scoped_restore restore_set_backtrace_options
2911 = make_scoped_restore (&user_set_backtrace_options
, set_bt_opts
);
2913 for (frame_info
*fi
= trailing
; fi
&& count
--; fi
= get_prev_frame (fi
))
2920 std::string cmd_result
;
2922 /* In case CMD switches of inferior/thread/frame, the below
2923 restores the inferior/thread/frame. FI can then be
2924 set to the selected frame. */
2925 scoped_restore_current_thread restore_fi_current_frame
;
2927 cmd_result
= execute_command_to_string
2928 (cmd
, from_tty
, gdb_stdout
->term_out ());
2930 fi
= get_selected_frame (_("frame apply "
2931 "unable to get selected frame."));
2932 if (!flags
.silent
|| cmd_result
.length () > 0)
2935 print_stack_frame (fi
, 1, LOCATION
, 0);
2936 printf_filtered ("%s", cmd_result
.c_str ());
2939 catch (const gdb_exception_error
&ex
)
2941 fi
= get_selected_frame (_("frame apply "
2942 "unable to get selected frame."));
2946 print_stack_frame (fi
, 1, LOCATION
, 0);
2948 printf_filtered ("%s\n", ex
.what ());
2956 /* Completer for the "frame apply ..." commands. */
2959 frame_apply_completer (completion_tracker
&tracker
, const char *text
)
2961 const auto group
= make_frame_apply_options_def_group (nullptr, nullptr);
2962 if (gdb::option::complete_options
2963 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
2966 complete_nested_command_line (tracker
, text
);
2969 /* Completer for the "frame apply" commands. */
2972 frame_apply_level_cmd_completer (struct cmd_list_element
*ignore
,
2973 completion_tracker
&tracker
,
2974 const char *text
, const char */
*word*/
)
2976 /* Do this explicitly because there's an early return below. */
2977 tracker
.set_use_custom_word_point (true);
2979 number_or_range_parser
levels (text
);
2981 /* Skip the LEVEL list to find the options and command args. */
2984 while (!levels
.finished ())
2986 /* Call for effect. */
2987 levels
.get_number ();
2989 if (levels
.in_range ())
2990 levels
.skip_range ();
2993 catch (const gdb_exception_error
&ex
)
2995 /* get_number throws if it parses a negative number, for
2996 example. But a seemingly negative number may be the start of
2997 an option instead. */
3000 const char *cmd
= levels
.cur_tok ();
3004 /* No level list yet. */
3008 /* Check if we're past a valid LEVEL already. */
3009 if (levels
.finished ()
3010 && cmd
> text
&& !isspace (cmd
[-1]))
3013 /* We're past LEVELs, advance word point. */
3014 tracker
.advance_custom_word_point_by (cmd
- text
);
3017 frame_apply_completer (tracker
, text
);
3020 /* Completer for the "frame apply all" command. */
3023 frame_apply_all_cmd_completer (struct cmd_list_element
*ignore
,
3024 completion_tracker
&tracker
,
3025 const char *text
, const char */
*word*/
)
3027 frame_apply_completer (tracker
, text
);
3030 /* Completer for the "frame apply COUNT" command. */
3033 frame_apply_cmd_completer (struct cmd_list_element
*ignore
,
3034 completion_tracker
&tracker
,
3035 const char *text
, const char */
*word*/
)
3037 const char *cmd
= text
;
3039 int count
= get_number_trailer (&cmd
, 0);
3043 /* Check if we're past a valid COUNT already. */
3044 if (cmd
> text
&& !isspace (cmd
[-1]))
3047 /* We're past COUNT, advance word point. */
3048 tracker
.advance_custom_word_point_by (cmd
- text
);
3051 frame_apply_completer (tracker
, text
);
3054 /* Implementation of the "frame apply level" command. */
3057 frame_apply_level_command (const char *cmd
, int from_tty
)
3059 if (!target_has_stack
)
3060 error (_("No stack."));
3062 bool level_found
= false;
3063 const char *levels_str
= cmd
;
3064 number_or_range_parser
levels (levels_str
);
3066 /* Skip the LEVEL list to find the flags and command args. */
3067 while (!levels
.finished ())
3069 /* Call for effect. */
3070 levels
.get_number ();
3073 if (levels
.in_range ())
3074 levels
.skip_range ();
3078 error (_("Missing or invalid LEVEL... argument"));
3080 cmd
= levels
.cur_tok ();
3082 /* Redo the LEVELS parsing, but applying COMMAND. */
3083 levels
.init (levels_str
);
3084 while (!levels
.finished ())
3086 const int level_beg
= levels
.get_number ();
3089 if (levels
.in_range ())
3091 n_frames
= levels
.end_value () - level_beg
+ 1;
3092 levels
.skip_range ();
3097 frame_apply_command_count ("frame apply level", cmd
, from_tty
,
3098 leading_innermost_frame (level_beg
), n_frames
);
3102 /* Implementation of the "frame apply all" command. */
3105 frame_apply_all_command (const char *cmd
, int from_tty
)
3107 if (!target_has_stack
)
3108 error (_("No stack."));
3110 frame_apply_command_count ("frame apply all", cmd
, from_tty
,
3111 get_current_frame (), INT_MAX
);
3114 /* Implementation of the "frame apply" command. */
3117 frame_apply_command (const char* cmd
, int from_tty
)
3120 struct frame_info
*trailing
;
3122 if (!target_has_stack
)
3123 error (_("No stack."));
3126 error (_("Missing COUNT argument."));
3127 count
= get_number_trailer (&cmd
, 0);
3129 error (_("Invalid COUNT argument."));
3133 trailing
= trailing_outermost_frame (-count
);
3137 trailing
= get_current_frame ();
3139 frame_apply_command_count ("frame apply", cmd
, from_tty
,
3143 /* Implementation of the "faas" command. */
3146 faas_command (const char *cmd
, int from_tty
)
3148 std::string expanded
= std::string ("frame apply all -s ") + cmd
;
3149 execute_command (expanded
.c_str (), from_tty
);
3153 /* Find inner-mode frame with frame address ADDRESS. Return NULL if no
3154 matching frame can be found. */
3156 static struct frame_info
*
3157 find_frame_for_address (CORE_ADDR address
)
3160 struct frame_info
*fid
;
3162 id
= frame_id_build_wild (address
);
3164 /* If (s)he specifies the frame with an address, he deserves
3165 what (s)he gets. Still, give the highest one that matches.
3166 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
3168 for (fid
= get_current_frame ();
3170 fid
= get_prev_frame (fid
))
3172 if (frame_id_eq (id
, get_frame_id (fid
)))
3174 struct frame_info
*prev_frame
;
3178 prev_frame
= get_prev_frame (fid
);
3180 || !frame_id_eq (id
, get_frame_id (prev_frame
)))
3192 /* Commands with a prefix of `frame apply'. */
3193 static struct cmd_list_element
*frame_apply_cmd_list
= NULL
;
3195 /* Commands with a prefix of `frame'. */
3196 static struct cmd_list_element
*frame_cmd_list
= NULL
;
3198 /* Commands with a prefix of `select frame'. */
3199 static struct cmd_list_element
*select_frame_cmd_list
= NULL
;
3201 /* Commands with a prefix of `info frame'. */
3202 static struct cmd_list_element
*info_frame_cmd_list
= NULL
;
3205 _initialize_stack (void)
3207 struct cmd_list_element
*cmd
;
3209 add_com ("return", class_stack
, return_command
, _("\
3210 Make selected stack frame return to its caller.\n\
3211 Control remains in the debugger, but when you continue\n\
3212 execution will resume in the frame above the one now selected.\n\
3213 If an argument is given, it is an expression for the value to return."));
3215 add_com ("up", class_stack
, up_command
, _("\
3216 Select and print stack frame that called this one.\n\
3217 An argument says how many frames up to go."));
3218 add_com ("up-silently", class_support
, up_silently_command
, _("\
3219 Same as the `up' command, but does not print anything.\n\
3220 This is useful in command scripts."));
3222 add_com ("down", class_stack
, down_command
, _("\
3223 Select and print stack frame called by this one.\n\
3224 An argument says how many frames down to go."));
3225 add_com_alias ("do", "down", class_stack
, 1);
3226 add_com_alias ("dow", "down", class_stack
, 1);
3227 add_com ("down-silently", class_support
, down_silently_command
, _("\
3228 Same as the `down' command, but does not print anything.\n\
3229 This is useful in command scripts."));
3231 add_prefix_cmd ("frame", class_stack
,
3232 &frame_cmd
.base_command
, _("\
3233 Select and print a stack frame.\n\
3234 With no argument, print the selected stack frame. (See also \"info frame\").\n\
3235 A single numerical argument specifies the frame to select."),
3236 &frame_cmd_list
, "frame ", 1, &cmdlist
);
3238 add_com_alias ("f", "frame", class_stack
, 1);
3240 #define FRAME_APPLY_OPTION_HELP "\
3241 Prints the frame location information followed by COMMAND output.\n\
3243 By default, an error raised during the execution of COMMAND\n\
3244 aborts \"frame apply\".\n\
3249 const auto frame_apply_opts
3250 = make_frame_apply_options_def_group (nullptr, nullptr);
3252 static std::string frame_apply_cmd_help
= gdb::option::build_help (N_("\
3253 Apply a command to a number of frames.\n\
3254 Usage: frame apply COUNT [OPTION]... COMMAND\n\
3255 With a negative COUNT argument, applies the command on outermost -COUNT frames.\n"
3256 FRAME_APPLY_OPTION_HELP
),
3259 cmd
= add_prefix_cmd ("apply", class_stack
, frame_apply_command
,
3260 frame_apply_cmd_help
.c_str (),
3261 &frame_apply_cmd_list
, "frame apply ", 1,
3263 set_cmd_completer_handle_brkchars (cmd
, frame_apply_cmd_completer
);
3265 static std::string frame_apply_all_cmd_help
= gdb::option::build_help (N_("\
3266 Apply a command to all frames.\n\
3268 Usage: frame apply all [OPTION]... COMMAND\n"
3269 FRAME_APPLY_OPTION_HELP
),
3272 cmd
= add_cmd ("all", class_stack
, frame_apply_all_command
,
3273 frame_apply_all_cmd_help
.c_str (),
3274 &frame_apply_cmd_list
);
3275 set_cmd_completer_handle_brkchars (cmd
, frame_apply_all_cmd_completer
);
3277 static std::string frame_apply_level_cmd_help
= gdb::option::build_help (N_("\
3278 Apply a command to a list of frames.\n\
3280 Usage: frame apply level LEVEL... [OPTION]... COMMAND\n\
3281 LEVEL is a space-separated list of levels of frames to apply COMMAND on.\n"
3282 FRAME_APPLY_OPTION_HELP
),
3285 cmd
= add_cmd ("level", class_stack
, frame_apply_level_command
,
3286 frame_apply_level_cmd_help
.c_str (),
3287 &frame_apply_cmd_list
);
3288 set_cmd_completer_handle_brkchars (cmd
, frame_apply_level_cmd_completer
);
3290 cmd
= add_com ("faas", class_stack
, faas_command
, _("\
3291 Apply a command to all frames (ignoring errors and empty output).\n\
3292 Usage: faas [OPTION]... COMMAND\n\
3293 shortcut for 'frame apply all -s [OPTION]... COMMAND'\n\
3294 See \"help frame apply all\" for available options."));
3295 set_cmd_completer_handle_brkchars (cmd
, frame_apply_all_cmd_completer
);
3297 add_prefix_cmd ("frame", class_stack
,
3298 &frame_cmd
.base_command
, _("\
3299 Select and print a stack frame.\n\
3300 With no argument, print the selected stack frame. (See also \"info frame\").\n\
3301 A single numerical argument specifies the frame to select."),
3302 &frame_cmd_list
, "frame ", 1, &cmdlist
);
3303 add_com_alias ("f", "frame", class_stack
, 1);
3305 add_cmd ("address", class_stack
, &frame_cmd
.address
,
3307 Select and print a stack frame by stack address\n\
3309 Usage: frame address STACK-ADDRESS"),
3312 add_cmd ("view", class_stack
, &frame_cmd
.view
,
3314 View a stack frame that might be outside the current backtrace.\n\
3316 Usage: frame view STACK-ADDRESS\n\
3317 frame view STACK-ADDRESS PC-ADDRESS"),
3320 cmd
= add_cmd ("function", class_stack
, &frame_cmd
.function
,
3322 Select and print a stack frame by function name.\n\
3324 Usage: frame function NAME\n\
3326 The innermost frame that visited function NAME is selected."),
3328 set_cmd_completer (cmd
, frame_selection_by_function_completer
);
3331 add_cmd ("level", class_stack
, &frame_cmd
.level
,
3333 Select and print a stack frame by level.\n\
3335 Usage: frame level LEVEL"),
3338 cmd
= add_prefix_cmd_suppress_notification ("select-frame", class_stack
,
3339 &select_frame_cmd
.base_command
, _("\
3340 Select a stack frame without printing anything.\n\
3341 A single numerical argument specifies the frame to select."),
3342 &select_frame_cmd_list
, "select-frame ", 1, &cmdlist
,
3343 &cli_suppress_notification
.user_selected_context
);
3345 add_cmd_suppress_notification ("address", class_stack
,
3346 &select_frame_cmd
.address
, _("\
3347 Select a stack frame by stack address.\n\
3349 Usage: select-frame address STACK-ADDRESS"),
3350 &select_frame_cmd_list
,
3351 &cli_suppress_notification
.user_selected_context
);
3354 add_cmd_suppress_notification ("view", class_stack
,
3355 &select_frame_cmd
.view
, _("\
3356 Select a stack frame that might be outside the current backtrace.\n\
3358 Usage: select-frame view STACK-ADDRESS\n\
3359 select-frame view STACK-ADDRESS PC-ADDRESS"),
3360 &select_frame_cmd_list
,
3361 &cli_suppress_notification
.user_selected_context
);
3363 cmd
= add_cmd_suppress_notification ("function", class_stack
,
3364 &select_frame_cmd
.function
, _("\
3365 Select a stack frame by function name.\n\
3367 Usage: select-frame function NAME"),
3368 &select_frame_cmd_list
,
3369 &cli_suppress_notification
.user_selected_context
);
3370 set_cmd_completer (cmd
, frame_selection_by_function_completer
);
3372 add_cmd_suppress_notification ("level", class_stack
,
3373 &select_frame_cmd
.level
, _("\
3374 Select a stack frame by level.\n\
3376 Usage: select-frame level LEVEL"),
3377 &select_frame_cmd_list
,
3378 &cli_suppress_notification
.user_selected_context
);
3380 const auto backtrace_opts
3381 = make_backtrace_options_def_group (nullptr, nullptr, nullptr);
3383 static std::string backtrace_help
3384 = gdb::option::build_help (N_("\
3385 Print backtrace of all stack frames, or innermost COUNT frames.\n\
3386 Usage: backtrace [OPTION]... [QUALIFIER]... [COUNT | -COUNT]\n\
3390 For backward compatibility, the following qualifiers are supported:\n\
3392 full - same as -full option.\n\
3393 no-filters - same as -no-filters option.\n\
3394 hide - same as -hide.\n\
3396 With a negative COUNT, print outermost -COUNT frames."),
3399 cmd_list_element
*c
= add_com ("backtrace", class_stack
,
3401 backtrace_help
.c_str ());
3402 set_cmd_completer_handle_brkchars (c
, backtrace_command_completer
);
3404 add_com_alias ("bt", "backtrace", class_stack
, 0);
3406 add_com_alias ("where", "backtrace", class_alias
, 0);
3407 add_info ("stack", backtrace_command
,
3408 _("Backtrace of the stack, or innermost COUNT frames."));
3409 add_info_alias ("s", "stack", 1);
3411 add_prefix_cmd ("frame", class_info
, &info_frame_cmd
.base_command
,
3412 _("All about the selected stack frame.\n\
3413 With no arguments, displays information about the currently selected stack\n\
3414 frame. Alternatively a frame specification may be provided (See \"frame\")\n\
3415 the information is then printed about the specified frame."),
3416 &info_frame_cmd_list
, "info frame ", 1, &infolist
);
3417 add_info_alias ("f", "frame", 1);
3419 add_cmd ("address", class_stack
, &info_frame_cmd
.address
,
3421 Print information about a stack frame selected by stack address.\n\
3423 Usage: info frame address STACK-ADDRESS"),
3424 &info_frame_cmd_list
);
3426 add_cmd ("view", class_stack
, &info_frame_cmd
.view
,
3428 Print information about a stack frame outside the current backtrace.\n\
3430 Usage: info frame view STACK-ADDRESS\n\
3431 info frame view STACK-ADDRESS PC-ADDRESS"),
3432 &info_frame_cmd_list
);
3434 cmd
= add_cmd ("function", class_stack
, &info_frame_cmd
.function
,
3436 Print information about a stack frame selected by function name.\n\
3438 Usage: info frame function NAME"),
3439 &info_frame_cmd_list
);
3440 set_cmd_completer (cmd
, frame_selection_by_function_completer
);
3442 add_cmd ("level", class_stack
, &info_frame_cmd
.level
,
3444 Print information about a stack frame selected by level.\n\
3446 Usage: info frame level LEVEL"),
3447 &info_frame_cmd_list
);
3449 add_info ("locals", info_locals_command
,
3450 info_print_args_help (_("\
3451 All local variables of current stack frame or those matching REGEXPs.\n\
3452 Usage: info locals [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
3453 Prints the local variables of the current stack frame.\n"),
3454 _("local variables")));
3455 add_info ("args", info_args_command
,
3456 info_print_args_help (_("\
3457 All argument variables of current stack frame or those matching REGEXPs.\n\
3458 Usage: info args [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
3459 Prints the argument variables of the current stack frame.\n"),
3460 _("argument variables")));
3463 add_com ("func", class_stack
, func_command
, _("\
3464 Select the stack frame that contains NAME.\n\
3465 Usage: func NAME"));
3467 /* Install "set print raw frame-arguments", a deprecated spelling of
3468 "set print raw-frame-arguments". */
3469 cmd
= add_setshow_boolean_cmd
3470 ("frame-arguments", no_class
,
3471 &user_frame_print_options
.print_raw_frame_arguments
,
3473 Set whether to print frame arguments in raw form."), _("\
3474 Show whether to print frame arguments in raw form."), _("\
3475 If set, frame arguments are printed in raw form, bypassing any\n\
3476 pretty-printers for that value."),
3478 &setprintrawlist
, &showprintrawlist
);
3479 deprecate_cmd (cmd
, "set print raw-frame-arguments");
3481 add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack
,
3482 &disassemble_next_line
, _("\
3483 Set whether to disassemble next source line or insn when execution stops."),
3485 Show whether to disassemble next source line or insn when execution stops."),
3487 If ON, GDB will display disassembly of the next source line, in addition\n\
3488 to displaying the source line itself. If the next source line cannot\n\
3489 be displayed (e.g., source is unavailable or there's no line info), GDB\n\
3490 will display disassembly of next instruction instead of showing the\n\
3492 If AUTO, display disassembly of next instruction only if the source line\n\
3493 cannot be displayed.\n\
3494 If OFF (which is the default), never display the disassembly of the next\n\
3497 show_disassemble_next_line
,
3498 &setlist
, &showlist
);
3499 disassemble_next_line
= AUTO_BOOLEAN_FALSE
;
3501 gdb::option::add_setshow_cmds_for_options
3502 (class_stack
, &user_frame_print_options
,
3503 frame_print_option_defs
, &setprintlist
, &showprintlist
);