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 /* Prototypes for local functions. */
69 static void print_frame_local_vars (struct frame_info
*, int,
72 static void print_frame (struct frame_info
*frame
, int print_level
,
73 enum print_what print_what
, int print_args
,
74 struct symtab_and_line sal
);
76 /* Zero means do things normally; we are interacting directly with the
77 user. One means print the full filename and linenumber when a
78 frame is printed, and do so in a format emacs18/emacs19.22 can
79 parse. Two means print similar annotations, but in many more
80 cases and in a slightly different syntax. */
82 int annotation_level
= 0;
85 /* Return 1 if we should display the address in addition to the location,
86 because we are in the middle of a statement. */
89 frame_show_address (struct frame_info
*frame
,
90 struct symtab_and_line sal
)
92 /* If there is a line number, but no PC, then there is no location
93 information associated with this sal. The only way that should
94 happen is for the call sites of inlined functions (SAL comes from
95 find_frame_sal). Otherwise, we would have some PC range if the
96 SAL came from a line table. */
97 if (sal
.line
!= 0 && sal
.pc
== 0 && sal
.end
== 0)
99 if (get_next_frame (frame
) == NULL
)
100 gdb_assert (inline_skipped_frames (inferior_ptid
) > 0);
102 gdb_assert (get_frame_type (get_next_frame (frame
)) == INLINE_FRAME
);
106 return get_frame_pc (frame
) != sal
.pc
;
109 /* Show or print a stack frame FRAME briefly. The output is format
110 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
111 relative level, function name, argument list, and file name and
112 line number. If the frame's PC is not at the beginning of the
113 source line, the actual PC is printed at the beginning. */
116 print_stack_frame (struct frame_info
*frame
, int print_level
,
117 enum print_what print_what
)
119 volatile struct gdb_exception e
;
121 /* For mi, alway print location and address. */
122 if (ui_out_is_mi_like_p (current_uiout
))
123 print_what
= LOC_AND_ADDRESS
;
125 TRY_CATCH (e
, RETURN_MASK_ERROR
)
127 int center
= (print_what
== SRC_LINE
|| print_what
== SRC_AND_LOC
);
129 print_frame_info (frame
, print_level
, print_what
, 1 /* print_args */);
130 set_current_sal_from_frame (frame
, center
);
134 /* Print nameless arguments of frame FRAME on STREAM, where START is
135 the offset of the first nameless argument, and NUM is the number of
136 nameless arguments to print. FIRST is nonzero if this is the first
137 argument (not just the first nameless argument). */
140 print_frame_nameless_args (struct frame_info
*frame
, long start
, int num
,
141 int first
, struct ui_file
*stream
)
143 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
144 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
149 for (i
= 0; i
< num
; i
++)
152 argsaddr
= get_frame_args_address (frame
);
155 arg_value
= read_memory_integer (argsaddr
+ start
,
156 sizeof (int), byte_order
);
158 fprintf_filtered (stream
, ", ");
159 fprintf_filtered (stream
, "%ld", arg_value
);
161 start
+= sizeof (int);
165 /* Print single argument of inferior function. ARG must be already
168 Errors are printed as if they would be the parameter value. Use zeroed ARG
169 iff it should not be printed accoring to user settings. */
172 print_frame_arg (const struct frame_arg
*arg
)
174 struct ui_out
*uiout
= current_uiout
;
175 volatile struct gdb_exception except
;
176 struct cleanup
*old_chain
;
177 struct ui_stream
*stb
;
179 stb
= ui_out_stream_new (uiout
);
180 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
182 gdb_assert (!arg
->val
|| !arg
->error
);
184 annotate_arg_begin ();
186 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
187 fprintf_symbol_filtered (stb
->stream
, SYMBOL_PRINT_NAME (arg
->sym
),
188 SYMBOL_LANGUAGE (arg
->sym
), DMGL_PARAMS
| DMGL_ANSI
);
189 ui_out_field_stream (uiout
, "name", stb
);
190 annotate_arg_name_end ();
191 ui_out_text (uiout
, "=");
193 if (!arg
->val
&& !arg
->error
)
194 ui_out_text (uiout
, "...");
198 except
.message
= arg
->error
;
201 /* TRY_CATCH has two statements, wrap it in a block. */
203 TRY_CATCH (except
, RETURN_MASK_ERROR
)
205 const struct language_defn
*language
;
206 struct value_print_options opts
;
208 /* Avoid value_print because it will deref ref parameters. We
209 just want to print their addresses. Print ??? for args whose
210 address we do not know. We pass 2 as "recurse" to val_print
211 because our standard indentation here is 4 spaces, and
212 val_print indents 2 for each recurse. */
214 annotate_arg_value (value_type (arg
->val
));
216 /* Use the appropriate language to display our symbol, unless the
217 user forced the language to a specific language. */
218 if (language_mode
== language_mode_auto
)
219 language
= language_def (SYMBOL_LANGUAGE (arg
->sym
));
221 language
= current_language
;
223 get_raw_print_options (&opts
);
226 /* True in "summary" mode, false otherwise. */
227 opts
.summary
= !strcmp (print_frame_arguments
, "scalars");
229 common_val_print (arg
->val
, stb
->stream
, 2, &opts
, language
);
233 fprintf_filtered (stb
->stream
, _("<error reading variable: %s>"),
237 ui_out_field_stream (uiout
, "value", stb
);
239 /* Aleo invoke ui_out_tuple_end. */
240 do_cleanups (old_chain
);
245 /* Read in inferior function parameter SYM at FRAME into ARGP. Caller is
246 responsible for xfree of ARGP->ERROR. This function never throws an
250 read_frame_arg (struct symbol
*sym
, struct frame_info
*frame
,
251 struct frame_arg
*argp
)
253 struct value
*val
= NULL
;
254 char *val_error
= NULL
;
255 volatile struct gdb_exception except
;
257 TRY_CATCH (except
, RETURN_MASK_ERROR
)
259 val
= read_var_value (sym
, frame
);
263 val_error
= alloca (strlen (except
.message
) + 1);
264 strcpy (val_error
, except
.message
);
269 argp
->error
= val_error
? xstrdup (val_error
) : NULL
;
272 /* Print the arguments of frame FRAME on STREAM, given the function
273 FUNC running in that frame (as a symbol), where NUM is the number
274 of arguments according to the stack frame (or -1 if the number of
275 arguments is unknown). */
277 /* Note that currently the "number of arguments according to the
278 stack frame" is only known on VAX where i refers to the "number of
279 ints of arguments according to the stack frame". */
282 print_frame_args (struct symbol
*func
, struct frame_info
*frame
,
283 int num
, struct ui_file
*stream
)
285 struct ui_out
*uiout
= current_uiout
;
287 /* Offset of next stack argument beyond the one we have seen that is
288 at the highest offset, or -1 if we haven't come to a stack
290 long highest_offset
= -1;
291 /* Number of ints of arguments that we have printed so far. */
292 int args_printed
= 0;
293 struct cleanup
*old_chain
, *list_chain
;
294 struct ui_stream
*stb
;
295 /* True if we should print arguments, false otherwise. */
296 int print_args
= strcmp (print_frame_arguments
, "none");
297 /* True in "summary" mode, false otherwise. */
298 int summary
= !strcmp (print_frame_arguments
, "scalars");
300 stb
= ui_out_stream_new (uiout
);
301 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
305 struct block
*b
= SYMBOL_BLOCK_VALUE (func
);
306 struct dict_iterator iter
;
309 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
311 struct frame_arg arg
;
315 /* Keep track of the highest stack argument offset seen, and
316 skip over any kinds of symbols we don't care about. */
318 if (!SYMBOL_IS_ARGUMENT (sym
))
321 switch (SYMBOL_CLASS (sym
))
326 long current_offset
= SYMBOL_VALUE (sym
);
327 int arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
329 /* Compute address of next argument by adding the size of
330 this argument and rounding to an int boundary. */
332 ((current_offset
+ arg_size
+ sizeof (int) - 1)
333 & ~(sizeof (int) - 1));
335 /* If this is the highest offset seen yet, set
337 if (highest_offset
== -1
338 || (current_offset
> highest_offset
))
339 highest_offset
= current_offset
;
341 /* Add the number of ints we're about to print to
343 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
346 /* We care about types of symbols, but don't need to
347 keep track of stack offsets in them. */
349 case LOC_REGPARM_ADDR
:
351 case LOC_OPTIMIZED_OUT
:
356 /* We have to look up the symbol because arguments can have
357 two entries (one a parameter, one a local) and the one we
358 want is the local, which lookup_symbol will find for us.
359 This includes gcc1 (not gcc2) on SPARC when passing a
360 small structure and gcc2 when the argument type is float
361 and it is passed as a double and converted to float by
362 the prologue (in the latter case the type of the LOC_ARG
363 symbol is double and the type of the LOC_LOCAL symbol is
365 /* But if the parameter name is null, don't try it. Null
366 parameter names occur on the RS/6000, for traceback
367 tables. FIXME, should we even print them? */
369 if (*SYMBOL_LINKAGE_NAME (sym
))
373 nsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
),
374 b
, VAR_DOMAIN
, NULL
);
375 gdb_assert (nsym
!= NULL
);
376 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
377 && !SYMBOL_IS_ARGUMENT (nsym
))
379 /* There is a LOC_ARG/LOC_REGISTER pair. This means
380 that it was passed on the stack and loaded into a
381 register, or passed in a register and stored in a
382 stack slot. GDB 3.x used the LOC_ARG; GDB
383 4.0-4.11 used the LOC_REGISTER.
385 Reasons for using the LOC_ARG:
387 (1) Because find_saved_registers may be slow for
390 (2) Because registers are often re-used and stack
391 slots rarely (never?) are. Therefore using
392 the stack slot is much less likely to print
395 Reasons why we might want to use the LOC_REGISTER:
397 (1) So that the backtrace prints the same value
398 as "print foo". I see no compelling reason
399 why this needs to be the case; having the
400 backtrace print the value which was passed
401 in, and "print foo" print the value as
402 modified within the called function, makes
405 Additional note: It might be nice if "info args"
406 displayed both values.
408 One more note: There is a case with SPARC
409 structure passing where we need to use the
410 LOC_REGISTER, but this is dealt with by creating
411 a single LOC_REGPARM in symbol reading. */
413 /* Leave sym (the LOC_ARG) alone. */
420 /* Print the current arg. */
422 ui_out_text (uiout
, ", ");
423 ui_out_wrap_hint (uiout
, " ");
427 memset (&arg
, 0, sizeof (arg
));
431 read_frame_arg (sym
, frame
, &arg
);
433 print_frame_arg (&arg
);
441 /* Don't print nameless args in situations where we don't know
442 enough about the stack to find them. */
447 if (highest_offset
== -1)
448 start
= gdbarch_frame_args_skip (get_frame_arch (frame
));
450 start
= highest_offset
;
452 print_frame_nameless_args (frame
, start
, num
- args_printed
,
456 do_cleanups (old_chain
);
459 /* Set the current source and line to the location given by frame
460 FRAME, if possible. When CENTER is true, adjust so the relevant
461 line is in the center of the next 'list'. */
464 set_current_sal_from_frame (struct frame_info
*frame
, int center
)
466 struct symtab_and_line sal
;
468 find_frame_sal (frame
, &sal
);
472 sal
.line
= max (sal
.line
- get_lines_to_list () / 2, 1);
473 set_current_source_symtab_and_line (&sal
);
477 /* If ON, GDB will display disassembly of the next source line when
478 execution of the program being debugged stops.
479 If AUTO (which is the default), or there's no line info to determine
480 the source line of the next instruction, display disassembly of next
481 instruction instead. */
483 static enum auto_boolean disassemble_next_line
;
486 show_disassemble_next_line (struct ui_file
*file
, int from_tty
,
487 struct cmd_list_element
*c
,
490 fprintf_filtered (file
,
491 _("Debugger's willingness to use "
492 "disassemble-next-line is %s.\n"),
496 /* Use TRY_CATCH to catch the exception from the gdb_disassembly
497 because it will be broken by filter sometime. */
500 do_gdb_disassembly (struct gdbarch
*gdbarch
,
501 int how_many
, CORE_ADDR low
, CORE_ADDR high
)
503 volatile struct gdb_exception exception
;
505 TRY_CATCH (exception
, RETURN_MASK_ERROR
)
507 gdb_disassembly (gdbarch
, current_uiout
, 0,
508 DISASSEMBLY_RAW_INSN
, how_many
,
511 if (exception
.reason
< 0)
513 /* If an exception was thrown while doing the disassembly, print
514 the error message, to give the user a clue of what happened. */
515 exception_print (gdb_stderr
, exception
);
519 /* Print information about frame FRAME. The output is format according
520 to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. The meaning of
523 SRC_LINE: Print only source line.
524 LOCATION: Print only location.
525 LOC_AND_SRC: Print location and source line.
527 Used in "where" output, and to emit breakpoint or step
531 print_frame_info (struct frame_info
*frame
, int print_level
,
532 enum print_what print_what
, int print_args
)
534 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
535 struct symtab_and_line sal
;
538 struct ui_out
*uiout
= current_uiout
;
540 if (get_frame_type (frame
) == DUMMY_FRAME
541 || get_frame_type (frame
) == SIGTRAMP_FRAME
542 || get_frame_type (frame
) == ARCH_FRAME
)
544 struct cleanup
*uiout_cleanup
545 = make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
547 annotate_frame_begin (print_level
? frame_relative_level (frame
) : 0,
548 gdbarch
, get_frame_pc (frame
));
550 /* Do this regardless of SOURCE because we don't have any source
551 to list for this frame. */
554 ui_out_text (uiout
, "#");
555 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
556 frame_relative_level (frame
));
558 if (ui_out_is_mi_like_p (uiout
))
560 annotate_frame_address ();
561 ui_out_field_core_addr (uiout
, "addr",
562 gdbarch
, get_frame_pc (frame
));
563 annotate_frame_address_end ();
566 if (get_frame_type (frame
) == DUMMY_FRAME
)
568 annotate_function_call ();
569 ui_out_field_string (uiout
, "func", "<function called from gdb>");
571 else if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
573 annotate_signal_handler_caller ();
574 ui_out_field_string (uiout
, "func", "<signal handler called>");
576 else if (get_frame_type (frame
) == ARCH_FRAME
)
578 ui_out_field_string (uiout
, "func", "<cross-architecture call>");
580 ui_out_text (uiout
, "\n");
581 annotate_frame_end ();
583 do_cleanups (uiout_cleanup
);
587 /* If FRAME is not the innermost frame, that normally means that
588 FRAME->pc points to *after* the call instruction, and we want to
589 get the line containing the call, never the next line. But if
590 the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
591 next frame was not entered as the result of a call, and we want
592 to get the line containing FRAME->pc. */
593 find_frame_sal (frame
, &sal
);
595 location_print
= (print_what
== LOCATION
596 || print_what
== LOC_AND_ADDRESS
597 || print_what
== SRC_AND_LOC
);
599 if (location_print
|| !sal
.symtab
)
600 print_frame (frame
, print_level
, print_what
, print_args
, sal
);
602 source_print
= (print_what
== SRC_LINE
|| print_what
== SRC_AND_LOC
);
604 /* If disassemble-next-line is set to auto or on and doesn't have
605 the line debug messages for $pc, output the next instruction. */
606 if ((disassemble_next_line
== AUTO_BOOLEAN_AUTO
607 || disassemble_next_line
== AUTO_BOOLEAN_TRUE
)
608 && source_print
&& !sal
.symtab
)
609 do_gdb_disassembly (get_frame_arch (frame
), 1,
610 get_frame_pc (frame
), get_frame_pc (frame
) + 1);
612 if (source_print
&& sal
.symtab
)
615 int mid_statement
= ((print_what
== SRC_LINE
)
616 && frame_show_address (frame
, sal
));
618 if (annotation_level
)
619 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
620 get_frame_pc (frame
));
623 if (deprecated_print_frame_info_listing_hook
)
624 deprecated_print_frame_info_listing_hook (sal
.symtab
,
629 struct value_print_options opts
;
631 get_user_print_options (&opts
);
632 /* We used to do this earlier, but that is clearly
633 wrong. This function is used by many different
634 parts of gdb, including normal_stop in infrun.c,
635 which uses this to print out the current PC
636 when we stepi/nexti into the middle of a source
637 line. Only the command line really wants this
638 behavior. Other UIs probably would like the
639 ability to decide for themselves if it is desired. */
640 if (opts
.addressprint
&& mid_statement
)
642 ui_out_field_core_addr (uiout
, "addr",
643 gdbarch
, get_frame_pc (frame
));
644 ui_out_text (uiout
, "\t");
647 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
651 /* If disassemble-next-line is set to on and there is line debug
652 messages, output assembly codes for next line. */
653 if (disassemble_next_line
== AUTO_BOOLEAN_TRUE
)
654 do_gdb_disassembly (get_frame_arch (frame
), -1, sal
.pc
, sal
.end
);
657 if (print_what
!= LOCATION
)
661 if (get_frame_pc_if_available (frame
, &pc
))
662 set_default_breakpoint (1, sal
.pspace
, pc
, sal
.symtab
, sal
.line
);
664 set_default_breakpoint (0, 0, 0, 0, 0);
667 annotate_frame_end ();
669 gdb_flush (gdb_stdout
);
672 /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
673 corresponding to FRAME. */
676 find_frame_funname (struct frame_info
*frame
, char **funname
,
677 enum language
*funlang
, struct symbol
**funcp
)
682 *funlang
= language_unknown
;
686 func
= get_frame_function (frame
);
689 /* In certain pathological cases, the symtabs give the wrong
690 function (when we are in the first function in a file which
691 is compiled without debugging symbols, the previous function
692 is compiled with debugging symbols, and the "foo.o" symbol
693 that is supposed to tell us where the file with debugging
694 symbols ends has been truncated by ar because it is longer
695 than 15 characters). This also occurs if the user uses asm()
696 to create a function but not stabs for it (in a file compiled
699 So look in the minimal symbol tables as well, and if it comes
700 up with a larger address for the function use that instead.
701 I don't think this can ever cause any problems; there
702 shouldn't be any minimal symbols in the middle of a function;
703 if this is ever changed many parts of GDB will need to be
704 changed (and we'll create a find_pc_minimal_function or some
707 struct minimal_symbol
*msymbol
= NULL
;
709 /* Don't attempt to do this for inlined functions, which do not
710 have a corresponding minimal symbol. */
711 if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func
)))
713 = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame
));
716 && (SYMBOL_VALUE_ADDRESS (msymbol
)
717 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
719 /* We also don't know anything about the function besides
720 its address and name. */
722 *funname
= SYMBOL_PRINT_NAME (msymbol
);
723 *funlang
= SYMBOL_LANGUAGE (msymbol
);
727 *funname
= SYMBOL_PRINT_NAME (func
);
728 *funlang
= SYMBOL_LANGUAGE (func
);
731 if (*funlang
== language_cplus
)
733 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
734 to display the demangled name that we already have
735 stored in the symbol table, but we stored a version
736 with DMGL_PARAMS turned on, and here we don't want to
737 display parameters. So remove the parameters. */
738 char *func_only
= cp_remove_params (*funname
);
742 *funname
= func_only
;
743 make_cleanup (xfree
, func_only
);
750 struct minimal_symbol
*msymbol
;
753 if (!get_frame_address_in_block_if_available (frame
, &pc
))
756 msymbol
= lookup_minimal_symbol_by_pc (pc
);
759 *funname
= SYMBOL_PRINT_NAME (msymbol
);
760 *funlang
= SYMBOL_LANGUAGE (msymbol
);
766 print_frame (struct frame_info
*frame
, int print_level
,
767 enum print_what print_what
, int print_args
,
768 struct symtab_and_line sal
)
770 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
771 struct ui_out
*uiout
= current_uiout
;
772 char *funname
= NULL
;
773 enum language funlang
= language_unknown
;
774 struct ui_stream
*stb
;
775 struct cleanup
*old_chain
, *list_chain
;
776 struct value_print_options opts
;
781 pc_p
= get_frame_pc_if_available (frame
, &pc
);
783 stb
= ui_out_stream_new (uiout
);
784 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
786 find_frame_funname (frame
, &funname
, &funlang
, &func
);
788 annotate_frame_begin (print_level
? frame_relative_level (frame
) : 0,
791 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
795 ui_out_text (uiout
, "#");
796 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
797 frame_relative_level (frame
));
799 get_user_print_options (&opts
);
800 if (opts
.addressprint
)
802 || frame_show_address (frame
, sal
)
803 || print_what
== LOC_AND_ADDRESS
)
805 annotate_frame_address ();
807 ui_out_field_core_addr (uiout
, "addr", gdbarch
, pc
);
809 ui_out_field_string (uiout
, "addr", "<unavailable>");
810 annotate_frame_address_end ();
811 ui_out_text (uiout
, " in ");
813 annotate_frame_function_name ();
814 fprintf_symbol_filtered (stb
->stream
, funname
? funname
: "??",
816 ui_out_field_stream (uiout
, "func", stb
);
817 ui_out_wrap_hint (uiout
, " ");
818 annotate_frame_args ();
820 ui_out_text (uiout
, " (");
823 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
825 struct cleanup
*args_list_chain
;
826 volatile struct gdb_exception e
;
828 if (gdbarch_frame_num_args_p (gdbarch
))
830 numargs
= gdbarch_frame_num_args (gdbarch
, frame
);
831 gdb_assert (numargs
>= 0);
836 args_list_chain
= make_cleanup_ui_out_list_begin_end (uiout
, "args");
837 TRY_CATCH (e
, RETURN_MASK_ERROR
)
839 print_frame_args (func
, frame
, numargs
, gdb_stdout
);
841 /* FIXME: ARGS must be a list. If one argument is a string it
842 will have " that will not be properly escaped. */
843 /* Invoke ui_out_tuple_end. */
844 do_cleanups (args_list_chain
);
847 ui_out_text (uiout
, ")");
848 if (sal
.symtab
&& sal
.symtab
->filename
)
850 annotate_frame_source_begin ();
851 ui_out_wrap_hint (uiout
, " ");
852 ui_out_text (uiout
, " at ");
853 annotate_frame_source_file ();
854 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
855 if (ui_out_is_mi_like_p (uiout
))
857 const char *fullname
= symtab_to_fullname (sal
.symtab
);
859 if (fullname
!= NULL
)
860 ui_out_field_string (uiout
, "fullname", fullname
);
862 annotate_frame_source_file_end ();
863 ui_out_text (uiout
, ":");
864 annotate_frame_source_line ();
865 ui_out_field_int (uiout
, "line", sal
.line
);
866 annotate_frame_source_end ();
869 if (pc_p
&& (!funname
|| (!sal
.symtab
|| !sal
.symtab
->filename
)))
872 char *lib
= PC_SOLIB (get_frame_pc (frame
));
874 char *lib
= solib_name_from_address (get_frame_program_space (frame
),
875 get_frame_pc (frame
));
879 annotate_frame_where ();
880 ui_out_wrap_hint (uiout
, " ");
881 ui_out_text (uiout
, " from ");
882 ui_out_field_string (uiout
, "from", lib
);
886 /* do_cleanups will call ui_out_tuple_end() for us. */
887 do_cleanups (list_chain
);
888 ui_out_text (uiout
, "\n");
889 do_cleanups (old_chain
);
893 /* Read a frame specification in whatever the appropriate format is
894 from FRAME_EXP. Call error(), printing MESSAGE, if the
895 specification is in any way invalid (so this function never returns
896 NULL). When SEPECTED_P is non-NULL set its target to indicate that
897 the default selected frame was used. */
899 static struct frame_info
*
900 parse_frame_specification_1 (const char *frame_exp
, const char *message
,
901 int *selected_frame_p
)
904 struct value
*args
[4];
905 CORE_ADDR addrs
[ARRAY_SIZE (args
)];
907 if (frame_exp
== NULL
)
915 struct cleanup
*cleanup
;
918 /* Skip leading white space, bail of EOL. */
919 while (isspace (*frame_exp
))
924 /* Parse the argument, extract it, save it. */
928 addr_string
= savestring (frame_exp
, p
- frame_exp
);
930 cleanup
= make_cleanup (xfree
, addr_string
);
932 /* NOTE: Parse and evaluate expression, but do not use
933 functions such as parse_and_eval_long or
934 parse_and_eval_address to also extract the value.
935 Instead value_as_long and value_as_address are used.
936 This avoids problems with expressions that contain
938 if (numargs
>= ARRAY_SIZE (args
))
939 error (_("Too many args in frame specification"));
940 args
[numargs
++] = parse_and_eval (addr_string
);
942 do_cleanups (cleanup
);
946 /* If no args, default to the selected frame. */
949 if (selected_frame_p
!= NULL
)
950 (*selected_frame_p
) = 1;
951 return get_selected_frame (message
);
954 /* None of the remaining use the selected frame. */
955 if (selected_frame_p
!= NULL
)
956 (*selected_frame_p
) = 0;
958 /* Assume the single arg[0] is an integer, and try using that to
959 select a frame relative to current. */
962 struct frame_info
*fid
;
963 int level
= value_as_long (args
[0]);
965 fid
= find_relative_frame (get_current_frame (), &level
);
967 /* find_relative_frame was successful. */
971 /* Convert each value into a corresponding address. */
975 for (i
= 0; i
< numargs
; i
++)
976 addrs
[i
] = value_as_address (args
[i
]);
979 /* Assume that the single arg[0] is an address, use that to identify
980 a frame with a matching ID. Should this also accept stack/pc or
984 struct frame_id id
= frame_id_build_wild (addrs
[0]);
985 struct frame_info
*fid
;
987 /* If (s)he specifies the frame with an address, he deserves
988 what (s)he gets. Still, give the highest one that matches.
989 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
991 for (fid
= get_current_frame ();
993 fid
= get_prev_frame (fid
))
995 if (frame_id_eq (id
, get_frame_id (fid
)))
997 struct frame_info
*prev_frame
;
1001 prev_frame
= get_prev_frame (fid
);
1003 || !frame_id_eq (id
, get_frame_id (prev_frame
)))
1012 /* We couldn't identify the frame as an existing frame, but
1013 perhaps we can create one with a single argument. */
1015 return create_new_frame (addrs
[0], 0);
1016 else if (numargs
== 2)
1017 return create_new_frame (addrs
[0], addrs
[1]);
1019 error (_("Too many args in frame specification"));
1022 static struct frame_info
*
1023 parse_frame_specification (char *frame_exp
)
1025 return parse_frame_specification_1 (frame_exp
, NULL
, NULL
);
1028 /* Print verbosely the selected frame or the frame at address
1029 ADDR_EXP. Absolutely all information in the frame is printed. */
1032 frame_info (char *addr_exp
, int from_tty
)
1034 struct frame_info
*fi
;
1035 struct symtab_and_line sal
;
1036 struct symbol
*func
;
1038 struct frame_info
*calling_frame_info
;
1041 enum language funlang
= language_unknown
;
1042 const char *pc_regname
;
1043 int selected_frame_p
;
1044 struct gdbarch
*gdbarch
;
1045 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
1048 CORE_ADDR caller_pc
;
1050 fi
= parse_frame_specification_1 (addr_exp
, "No stack.", &selected_frame_p
);
1051 gdbarch
= get_frame_arch (fi
);
1053 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
1054 is not a good name. */
1055 if (gdbarch_pc_regnum (gdbarch
) >= 0)
1056 /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can
1057 easily not match that of the internal value returned by
1059 pc_regname
= gdbarch_register_name (gdbarch
, gdbarch_pc_regnum (gdbarch
));
1061 /* But then, this is weird to. Even without gdbarch_pc_regnum, an
1062 architectures will often have a hardware register called "pc",
1063 and that register's value, again, can easily not match
1067 frame_pc_p
= get_frame_pc_if_available (fi
, &frame_pc
);
1068 find_frame_sal (fi
, &sal
);
1069 func
= get_frame_function (fi
);
1073 funname
= SYMBOL_PRINT_NAME (func
);
1074 funlang
= SYMBOL_LANGUAGE (func
);
1075 if (funlang
== language_cplus
)
1077 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
1078 to display the demangled name that we already have
1079 stored in the symbol table, but we stored a version
1080 with DMGL_PARAMS turned on, and here we don't want to
1081 display parameters. So remove the parameters. */
1082 char *func_only
= cp_remove_params (funname
);
1086 funname
= func_only
;
1087 make_cleanup (xfree
, func_only
);
1091 else if (frame_pc_p
)
1093 struct minimal_symbol
*msymbol
;
1095 msymbol
= lookup_minimal_symbol_by_pc (frame_pc
);
1096 if (msymbol
!= NULL
)
1098 funname
= SYMBOL_PRINT_NAME (msymbol
);
1099 funlang
= SYMBOL_LANGUAGE (msymbol
);
1102 calling_frame_info
= get_prev_frame (fi
);
1104 if (selected_frame_p
&& frame_relative_level (fi
) >= 0)
1106 printf_filtered (_("Stack level %d, frame at "),
1107 frame_relative_level (fi
));
1111 printf_filtered (_("Stack frame at "));
1113 fputs_filtered (paddress (gdbarch
, get_frame_base (fi
)), gdb_stdout
);
1114 printf_filtered (":\n");
1115 printf_filtered (" %s = ", pc_regname
);
1117 fputs_filtered (paddress (gdbarch
, get_frame_pc (fi
)), gdb_stdout
);
1119 fputs_filtered ("<unavailable>", gdb_stdout
);
1124 printf_filtered (" in ");
1125 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
1126 DMGL_ANSI
| DMGL_PARAMS
);
1130 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
1131 puts_filtered ("; ");
1133 printf_filtered ("saved %s ", pc_regname
);
1134 if (frame_unwind_caller_pc_if_available (fi
, &caller_pc
))
1135 fputs_filtered (paddress (gdbarch
, caller_pc
), gdb_stdout
);
1137 fputs_filtered ("<unavailable>", gdb_stdout
);
1138 printf_filtered ("\n");
1140 if (calling_frame_info
== NULL
)
1142 enum unwind_stop_reason reason
;
1144 reason
= get_frame_unwind_stop_reason (fi
);
1145 if (reason
!= UNWIND_NO_REASON
)
1146 printf_filtered (_(" Outermost frame: %s\n"),
1147 frame_stop_reason_string (reason
));
1149 else if (get_frame_type (fi
) == TAILCALL_FRAME
)
1150 puts_filtered (" tail call frame");
1151 else if (get_frame_type (fi
) == INLINE_FRAME
)
1152 printf_filtered (" inlined into frame %d",
1153 frame_relative_level (get_prev_frame (fi
)));
1156 printf_filtered (" called by frame at ");
1157 fputs_filtered (paddress (gdbarch
, get_frame_base (calling_frame_info
)),
1160 if (get_next_frame (fi
) && calling_frame_info
)
1161 puts_filtered (",");
1163 if (get_next_frame (fi
))
1165 printf_filtered (" caller of frame at ");
1166 fputs_filtered (paddress (gdbarch
, get_frame_base (get_next_frame (fi
))),
1169 if (get_next_frame (fi
) || calling_frame_info
)
1170 puts_filtered ("\n");
1173 printf_filtered (" source language %s.\n",
1174 language_str (s
->language
));
1177 /* Address of the argument list for this frame, or 0. */
1178 CORE_ADDR arg_list
= get_frame_args_address (fi
);
1179 /* Number of args for this frame, or -1 if unknown. */
1183 printf_filtered (" Arglist at unknown address.\n");
1186 printf_filtered (" Arglist at ");
1187 fputs_filtered (paddress (gdbarch
, arg_list
), gdb_stdout
);
1188 printf_filtered (",");
1190 if (!gdbarch_frame_num_args_p (gdbarch
))
1193 puts_filtered (" args: ");
1197 numargs
= gdbarch_frame_num_args (gdbarch
, fi
);
1198 gdb_assert (numargs
>= 0);
1200 puts_filtered (" no args.");
1201 else if (numargs
== 1)
1202 puts_filtered (" 1 arg: ");
1204 printf_filtered (" %d args: ", numargs
);
1206 print_frame_args (func
, fi
, numargs
, gdb_stdout
);
1207 puts_filtered ("\n");
1211 /* Address of the local variables for this frame, or 0. */
1212 CORE_ADDR arg_list
= get_frame_locals_address (fi
);
1215 printf_filtered (" Locals at unknown address,");
1218 printf_filtered (" Locals at ");
1219 fputs_filtered (paddress (gdbarch
, arg_list
), gdb_stdout
);
1220 printf_filtered (",");
1224 /* Print as much information as possible on the location of all the
1227 enum lval_type lval
;
1236 /* The sp is special; what's displayed isn't the save address, but
1237 the value of the previous frame's sp. This is a legacy thing,
1238 at one stage the frame cached the previous frame's SP instead
1239 of its address, hence it was easiest to just display the cached
1241 if (gdbarch_sp_regnum (gdbarch
) >= 0)
1243 /* Find out the location of the saved stack pointer with out
1244 actually evaluating it. */
1245 frame_register_unwind (fi
, gdbarch_sp_regnum (gdbarch
),
1246 &optimized
, &unavailable
, &lval
, &addr
,
1248 if (!optimized
&& !unavailable
&& lval
== not_lval
)
1250 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1251 int sp_size
= register_size (gdbarch
, gdbarch_sp_regnum (gdbarch
));
1252 gdb_byte value
[MAX_REGISTER_SIZE
];
1255 frame_register_unwind (fi
, gdbarch_sp_regnum (gdbarch
),
1256 &optimized
, &unavailable
, &lval
, &addr
,
1258 /* NOTE: cagney/2003-05-22: This is assuming that the
1259 stack pointer was packed as an unsigned integer. That
1260 may or may not be valid. */
1261 sp
= extract_unsigned_integer (value
, sp_size
, byte_order
);
1262 printf_filtered (" Previous frame's sp is ");
1263 fputs_filtered (paddress (gdbarch
, sp
), gdb_stdout
);
1264 printf_filtered ("\n");
1267 else if (!optimized
&& !unavailable
&& lval
== lval_memory
)
1269 printf_filtered (" Previous frame's sp at ");
1270 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1271 printf_filtered ("\n");
1274 else if (!optimized
&& !unavailable
&& lval
== lval_register
)
1276 printf_filtered (" Previous frame's sp in %s\n",
1277 gdbarch_register_name (gdbarch
, realnum
));
1280 /* else keep quiet. */
1284 numregs
= gdbarch_num_regs (gdbarch
)
1285 + gdbarch_num_pseudo_regs (gdbarch
);
1286 for (i
= 0; i
< numregs
; i
++)
1287 if (i
!= gdbarch_sp_regnum (gdbarch
)
1288 && gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1290 /* Find out the location of the saved register without
1291 fetching the corresponding value. */
1292 frame_register_unwind (fi
, i
, &optimized
, &unavailable
,
1293 &lval
, &addr
, &realnum
, NULL
);
1294 /* For moment, only display registers that were saved on the
1296 if (!optimized
&& !unavailable
&& lval
== lval_memory
)
1299 puts_filtered (" Saved registers:\n ");
1301 puts_filtered (",");
1303 printf_filtered (" %s at ",
1304 gdbarch_register_name (gdbarch
, i
));
1305 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1309 if (count
|| need_nl
)
1310 puts_filtered ("\n");
1313 do_cleanups (back_to
);
1316 /* Print briefly all stack frames or just the innermost COUNT_EXP
1320 backtrace_command_1 (char *count_exp
, int show_locals
, int from_tty
)
1322 struct frame_info
*fi
;
1325 struct frame_info
*trailing
;
1328 if (!target_has_stack
)
1329 error (_("No stack."));
1331 /* The following code must do two things. First, it must set the
1332 variable TRAILING to the frame from which we should start
1333 printing. Second, it must set the variable count to the number
1334 of frames which we should print, or -1 if all of them. */
1335 trailing
= get_current_frame ();
1340 count
= parse_and_eval_long (count_exp
);
1343 struct frame_info
*current
;
1348 while (current
&& count
--)
1351 current
= get_prev_frame (current
);
1354 /* Will stop when CURRENT reaches the top of the stack.
1355 TRAILING will be COUNT below it. */
1359 trailing
= get_prev_frame (trailing
);
1360 current
= get_prev_frame (current
);
1372 /* Read in symbols for all of the frames. Need to do this in a
1373 separate pass so that "Reading in symbols for xxx" messages
1374 don't screw up the appearance of the backtrace. Also if
1375 people have strong opinions against reading symbols for
1376 backtrace this may have to be an option. */
1378 for (fi
= trailing
; fi
!= NULL
&& i
--; fi
= get_prev_frame (fi
))
1383 pc
= get_frame_address_in_block (fi
);
1384 find_pc_sect_symtab_via_partial (pc
, find_pc_mapped_section (pc
));
1388 for (i
= 0, fi
= trailing
; fi
&& count
--; i
++, fi
= get_prev_frame (fi
))
1392 /* Don't use print_stack_frame; if an error() occurs it probably
1393 means further attempts to backtrace would fail (on the other
1394 hand, perhaps the code does or could be fixed to make sure
1395 the frame->prev field gets set to NULL in that case). */
1396 print_frame_info (fi
, 1, LOCATION
, 1);
1398 print_frame_local_vars (fi
, 1, gdb_stdout
);
1400 /* Save the last frame to check for error conditions. */
1404 /* If we've stopped before the end, mention that. */
1406 printf_filtered (_("(More stack frames follow...)\n"));
1408 /* If we've run out of frames, and the reason appears to be an error
1409 condition, print it. */
1410 if (fi
== NULL
&& trailing
!= NULL
)
1412 enum unwind_stop_reason reason
;
1414 reason
= get_frame_unwind_stop_reason (trailing
);
1415 if (reason
> UNWIND_FIRST_ERROR
)
1416 printf_filtered (_("Backtrace stopped: %s\n"),
1417 frame_stop_reason_string (reason
));
1422 backtrace_command (char *arg
, int from_tty
)
1424 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
1425 int fulltrace_arg
= -1, arglen
= 0, argc
= 0;
1432 argv
= gdb_buildargv (arg
);
1433 make_cleanup_freeargv (argv
);
1435 for (i
= 0; argv
[i
]; i
++)
1439 for (j
= 0; j
< strlen (argv
[i
]); j
++)
1440 argv
[i
][j
] = tolower (argv
[i
][j
]);
1442 if (fulltrace_arg
< 0 && subset_compare (argv
[i
], "full"))
1443 fulltrace_arg
= argc
;
1446 arglen
+= strlen (argv
[i
]);
1451 if (fulltrace_arg
>= 0)
1455 arg
= xmalloc (arglen
+ 1);
1456 make_cleanup (xfree
, arg
);
1458 for (i
= 0; i
< (argc
+ 1); i
++)
1460 if (i
!= fulltrace_arg
)
1462 strcat (arg
, argv
[i
]);
1472 backtrace_command_1 (arg
, fulltrace_arg
>= 0 /* show_locals */, from_tty
);
1474 do_cleanups (old_chain
);
1478 backtrace_full_command (char *arg
, int from_tty
)
1480 backtrace_command_1 (arg
, 1 /* show_locals */, from_tty
);
1484 /* Iterate over the local variables of a block B, calling CB with
1488 iterate_over_block_locals (struct block
*b
,
1489 iterate_over_block_arg_local_vars_cb cb
,
1492 struct dict_iterator iter
;
1495 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1497 switch (SYMBOL_CLASS (sym
))
1503 if (SYMBOL_IS_ARGUMENT (sym
))
1505 (*cb
) (SYMBOL_PRINT_NAME (sym
), sym
, cb_data
);
1509 /* Ignore symbols which are not locals. */
1516 /* Same, but print labels. */
1519 /* Commented out, as the code using this function has also been
1520 commented out. FIXME:brobecker/2009-01-13: Find out why the code
1521 was commented out in the first place. The discussion introducing
1522 this change (2007-12-04: Support lexical blocks and function bodies
1523 that occupy non-contiguous address ranges) did not explain why
1524 this change was made. */
1526 print_block_frame_labels (struct gdbarch
*gdbarch
, struct block
*b
,
1527 int *have_default
, struct ui_file
*stream
)
1529 struct dict_iterator iter
;
1531 int values_printed
= 0;
1533 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1535 if (strcmp (SYMBOL_LINKAGE_NAME (sym
), "default") == 0)
1541 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
1543 struct symtab_and_line sal
;
1544 struct value_print_options opts
;
1546 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
1548 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1549 get_user_print_options (&opts
);
1550 if (opts
.addressprint
)
1552 fprintf_filtered (stream
, " ");
1553 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (sym
)),
1556 fprintf_filtered (stream
, " in file %s, line %d\n",
1557 sal
.symtab
->filename
, sal
.line
);
1561 return values_printed
;
1565 /* Iterate over all the local variables in block B, including all its
1566 superblocks, stopping when the top-level block is reached. */
1569 iterate_over_block_local_vars (struct block
*block
,
1570 iterate_over_block_arg_local_vars_cb cb
,
1575 iterate_over_block_locals (block
, cb
, cb_data
);
1576 /* After handling the function's top-level block, stop. Don't
1577 continue to its superblock, the block of per-file
1579 if (BLOCK_FUNCTION (block
))
1581 block
= BLOCK_SUPERBLOCK (block
);
1585 /* Data to be passed around in the calls to the locals and args
1588 struct print_variable_and_value_data
1590 struct frame_info
*frame
;
1592 struct ui_file
*stream
;
1596 /* The callback for the locals and args iterators. */
1599 do_print_variable_and_value (const char *print_name
,
1603 struct print_variable_and_value_data
*p
= cb_data
;
1605 print_variable_and_value (print_name
, sym
,
1606 p
->frame
, p
->stream
, p
->num_tabs
);
1607 p
->values_printed
= 1;
1611 print_frame_local_vars (struct frame_info
*frame
, int num_tabs
,
1612 struct ui_file
*stream
)
1614 struct print_variable_and_value_data cb_data
;
1615 struct block
*block
;
1618 if (!get_frame_pc_if_available (frame
, &pc
))
1620 fprintf_filtered (stream
,
1621 _("PC unavailable, cannot determine locals.\n"));
1625 block
= get_frame_block (frame
, 0);
1628 fprintf_filtered (stream
, "No symbol table info available.\n");
1632 cb_data
.frame
= frame
;
1633 cb_data
.num_tabs
= 4 * num_tabs
;
1634 cb_data
.stream
= stream
;
1635 cb_data
.values_printed
= 0;
1637 iterate_over_block_local_vars (block
,
1638 do_print_variable_and_value
,
1641 if (!cb_data
.values_printed
)
1642 fprintf_filtered (stream
, _("No locals.\n"));
1645 /* Same, but print labels. */
1648 print_frame_label_vars (struct frame_info
*frame
, int this_level_only
,
1649 struct ui_file
*stream
)
1652 fprintf_filtered (stream
, "print_frame_label_vars disabled.\n");
1654 struct blockvector
*bl
;
1655 struct block
*block
= get_frame_block (frame
, 0);
1656 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1657 int values_printed
= 0;
1658 int index
, have_default
= 0;
1659 char *blocks_printed
;
1660 CORE_ADDR pc
= get_frame_pc (frame
);
1664 fprintf_filtered (stream
, "No symbol table info available.\n");
1668 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
1669 blocks_printed
= alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1670 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1674 CORE_ADDR end
= BLOCK_END (block
) - 4;
1677 if (bl
!= blockvector_for_pc (end
, &index
))
1678 error (_("blockvector blotch"));
1679 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
1680 error (_("blockvector botch"));
1681 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
1684 /* Don't print out blocks that have gone by. */
1685 while (index
< last_index
1686 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
1689 while (index
< last_index
1690 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
1692 if (blocks_printed
[index
] == 0)
1694 if (print_block_frame_labels (gdbarch
,
1695 BLOCKVECTOR_BLOCK (bl
, index
),
1696 &have_default
, stream
))
1698 blocks_printed
[index
] = 1;
1704 if (values_printed
&& this_level_only
)
1707 /* After handling the function's top-level block, stop. Don't
1708 continue to its superblock, the block of per-file symbols.
1709 Also do not continue to the containing function of an inlined
1711 if (BLOCK_FUNCTION (block
))
1713 block
= BLOCK_SUPERBLOCK (block
);
1716 if (!values_printed
&& !this_level_only
)
1717 fprintf_filtered (stream
, _("No catches.\n"));
1722 locals_info (char *args
, int from_tty
)
1724 print_frame_local_vars (get_selected_frame (_("No frame selected.")),
1729 catch_info (char *ignore
, int from_tty
)
1731 /* Assume g++ compiled code; old GDB 4.16 behaviour. */
1732 print_frame_label_vars (get_selected_frame (_("No frame selected.")),
1736 /* Iterate over all the argument variables in block B.
1738 Returns 1 if any argument was walked; 0 otherwise. */
1741 iterate_over_block_arg_vars (struct block
*b
,
1742 iterate_over_block_arg_local_vars_cb cb
,
1745 struct dict_iterator iter
;
1746 struct symbol
*sym
, *sym2
;
1748 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1750 /* Don't worry about things which aren't arguments. */
1751 if (SYMBOL_IS_ARGUMENT (sym
))
1753 /* We have to look up the symbol because arguments can have
1754 two entries (one a parameter, one a local) and the one we
1755 want is the local, which lookup_symbol will find for us.
1756 This includes gcc1 (not gcc2) on the sparc when passing a
1757 small structure and gcc2 when the argument type is float
1758 and it is passed as a double and converted to float by
1759 the prologue (in the latter case the type of the LOC_ARG
1760 symbol is double and the type of the LOC_LOCAL symbol is
1761 float). There are also LOC_ARG/LOC_REGISTER pairs which
1762 are not combined in symbol-reading. */
1764 sym2
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
),
1765 b
, VAR_DOMAIN
, NULL
);
1766 (*cb
) (SYMBOL_PRINT_NAME (sym
), sym2
, cb_data
);
1772 print_frame_arg_vars (struct frame_info
*frame
, struct ui_file
*stream
)
1774 struct print_variable_and_value_data cb_data
;
1775 struct symbol
*func
;
1778 if (!get_frame_pc_if_available (frame
, &pc
))
1780 fprintf_filtered (stream
, _("PC unavailable, cannot determine args.\n"));
1784 func
= get_frame_function (frame
);
1787 fprintf_filtered (stream
, _("No symbol table info available.\n"));
1791 cb_data
.frame
= frame
;
1792 cb_data
.num_tabs
= 0;
1793 cb_data
.stream
= gdb_stdout
;
1794 cb_data
.values_printed
= 0;
1796 iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func
),
1797 do_print_variable_and_value
, &cb_data
);
1799 if (!cb_data
.values_printed
)
1800 fprintf_filtered (stream
, _("No arguments.\n"));
1804 args_info (char *ignore
, int from_tty
)
1806 print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
1812 args_plus_locals_info (char *ignore
, int from_tty
)
1814 args_info (ignore
, from_tty
);
1815 locals_info (ignore
, from_tty
);
1819 /* Select frame FRAME. Also print the stack frame and show the source
1820 if this is the tui version. */
1822 select_and_print_frame (struct frame_info
*frame
)
1824 select_frame (frame
);
1826 print_stack_frame (frame
, 1, SRC_AND_LOC
);
1829 /* Return the symbol-block in which the selected frame is executing.
1830 Can return zero under various legitimate circumstances.
1832 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1833 code address within the block returned. We use this to decide
1834 which macros are in scope. */
1837 get_selected_block (CORE_ADDR
*addr_in_block
)
1839 if (!has_stack_frames ())
1842 return get_frame_block (get_selected_frame (NULL
), addr_in_block
);
1845 /* Find a frame a certain number of levels away from FRAME.
1846 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1847 Positive means go to earlier frames (up); negative, the reverse.
1848 The int that contains the number of levels is counted toward
1849 zero as the frames for those levels are found.
1850 If the top or bottom frame is reached, that frame is returned,
1851 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1852 how much farther the original request asked to go. */
1855 find_relative_frame (struct frame_info
*frame
, int *level_offset_ptr
)
1857 /* Going up is simple: just call get_prev_frame enough times or
1858 until the initial frame is reached. */
1859 while (*level_offset_ptr
> 0)
1861 struct frame_info
*prev
= get_prev_frame (frame
);
1865 (*level_offset_ptr
)--;
1869 /* Going down is just as simple. */
1870 while (*level_offset_ptr
< 0)
1872 struct frame_info
*next
= get_next_frame (frame
);
1876 (*level_offset_ptr
)++;
1883 /* The "select_frame" command. With no argument this is a NOP.
1884 Select the frame at level LEVEL_EXP if it is a valid level.
1885 Otherwise, treat LEVEL_EXP as an address expression and select it.
1887 See parse_frame_specification for more info on proper frame
1891 select_frame_command (char *level_exp
, int from_tty
)
1893 select_frame (parse_frame_specification_1 (level_exp
, "No stack.", NULL
));
1896 /* The "frame" command. With no argument, print the selected frame
1897 briefly. With an argument, behave like select_frame and then print
1898 the selected frame. */
1901 frame_command (char *level_exp
, int from_tty
)
1903 select_frame_command (level_exp
, from_tty
);
1904 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1907 /* The XDB Compatibility command to print the current frame. */
1910 current_frame_command (char *level_exp
, int from_tty
)
1912 print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC
);
1915 /* Select the frame up one or COUNT_EXP stack levels from the
1916 previously selected frame, and print it briefly. */
1919 up_silently_base (char *count_exp
)
1921 struct frame_info
*frame
;
1925 count
= parse_and_eval_long (count_exp
);
1927 frame
= find_relative_frame (get_selected_frame ("No stack."), &count
);
1928 if (count
!= 0 && count_exp
== NULL
)
1929 error (_("Initial frame selected; you cannot go up."));
1930 select_frame (frame
);
1934 up_silently_command (char *count_exp
, int from_tty
)
1936 up_silently_base (count_exp
);
1940 up_command (char *count_exp
, int from_tty
)
1942 up_silently_base (count_exp
);
1943 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1946 /* Select the frame down one or COUNT_EXP stack levels from the previously
1947 selected frame, and print it briefly. */
1950 down_silently_base (char *count_exp
)
1952 struct frame_info
*frame
;
1956 count
= -parse_and_eval_long (count_exp
);
1958 frame
= find_relative_frame (get_selected_frame ("No stack."), &count
);
1959 if (count
!= 0 && count_exp
== NULL
)
1961 /* We only do this if COUNT_EXP is not specified. That way
1962 "down" means to really go down (and let me know if that is
1963 impossible), but "down 9999" can be used to mean go all the
1964 way down without getting an error. */
1966 error (_("Bottom (innermost) frame selected; you cannot go down."));
1969 select_frame (frame
);
1973 down_silently_command (char *count_exp
, int from_tty
)
1975 down_silently_base (count_exp
);
1979 down_command (char *count_exp
, int from_tty
)
1981 down_silently_base (count_exp
);
1982 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1987 return_command (char *retval_exp
, int from_tty
)
1989 struct frame_info
*thisframe
;
1990 struct gdbarch
*gdbarch
;
1991 struct symbol
*thisfun
;
1992 struct value
*return_value
= NULL
;
1993 const char *query_prefix
= "";
1995 thisframe
= get_selected_frame ("No selected frame.");
1996 thisfun
= get_frame_function (thisframe
);
1997 gdbarch
= get_frame_arch (thisframe
);
1999 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
)
2000 error (_("Can not force return from an inlined function."));
2002 /* Compute the return value. If the computation triggers an error,
2003 let it bail. If the return type can't be handled, set
2004 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
2008 struct expression
*retval_expr
= parse_expression (retval_exp
);
2009 struct cleanup
*old_chain
= make_cleanup (xfree
, retval_expr
);
2010 struct type
*return_type
= NULL
;
2012 /* Compute the return value. Should the computation fail, this
2013 call throws an error. */
2014 return_value
= evaluate_expression (retval_expr
);
2016 /* Cast return value to the return type of the function. Should
2017 the cast fail, this call throws an error. */
2018 if (thisfun
!= NULL
)
2019 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
2020 if (return_type
== NULL
)
2022 if (retval_expr
->elts
[0].opcode
!= UNOP_CAST
)
2023 error (_("Return value type not available for selected "
2025 "Please use an explicit cast of the value to return."));
2026 return_type
= value_type (return_value
);
2028 do_cleanups (old_chain
);
2029 CHECK_TYPEDEF (return_type
);
2030 return_value
= value_cast (return_type
, return_value
);
2032 /* Make sure the value is fully evaluated. It may live in the
2033 stack frame we're about to pop. */
2034 if (value_lazy (return_value
))
2035 value_fetch_lazy (return_value
);
2037 if (TYPE_CODE (return_type
) == TYPE_CODE_VOID
)
2038 /* If the return-type is "void", don't try to find the
2039 return-value's location. However, do still evaluate the
2040 return expression so that, even when the expression result
2041 is discarded, side effects such as "return i++" still
2043 return_value
= NULL
;
2044 else if (thisfun
!= NULL
2045 && using_struct_return (gdbarch
,
2046 SYMBOL_TYPE (thisfun
), return_type
))
2048 query_prefix
= "The location at which to store the "
2049 "function's return value is unknown.\n"
2050 "If you continue, the return value "
2051 "that you specified will be ignored.\n";
2052 return_value
= NULL
;
2056 /* Does an interactive user really want to do this? Include
2057 information, such as how well GDB can handle the return value, in
2058 the query message. */
2063 if (thisfun
== NULL
)
2064 confirmed
= query (_("%sMake selected stack frame return now? "),
2067 confirmed
= query (_("%sMake %s return now? "), query_prefix
,
2068 SYMBOL_PRINT_NAME (thisfun
));
2070 error (_("Not confirmed"));
2073 /* Discard the selected frame and all frames inner-to it. */
2074 frame_pop (get_selected_frame (NULL
));
2076 /* Store RETURN_VALUE in the just-returned register set. */
2077 if (return_value
!= NULL
)
2079 struct type
*return_type
= value_type (return_value
);
2080 struct gdbarch
*gdbarch
= get_regcache_arch (get_current_regcache ());
2081 struct type
*func_type
= thisfun
== NULL
? NULL
: SYMBOL_TYPE (thisfun
);
2083 gdb_assert (gdbarch_return_value (gdbarch
, func_type
, return_type
, NULL
,
2085 == RETURN_VALUE_REGISTER_CONVENTION
);
2086 gdbarch_return_value (gdbarch
, func_type
, return_type
,
2087 get_current_regcache (), NULL
/*read*/,
2088 value_contents (return_value
) /*write*/);
2091 /* If we are at the end of a call dummy now, pop the dummy frame
2093 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME
)
2094 frame_pop (get_current_frame ());
2096 /* If interactive, print the frame that is now current. */
2098 frame_command ("0", 1);
2100 select_frame_command ("0", 0);
2103 /* Sets the scope to input function name, provided that the function
2104 is within the current stack frame. */
2106 struct function_bounds
2108 CORE_ADDR low
, high
;
2112 func_command (char *arg
, int from_tty
)
2114 struct frame_info
*frame
;
2116 struct symtabs_and_lines sals
;
2119 struct function_bounds
*func_bounds
= NULL
;
2124 frame
= parse_frame_specification ("0");
2125 sals
= decode_line_spec (arg
, 1);
2126 func_bounds
= (struct function_bounds
*) xmalloc (
2127 sizeof (struct function_bounds
) * sals
.nelts
);
2128 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
2130 if (sals
.sals
[i
].pc
== 0
2131 || find_pc_partial_function (sals
.sals
[i
].pc
, NULL
,
2132 &func_bounds
[i
].low
,
2133 &func_bounds
[i
].high
) == 0)
2135 func_bounds
[i
].low
= func_bounds
[i
].high
= 0;
2141 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
2142 found
= (get_frame_pc (frame
) >= func_bounds
[i
].low
2143 && get_frame_pc (frame
) < func_bounds
[i
].high
);
2147 frame
= find_relative_frame (frame
, &level
);
2150 while (!found
&& level
== 0);
2153 xfree (func_bounds
);
2156 printf_filtered (_("'%s' not within current stack frame.\n"), arg
);
2157 else if (frame
!= get_selected_frame (NULL
))
2158 select_and_print_frame (frame
);
2161 /* Gets the language of the current frame. */
2164 get_frame_language (void)
2166 struct frame_info
*frame
= deprecated_safe_get_selected_frame ();
2170 volatile struct gdb_exception ex
;
2174 /* We determine the current frame language by looking up its
2175 associated symtab. To retrieve this symtab, we use the frame
2176 PC. However we cannot use the frame PC as is, because it
2177 usually points to the instruction following the "call", which
2178 is sometimes the first instruction of another function. So
2179 we rely on get_frame_address_in_block(), it provides us with
2180 a PC that is guaranteed to be inside the frame's code
2183 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2185 pc
= get_frame_address_in_block (frame
);
2189 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
2190 throw_exception (ex
);
2194 s
= find_pc_symtab (pc
);
2200 return language_unknown
;
2204 /* Provide a prototype to silence -Wmissing-prototypes. */
2205 void _initialize_stack (void);
2208 _initialize_stack (void)
2210 add_com ("return", class_stack
, return_command
, _("\
2211 Make selected stack frame return to its caller.\n\
2212 Control remains in the debugger, but when you continue\n\
2213 execution will resume in the frame above the one now selected.\n\
2214 If an argument is given, it is an expression for the value to return."));
2216 add_com ("up", class_stack
, up_command
, _("\
2217 Select and print stack frame that called this one.\n\
2218 An argument says how many frames up to go."));
2219 add_com ("up-silently", class_support
, up_silently_command
, _("\
2220 Same as the `up' command, but does not print anything.\n\
2221 This is useful in command scripts."));
2223 add_com ("down", class_stack
, down_command
, _("\
2224 Select and print stack frame called by this one.\n\
2225 An argument says how many frames down to go."));
2226 add_com_alias ("do", "down", class_stack
, 1);
2227 add_com_alias ("dow", "down", class_stack
, 1);
2228 add_com ("down-silently", class_support
, down_silently_command
, _("\
2229 Same as the `down' command, but does not print anything.\n\
2230 This is useful in command scripts."));
2232 add_com ("frame", class_stack
, frame_command
, _("\
2233 Select and print a stack frame.\nWith no argument, \
2234 print the selected stack frame. (See also \"info frame\").\n\
2235 An argument specifies the frame to select.\n\
2236 It can be a stack frame number or the address of the frame.\n\
2237 With argument, nothing is printed if input is coming from\n\
2238 a command file or a user-defined command."));
2240 add_com_alias ("f", "frame", class_stack
, 1);
2244 add_com ("L", class_stack
, current_frame_command
,
2245 _("Print the current stack frame.\n"));
2246 add_com_alias ("V", "frame", class_stack
, 1);
2248 add_com ("select-frame", class_stack
, select_frame_command
, _("\
2249 Select a stack frame without printing anything.\n\
2250 An argument specifies the frame to select.\n\
2251 It can be a stack frame number or the address of the frame.\n"));
2253 add_com ("backtrace", class_stack
, backtrace_command
, _("\
2254 Print backtrace of all stack frames, or innermost COUNT frames.\n\
2255 With a negative argument, print outermost -COUNT frames.\nUse of the \
2256 'full' qualifier also prints the values of the local variables.\n"));
2257 add_com_alias ("bt", "backtrace", class_stack
, 0);
2260 add_com_alias ("t", "backtrace", class_stack
, 0);
2261 add_com ("T", class_stack
, backtrace_full_command
, _("\
2262 Print backtrace of all stack frames, or innermost COUNT frames\n\
2263 and the values of the local variables.\n\
2264 With a negative argument, print outermost -COUNT frames.\n\
2265 Usage: T <count>\n"));
2268 add_com_alias ("where", "backtrace", class_alias
, 0);
2269 add_info ("stack", backtrace_command
,
2270 _("Backtrace of the stack, or innermost COUNT frames."));
2271 add_info_alias ("s", "stack", 1);
2272 add_info ("frame", frame_info
,
2273 _("All about selected stack frame, or frame at ADDR."));
2274 add_info_alias ("f", "frame", 1);
2275 add_info ("locals", locals_info
,
2276 _("Local variables of current stack frame."));
2277 add_info ("args", args_info
,
2278 _("Argument variables of current stack frame."));
2280 add_com ("l", class_info
, args_plus_locals_info
,
2281 _("Argument and local variables of current stack frame."));
2284 add_com ("func", class_stack
, func_command
, _("\
2285 Select the stack frame that contains <func>.\n\
2286 Usage: func <name>\n"));
2288 add_info ("catch", catch_info
,
2289 _("Exceptions that can be caught in the current stack frame."));
2291 add_setshow_enum_cmd ("frame-arguments", class_stack
,
2292 print_frame_arguments_choices
, &print_frame_arguments
,
2293 _("Set printing of non-scalar frame arguments"),
2294 _("Show printing of non-scalar frame arguments"),
2295 NULL
, NULL
, NULL
, &setprintlist
, &showprintlist
);
2297 add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack
,
2298 &disassemble_next_line
, _("\
2299 Set whether to disassemble next source line or insn when execution stops."),
2301 Show whether to disassemble next source line or insn when execution stops."),
2303 If ON, GDB will display disassembly of the next source line, in addition\n\
2304 to displaying the source line itself. If the next source line cannot\n\
2305 be displayed (e.g., source is unavailable or there's no line info), GDB\n\
2306 will display disassembly of next instruction instead of showing the\n\
2308 If AUTO, display disassembly of next instruction only if the source line\n\
2309 cannot be displayed.\n\
2310 If OFF (which is the default), never display the disassembly of the next\n\
2313 show_disassemble_next_line
,
2314 &setlist
, &showlist
);
2315 disassemble_next_line
= AUTO_BOOLEAN_FALSE
;