1 /* Print and select stack frames for GDB, the GNU debugger.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
5 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "expression.h"
33 #include "breakpoint.h"
40 #include "dictionary.h"
41 #include "exceptions.h"
42 #include "reggroups.h"
46 #include "gdbthread.h"
47 #include "cp-support.h"
49 #include "inline-frame.h"
51 #include "gdb_assert.h"
53 #include "gdb_string.h"
58 void (*deprecated_selected_frame_level_changed_hook) (int);
60 /* The possible choices of "set print frame-arguments", and the value
63 static const char *print_frame_arguments_choices[] =
64 {"all", "scalars", "none", NULL};
65 static const char *print_frame_arguments = "scalars";
67 /* The possible choices of "set print entry-values", and the value
70 const char print_entry_values_no[] = "no";
71 const char print_entry_values_only[] = "only";
72 const char print_entry_values_preferred[] = "preferred";
73 const char print_entry_values_if_needed[] = "if-needed";
74 const char print_entry_values_both[] = "both";
75 const char print_entry_values_compact[] = "compact";
76 const char print_entry_values_default[] = "default";
77 static const char *print_entry_values_choices[] =
79 print_entry_values_no,
80 print_entry_values_only,
81 print_entry_values_preferred,
82 print_entry_values_if_needed,
83 print_entry_values_both,
84 print_entry_values_compact,
85 print_entry_values_default,
88 const char *print_entry_values = print_entry_values_default;
90 /* Prototypes for local functions. */
92 static void print_frame_local_vars (struct frame_info *, int,
95 static void print_frame (struct frame_info *frame, int print_level,
96 enum print_what print_what, int print_args,
97 struct symtab_and_line sal);
99 /* Zero means do things normally; we are interacting directly with the
100 user. One means print the full filename and linenumber when a
101 frame is printed, and do so in a format emacs18/emacs19.22 can
102 parse. Two means print similar annotations, but in many more
103 cases and in a slightly different syntax. */
105 int annotation_level = 0;
108 /* Return 1 if we should display the address in addition to the location,
109 because we are in the middle of a statement. */
112 frame_show_address (struct frame_info *frame,
113 struct symtab_and_line sal)
115 /* If there is a line number, but no PC, then there is no location
116 information associated with this sal. The only way that should
117 happen is for the call sites of inlined functions (SAL comes from
118 find_frame_sal). Otherwise, we would have some PC range if the
119 SAL came from a line table. */
120 if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
122 if (get_next_frame (frame) == NULL)
123 gdb_assert (inline_skipped_frames (inferior_ptid) > 0);
125 gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
129 return get_frame_pc (frame) != sal.pc;
132 /* Show or print a stack frame FRAME briefly. The output is format
133 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
134 relative level, function name, argument list, and file name and
135 line number. If the frame's PC is not at the beginning of the
136 source line, the actual PC is printed at the beginning. */
139 print_stack_frame (struct frame_info *frame, int print_level,
140 enum print_what print_what)
142 volatile struct gdb_exception e;
144 /* For mi, alway print location and address. */
145 if (ui_out_is_mi_like_p (current_uiout))
146 print_what = LOC_AND_ADDRESS;
148 TRY_CATCH (e, RETURN_MASK_ERROR)
150 int center = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
152 print_frame_info (frame, print_level, print_what, 1 /* print_args */);
153 set_current_sal_from_frame (frame, center);
157 /* Print nameless arguments of frame FRAME on STREAM, where START is
158 the offset of the first nameless argument, and NUM is the number of
159 nameless arguments to print. FIRST is nonzero if this is the first
160 argument (not just the first nameless argument). */
163 print_frame_nameless_args (struct frame_info *frame, long start, int num,
164 int first, struct ui_file *stream)
166 struct gdbarch *gdbarch = get_frame_arch (frame);
167 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
172 for (i = 0; i < num; i++)
175 argsaddr = get_frame_args_address (frame);
178 arg_value = read_memory_integer (argsaddr + start,
179 sizeof (int), byte_order);
181 fprintf_filtered (stream, ", ");
182 fprintf_filtered (stream, "%ld", arg_value);
184 start += sizeof (int);
188 /* Print single argument of inferior function. ARG must be already
191 Errors are printed as if they would be the parameter value. Use zeroed ARG
192 iff it should not be printed accoring to user settings. */
195 print_frame_arg (const struct frame_arg *arg)
197 struct ui_out *uiout = current_uiout;
198 volatile struct gdb_exception except;
199 struct cleanup *old_chain;
200 struct ui_stream *stb;
202 stb = ui_out_stream_new (uiout);
203 old_chain = make_cleanup_ui_out_stream_delete (stb);
205 gdb_assert (!arg->val || !arg->error);
206 gdb_assert (arg->entry_kind == print_entry_values_no
207 || arg->entry_kind == print_entry_values_only
208 || (!ui_out_is_mi_like_p (uiout)
209 && arg->entry_kind == print_entry_values_compact));
211 annotate_arg_begin ();
213 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
214 fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
215 SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
216 if (arg->entry_kind == print_entry_values_compact)
218 /* It is OK to provide invalid MI-like stream as with
219 PRINT_ENTRY_VALUE_COMPACT we never use MI. */
220 fputs_filtered ("=", stb->stream);
222 fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
223 SYMBOL_LANGUAGE (arg->sym),
224 DMGL_PARAMS | DMGL_ANSI);
226 if (arg->entry_kind == print_entry_values_only
227 || arg->entry_kind == print_entry_values_compact)
228 fputs_filtered ("@entry", stb->stream);
229 ui_out_field_stream (uiout, "name", stb);
230 annotate_arg_name_end ();
231 ui_out_text (uiout, "=");
233 if (!arg->val && !arg->error)
234 ui_out_text (uiout, "...");
238 except.message = arg->error;
241 /* TRY_CATCH has two statements, wrap it in a block. */
243 TRY_CATCH (except, RETURN_MASK_ERROR)
245 const struct language_defn *language;
246 struct value_print_options opts;
248 /* Avoid value_print because it will deref ref parameters. We
249 just want to print their addresses. Print ??? for args whose
250 address we do not know. We pass 2 as "recurse" to val_print
251 because our standard indentation here is 4 spaces, and
252 val_print indents 2 for each recurse. */
254 annotate_arg_value (value_type (arg->val));
256 /* Use the appropriate language to display our symbol, unless the
257 user forced the language to a specific language. */
258 if (language_mode == language_mode_auto)
259 language = language_def (SYMBOL_LANGUAGE (arg->sym));
261 language = current_language;
263 get_raw_print_options (&opts);
266 /* True in "summary" mode, false otherwise. */
267 opts.summary = !strcmp (print_frame_arguments, "scalars");
269 common_val_print (arg->val, stb->stream, 2, &opts, language);
273 fprintf_filtered (stb->stream, _("<error reading variable: %s>"),
277 ui_out_field_stream (uiout, "value", stb);
279 /* Aleo invoke ui_out_tuple_end. */
280 do_cleanups (old_chain);
285 /* Read in inferior function parameter SYM at FRAME into ARGP. Caller is
286 responsible for xfree of ARGP->ERROR. This function never throws an
290 read_frame_arg (struct symbol *sym, struct frame_info *frame,
291 struct frame_arg *argp, struct frame_arg *entryargp)
293 struct value *val = NULL, *entryval = NULL;
294 char *val_error = NULL, *entryval_error = NULL;
296 volatile struct gdb_exception except;
298 if (print_entry_values != print_entry_values_only
299 && print_entry_values != print_entry_values_preferred)
301 TRY_CATCH (except, RETURN_MASK_ERROR)
303 val = read_var_value (sym, frame);
307 val_error = alloca (strlen (except.message) + 1);
308 strcpy (val_error, except.message);
312 if (SYMBOL_CLASS (sym) == LOC_COMPUTED
313 && print_entry_values != print_entry_values_no
314 && (print_entry_values != print_entry_values_if_needed
315 || !val || value_optimized_out (val)))
317 TRY_CATCH (except, RETURN_MASK_ERROR)
319 const struct symbol_computed_ops *ops;
321 ops = SYMBOL_COMPUTED_OPS (sym);
322 entryval = ops->read_variable_at_entry (sym, frame);
326 entryval_error = alloca (strlen (except.message) + 1);
327 strcpy (entryval_error, except.message);
330 if (except.error == NO_ENTRY_VALUE_ERROR
331 || (entryval && value_optimized_out (entryval)))
334 entryval_error = NULL;
337 if (print_entry_values == print_entry_values_compact
338 || print_entry_values == print_entry_values_default)
340 /* For MI do not try to use print_entry_values_compact for ARGP. */
342 if (val && entryval && !ui_out_is_mi_like_p (current_uiout))
344 unsigned len = TYPE_LENGTH (value_type (val));
346 if (!value_optimized_out (val) && value_lazy (val))
347 value_fetch_lazy (val);
348 if (!value_optimized_out (val) && value_lazy (entryval))
349 value_fetch_lazy (entryval);
350 if (!value_optimized_out (val)
351 && value_available_contents_eq (val, 0, entryval, 0, len))
353 struct value *val_deref, *entryval_deref;
355 /* DW_AT_GNU_call_site_value does match with the current
356 value. If it is a reference still try to verify if
357 dereferenced DW_AT_GNU_call_site_data_value does not
360 TRY_CATCH (except, RETURN_MASK_ERROR)
364 val_deref = coerce_ref (val);
365 if (value_lazy (val_deref))
366 value_fetch_lazy (val_deref);
367 len_deref = TYPE_LENGTH (value_type (val_deref));
369 entryval_deref = coerce_ref (entryval);
370 if (value_lazy (entryval_deref))
371 value_fetch_lazy (entryval_deref);
373 /* If the reference addresses match but dereferenced
374 content does not match print them. */
376 && value_available_contents_eq (val_deref, 0,
382 /* Value was not a reference; and its content matches. */
383 if (val == val_deref)
385 /* If the dereferenced content could not be fetched do not
387 else if (except.error == NO_ENTRY_VALUE_ERROR)
389 else if (except.message)
391 entryval_error = alloca (strlen (except.message) + 1);
392 strcpy (entryval_error, except.message);
400 /* Try to remove possibly duplicate error message for ENTRYARGP even
403 if (val_error && entryval_error
404 && strcmp (val_error, entryval_error) == 0)
406 entryval_error = NULL;
408 /* Do not se VAL_EQUAL as the same error message may be shown for
409 the entry value even if no entry values are present in the
415 if (entryval == NULL)
417 if (print_entry_values == print_entry_values_preferred)
419 TRY_CATCH (except, RETURN_MASK_ERROR)
421 val = read_var_value (sym, frame);
425 val_error = alloca (strlen (except.message) + 1);
426 strcpy (val_error, except.message);
429 if (print_entry_values == print_entry_values_only
430 || print_entry_values == print_entry_values_both
431 || (print_entry_values == print_entry_values_preferred
432 && (!val || value_optimized_out (val))))
433 entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
435 if ((print_entry_values == print_entry_values_compact
436 || print_entry_values == print_entry_values_if_needed
437 || print_entry_values == print_entry_values_preferred)
438 && (!val || value_optimized_out (val)) && entryval != NULL)
446 argp->error = val_error ? xstrdup (val_error) : NULL;
447 if (!val && !val_error)
448 argp->entry_kind = print_entry_values_only;
449 else if ((print_entry_values == print_entry_values_compact
450 || print_entry_values == print_entry_values_default) && val_equal)
452 argp->entry_kind = print_entry_values_compact;
453 gdb_assert (!ui_out_is_mi_like_p (current_uiout));
456 argp->entry_kind = print_entry_values_no;
458 entryargp->sym = sym;
459 entryargp->val = entryval;
460 entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
461 if (!entryval && !entryval_error)
462 entryargp->entry_kind = print_entry_values_no;
464 entryargp->entry_kind = print_entry_values_only;
467 /* Print the arguments of frame FRAME on STREAM, given the function
468 FUNC running in that frame (as a symbol), where NUM is the number
469 of arguments according to the stack frame (or -1 if the number of
470 arguments is unknown). */
472 /* Note that currently the "number of arguments according to the
473 stack frame" is only known on VAX where i refers to the "number of
474 ints of arguments according to the stack frame". */
477 print_frame_args (struct symbol *func, struct frame_info *frame,
478 int num, struct ui_file *stream)
480 struct ui_out *uiout = current_uiout;
482 /* Offset of next stack argument beyond the one we have seen that is
483 at the highest offset, or -1 if we haven't come to a stack
485 long highest_offset = -1;
486 /* Number of ints of arguments that we have printed so far. */
487 int args_printed = 0;
488 struct cleanup *old_chain, *list_chain;
489 struct ui_stream *stb;
490 /* True if we should print arguments, false otherwise. */
491 int print_args = strcmp (print_frame_arguments, "none");
492 /* True in "summary" mode, false otherwise. */
493 int summary = !strcmp (print_frame_arguments, "scalars");
495 stb = ui_out_stream_new (uiout);
496 old_chain = make_cleanup_ui_out_stream_delete (stb);
500 struct block *b = SYMBOL_BLOCK_VALUE (func);
501 struct dict_iterator iter;
504 ALL_BLOCK_SYMBOLS (b, iter, sym)
506 struct frame_arg arg, entryarg;
510 /* Keep track of the highest stack argument offset seen, and
511 skip over any kinds of symbols we don't care about. */
513 if (!SYMBOL_IS_ARGUMENT (sym))
516 switch (SYMBOL_CLASS (sym))
521 long current_offset = SYMBOL_VALUE (sym);
522 int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
524 /* Compute address of next argument by adding the size of
525 this argument and rounding to an int boundary. */
527 ((current_offset + arg_size + sizeof (int) - 1)
528 & ~(sizeof (int) - 1));
530 /* If this is the highest offset seen yet, set
532 if (highest_offset == -1
533 || (current_offset > highest_offset))
534 highest_offset = current_offset;
536 /* Add the number of ints we're about to print to
538 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
541 /* We care about types of symbols, but don't need to
542 keep track of stack offsets in them. */
544 case LOC_REGPARM_ADDR:
546 case LOC_OPTIMIZED_OUT:
551 /* We have to look up the symbol because arguments can have
552 two entries (one a parameter, one a local) and the one we
553 want is the local, which lookup_symbol will find for us.
554 This includes gcc1 (not gcc2) on SPARC when passing a
555 small structure and gcc2 when the argument type is float
556 and it is passed as a double and converted to float by
557 the prologue (in the latter case the type of the LOC_ARG
558 symbol is double and the type of the LOC_LOCAL symbol is
560 /* But if the parameter name is null, don't try it. Null
561 parameter names occur on the RS/6000, for traceback
562 tables. FIXME, should we even print them? */
564 if (*SYMBOL_LINKAGE_NAME (sym))
568 nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
569 b, VAR_DOMAIN, NULL);
570 gdb_assert (nsym != NULL);
571 if (SYMBOL_CLASS (nsym) == LOC_REGISTER
572 && !SYMBOL_IS_ARGUMENT (nsym))
574 /* There is a LOC_ARG/LOC_REGISTER pair. This means
575 that it was passed on the stack and loaded into a
576 register, or passed in a register and stored in a
577 stack slot. GDB 3.x used the LOC_ARG; GDB
578 4.0-4.11 used the LOC_REGISTER.
580 Reasons for using the LOC_ARG:
582 (1) Because find_saved_registers may be slow for
585 (2) Because registers are often re-used and stack
586 slots rarely (never?) are. Therefore using
587 the stack slot is much less likely to print
590 Reasons why we might want to use the LOC_REGISTER:
592 (1) So that the backtrace prints the same value
593 as "print foo". I see no compelling reason
594 why this needs to be the case; having the
595 backtrace print the value which was passed
596 in, and "print foo" print the value as
597 modified within the called function, makes
600 Additional note: It might be nice if "info args"
601 displayed both values.
603 One more note: There is a case with SPARC
604 structure passing where we need to use the
605 LOC_REGISTER, but this is dealt with by creating
606 a single LOC_REGPARM in symbol reading. */
608 /* Leave sym (the LOC_ARG) alone. */
615 /* Print the current arg. */
617 ui_out_text (uiout, ", ");
618 ui_out_wrap_hint (uiout, " ");
622 memset (&arg, 0, sizeof (arg));
624 arg.entry_kind = print_entry_values_no;
625 memset (&entryarg, 0, sizeof (entryarg));
627 entryarg.entry_kind = print_entry_values_no;
630 read_frame_arg (sym, frame, &arg, &entryarg);
632 if (arg.entry_kind != print_entry_values_only)
633 print_frame_arg (&arg);
635 if (entryarg.entry_kind != print_entry_values_no)
637 if (arg.entry_kind != print_entry_values_only)
639 ui_out_text (uiout, ", ");
640 ui_out_wrap_hint (uiout, " ");
643 print_frame_arg (&entryarg);
647 xfree (entryarg.error);
653 /* Don't print nameless args in situations where we don't know
654 enough about the stack to find them. */
659 if (highest_offset == -1)
660 start = gdbarch_frame_args_skip (get_frame_arch (frame));
662 start = highest_offset;
664 print_frame_nameless_args (frame, start, num - args_printed,
668 do_cleanups (old_chain);
671 /* Set the current source and line to the location given by frame
672 FRAME, if possible. When CENTER is true, adjust so the relevant
673 line is in the center of the next 'list'. */
676 set_current_sal_from_frame (struct frame_info *frame, int center)
678 struct symtab_and_line sal;
680 find_frame_sal (frame, &sal);
684 sal.line = max (sal.line - get_lines_to_list () / 2, 1);
685 set_current_source_symtab_and_line (&sal);
689 /* If ON, GDB will display disassembly of the next source line when
690 execution of the program being debugged stops.
691 If AUTO (which is the default), or there's no line info to determine
692 the source line of the next instruction, display disassembly of next
693 instruction instead. */
695 static enum auto_boolean disassemble_next_line;
698 show_disassemble_next_line (struct ui_file *file, int from_tty,
699 struct cmd_list_element *c,
702 fprintf_filtered (file,
703 _("Debugger's willingness to use "
704 "disassemble-next-line is %s.\n"),
708 /* Use TRY_CATCH to catch the exception from the gdb_disassembly
709 because it will be broken by filter sometime. */
712 do_gdb_disassembly (struct gdbarch *gdbarch,
713 int how_many, CORE_ADDR low, CORE_ADDR high)
715 volatile struct gdb_exception exception;
717 TRY_CATCH (exception, RETURN_MASK_ERROR)
719 gdb_disassembly (gdbarch, current_uiout, 0,
720 DISASSEMBLY_RAW_INSN, how_many,
723 if (exception.reason < 0)
725 /* If an exception was thrown while doing the disassembly, print
726 the error message, to give the user a clue of what happened. */
727 exception_print (gdb_stderr, exception);
731 /* Print information about frame FRAME. The output is format according
732 to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. The meaning of
735 SRC_LINE: Print only source line.
736 LOCATION: Print only location.
737 LOC_AND_SRC: Print location and source line.
739 Used in "where" output, and to emit breakpoint or step
743 print_frame_info (struct frame_info *frame, int print_level,
744 enum print_what print_what, int print_args)
746 struct gdbarch *gdbarch = get_frame_arch (frame);
747 struct symtab_and_line sal;
750 struct ui_out *uiout = current_uiout;
752 if (get_frame_type (frame) == DUMMY_FRAME
753 || get_frame_type (frame) == SIGTRAMP_FRAME
754 || get_frame_type (frame) == ARCH_FRAME)
756 struct cleanup *uiout_cleanup
757 = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
759 annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
760 gdbarch, get_frame_pc (frame));
762 /* Do this regardless of SOURCE because we don't have any source
763 to list for this frame. */
766 ui_out_text (uiout, "#");
767 ui_out_field_fmt_int (uiout, 2, ui_left, "level",
768 frame_relative_level (frame));
770 if (ui_out_is_mi_like_p (uiout))
772 annotate_frame_address ();
773 ui_out_field_core_addr (uiout, "addr",
774 gdbarch, get_frame_pc (frame));
775 annotate_frame_address_end ();
778 if (get_frame_type (frame) == DUMMY_FRAME)
780 annotate_function_call ();
781 ui_out_field_string (uiout, "func", "<function called from gdb>");
783 else if (get_frame_type (frame) == SIGTRAMP_FRAME)
785 annotate_signal_handler_caller ();
786 ui_out_field_string (uiout, "func", "<signal handler called>");
788 else if (get_frame_type (frame) == ARCH_FRAME)
790 ui_out_field_string (uiout, "func", "<cross-architecture call>");
792 ui_out_text (uiout, "\n");
793 annotate_frame_end ();
795 do_cleanups (uiout_cleanup);
799 /* If FRAME is not the innermost frame, that normally means that
800 FRAME->pc points to *after* the call instruction, and we want to
801 get the line containing the call, never the next line. But if
802 the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
803 next frame was not entered as the result of a call, and we want
804 to get the line containing FRAME->pc. */
805 find_frame_sal (frame, &sal);
807 location_print = (print_what == LOCATION
808 || print_what == LOC_AND_ADDRESS
809 || print_what == SRC_AND_LOC);
811 if (location_print || !sal.symtab)
812 print_frame (frame, print_level, print_what, print_args, sal);
814 source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
816 /* If disassemble-next-line is set to auto or on and doesn't have
817 the line debug messages for $pc, output the next instruction. */
818 if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
819 || disassemble_next_line == AUTO_BOOLEAN_TRUE)
820 && source_print && !sal.symtab)
821 do_gdb_disassembly (get_frame_arch (frame), 1,
822 get_frame_pc (frame), get_frame_pc (frame) + 1);
824 if (source_print && sal.symtab)
827 int mid_statement = ((print_what == SRC_LINE)
828 && frame_show_address (frame, sal));
830 if (annotation_level)
831 done = identify_source_line (sal.symtab, sal.line, mid_statement,
832 get_frame_pc (frame));
835 if (deprecated_print_frame_info_listing_hook)
836 deprecated_print_frame_info_listing_hook (sal.symtab,
841 struct value_print_options opts;
843 get_user_print_options (&opts);
844 /* We used to do this earlier, but that is clearly
845 wrong. This function is used by many different
846 parts of gdb, including normal_stop in infrun.c,
847 which uses this to print out the current PC
848 when we stepi/nexti into the middle of a source
849 line. Only the command line really wants this
850 behavior. Other UIs probably would like the
851 ability to decide for themselves if it is desired. */
852 if (opts.addressprint && mid_statement)
854 ui_out_field_core_addr (uiout, "addr",
855 gdbarch, get_frame_pc (frame));
856 ui_out_text (uiout, "\t");
859 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
863 /* If disassemble-next-line is set to on and there is line debug
864 messages, output assembly codes for next line. */
865 if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
866 do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
869 if (print_what != LOCATION)
873 if (get_frame_pc_if_available (frame, &pc))
874 set_default_breakpoint (1, sal.pspace, pc, sal.symtab, sal.line);
876 set_default_breakpoint (0, 0, 0, 0, 0);
879 annotate_frame_end ();
881 gdb_flush (gdb_stdout);
884 /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
885 corresponding to FRAME. */
888 find_frame_funname (struct frame_info *frame, char **funname,
889 enum language *funlang, struct symbol **funcp)
894 *funlang = language_unknown;
898 func = get_frame_function (frame);
901 /* In certain pathological cases, the symtabs give the wrong
902 function (when we are in the first function in a file which
903 is compiled without debugging symbols, the previous function
904 is compiled with debugging symbols, and the "foo.o" symbol
905 that is supposed to tell us where the file with debugging
906 symbols ends has been truncated by ar because it is longer
907 than 15 characters). This also occurs if the user uses asm()
908 to create a function but not stabs for it (in a file compiled
911 So look in the minimal symbol tables as well, and if it comes
912 up with a larger address for the function use that instead.
913 I don't think this can ever cause any problems; there
914 shouldn't be any minimal symbols in the middle of a function;
915 if this is ever changed many parts of GDB will need to be
916 changed (and we'll create a find_pc_minimal_function or some
919 struct minimal_symbol *msymbol = NULL;
921 /* Don't attempt to do this for inlined functions, which do not
922 have a corresponding minimal symbol. */
923 if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
925 = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
928 && (SYMBOL_VALUE_ADDRESS (msymbol)
929 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
931 /* We also don't know anything about the function besides
932 its address and name. */
934 *funname = SYMBOL_PRINT_NAME (msymbol);
935 *funlang = SYMBOL_LANGUAGE (msymbol);
939 *funname = SYMBOL_PRINT_NAME (func);
940 *funlang = SYMBOL_LANGUAGE (func);
943 if (*funlang == language_cplus)
945 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
946 to display the demangled name that we already have
947 stored in the symbol table, but we stored a version
948 with DMGL_PARAMS turned on, and here we don't want to
949 display parameters. So remove the parameters. */
950 char *func_only = cp_remove_params (*funname);
954 *funname = func_only;
955 make_cleanup (xfree, func_only);
962 struct minimal_symbol *msymbol;
965 if (!get_frame_address_in_block_if_available (frame, &pc))
968 msymbol = lookup_minimal_symbol_by_pc (pc);
971 *funname = SYMBOL_PRINT_NAME (msymbol);
972 *funlang = SYMBOL_LANGUAGE (msymbol);
978 print_frame (struct frame_info *frame, int print_level,
979 enum print_what print_what, int print_args,
980 struct symtab_and_line sal)
982 struct gdbarch *gdbarch = get_frame_arch (frame);
983 struct ui_out *uiout = current_uiout;
984 char *funname = NULL;
985 enum language funlang = language_unknown;
986 struct ui_stream *stb;
987 struct cleanup *old_chain, *list_chain;
988 struct value_print_options opts;
993 pc_p = get_frame_pc_if_available (frame, &pc);
995 stb = ui_out_stream_new (uiout);
996 old_chain = make_cleanup_ui_out_stream_delete (stb);
998 find_frame_funname (frame, &funname, &funlang, &func);
1000 annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
1003 list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
1007 ui_out_text (uiout, "#");
1008 ui_out_field_fmt_int (uiout, 2, ui_left, "level",
1009 frame_relative_level (frame));
1011 get_user_print_options (&opts);
1012 if (opts.addressprint)
1014 || frame_show_address (frame, sal)
1015 || print_what == LOC_AND_ADDRESS)
1017 annotate_frame_address ();
1019 ui_out_field_core_addr (uiout, "addr", gdbarch, pc);
1021 ui_out_field_string (uiout, "addr", "<unavailable>");
1022 annotate_frame_address_end ();
1023 ui_out_text (uiout, " in ");
1025 annotate_frame_function_name ();
1026 fprintf_symbol_filtered (stb->stream, funname ? funname : "??",
1027 funlang, DMGL_ANSI);
1028 ui_out_field_stream (uiout, "func", stb);
1029 ui_out_wrap_hint (uiout, " ");
1030 annotate_frame_args ();
1032 ui_out_text (uiout, " (");
1035 struct gdbarch *gdbarch = get_frame_arch (frame);
1037 struct cleanup *args_list_chain;
1038 volatile struct gdb_exception e;
1040 if (gdbarch_frame_num_args_p (gdbarch))
1042 numargs = gdbarch_frame_num_args (gdbarch, frame);
1043 gdb_assert (numargs >= 0);
1048 args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
1049 TRY_CATCH (e, RETURN_MASK_ERROR)
1051 print_frame_args (func, frame, numargs, gdb_stdout);
1053 /* FIXME: ARGS must be a list. If one argument is a string it
1054 will have " that will not be properly escaped. */
1055 /* Invoke ui_out_tuple_end. */
1056 do_cleanups (args_list_chain);
1059 ui_out_text (uiout, ")");
1060 if (sal.symtab && sal.symtab->filename)
1062 annotate_frame_source_begin ();
1063 ui_out_wrap_hint (uiout, " ");
1064 ui_out_text (uiout, " at ");
1065 annotate_frame_source_file ();
1066 ui_out_field_string (uiout, "file", sal.symtab->filename);
1067 if (ui_out_is_mi_like_p (uiout))
1069 const char *fullname = symtab_to_fullname (sal.symtab);
1071 if (fullname != NULL)
1072 ui_out_field_string (uiout, "fullname", fullname);
1074 annotate_frame_source_file_end ();
1075 ui_out_text (uiout, ":");
1076 annotate_frame_source_line ();
1077 ui_out_field_int (uiout, "line", sal.line);
1078 annotate_frame_source_end ();
1081 if (pc_p && (!funname || (!sal.symtab || !sal.symtab->filename)))
1084 char *lib = PC_SOLIB (get_frame_pc (frame));
1086 char *lib = solib_name_from_address (get_frame_program_space (frame),
1087 get_frame_pc (frame));
1091 annotate_frame_where ();
1092 ui_out_wrap_hint (uiout, " ");
1093 ui_out_text (uiout, " from ");
1094 ui_out_field_string (uiout, "from", lib);
1098 /* do_cleanups will call ui_out_tuple_end() for us. */
1099 do_cleanups (list_chain);
1100 ui_out_text (uiout, "\n");
1101 do_cleanups (old_chain);
1105 /* Read a frame specification in whatever the appropriate format is
1106 from FRAME_EXP. Call error(), printing MESSAGE, if the
1107 specification is in any way invalid (so this function never returns
1108 NULL). When SEPECTED_P is non-NULL set its target to indicate that
1109 the default selected frame was used. */
1111 static struct frame_info *
1112 parse_frame_specification_1 (const char *frame_exp, const char *message,
1113 int *selected_frame_p)
1116 struct value *args[4];
1117 CORE_ADDR addrs[ARRAY_SIZE (args)];
1119 if (frame_exp == NULL)
1127 struct cleanup *cleanup;
1130 /* Skip leading white space, bail of EOL. */
1131 while (isspace (*frame_exp))
1136 /* Parse the argument, extract it, save it. */
1138 *p && !isspace (*p);
1140 addr_string = savestring (frame_exp, p - frame_exp);
1142 cleanup = make_cleanup (xfree, addr_string);
1144 /* NOTE: Parse and evaluate expression, but do not use
1145 functions such as parse_and_eval_long or
1146 parse_and_eval_address to also extract the value.
1147 Instead value_as_long and value_as_address are used.
1148 This avoids problems with expressions that contain
1150 if (numargs >= ARRAY_SIZE (args))
1151 error (_("Too many args in frame specification"));
1152 args[numargs++] = parse_and_eval (addr_string);
1154 do_cleanups (cleanup);
1158 /* If no args, default to the selected frame. */
1161 if (selected_frame_p != NULL)
1162 (*selected_frame_p) = 1;
1163 return get_selected_frame (message);
1166 /* None of the remaining use the selected frame. */
1167 if (selected_frame_p != NULL)
1168 (*selected_frame_p) = 0;
1170 /* Assume the single arg[0] is an integer, and try using that to
1171 select a frame relative to current. */
1174 struct frame_info *fid;
1175 int level = value_as_long (args[0]);
1177 fid = find_relative_frame (get_current_frame (), &level);
1179 /* find_relative_frame was successful. */
1183 /* Convert each value into a corresponding address. */
1187 for (i = 0; i < numargs; i++)
1188 addrs[i] = value_as_address (args[i]);
1191 /* Assume that the single arg[0] is an address, use that to identify
1192 a frame with a matching ID. Should this also accept stack/pc or
1193 stack/pc/special. */
1196 struct frame_id id = frame_id_build_wild (addrs[0]);
1197 struct frame_info *fid;
1199 /* If (s)he specifies the frame with an address, he deserves
1200 what (s)he gets. Still, give the highest one that matches.
1201 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
1203 for (fid = get_current_frame ();
1205 fid = get_prev_frame (fid))
1207 if (frame_id_eq (id, get_frame_id (fid)))
1209 struct frame_info *prev_frame;
1213 prev_frame = get_prev_frame (fid);
1215 || !frame_id_eq (id, get_frame_id (prev_frame)))
1224 /* We couldn't identify the frame as an existing frame, but
1225 perhaps we can create one with a single argument. */
1227 return create_new_frame (addrs[0], 0);
1228 else if (numargs == 2)
1229 return create_new_frame (addrs[0], addrs[1]);
1231 error (_("Too many args in frame specification"));
1234 static struct frame_info *
1235 parse_frame_specification (char *frame_exp)
1237 return parse_frame_specification_1 (frame_exp, NULL, NULL);
1240 /* Print verbosely the selected frame or the frame at address
1241 ADDR_EXP. Absolutely all information in the frame is printed. */
1244 frame_info (char *addr_exp, int from_tty)
1246 struct frame_info *fi;
1247 struct symtab_and_line sal;
1248 struct symbol *func;
1250 struct frame_info *calling_frame_info;
1253 enum language funlang = language_unknown;
1254 const char *pc_regname;
1255 int selected_frame_p;
1256 struct gdbarch *gdbarch;
1257 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
1260 CORE_ADDR caller_pc;
1262 fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
1263 gdbarch = get_frame_arch (fi);
1265 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
1266 is not a good name. */
1267 if (gdbarch_pc_regnum (gdbarch) >= 0)
1268 /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can
1269 easily not match that of the internal value returned by
1271 pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch));
1273 /* But then, this is weird to. Even without gdbarch_pc_regnum, an
1274 architectures will often have a hardware register called "pc",
1275 and that register's value, again, can easily not match
1279 frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
1280 find_frame_sal (fi, &sal);
1281 func = get_frame_function (fi);
1285 funname = SYMBOL_PRINT_NAME (func);
1286 funlang = SYMBOL_LANGUAGE (func);
1287 if (funlang == language_cplus)
1289 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
1290 to display the demangled name that we already have
1291 stored in the symbol table, but we stored a version
1292 with DMGL_PARAMS turned on, and here we don't want to
1293 display parameters. So remove the parameters. */
1294 char *func_only = cp_remove_params (funname);
1298 funname = func_only;
1299 make_cleanup (xfree, func_only);
1303 else if (frame_pc_p)
1305 struct minimal_symbol *msymbol;
1307 msymbol = lookup_minimal_symbol_by_pc (frame_pc);
1308 if (msymbol != NULL)
1310 funname = SYMBOL_PRINT_NAME (msymbol);
1311 funlang = SYMBOL_LANGUAGE (msymbol);
1314 calling_frame_info = get_prev_frame (fi);
1316 if (selected_frame_p && frame_relative_level (fi) >= 0)
1318 printf_filtered (_("Stack level %d, frame at "),
1319 frame_relative_level (fi));
1323 printf_filtered (_("Stack frame at "));
1325 fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
1326 printf_filtered (":\n");
1327 printf_filtered (" %s = ", pc_regname);
1329 fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
1331 fputs_filtered ("<unavailable>", gdb_stdout);
1336 printf_filtered (" in ");
1337 fprintf_symbol_filtered (gdb_stdout, funname, funlang,
1338 DMGL_ANSI | DMGL_PARAMS);
1342 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
1343 puts_filtered ("; ");
1345 printf_filtered ("saved %s ", pc_regname);
1346 if (frame_unwind_caller_pc_if_available (fi, &caller_pc))
1347 fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
1349 fputs_filtered ("<unavailable>", gdb_stdout);
1350 printf_filtered ("\n");
1352 if (calling_frame_info == NULL)
1354 enum unwind_stop_reason reason;
1356 reason = get_frame_unwind_stop_reason (fi);
1357 if (reason != UNWIND_NO_REASON)
1358 printf_filtered (_(" Outermost frame: %s\n"),
1359 frame_stop_reason_string (reason));
1361 else if (get_frame_type (fi) == TAILCALL_FRAME)
1362 puts_filtered (" tail call frame");
1363 else if (get_frame_type (fi) == INLINE_FRAME)
1364 printf_filtered (" inlined into frame %d",
1365 frame_relative_level (get_prev_frame (fi)));
1368 printf_filtered (" called by frame at ");
1369 fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)),
1372 if (get_next_frame (fi) && calling_frame_info)
1373 puts_filtered (",");
1375 if (get_next_frame (fi))
1377 printf_filtered (" caller of frame at ");
1378 fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))),
1381 if (get_next_frame (fi) || calling_frame_info)
1382 puts_filtered ("\n");
1385 printf_filtered (" source language %s.\n",
1386 language_str (s->language));
1389 /* Address of the argument list for this frame, or 0. */
1390 CORE_ADDR arg_list = get_frame_args_address (fi);
1391 /* Number of args for this frame, or -1 if unknown. */
1395 printf_filtered (" Arglist at unknown address.\n");
1398 printf_filtered (" Arglist at ");
1399 fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
1400 printf_filtered (",");
1402 if (!gdbarch_frame_num_args_p (gdbarch))
1405 puts_filtered (" args: ");
1409 numargs = gdbarch_frame_num_args (gdbarch, fi);
1410 gdb_assert (numargs >= 0);
1412 puts_filtered (" no args.");
1413 else if (numargs == 1)
1414 puts_filtered (" 1 arg: ");
1416 printf_filtered (" %d args: ", numargs);
1418 print_frame_args (func, fi, numargs, gdb_stdout);
1419 puts_filtered ("\n");
1423 /* Address of the local variables for this frame, or 0. */
1424 CORE_ADDR arg_list = get_frame_locals_address (fi);
1427 printf_filtered (" Locals at unknown address,");
1430 printf_filtered (" Locals at ");
1431 fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
1432 printf_filtered (",");
1436 /* Print as much information as possible on the location of all the
1439 enum lval_type lval;
1448 /* The sp is special; what's displayed isn't the save address, but
1449 the value of the previous frame's sp. This is a legacy thing,
1450 at one stage the frame cached the previous frame's SP instead
1451 of its address, hence it was easiest to just display the cached
1453 if (gdbarch_sp_regnum (gdbarch) >= 0)
1455 /* Find out the location of the saved stack pointer with out
1456 actually evaluating it. */
1457 frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
1458 &optimized, &unavailable, &lval, &addr,
1460 if (!optimized && !unavailable && lval == not_lval)
1462 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1463 int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch));
1464 gdb_byte value[MAX_REGISTER_SIZE];
1467 frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
1468 &optimized, &unavailable, &lval, &addr,
1470 /* NOTE: cagney/2003-05-22: This is assuming that the
1471 stack pointer was packed as an unsigned integer. That
1472 may or may not be valid. */
1473 sp = extract_unsigned_integer (value, sp_size, byte_order);
1474 printf_filtered (" Previous frame's sp is ");
1475 fputs_filtered (paddress (gdbarch, sp), gdb_stdout);
1476 printf_filtered ("\n");
1479 else if (!optimized && !unavailable && lval == lval_memory)
1481 printf_filtered (" Previous frame's sp at ");
1482 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
1483 printf_filtered ("\n");
1486 else if (!optimized && !unavailable && lval == lval_register)
1488 printf_filtered (" Previous frame's sp in %s\n",
1489 gdbarch_register_name (gdbarch, realnum));
1492 /* else keep quiet. */
1496 numregs = gdbarch_num_regs (gdbarch)
1497 + gdbarch_num_pseudo_regs (gdbarch);
1498 for (i = 0; i < numregs; i++)
1499 if (i != gdbarch_sp_regnum (gdbarch)
1500 && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1502 /* Find out the location of the saved register without
1503 fetching the corresponding value. */
1504 frame_register_unwind (fi, i, &optimized, &unavailable,
1505 &lval, &addr, &realnum, NULL);
1506 /* For moment, only display registers that were saved on the
1508 if (!optimized && !unavailable && lval == lval_memory)
1511 puts_filtered (" Saved registers:\n ");
1513 puts_filtered (",");
1515 printf_filtered (" %s at ",
1516 gdbarch_register_name (gdbarch, i));
1517 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
1521 if (count || need_nl)
1522 puts_filtered ("\n");
1525 do_cleanups (back_to);
1528 /* Print briefly all stack frames or just the innermost COUNT_EXP
1532 backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
1534 struct frame_info *fi;
1537 struct frame_info *trailing;
1540 if (!target_has_stack)
1541 error (_("No stack."));
1543 /* The following code must do two things. First, it must set the
1544 variable TRAILING to the frame from which we should start
1545 printing. Second, it must set the variable count to the number
1546 of frames which we should print, or -1 if all of them. */
1547 trailing = get_current_frame ();
1552 count = parse_and_eval_long (count_exp);
1555 struct frame_info *current;
1560 while (current && count--)
1563 current = get_prev_frame (current);
1566 /* Will stop when CURRENT reaches the top of the stack.
1567 TRAILING will be COUNT below it. */
1571 trailing = get_prev_frame (trailing);
1572 current = get_prev_frame (current);
1584 /* Read in symbols for all of the frames. Need to do this in a
1585 separate pass so that "Reading in symbols for xxx" messages
1586 don't screw up the appearance of the backtrace. Also if
1587 people have strong opinions against reading symbols for
1588 backtrace this may have to be an option. */
1590 for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
1595 pc = get_frame_address_in_block (fi);
1596 find_pc_sect_symtab_via_partial (pc, find_pc_mapped_section (pc));
1600 for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
1604 /* Don't use print_stack_frame; if an error() occurs it probably
1605 means further attempts to backtrace would fail (on the other
1606 hand, perhaps the code does or could be fixed to make sure
1607 the frame->prev field gets set to NULL in that case). */
1608 print_frame_info (fi, 1, LOCATION, 1);
1610 print_frame_local_vars (fi, 1, gdb_stdout);
1612 /* Save the last frame to check for error conditions. */
1616 /* If we've stopped before the end, mention that. */
1618 printf_filtered (_("(More stack frames follow...)\n"));
1620 /* If we've run out of frames, and the reason appears to be an error
1621 condition, print it. */
1622 if (fi == NULL && trailing != NULL)
1624 enum unwind_stop_reason reason;
1626 reason = get_frame_unwind_stop_reason (trailing);
1627 if (reason > UNWIND_FIRST_ERROR)
1628 printf_filtered (_("Backtrace stopped: %s\n"),
1629 frame_stop_reason_string (reason));
1634 backtrace_command (char *arg, int from_tty)
1636 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
1637 int fulltrace_arg = -1, arglen = 0, argc = 0;
1644 argv = gdb_buildargv (arg);
1645 make_cleanup_freeargv (argv);
1647 for (i = 0; argv[i]; i++)
1651 for (j = 0; j < strlen (argv[i]); j++)
1652 argv[i][j] = tolower (argv[i][j]);
1654 if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
1655 fulltrace_arg = argc;
1658 arglen += strlen (argv[i]);
1663 if (fulltrace_arg >= 0)
1667 arg = xmalloc (arglen + 1);
1668 make_cleanup (xfree, arg);
1670 for (i = 0; i < (argc + 1); i++)
1672 if (i != fulltrace_arg)
1674 strcat (arg, argv[i]);
1684 backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, from_tty);
1686 do_cleanups (old_chain);
1690 backtrace_full_command (char *arg, int from_tty)
1692 backtrace_command_1 (arg, 1 /* show_locals */, from_tty);
1696 /* Iterate over the local variables of a block B, calling CB with
1700 iterate_over_block_locals (struct block *b,
1701 iterate_over_block_arg_local_vars_cb cb,
1704 struct dict_iterator iter;
1707 ALL_BLOCK_SYMBOLS (b, iter, sym)
1709 switch (SYMBOL_CLASS (sym))
1715 if (SYMBOL_IS_ARGUMENT (sym))
1717 (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
1721 /* Ignore symbols which are not locals. */
1728 /* Same, but print labels. */
1731 /* Commented out, as the code using this function has also been
1732 commented out. FIXME:brobecker/2009-01-13: Find out why the code
1733 was commented out in the first place. The discussion introducing
1734 this change (2007-12-04: Support lexical blocks and function bodies
1735 that occupy non-contiguous address ranges) did not explain why
1736 this change was made. */
1738 print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
1739 int *have_default, struct ui_file *stream)
1741 struct dict_iterator iter;
1743 int values_printed = 0;
1745 ALL_BLOCK_SYMBOLS (b, iter, sym)
1747 if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0)
1753 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1755 struct symtab_and_line sal;
1756 struct value_print_options opts;
1758 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1760 fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
1761 get_user_print_options (&opts);
1762 if (opts.addressprint)
1764 fprintf_filtered (stream, " ");
1765 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)),
1768 fprintf_filtered (stream, " in file %s, line %d\n",
1769 sal.symtab->filename, sal.line);
1773 return values_printed;
1777 /* Iterate over all the local variables in block B, including all its
1778 superblocks, stopping when the top-level block is reached. */
1781 iterate_over_block_local_vars (struct block *block,
1782 iterate_over_block_arg_local_vars_cb cb,
1787 iterate_over_block_locals (block, cb, cb_data);
1788 /* After handling the function's top-level block, stop. Don't
1789 continue to its superblock, the block of per-file
1791 if (BLOCK_FUNCTION (block))
1793 block = BLOCK_SUPERBLOCK (block);
1797 /* Data to be passed around in the calls to the locals and args
1800 struct print_variable_and_value_data
1802 struct frame_info *frame;
1804 struct ui_file *stream;
1808 /* The callback for the locals and args iterators. */
1811 do_print_variable_and_value (const char *print_name,
1815 struct print_variable_and_value_data *p = cb_data;
1817 print_variable_and_value (print_name, sym,
1818 p->frame, p->stream, p->num_tabs);
1819 p->values_printed = 1;
1823 print_frame_local_vars (struct frame_info *frame, int num_tabs,
1824 struct ui_file *stream)
1826 struct print_variable_and_value_data cb_data;
1827 struct block *block;
1830 if (!get_frame_pc_if_available (frame, &pc))
1832 fprintf_filtered (stream,
1833 _("PC unavailable, cannot determine locals.\n"));
1837 block = get_frame_block (frame, 0);
1840 fprintf_filtered (stream, "No symbol table info available.\n");
1844 cb_data.frame = frame;
1845 cb_data.num_tabs = 4 * num_tabs;
1846 cb_data.stream = stream;
1847 cb_data.values_printed = 0;
1849 iterate_over_block_local_vars (block,
1850 do_print_variable_and_value,
1853 if (!cb_data.values_printed)
1854 fprintf_filtered (stream, _("No locals.\n"));
1857 /* Same, but print labels. */
1860 print_frame_label_vars (struct frame_info *frame, int this_level_only,
1861 struct ui_file *stream)
1864 fprintf_filtered (stream, "print_frame_label_vars disabled.\n");
1866 struct blockvector *bl;
1867 struct block *block = get_frame_block (frame, 0);
1868 struct gdbarch *gdbarch = get_frame_arch (frame);
1869 int values_printed = 0;
1870 int index, have_default = 0;
1871 char *blocks_printed;
1872 CORE_ADDR pc = get_frame_pc (frame);
1876 fprintf_filtered (stream, "No symbol table info available.\n");
1880 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1881 blocks_printed = alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1882 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1886 CORE_ADDR end = BLOCK_END (block) - 4;
1889 if (bl != blockvector_for_pc (end, &index))
1890 error (_("blockvector blotch"));
1891 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1892 error (_("blockvector botch"));
1893 last_index = BLOCKVECTOR_NBLOCKS (bl);
1896 /* Don't print out blocks that have gone by. */
1897 while (index < last_index
1898 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1901 while (index < last_index
1902 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1904 if (blocks_printed[index] == 0)
1906 if (print_block_frame_labels (gdbarch,
1907 BLOCKVECTOR_BLOCK (bl, index),
1908 &have_default, stream))
1910 blocks_printed[index] = 1;
1916 if (values_printed && this_level_only)
1919 /* After handling the function's top-level block, stop. Don't
1920 continue to its superblock, the block of per-file symbols.
1921 Also do not continue to the containing function of an inlined
1923 if (BLOCK_FUNCTION (block))
1925 block = BLOCK_SUPERBLOCK (block);
1928 if (!values_printed && !this_level_only)
1929 fprintf_filtered (stream, _("No catches.\n"));
1934 locals_info (char *args, int from_tty)
1936 print_frame_local_vars (get_selected_frame (_("No frame selected.")),
1941 catch_info (char *ignore, int from_tty)
1943 /* Assume g++ compiled code; old GDB 4.16 behaviour. */
1944 print_frame_label_vars (get_selected_frame (_("No frame selected.")),
1948 /* Iterate over all the argument variables in block B.
1950 Returns 1 if any argument was walked; 0 otherwise. */
1953 iterate_over_block_arg_vars (struct block *b,
1954 iterate_over_block_arg_local_vars_cb cb,
1957 struct dict_iterator iter;
1958 struct symbol *sym, *sym2;
1960 ALL_BLOCK_SYMBOLS (b, iter, sym)
1962 /* Don't worry about things which aren't arguments. */
1963 if (SYMBOL_IS_ARGUMENT (sym))
1965 /* We have to look up the symbol because arguments can have
1966 two entries (one a parameter, one a local) and the one we
1967 want is the local, which lookup_symbol will find for us.
1968 This includes gcc1 (not gcc2) on the sparc when passing a
1969 small structure and gcc2 when the argument type is float
1970 and it is passed as a double and converted to float by
1971 the prologue (in the latter case the type of the LOC_ARG
1972 symbol is double and the type of the LOC_LOCAL symbol is
1973 float). There are also LOC_ARG/LOC_REGISTER pairs which
1974 are not combined in symbol-reading. */
1976 sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
1977 b, VAR_DOMAIN, NULL);
1978 (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
1984 print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
1986 struct print_variable_and_value_data cb_data;
1987 struct symbol *func;
1990 if (!get_frame_pc_if_available (frame, &pc))
1992 fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n"));
1996 func = get_frame_function (frame);
1999 fprintf_filtered (stream, _("No symbol table info available.\n"));
2003 cb_data.frame = frame;
2004 cb_data.num_tabs = 0;
2005 cb_data.stream = gdb_stdout;
2006 cb_data.values_printed = 0;
2008 iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func),
2009 do_print_variable_and_value, &cb_data);
2011 if (!cb_data.values_printed)
2012 fprintf_filtered (stream, _("No arguments.\n"));
2016 args_info (char *ignore, int from_tty)
2018 print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
2024 args_plus_locals_info (char *ignore, int from_tty)
2026 args_info (ignore, from_tty);
2027 locals_info (ignore, from_tty);
2031 /* Select frame FRAME. Also print the stack frame and show the source
2032 if this is the tui version. */
2034 select_and_print_frame (struct frame_info *frame)
2036 select_frame (frame);
2038 print_stack_frame (frame, 1, SRC_AND_LOC);
2041 /* Return the symbol-block in which the selected frame is executing.
2042 Can return zero under various legitimate circumstances.
2044 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
2045 code address within the block returned. We use this to decide
2046 which macros are in scope. */
2049 get_selected_block (CORE_ADDR *addr_in_block)
2051 if (!has_stack_frames ())
2054 return get_frame_block (get_selected_frame (NULL), addr_in_block);
2057 /* Find a frame a certain number of levels away from FRAME.
2058 LEVEL_OFFSET_PTR points to an int containing the number of levels.
2059 Positive means go to earlier frames (up); negative, the reverse.
2060 The int that contains the number of levels is counted toward
2061 zero as the frames for those levels are found.
2062 If the top or bottom frame is reached, that frame is returned,
2063 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
2064 how much farther the original request asked to go. */
2067 find_relative_frame (struct frame_info *frame, int *level_offset_ptr)
2069 /* Going up is simple: just call get_prev_frame enough times or
2070 until the initial frame is reached. */
2071 while (*level_offset_ptr > 0)
2073 struct frame_info *prev = get_prev_frame (frame);
2077 (*level_offset_ptr)--;
2081 /* Going down is just as simple. */
2082 while (*level_offset_ptr < 0)
2084 struct frame_info *next = get_next_frame (frame);
2088 (*level_offset_ptr)++;
2095 /* The "select_frame" command. With no argument this is a NOP.
2096 Select the frame at level LEVEL_EXP if it is a valid level.
2097 Otherwise, treat LEVEL_EXP as an address expression and select it.
2099 See parse_frame_specification for more info on proper frame
2103 select_frame_command (char *level_exp, int from_tty)
2105 select_frame (parse_frame_specification_1 (level_exp, "No stack.", NULL));
2108 /* The "frame" command. With no argument, print the selected frame
2109 briefly. With an argument, behave like select_frame and then print
2110 the selected frame. */
2113 frame_command (char *level_exp, int from_tty)
2115 select_frame_command (level_exp, from_tty);
2116 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2119 /* The XDB Compatibility command to print the current frame. */
2122 current_frame_command (char *level_exp, int from_tty)
2124 print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC);
2127 /* Select the frame up one or COUNT_EXP stack levels from the
2128 previously selected frame, and print it briefly. */
2131 up_silently_base (char *count_exp)
2133 struct frame_info *frame;
2137 count = parse_and_eval_long (count_exp);
2139 frame = find_relative_frame (get_selected_frame ("No stack."), &count);
2140 if (count != 0 && count_exp == NULL)
2141 error (_("Initial frame selected; you cannot go up."));
2142 select_frame (frame);
2146 up_silently_command (char *count_exp, int from_tty)
2148 up_silently_base (count_exp);
2152 up_command (char *count_exp, int from_tty)
2154 up_silently_base (count_exp);
2155 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2158 /* Select the frame down one or COUNT_EXP stack levels from the previously
2159 selected frame, and print it briefly. */
2162 down_silently_base (char *count_exp)
2164 struct frame_info *frame;
2168 count = -parse_and_eval_long (count_exp);
2170 frame = find_relative_frame (get_selected_frame ("No stack."), &count);
2171 if (count != 0 && count_exp == NULL)
2173 /* We only do this if COUNT_EXP is not specified. That way
2174 "down" means to really go down (and let me know if that is
2175 impossible), but "down 9999" can be used to mean go all the
2176 way down without getting an error. */
2178 error (_("Bottom (innermost) frame selected; you cannot go down."));
2181 select_frame (frame);
2185 down_silently_command (char *count_exp, int from_tty)
2187 down_silently_base (count_exp);
2191 down_command (char *count_exp, int from_tty)
2193 down_silently_base (count_exp);
2194 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2199 return_command (char *retval_exp, int from_tty)
2201 struct frame_info *thisframe;
2202 struct gdbarch *gdbarch;
2203 struct symbol *thisfun;
2204 struct value *return_value = NULL;
2205 const char *query_prefix = "";
2207 thisframe = get_selected_frame ("No selected frame.");
2208 thisfun = get_frame_function (thisframe);
2209 gdbarch = get_frame_arch (thisframe);
2211 if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
2212 error (_("Can not force return from an inlined function."));
2214 /* Compute the return value. If the computation triggers an error,
2215 let it bail. If the return type can't be handled, set
2216 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
2220 struct expression *retval_expr = parse_expression (retval_exp);
2221 struct cleanup *old_chain = make_cleanup (xfree, retval_expr);
2222 struct type *return_type = NULL;
2224 /* Compute the return value. Should the computation fail, this
2225 call throws an error. */
2226 return_value = evaluate_expression (retval_expr);
2228 /* Cast return value to the return type of the function. Should
2229 the cast fail, this call throws an error. */
2230 if (thisfun != NULL)
2231 return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
2232 if (return_type == NULL)
2234 if (retval_expr->elts[0].opcode != UNOP_CAST)
2235 error (_("Return value type not available for selected "
2237 "Please use an explicit cast of the value to return."));
2238 return_type = value_type (return_value);
2240 do_cleanups (old_chain);
2241 CHECK_TYPEDEF (return_type);
2242 return_value = value_cast (return_type, return_value);
2244 /* Make sure the value is fully evaluated. It may live in the
2245 stack frame we're about to pop. */
2246 if (value_lazy (return_value))
2247 value_fetch_lazy (return_value);
2249 if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
2250 /* If the return-type is "void", don't try to find the
2251 return-value's location. However, do still evaluate the
2252 return expression so that, even when the expression result
2253 is discarded, side effects such as "return i++" still
2255 return_value = NULL;
2256 else if (thisfun != NULL
2257 && using_struct_return (gdbarch,
2258 SYMBOL_TYPE (thisfun), return_type))
2260 query_prefix = "The location at which to store the "
2261 "function's return value is unknown.\n"
2262 "If you continue, the return value "
2263 "that you specified will be ignored.\n";
2264 return_value = NULL;
2268 /* Does an interactive user really want to do this? Include
2269 information, such as how well GDB can handle the return value, in
2270 the query message. */
2275 if (thisfun == NULL)
2276 confirmed = query (_("%sMake selected stack frame return now? "),
2279 confirmed = query (_("%sMake %s return now? "), query_prefix,
2280 SYMBOL_PRINT_NAME (thisfun));
2282 error (_("Not confirmed"));
2285 /* Discard the selected frame and all frames inner-to it. */
2286 frame_pop (get_selected_frame (NULL));
2288 /* Store RETURN_VALUE in the just-returned register set. */
2289 if (return_value != NULL)
2291 struct type *return_type = value_type (return_value);
2292 struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ());
2293 struct type *func_type = thisfun == NULL ? NULL : SYMBOL_TYPE (thisfun);
2295 gdb_assert (gdbarch_return_value (gdbarch, func_type, return_type, NULL,
2297 == RETURN_VALUE_REGISTER_CONVENTION);
2298 gdbarch_return_value (gdbarch, func_type, return_type,
2299 get_current_regcache (), NULL /*read*/,
2300 value_contents (return_value) /*write*/);
2303 /* If we are at the end of a call dummy now, pop the dummy frame
2305 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
2306 frame_pop (get_current_frame ());
2308 /* If interactive, print the frame that is now current. */
2310 frame_command ("0", 1);
2312 select_frame_command ("0", 0);
2315 /* Sets the scope to input function name, provided that the function
2316 is within the current stack frame. */
2318 struct function_bounds
2320 CORE_ADDR low, high;
2324 func_command (char *arg, int from_tty)
2326 struct frame_info *frame;
2328 struct symtabs_and_lines sals;
2331 struct function_bounds *func_bounds = NULL;
2336 frame = parse_frame_specification ("0");
2337 sals = decode_line_spec (arg, 1);
2338 func_bounds = (struct function_bounds *) xmalloc (
2339 sizeof (struct function_bounds) * sals.nelts);
2340 for (i = 0; (i < sals.nelts && !found); i++)
2342 if (sals.sals[i].pc == 0
2343 || find_pc_partial_function (sals.sals[i].pc, NULL,
2344 &func_bounds[i].low,
2345 &func_bounds[i].high) == 0)
2347 func_bounds[i].low = func_bounds[i].high = 0;
2353 for (i = 0; (i < sals.nelts && !found); i++)
2354 found = (get_frame_pc (frame) >= func_bounds[i].low
2355 && get_frame_pc (frame) < func_bounds[i].high);
2359 frame = find_relative_frame (frame, &level);
2362 while (!found && level == 0);
2365 xfree (func_bounds);
2368 printf_filtered (_("'%s' not within current stack frame.\n"), arg);
2369 else if (frame != get_selected_frame (NULL))
2370 select_and_print_frame (frame);
2373 /* Gets the language of the current frame. */
2376 get_frame_language (void)
2378 struct frame_info *frame = deprecated_safe_get_selected_frame ();
2382 volatile struct gdb_exception ex;
2386 /* We determine the current frame language by looking up its
2387 associated symtab. To retrieve this symtab, we use the frame
2388 PC. However we cannot use the frame PC as is, because it
2389 usually points to the instruction following the "call", which
2390 is sometimes the first instruction of another function. So
2391 we rely on get_frame_address_in_block(), it provides us with
2392 a PC that is guaranteed to be inside the frame's code
2395 TRY_CATCH (ex, RETURN_MASK_ERROR)
2397 pc = get_frame_address_in_block (frame);
2401 if (ex.error != NOT_AVAILABLE_ERROR)
2402 throw_exception (ex);
2406 s = find_pc_symtab (pc);
2412 return language_unknown;
2416 /* Provide a prototype to silence -Wmissing-prototypes. */
2417 void _initialize_stack (void);
2420 _initialize_stack (void)
2422 add_com ("return", class_stack, return_command, _("\
2423 Make selected stack frame return to its caller.\n\
2424 Control remains in the debugger, but when you continue\n\
2425 execution will resume in the frame above the one now selected.\n\
2426 If an argument is given, it is an expression for the value to return."));
2428 add_com ("up", class_stack, up_command, _("\
2429 Select and print stack frame that called this one.\n\
2430 An argument says how many frames up to go."));
2431 add_com ("up-silently", class_support, up_silently_command, _("\
2432 Same as the `up' command, but does not print anything.\n\
2433 This is useful in command scripts."));
2435 add_com ("down", class_stack, down_command, _("\
2436 Select and print stack frame called by this one.\n\
2437 An argument says how many frames down to go."));
2438 add_com_alias ("do", "down", class_stack, 1);
2439 add_com_alias ("dow", "down", class_stack, 1);
2440 add_com ("down-silently", class_support, down_silently_command, _("\
2441 Same as the `down' command, but does not print anything.\n\
2442 This is useful in command scripts."));
2444 add_com ("frame", class_stack, frame_command, _("\
2445 Select and print a stack frame.\nWith no argument, \
2446 print the selected stack frame. (See also \"info frame\").\n\
2447 An argument specifies the frame to select.\n\
2448 It can be a stack frame number or the address of the frame.\n\
2449 With argument, nothing is printed if input is coming from\n\
2450 a command file or a user-defined command."));
2452 add_com_alias ("f", "frame", class_stack, 1);
2456 add_com ("L", class_stack, current_frame_command,
2457 _("Print the current stack frame.\n"));
2458 add_com_alias ("V", "frame", class_stack, 1);
2460 add_com ("select-frame", class_stack, select_frame_command, _("\
2461 Select a stack frame without printing anything.\n\
2462 An argument specifies the frame to select.\n\
2463 It can be a stack frame number or the address of the frame.\n"));
2465 add_com ("backtrace", class_stack, backtrace_command, _("\
2466 Print backtrace of all stack frames, or innermost COUNT frames.\n\
2467 With a negative argument, print outermost -COUNT frames.\nUse of the \
2468 'full' qualifier also prints the values of the local variables.\n"));
2469 add_com_alias ("bt", "backtrace", class_stack, 0);
2472 add_com_alias ("t", "backtrace", class_stack, 0);
2473 add_com ("T", class_stack, backtrace_full_command, _("\
2474 Print backtrace of all stack frames, or innermost COUNT frames\n\
2475 and the values of the local variables.\n\
2476 With a negative argument, print outermost -COUNT frames.\n\
2477 Usage: T <count>\n"));
2480 add_com_alias ("where", "backtrace", class_alias, 0);
2481 add_info ("stack", backtrace_command,
2482 _("Backtrace of the stack, or innermost COUNT frames."));
2483 add_info_alias ("s", "stack", 1);
2484 add_info ("frame", frame_info,
2485 _("All about selected stack frame, or frame at ADDR."));
2486 add_info_alias ("f", "frame", 1);
2487 add_info ("locals", locals_info,
2488 _("Local variables of current stack frame."));
2489 add_info ("args", args_info,
2490 _("Argument variables of current stack frame."));
2492 add_com ("l", class_info, args_plus_locals_info,
2493 _("Argument and local variables of current stack frame."));
2496 add_com ("func", class_stack, func_command, _("\
2497 Select the stack frame that contains <func>.\n\
2498 Usage: func <name>\n"));
2500 add_info ("catch", catch_info,
2501 _("Exceptions that can be caught in the current stack frame."));
2503 add_setshow_enum_cmd ("frame-arguments", class_stack,
2504 print_frame_arguments_choices, &print_frame_arguments,
2505 _("Set printing of non-scalar frame arguments"),
2506 _("Show printing of non-scalar frame arguments"),
2507 NULL, NULL, NULL, &setprintlist, &showprintlist);
2509 add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
2510 &disassemble_next_line, _("\
2511 Set whether to disassemble next source line or insn when execution stops."),
2513 Show whether to disassemble next source line or insn when execution stops."),
2515 If ON, GDB will display disassembly of the next source line, in addition\n\
2516 to displaying the source line itself. If the next source line cannot\n\
2517 be displayed (e.g., source is unavailable or there's no line info), GDB\n\
2518 will display disassembly of next instruction instead of showing the\n\
2520 If AUTO, display disassembly of next instruction only if the source line\n\
2521 cannot be displayed.\n\
2522 If OFF (which is the default), never display the disassembly of the next\n\
2525 show_disassemble_next_line,
2526 &setlist, &showlist);
2527 disassemble_next_line = AUTO_BOOLEAN_FALSE;
2529 add_setshow_enum_cmd ("entry-values", class_stack,
2530 print_entry_values_choices, &print_entry_values,
2531 _("Set printing of function arguments at function "
2533 _("Show printing of function arguments at function "
2536 GDB can sometimes determine the values of function arguments at entry,\n\
2537 in addition to their current values. This option tells GDB whether\n\
2538 to print the current value, the value at entry (marked as val@entry),\n\
2539 or both. Note that one or both of these values may be <optimized out>."),
2540 NULL, NULL, &setprintlist, &showprintlist);