15796c8dcSSimon Schubert /* Print and select stack frames for GDB, the GNU debugger. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 45796c8dcSSimon Schubert 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 5*c50c785cSJohn Marino 2009, 2010, 2011 Free Software Foundation, Inc. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This file is part of GDB. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert (at your option) any later version. 135796c8dcSSimon Schubert 145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert GNU General Public License for more details. 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert #include "defs.h" 235796c8dcSSimon Schubert #include "value.h" 245796c8dcSSimon Schubert #include "symtab.h" 255796c8dcSSimon Schubert #include "gdbtypes.h" 265796c8dcSSimon Schubert #include "expression.h" 275796c8dcSSimon Schubert #include "language.h" 285796c8dcSSimon Schubert #include "frame.h" 295796c8dcSSimon Schubert #include "gdbcmd.h" 305796c8dcSSimon Schubert #include "gdbcore.h" 315796c8dcSSimon Schubert #include "target.h" 325796c8dcSSimon Schubert #include "source.h" 335796c8dcSSimon Schubert #include "breakpoint.h" 345796c8dcSSimon Schubert #include "demangle.h" 355796c8dcSSimon Schubert #include "inferior.h" 365796c8dcSSimon Schubert #include "annotate.h" 375796c8dcSSimon Schubert #include "ui-out.h" 385796c8dcSSimon Schubert #include "block.h" 395796c8dcSSimon Schubert #include "stack.h" 405796c8dcSSimon Schubert #include "dictionary.h" 415796c8dcSSimon Schubert #include "exceptions.h" 425796c8dcSSimon Schubert #include "reggroups.h" 435796c8dcSSimon Schubert #include "regcache.h" 445796c8dcSSimon Schubert #include "solib.h" 455796c8dcSSimon Schubert #include "valprint.h" 465796c8dcSSimon Schubert #include "gdbthread.h" 475796c8dcSSimon Schubert #include "cp-support.h" 485796c8dcSSimon Schubert #include "disasm.h" 495796c8dcSSimon Schubert #include "inline-frame.h" 505796c8dcSSimon Schubert 515796c8dcSSimon Schubert #include "gdb_assert.h" 525796c8dcSSimon Schubert #include <ctype.h> 535796c8dcSSimon Schubert #include "gdb_string.h" 545796c8dcSSimon Schubert 55cf7f2e2dSJohn Marino #include "psymtab.h" 56cf7f2e2dSJohn Marino #include "symfile.h" 57cf7f2e2dSJohn Marino 585796c8dcSSimon Schubert void (*deprecated_selected_frame_level_changed_hook) (int); 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert /* The possible choices of "set print frame-arguments, and the value 615796c8dcSSimon Schubert of this setting. */ 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert static const char *print_frame_arguments_choices[] = 645796c8dcSSimon Schubert {"all", "scalars", "none", NULL}; 655796c8dcSSimon Schubert static const char *print_frame_arguments = "scalars"; 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert /* Prototypes for local functions. */ 685796c8dcSSimon Schubert 695796c8dcSSimon Schubert static void print_frame_local_vars (struct frame_info *, int, 705796c8dcSSimon Schubert struct ui_file *); 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert static void print_frame (struct frame_info *frame, int print_level, 735796c8dcSSimon Schubert enum print_what print_what, int print_args, 745796c8dcSSimon Schubert struct symtab_and_line sal); 755796c8dcSSimon Schubert 765796c8dcSSimon Schubert /* Zero means do things normally; we are interacting directly with the 775796c8dcSSimon Schubert user. One means print the full filename and linenumber when a 785796c8dcSSimon Schubert frame is printed, and do so in a format emacs18/emacs19.22 can 795796c8dcSSimon Schubert parse. Two means print similar annotations, but in many more 805796c8dcSSimon Schubert cases and in a slightly different syntax. */ 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert int annotation_level = 0; 835796c8dcSSimon Schubert 845796c8dcSSimon Schubert 855796c8dcSSimon Schubert struct print_stack_frame_args 865796c8dcSSimon Schubert { 875796c8dcSSimon Schubert struct frame_info *frame; 885796c8dcSSimon Schubert int print_level; 895796c8dcSSimon Schubert enum print_what print_what; 905796c8dcSSimon Schubert int print_args; 915796c8dcSSimon Schubert }; 925796c8dcSSimon Schubert 935796c8dcSSimon Schubert /* Show or print the frame arguments; stub for catch_errors. */ 945796c8dcSSimon Schubert 955796c8dcSSimon Schubert static int 965796c8dcSSimon Schubert print_stack_frame_stub (void *args) 975796c8dcSSimon Schubert { 985796c8dcSSimon Schubert struct print_stack_frame_args *p = args; 995796c8dcSSimon Schubert int center = (p->print_what == SRC_LINE || p->print_what == SRC_AND_LOC); 1005796c8dcSSimon Schubert 1015796c8dcSSimon Schubert print_frame_info (p->frame, p->print_level, p->print_what, p->print_args); 1025796c8dcSSimon Schubert set_current_sal_from_frame (p->frame, center); 1035796c8dcSSimon Schubert return 0; 1045796c8dcSSimon Schubert } 1055796c8dcSSimon Schubert 1065796c8dcSSimon Schubert /* Return 1 if we should display the address in addition to the location, 1075796c8dcSSimon Schubert because we are in the middle of a statement. */ 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert static int 1105796c8dcSSimon Schubert frame_show_address (struct frame_info *frame, 1115796c8dcSSimon Schubert struct symtab_and_line sal) 1125796c8dcSSimon Schubert { 1135796c8dcSSimon Schubert /* If there is a line number, but no PC, then there is no location 1145796c8dcSSimon Schubert information associated with this sal. The only way that should 1155796c8dcSSimon Schubert happen is for the call sites of inlined functions (SAL comes from 1165796c8dcSSimon Schubert find_frame_sal). Otherwise, we would have some PC range if the 1175796c8dcSSimon Schubert SAL came from a line table. */ 1185796c8dcSSimon Schubert if (sal.line != 0 && sal.pc == 0 && sal.end == 0) 1195796c8dcSSimon Schubert { 1205796c8dcSSimon Schubert if (get_next_frame (frame) == NULL) 1215796c8dcSSimon Schubert gdb_assert (inline_skipped_frames (inferior_ptid) > 0); 1225796c8dcSSimon Schubert else 1235796c8dcSSimon Schubert gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME); 1245796c8dcSSimon Schubert return 0; 1255796c8dcSSimon Schubert } 1265796c8dcSSimon Schubert 1275796c8dcSSimon Schubert return get_frame_pc (frame) != sal.pc; 1285796c8dcSSimon Schubert } 1295796c8dcSSimon Schubert 1305796c8dcSSimon Schubert /* Show or print a stack frame FRAME briefly. The output is format 1315796c8dcSSimon Schubert according to PRINT_LEVEL and PRINT_WHAT printing the frame's 1325796c8dcSSimon Schubert relative level, function name, argument list, and file name and 1335796c8dcSSimon Schubert line number. If the frame's PC is not at the beginning of the 1345796c8dcSSimon Schubert source line, the actual PC is printed at the beginning. */ 1355796c8dcSSimon Schubert 1365796c8dcSSimon Schubert void 1375796c8dcSSimon Schubert print_stack_frame (struct frame_info *frame, int print_level, 1385796c8dcSSimon Schubert enum print_what print_what) 1395796c8dcSSimon Schubert { 1405796c8dcSSimon Schubert struct print_stack_frame_args args; 1415796c8dcSSimon Schubert 1425796c8dcSSimon Schubert args.frame = frame; 1435796c8dcSSimon Schubert args.print_level = print_level; 1445796c8dcSSimon Schubert args.print_what = print_what; 1455796c8dcSSimon Schubert /* For mi, alway print location and address. */ 1465796c8dcSSimon Schubert args.print_what = ui_out_is_mi_like_p (uiout) ? LOC_AND_ADDRESS : print_what; 1475796c8dcSSimon Schubert args.print_args = 1; 1485796c8dcSSimon Schubert 1495796c8dcSSimon Schubert catch_errors (print_stack_frame_stub, &args, "", RETURN_MASK_ERROR); 1505796c8dcSSimon Schubert } 1515796c8dcSSimon Schubert 1525796c8dcSSimon Schubert struct print_args_args 1535796c8dcSSimon Schubert { 1545796c8dcSSimon Schubert struct symbol *func; 1555796c8dcSSimon Schubert struct frame_info *frame; 1565796c8dcSSimon Schubert struct ui_file *stream; 1575796c8dcSSimon Schubert }; 1585796c8dcSSimon Schubert 1595796c8dcSSimon Schubert static int print_args_stub (void *args); 1605796c8dcSSimon Schubert 1615796c8dcSSimon Schubert /* Print nameless arguments of frame FRAME on STREAM, where START is 1625796c8dcSSimon Schubert the offset of the first nameless argument, and NUM is the number of 1635796c8dcSSimon Schubert nameless arguments to print. FIRST is nonzero if this is the first 1645796c8dcSSimon Schubert argument (not just the first nameless argument). */ 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert static void 1675796c8dcSSimon Schubert print_frame_nameless_args (struct frame_info *frame, long start, int num, 1685796c8dcSSimon Schubert int first, struct ui_file *stream) 1695796c8dcSSimon Schubert { 1705796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 1715796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 1725796c8dcSSimon Schubert int i; 1735796c8dcSSimon Schubert CORE_ADDR argsaddr; 1745796c8dcSSimon Schubert long arg_value; 1755796c8dcSSimon Schubert 1765796c8dcSSimon Schubert for (i = 0; i < num; i++) 1775796c8dcSSimon Schubert { 1785796c8dcSSimon Schubert QUIT; 1795796c8dcSSimon Schubert argsaddr = get_frame_args_address (frame); 1805796c8dcSSimon Schubert if (!argsaddr) 1815796c8dcSSimon Schubert return; 1825796c8dcSSimon Schubert arg_value = read_memory_integer (argsaddr + start, 1835796c8dcSSimon Schubert sizeof (int), byte_order); 1845796c8dcSSimon Schubert if (!first) 1855796c8dcSSimon Schubert fprintf_filtered (stream, ", "); 1865796c8dcSSimon Schubert fprintf_filtered (stream, "%ld", arg_value); 1875796c8dcSSimon Schubert first = 0; 1885796c8dcSSimon Schubert start += sizeof (int); 1895796c8dcSSimon Schubert } 1905796c8dcSSimon Schubert } 1915796c8dcSSimon Schubert 1925796c8dcSSimon Schubert /* Print the arguments of frame FRAME on STREAM, given the function 1935796c8dcSSimon Schubert FUNC running in that frame (as a symbol), where NUM is the number 1945796c8dcSSimon Schubert of arguments according to the stack frame (or -1 if the number of 1955796c8dcSSimon Schubert arguments is unknown). */ 1965796c8dcSSimon Schubert 1975796c8dcSSimon Schubert /* Note that currently the "number of arguments according to the 1985796c8dcSSimon Schubert stack frame" is only known on VAX where i refers to the "number of 1995796c8dcSSimon Schubert ints of arguments according to the stack frame". */ 2005796c8dcSSimon Schubert 2015796c8dcSSimon Schubert static void 2025796c8dcSSimon Schubert print_frame_args (struct symbol *func, struct frame_info *frame, 2035796c8dcSSimon Schubert int num, struct ui_file *stream) 2045796c8dcSSimon Schubert { 2055796c8dcSSimon Schubert int first = 1; 2065796c8dcSSimon Schubert /* Offset of next stack argument beyond the one we have seen that is 2075796c8dcSSimon Schubert at the highest offset, or -1 if we haven't come to a stack 2085796c8dcSSimon Schubert argument yet. */ 2095796c8dcSSimon Schubert long highest_offset = -1; 2105796c8dcSSimon Schubert /* Number of ints of arguments that we have printed so far. */ 2115796c8dcSSimon Schubert int args_printed = 0; 2125796c8dcSSimon Schubert struct cleanup *old_chain, *list_chain; 2135796c8dcSSimon Schubert struct ui_stream *stb; 2145796c8dcSSimon Schubert /* True if we should print arguments, false otherwise. */ 2155796c8dcSSimon Schubert int print_args = strcmp (print_frame_arguments, "none"); 2165796c8dcSSimon Schubert /* True in "summary" mode, false otherwise. */ 2175796c8dcSSimon Schubert int summary = !strcmp (print_frame_arguments, "scalars"); 2185796c8dcSSimon Schubert 2195796c8dcSSimon Schubert stb = ui_out_stream_new (uiout); 2205796c8dcSSimon Schubert old_chain = make_cleanup_ui_out_stream_delete (stb); 2215796c8dcSSimon Schubert 2225796c8dcSSimon Schubert if (func) 2235796c8dcSSimon Schubert { 2245796c8dcSSimon Schubert struct block *b = SYMBOL_BLOCK_VALUE (func); 2255796c8dcSSimon Schubert struct dict_iterator iter; 2265796c8dcSSimon Schubert struct symbol *sym; 2275796c8dcSSimon Schubert struct value *val; 2285796c8dcSSimon Schubert 2295796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (b, iter, sym) 2305796c8dcSSimon Schubert { 2315796c8dcSSimon Schubert QUIT; 2325796c8dcSSimon Schubert 2335796c8dcSSimon Schubert /* Keep track of the highest stack argument offset seen, and 2345796c8dcSSimon Schubert skip over any kinds of symbols we don't care about. */ 2355796c8dcSSimon Schubert 2365796c8dcSSimon Schubert if (!SYMBOL_IS_ARGUMENT (sym)) 2375796c8dcSSimon Schubert continue; 2385796c8dcSSimon Schubert 2395796c8dcSSimon Schubert switch (SYMBOL_CLASS (sym)) 2405796c8dcSSimon Schubert { 2415796c8dcSSimon Schubert case LOC_ARG: 2425796c8dcSSimon Schubert case LOC_REF_ARG: 2435796c8dcSSimon Schubert { 2445796c8dcSSimon Schubert long current_offset = SYMBOL_VALUE (sym); 2455796c8dcSSimon Schubert int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym)); 2465796c8dcSSimon Schubert 2475796c8dcSSimon Schubert /* Compute address of next argument by adding the size of 2485796c8dcSSimon Schubert this argument and rounding to an int boundary. */ 2495796c8dcSSimon Schubert current_offset = 2505796c8dcSSimon Schubert ((current_offset + arg_size + sizeof (int) - 1) 2515796c8dcSSimon Schubert & ~(sizeof (int) - 1)); 2525796c8dcSSimon Schubert 2535796c8dcSSimon Schubert /* If this is the highest offset seen yet, set 2545796c8dcSSimon Schubert highest_offset. */ 2555796c8dcSSimon Schubert if (highest_offset == -1 2565796c8dcSSimon Schubert || (current_offset > highest_offset)) 2575796c8dcSSimon Schubert highest_offset = current_offset; 2585796c8dcSSimon Schubert 2595796c8dcSSimon Schubert /* Add the number of ints we're about to print to 2605796c8dcSSimon Schubert args_printed. */ 2615796c8dcSSimon Schubert args_printed += (arg_size + sizeof (int) - 1) / sizeof (int); 2625796c8dcSSimon Schubert } 2635796c8dcSSimon Schubert 2645796c8dcSSimon Schubert /* We care about types of symbols, but don't need to 2655796c8dcSSimon Schubert keep track of stack offsets in them. */ 2665796c8dcSSimon Schubert case LOC_REGISTER: 2675796c8dcSSimon Schubert case LOC_REGPARM_ADDR: 2685796c8dcSSimon Schubert case LOC_COMPUTED: 2695796c8dcSSimon Schubert case LOC_OPTIMIZED_OUT: 2705796c8dcSSimon Schubert default: 2715796c8dcSSimon Schubert break; 2725796c8dcSSimon Schubert } 2735796c8dcSSimon Schubert 2745796c8dcSSimon Schubert /* We have to look up the symbol because arguments can have 2755796c8dcSSimon Schubert two entries (one a parameter, one a local) and the one we 2765796c8dcSSimon Schubert want is the local, which lookup_symbol will find for us. 2775796c8dcSSimon Schubert This includes gcc1 (not gcc2) on SPARC when passing a 2785796c8dcSSimon Schubert small structure and gcc2 when the argument type is float 2795796c8dcSSimon Schubert and it is passed as a double and converted to float by 2805796c8dcSSimon Schubert the prologue (in the latter case the type of the LOC_ARG 2815796c8dcSSimon Schubert symbol is double and the type of the LOC_LOCAL symbol is 2825796c8dcSSimon Schubert float). */ 2835796c8dcSSimon Schubert /* But if the parameter name is null, don't try it. Null 2845796c8dcSSimon Schubert parameter names occur on the RS/6000, for traceback 2855796c8dcSSimon Schubert tables. FIXME, should we even print them? */ 2865796c8dcSSimon Schubert 2875796c8dcSSimon Schubert if (*SYMBOL_LINKAGE_NAME (sym)) 2885796c8dcSSimon Schubert { 2895796c8dcSSimon Schubert struct symbol *nsym; 290cf7f2e2dSJohn Marino 2915796c8dcSSimon Schubert nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), 2925796c8dcSSimon Schubert b, VAR_DOMAIN, NULL); 2935796c8dcSSimon Schubert gdb_assert (nsym != NULL); 2945796c8dcSSimon Schubert if (SYMBOL_CLASS (nsym) == LOC_REGISTER 2955796c8dcSSimon Schubert && !SYMBOL_IS_ARGUMENT (nsym)) 2965796c8dcSSimon Schubert { 2975796c8dcSSimon Schubert /* There is a LOC_ARG/LOC_REGISTER pair. This means 2985796c8dcSSimon Schubert that it was passed on the stack and loaded into a 2995796c8dcSSimon Schubert register, or passed in a register and stored in a 3005796c8dcSSimon Schubert stack slot. GDB 3.x used the LOC_ARG; GDB 3015796c8dcSSimon Schubert 4.0-4.11 used the LOC_REGISTER. 3025796c8dcSSimon Schubert 3035796c8dcSSimon Schubert Reasons for using the LOC_ARG: 3045796c8dcSSimon Schubert 3055796c8dcSSimon Schubert (1) Because find_saved_registers may be slow for 3065796c8dcSSimon Schubert remote debugging. 3075796c8dcSSimon Schubert 3085796c8dcSSimon Schubert (2) Because registers are often re-used and stack 3095796c8dcSSimon Schubert slots rarely (never?) are. Therefore using 3105796c8dcSSimon Schubert the stack slot is much less likely to print 3115796c8dcSSimon Schubert garbage. 3125796c8dcSSimon Schubert 3135796c8dcSSimon Schubert Reasons why we might want to use the LOC_REGISTER: 3145796c8dcSSimon Schubert 3155796c8dcSSimon Schubert (1) So that the backtrace prints the same value 3165796c8dcSSimon Schubert as "print foo". I see no compelling reason 3175796c8dcSSimon Schubert why this needs to be the case; having the 3185796c8dcSSimon Schubert backtrace print the value which was passed 3195796c8dcSSimon Schubert in, and "print foo" print the value as 3205796c8dcSSimon Schubert modified within the called function, makes 3215796c8dcSSimon Schubert perfect sense to me. 3225796c8dcSSimon Schubert 3235796c8dcSSimon Schubert Additional note: It might be nice if "info args" 3245796c8dcSSimon Schubert displayed both values. 3255796c8dcSSimon Schubert 3265796c8dcSSimon Schubert One more note: There is a case with SPARC 3275796c8dcSSimon Schubert structure passing where we need to use the 3285796c8dcSSimon Schubert LOC_REGISTER, but this is dealt with by creating 3295796c8dcSSimon Schubert a single LOC_REGPARM in symbol reading. */ 3305796c8dcSSimon Schubert 3315796c8dcSSimon Schubert /* Leave sym (the LOC_ARG) alone. */ 3325796c8dcSSimon Schubert ; 3335796c8dcSSimon Schubert } 3345796c8dcSSimon Schubert else 3355796c8dcSSimon Schubert sym = nsym; 3365796c8dcSSimon Schubert } 3375796c8dcSSimon Schubert 3385796c8dcSSimon Schubert /* Print the current arg. */ 3395796c8dcSSimon Schubert if (!first) 3405796c8dcSSimon Schubert ui_out_text (uiout, ", "); 3415796c8dcSSimon Schubert ui_out_wrap_hint (uiout, " "); 3425796c8dcSSimon Schubert 3435796c8dcSSimon Schubert annotate_arg_begin (); 3445796c8dcSSimon Schubert 3455796c8dcSSimon Schubert list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); 3465796c8dcSSimon Schubert fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (sym), 3475796c8dcSSimon Schubert SYMBOL_LANGUAGE (sym), 3485796c8dcSSimon Schubert DMGL_PARAMS | DMGL_ANSI); 3495796c8dcSSimon Schubert ui_out_field_stream (uiout, "name", stb); 3505796c8dcSSimon Schubert annotate_arg_name_end (); 3515796c8dcSSimon Schubert ui_out_text (uiout, "="); 3525796c8dcSSimon Schubert 3535796c8dcSSimon Schubert if (print_args) 3545796c8dcSSimon Schubert { 3555796c8dcSSimon Schubert /* Avoid value_print because it will deref ref parameters. 3565796c8dcSSimon Schubert We just want to print their addresses. Print ??? for 3575796c8dcSSimon Schubert args whose address we do not know. We pass 2 as 3585796c8dcSSimon Schubert "recurse" to val_print because our standard indentation 3595796c8dcSSimon Schubert here is 4 spaces, and val_print indents 2 for each 3605796c8dcSSimon Schubert recurse. */ 3615796c8dcSSimon Schubert val = read_var_value (sym, frame); 3625796c8dcSSimon Schubert 3635796c8dcSSimon Schubert annotate_arg_value (val == NULL ? NULL : value_type (val)); 3645796c8dcSSimon Schubert 3655796c8dcSSimon Schubert if (val) 3665796c8dcSSimon Schubert { 3675796c8dcSSimon Schubert const struct language_defn *language; 3685796c8dcSSimon Schubert struct value_print_options opts; 3695796c8dcSSimon Schubert 3705796c8dcSSimon Schubert /* Use the appropriate language to display our symbol, 3715796c8dcSSimon Schubert unless the user forced the language to a specific 3725796c8dcSSimon Schubert language. */ 3735796c8dcSSimon Schubert if (language_mode == language_mode_auto) 3745796c8dcSSimon Schubert language = language_def (SYMBOL_LANGUAGE (sym)); 3755796c8dcSSimon Schubert else 3765796c8dcSSimon Schubert language = current_language; 3775796c8dcSSimon Schubert 3785796c8dcSSimon Schubert get_raw_print_options (&opts); 3795796c8dcSSimon Schubert opts.deref_ref = 0; 3805796c8dcSSimon Schubert opts.summary = summary; 3815796c8dcSSimon Schubert common_val_print (val, stb->stream, 2, &opts, language); 3825796c8dcSSimon Schubert ui_out_field_stream (uiout, "value", stb); 3835796c8dcSSimon Schubert } 3845796c8dcSSimon Schubert else 3855796c8dcSSimon Schubert ui_out_text (uiout, "???"); 3865796c8dcSSimon Schubert } 3875796c8dcSSimon Schubert else 3885796c8dcSSimon Schubert ui_out_text (uiout, "..."); 3895796c8dcSSimon Schubert 3905796c8dcSSimon Schubert 3915796c8dcSSimon Schubert /* Invoke ui_out_tuple_end. */ 3925796c8dcSSimon Schubert do_cleanups (list_chain); 3935796c8dcSSimon Schubert 3945796c8dcSSimon Schubert annotate_arg_end (); 3955796c8dcSSimon Schubert 3965796c8dcSSimon Schubert first = 0; 3975796c8dcSSimon Schubert } 3985796c8dcSSimon Schubert } 3995796c8dcSSimon Schubert 4005796c8dcSSimon Schubert /* Don't print nameless args in situations where we don't know 4015796c8dcSSimon Schubert enough about the stack to find them. */ 4025796c8dcSSimon Schubert if (num != -1) 4035796c8dcSSimon Schubert { 4045796c8dcSSimon Schubert long start; 4055796c8dcSSimon Schubert 4065796c8dcSSimon Schubert if (highest_offset == -1) 4075796c8dcSSimon Schubert start = gdbarch_frame_args_skip (get_frame_arch (frame)); 4085796c8dcSSimon Schubert else 4095796c8dcSSimon Schubert start = highest_offset; 4105796c8dcSSimon Schubert 4115796c8dcSSimon Schubert print_frame_nameless_args (frame, start, num - args_printed, 4125796c8dcSSimon Schubert first, stream); 4135796c8dcSSimon Schubert } 4145796c8dcSSimon Schubert 4155796c8dcSSimon Schubert do_cleanups (old_chain); 4165796c8dcSSimon Schubert } 4175796c8dcSSimon Schubert 4185796c8dcSSimon Schubert /* Stub for catch_errors. */ 4195796c8dcSSimon Schubert 4205796c8dcSSimon Schubert static int 4215796c8dcSSimon Schubert print_args_stub (void *args) 4225796c8dcSSimon Schubert { 4235796c8dcSSimon Schubert struct print_args_args *p = args; 4245796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (p->frame); 4255796c8dcSSimon Schubert int numargs; 4265796c8dcSSimon Schubert 4275796c8dcSSimon Schubert if (gdbarch_frame_num_args_p (gdbarch)) 4285796c8dcSSimon Schubert { 4295796c8dcSSimon Schubert numargs = gdbarch_frame_num_args (gdbarch, p->frame); 4305796c8dcSSimon Schubert gdb_assert (numargs >= 0); 4315796c8dcSSimon Schubert } 4325796c8dcSSimon Schubert else 4335796c8dcSSimon Schubert numargs = -1; 4345796c8dcSSimon Schubert print_frame_args (p->func, p->frame, numargs, p->stream); 4355796c8dcSSimon Schubert return 0; 4365796c8dcSSimon Schubert } 4375796c8dcSSimon Schubert 4385796c8dcSSimon Schubert /* Set the current source and line to the location given by frame 4395796c8dcSSimon Schubert FRAME, if possible. When CENTER is true, adjust so the relevant 4405796c8dcSSimon Schubert line is in the center of the next 'list'. */ 4415796c8dcSSimon Schubert 4425796c8dcSSimon Schubert void 4435796c8dcSSimon Schubert set_current_sal_from_frame (struct frame_info *frame, int center) 4445796c8dcSSimon Schubert { 4455796c8dcSSimon Schubert struct symtab_and_line sal; 4465796c8dcSSimon Schubert 4475796c8dcSSimon Schubert find_frame_sal (frame, &sal); 4485796c8dcSSimon Schubert if (sal.symtab) 4495796c8dcSSimon Schubert { 4505796c8dcSSimon Schubert if (center) 4515796c8dcSSimon Schubert sal.line = max (sal.line - get_lines_to_list () / 2, 1); 4525796c8dcSSimon Schubert set_current_source_symtab_and_line (&sal); 4535796c8dcSSimon Schubert } 4545796c8dcSSimon Schubert } 4555796c8dcSSimon Schubert 4565796c8dcSSimon Schubert /* If ON, GDB will display disassembly of the next source line when 4575796c8dcSSimon Schubert execution of the program being debugged stops. 4585796c8dcSSimon Schubert If AUTO (which is the default), or there's no line info to determine 4595796c8dcSSimon Schubert the source line of the next instruction, display disassembly of next 4605796c8dcSSimon Schubert instruction instead. */ 4615796c8dcSSimon Schubert 4625796c8dcSSimon Schubert static enum auto_boolean disassemble_next_line; 4635796c8dcSSimon Schubert 4645796c8dcSSimon Schubert static void 4655796c8dcSSimon Schubert show_disassemble_next_line (struct ui_file *file, int from_tty, 4665796c8dcSSimon Schubert struct cmd_list_element *c, 4675796c8dcSSimon Schubert const char *value) 4685796c8dcSSimon Schubert { 469*c50c785cSJohn Marino fprintf_filtered (file, 470*c50c785cSJohn Marino _("Debugger's willingness to use " 471*c50c785cSJohn Marino "disassemble-next-line is %s.\n"), 4725796c8dcSSimon Schubert value); 4735796c8dcSSimon Schubert } 4745796c8dcSSimon Schubert 4755796c8dcSSimon Schubert /* Show assembly codes; stub for catch_errors. */ 4765796c8dcSSimon Schubert 4775796c8dcSSimon Schubert struct gdb_disassembly_stub_args 4785796c8dcSSimon Schubert { 4795796c8dcSSimon Schubert struct gdbarch *gdbarch; 4805796c8dcSSimon Schubert int how_many; 4815796c8dcSSimon Schubert CORE_ADDR low; 4825796c8dcSSimon Schubert CORE_ADDR high; 4835796c8dcSSimon Schubert }; 4845796c8dcSSimon Schubert 4855796c8dcSSimon Schubert static void 4865796c8dcSSimon Schubert gdb_disassembly_stub (void *args) 4875796c8dcSSimon Schubert { 4885796c8dcSSimon Schubert struct gdb_disassembly_stub_args *p = args; 489cf7f2e2dSJohn Marino 4905796c8dcSSimon Schubert gdb_disassembly (p->gdbarch, uiout, 0, 4915796c8dcSSimon Schubert DISASSEMBLY_RAW_INSN, p->how_many, 4925796c8dcSSimon Schubert p->low, p->high); 4935796c8dcSSimon Schubert } 4945796c8dcSSimon Schubert 4955796c8dcSSimon Schubert /* Use TRY_CATCH to catch the exception from the gdb_disassembly 4965796c8dcSSimon Schubert because it will be broken by filter sometime. */ 4975796c8dcSSimon Schubert 4985796c8dcSSimon Schubert static void 4995796c8dcSSimon Schubert do_gdb_disassembly (struct gdbarch *gdbarch, 5005796c8dcSSimon Schubert int how_many, CORE_ADDR low, CORE_ADDR high) 5015796c8dcSSimon Schubert { 5025796c8dcSSimon Schubert volatile struct gdb_exception exception; 5035796c8dcSSimon Schubert struct gdb_disassembly_stub_args args; 5045796c8dcSSimon Schubert 5055796c8dcSSimon Schubert args.gdbarch = gdbarch; 5065796c8dcSSimon Schubert args.how_many = how_many; 5075796c8dcSSimon Schubert args.low = low; 5085796c8dcSSimon Schubert args.high = high; 5095796c8dcSSimon Schubert TRY_CATCH (exception, RETURN_MASK_ALL) 5105796c8dcSSimon Schubert { 5115796c8dcSSimon Schubert gdb_disassembly_stub (&args); 5125796c8dcSSimon Schubert } 5135796c8dcSSimon Schubert /* If an exception was thrown while doing the disassembly, print 5145796c8dcSSimon Schubert the error message, to give the user a clue of what happened. */ 5155796c8dcSSimon Schubert if (exception.reason == RETURN_ERROR) 5165796c8dcSSimon Schubert exception_print (gdb_stderr, exception); 5175796c8dcSSimon Schubert } 5185796c8dcSSimon Schubert 5195796c8dcSSimon Schubert /* Print information about frame FRAME. The output is format according 5205796c8dcSSimon Schubert to PRINT_LEVEL and PRINT_WHAT and PRINT ARGS. The meaning of 5215796c8dcSSimon Schubert PRINT_WHAT is: 5225796c8dcSSimon Schubert 5235796c8dcSSimon Schubert SRC_LINE: Print only source line. 5245796c8dcSSimon Schubert LOCATION: Print only location. 5255796c8dcSSimon Schubert LOC_AND_SRC: Print location and source line. 5265796c8dcSSimon Schubert 5275796c8dcSSimon Schubert Used in "where" output, and to emit breakpoint or step 5285796c8dcSSimon Schubert messages. */ 5295796c8dcSSimon Schubert 5305796c8dcSSimon Schubert void 5315796c8dcSSimon Schubert print_frame_info (struct frame_info *frame, int print_level, 5325796c8dcSSimon Schubert enum print_what print_what, int print_args) 5335796c8dcSSimon Schubert { 5345796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 5355796c8dcSSimon Schubert struct symtab_and_line sal; 5365796c8dcSSimon Schubert int source_print; 5375796c8dcSSimon Schubert int location_print; 5385796c8dcSSimon Schubert 5395796c8dcSSimon Schubert if (get_frame_type (frame) == DUMMY_FRAME 5405796c8dcSSimon Schubert || get_frame_type (frame) == SIGTRAMP_FRAME 5415796c8dcSSimon Schubert || get_frame_type (frame) == ARCH_FRAME) 5425796c8dcSSimon Schubert { 5435796c8dcSSimon Schubert struct cleanup *uiout_cleanup 5445796c8dcSSimon Schubert = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); 5455796c8dcSSimon Schubert 5465796c8dcSSimon Schubert annotate_frame_begin (print_level ? frame_relative_level (frame) : 0, 5475796c8dcSSimon Schubert gdbarch, get_frame_pc (frame)); 5485796c8dcSSimon Schubert 5495796c8dcSSimon Schubert /* Do this regardless of SOURCE because we don't have any source 5505796c8dcSSimon Schubert to list for this frame. */ 5515796c8dcSSimon Schubert if (print_level) 5525796c8dcSSimon Schubert { 5535796c8dcSSimon Schubert ui_out_text (uiout, "#"); 5545796c8dcSSimon Schubert ui_out_field_fmt_int (uiout, 2, ui_left, "level", 5555796c8dcSSimon Schubert frame_relative_level (frame)); 5565796c8dcSSimon Schubert } 5575796c8dcSSimon Schubert if (ui_out_is_mi_like_p (uiout)) 5585796c8dcSSimon Schubert { 5595796c8dcSSimon Schubert annotate_frame_address (); 5605796c8dcSSimon Schubert ui_out_field_core_addr (uiout, "addr", 5615796c8dcSSimon Schubert gdbarch, get_frame_pc (frame)); 5625796c8dcSSimon Schubert annotate_frame_address_end (); 5635796c8dcSSimon Schubert } 5645796c8dcSSimon Schubert 5655796c8dcSSimon Schubert if (get_frame_type (frame) == DUMMY_FRAME) 5665796c8dcSSimon Schubert { 5675796c8dcSSimon Schubert annotate_function_call (); 5685796c8dcSSimon Schubert ui_out_field_string (uiout, "func", "<function called from gdb>"); 5695796c8dcSSimon Schubert } 5705796c8dcSSimon Schubert else if (get_frame_type (frame) == SIGTRAMP_FRAME) 5715796c8dcSSimon Schubert { 5725796c8dcSSimon Schubert annotate_signal_handler_caller (); 5735796c8dcSSimon Schubert ui_out_field_string (uiout, "func", "<signal handler called>"); 5745796c8dcSSimon Schubert } 5755796c8dcSSimon Schubert else if (get_frame_type (frame) == ARCH_FRAME) 5765796c8dcSSimon Schubert { 5775796c8dcSSimon Schubert ui_out_field_string (uiout, "func", "<cross-architecture call>"); 5785796c8dcSSimon Schubert } 5795796c8dcSSimon Schubert ui_out_text (uiout, "\n"); 5805796c8dcSSimon Schubert annotate_frame_end (); 5815796c8dcSSimon Schubert 5825796c8dcSSimon Schubert do_cleanups (uiout_cleanup); 5835796c8dcSSimon Schubert return; 5845796c8dcSSimon Schubert } 5855796c8dcSSimon Schubert 5865796c8dcSSimon Schubert /* If FRAME is not the innermost frame, that normally means that 5875796c8dcSSimon Schubert FRAME->pc points to *after* the call instruction, and we want to 5885796c8dcSSimon Schubert get the line containing the call, never the next line. But if 5895796c8dcSSimon Schubert the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the 5905796c8dcSSimon Schubert next frame was not entered as the result of a call, and we want 5915796c8dcSSimon Schubert to get the line containing FRAME->pc. */ 5925796c8dcSSimon Schubert find_frame_sal (frame, &sal); 5935796c8dcSSimon Schubert 5945796c8dcSSimon Schubert location_print = (print_what == LOCATION 5955796c8dcSSimon Schubert || print_what == LOC_AND_ADDRESS 5965796c8dcSSimon Schubert || print_what == SRC_AND_LOC); 5975796c8dcSSimon Schubert 5985796c8dcSSimon Schubert if (location_print || !sal.symtab) 5995796c8dcSSimon Schubert print_frame (frame, print_level, print_what, print_args, sal); 6005796c8dcSSimon Schubert 6015796c8dcSSimon Schubert source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC); 6025796c8dcSSimon Schubert 6035796c8dcSSimon Schubert /* If disassemble-next-line is set to auto or on and doesn't have 6045796c8dcSSimon Schubert the line debug messages for $pc, output the next instruction. */ 6055796c8dcSSimon Schubert if ((disassemble_next_line == AUTO_BOOLEAN_AUTO 6065796c8dcSSimon Schubert || disassemble_next_line == AUTO_BOOLEAN_TRUE) 6075796c8dcSSimon Schubert && source_print && !sal.symtab) 6085796c8dcSSimon Schubert do_gdb_disassembly (get_frame_arch (frame), 1, 6095796c8dcSSimon Schubert get_frame_pc (frame), get_frame_pc (frame) + 1); 6105796c8dcSSimon Schubert 6115796c8dcSSimon Schubert if (source_print && sal.symtab) 6125796c8dcSSimon Schubert { 6135796c8dcSSimon Schubert int done = 0; 6145796c8dcSSimon Schubert int mid_statement = ((print_what == SRC_LINE) 6155796c8dcSSimon Schubert && frame_show_address (frame, sal)); 6165796c8dcSSimon Schubert 6175796c8dcSSimon Schubert if (annotation_level) 6185796c8dcSSimon Schubert done = identify_source_line (sal.symtab, sal.line, mid_statement, 6195796c8dcSSimon Schubert get_frame_pc (frame)); 6205796c8dcSSimon Schubert if (!done) 6215796c8dcSSimon Schubert { 6225796c8dcSSimon Schubert if (deprecated_print_frame_info_listing_hook) 6235796c8dcSSimon Schubert deprecated_print_frame_info_listing_hook (sal.symtab, 6245796c8dcSSimon Schubert sal.line, 6255796c8dcSSimon Schubert sal.line + 1, 0); 6265796c8dcSSimon Schubert else 6275796c8dcSSimon Schubert { 6285796c8dcSSimon Schubert struct value_print_options opts; 629cf7f2e2dSJohn Marino 6305796c8dcSSimon Schubert get_user_print_options (&opts); 6315796c8dcSSimon Schubert /* We used to do this earlier, but that is clearly 6325796c8dcSSimon Schubert wrong. This function is used by many different 6335796c8dcSSimon Schubert parts of gdb, including normal_stop in infrun.c, 6345796c8dcSSimon Schubert which uses this to print out the current PC 6355796c8dcSSimon Schubert when we stepi/nexti into the middle of a source 6365796c8dcSSimon Schubert line. Only the command line really wants this 6375796c8dcSSimon Schubert behavior. Other UIs probably would like the 6385796c8dcSSimon Schubert ability to decide for themselves if it is desired. */ 6395796c8dcSSimon Schubert if (opts.addressprint && mid_statement) 6405796c8dcSSimon Schubert { 6415796c8dcSSimon Schubert ui_out_field_core_addr (uiout, "addr", 6425796c8dcSSimon Schubert gdbarch, get_frame_pc (frame)); 6435796c8dcSSimon Schubert ui_out_text (uiout, "\t"); 6445796c8dcSSimon Schubert } 6455796c8dcSSimon Schubert 6465796c8dcSSimon Schubert print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); 6475796c8dcSSimon Schubert } 6485796c8dcSSimon Schubert } 6495796c8dcSSimon Schubert 6505796c8dcSSimon Schubert /* If disassemble-next-line is set to on and there is line debug 6515796c8dcSSimon Schubert messages, output assembly codes for next line. */ 6525796c8dcSSimon Schubert if (disassemble_next_line == AUTO_BOOLEAN_TRUE) 653cf7f2e2dSJohn Marino do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end); 6545796c8dcSSimon Schubert } 6555796c8dcSSimon Schubert 6565796c8dcSSimon Schubert if (print_what != LOCATION) 657*c50c785cSJohn Marino { 658*c50c785cSJohn Marino CORE_ADDR pc; 659*c50c785cSJohn Marino 660*c50c785cSJohn Marino if (get_frame_pc_if_available (frame, &pc)) 661*c50c785cSJohn Marino set_default_breakpoint (1, sal.pspace, pc, sal.symtab, sal.line); 662*c50c785cSJohn Marino else 663*c50c785cSJohn Marino set_default_breakpoint (0, 0, 0, 0, 0); 664*c50c785cSJohn Marino } 6655796c8dcSSimon Schubert 6665796c8dcSSimon Schubert annotate_frame_end (); 6675796c8dcSSimon Schubert 6685796c8dcSSimon Schubert gdb_flush (gdb_stdout); 6695796c8dcSSimon Schubert } 6705796c8dcSSimon Schubert 671*c50c785cSJohn Marino /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function 672*c50c785cSJohn Marino corresponding to FRAME. */ 673*c50c785cSJohn Marino 6745796c8dcSSimon Schubert void 6755796c8dcSSimon Schubert find_frame_funname (struct frame_info *frame, char **funname, 676*c50c785cSJohn Marino enum language *funlang, struct symbol **funcp) 6775796c8dcSSimon Schubert { 6785796c8dcSSimon Schubert struct symbol *func; 6795796c8dcSSimon Schubert 6805796c8dcSSimon Schubert *funname = NULL; 6815796c8dcSSimon Schubert *funlang = language_unknown; 682*c50c785cSJohn Marino if (funcp) 683*c50c785cSJohn Marino *funcp = NULL; 6845796c8dcSSimon Schubert 6855796c8dcSSimon Schubert func = get_frame_function (frame); 6865796c8dcSSimon Schubert if (func) 6875796c8dcSSimon Schubert { 6885796c8dcSSimon Schubert /* In certain pathological cases, the symtabs give the wrong 6895796c8dcSSimon Schubert function (when we are in the first function in a file which 6905796c8dcSSimon Schubert is compiled without debugging symbols, the previous function 6915796c8dcSSimon Schubert is compiled with debugging symbols, and the "foo.o" symbol 6925796c8dcSSimon Schubert that is supposed to tell us where the file with debugging 6935796c8dcSSimon Schubert symbols ends has been truncated by ar because it is longer 6945796c8dcSSimon Schubert than 15 characters). This also occurs if the user uses asm() 6955796c8dcSSimon Schubert to create a function but not stabs for it (in a file compiled 6965796c8dcSSimon Schubert with -g). 6975796c8dcSSimon Schubert 6985796c8dcSSimon Schubert So look in the minimal symbol tables as well, and if it comes 6995796c8dcSSimon Schubert up with a larger address for the function use that instead. 7005796c8dcSSimon Schubert I don't think this can ever cause any problems; there 7015796c8dcSSimon Schubert shouldn't be any minimal symbols in the middle of a function; 7025796c8dcSSimon Schubert if this is ever changed many parts of GDB will need to be 7035796c8dcSSimon Schubert changed (and we'll create a find_pc_minimal_function or some 7045796c8dcSSimon Schubert such). */ 7055796c8dcSSimon Schubert 7065796c8dcSSimon Schubert struct minimal_symbol *msymbol = NULL; 7075796c8dcSSimon Schubert 7085796c8dcSSimon Schubert /* Don't attempt to do this for inlined functions, which do not 7095796c8dcSSimon Schubert have a corresponding minimal symbol. */ 7105796c8dcSSimon Schubert if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func))) 7115796c8dcSSimon Schubert msymbol 7125796c8dcSSimon Schubert = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame)); 7135796c8dcSSimon Schubert 7145796c8dcSSimon Schubert if (msymbol != NULL 7155796c8dcSSimon Schubert && (SYMBOL_VALUE_ADDRESS (msymbol) 7165796c8dcSSimon Schubert > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) 7175796c8dcSSimon Schubert { 7185796c8dcSSimon Schubert /* We also don't know anything about the function besides 7195796c8dcSSimon Schubert its address and name. */ 7205796c8dcSSimon Schubert func = 0; 7215796c8dcSSimon Schubert *funname = SYMBOL_PRINT_NAME (msymbol); 7225796c8dcSSimon Schubert *funlang = SYMBOL_LANGUAGE (msymbol); 7235796c8dcSSimon Schubert } 7245796c8dcSSimon Schubert else 7255796c8dcSSimon Schubert { 7265796c8dcSSimon Schubert *funname = SYMBOL_PRINT_NAME (func); 7275796c8dcSSimon Schubert *funlang = SYMBOL_LANGUAGE (func); 728*c50c785cSJohn Marino if (funcp) 729*c50c785cSJohn Marino *funcp = func; 7305796c8dcSSimon Schubert if (*funlang == language_cplus) 7315796c8dcSSimon Schubert { 7325796c8dcSSimon Schubert /* It seems appropriate to use SYMBOL_PRINT_NAME() here, 7335796c8dcSSimon Schubert to display the demangled name that we already have 7345796c8dcSSimon Schubert stored in the symbol table, but we stored a version 7355796c8dcSSimon Schubert with DMGL_PARAMS turned on, and here we don't want to 7365796c8dcSSimon Schubert display parameters. So remove the parameters. */ 7375796c8dcSSimon Schubert char *func_only = cp_remove_params (*funname); 738cf7f2e2dSJohn Marino 7395796c8dcSSimon Schubert if (func_only) 7405796c8dcSSimon Schubert { 7415796c8dcSSimon Schubert *funname = func_only; 7425796c8dcSSimon Schubert make_cleanup (xfree, func_only); 7435796c8dcSSimon Schubert } 7445796c8dcSSimon Schubert } 7455796c8dcSSimon Schubert } 7465796c8dcSSimon Schubert } 7475796c8dcSSimon Schubert else 7485796c8dcSSimon Schubert { 749*c50c785cSJohn Marino struct minimal_symbol *msymbol; 750*c50c785cSJohn Marino CORE_ADDR pc; 7515796c8dcSSimon Schubert 752*c50c785cSJohn Marino if (!get_frame_address_in_block_if_available (frame, &pc)) 753*c50c785cSJohn Marino return; 754*c50c785cSJohn Marino 755*c50c785cSJohn Marino msymbol = lookup_minimal_symbol_by_pc (pc); 7565796c8dcSSimon Schubert if (msymbol != NULL) 7575796c8dcSSimon Schubert { 7585796c8dcSSimon Schubert *funname = SYMBOL_PRINT_NAME (msymbol); 7595796c8dcSSimon Schubert *funlang = SYMBOL_LANGUAGE (msymbol); 7605796c8dcSSimon Schubert } 7615796c8dcSSimon Schubert } 7625796c8dcSSimon Schubert } 7635796c8dcSSimon Schubert 7645796c8dcSSimon Schubert static void 7655796c8dcSSimon Schubert print_frame (struct frame_info *frame, int print_level, 7665796c8dcSSimon Schubert enum print_what print_what, int print_args, 7675796c8dcSSimon Schubert struct symtab_and_line sal) 7685796c8dcSSimon Schubert { 7695796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 7705796c8dcSSimon Schubert char *funname = NULL; 7715796c8dcSSimon Schubert enum language funlang = language_unknown; 7725796c8dcSSimon Schubert struct ui_stream *stb; 7735796c8dcSSimon Schubert struct cleanup *old_chain, *list_chain; 7745796c8dcSSimon Schubert struct value_print_options opts; 775*c50c785cSJohn Marino struct symbol *func; 776*c50c785cSJohn Marino CORE_ADDR pc = 0; 777*c50c785cSJohn Marino int pc_p; 778*c50c785cSJohn Marino 779*c50c785cSJohn Marino pc_p = get_frame_pc_if_available (frame, &pc); 7805796c8dcSSimon Schubert 7815796c8dcSSimon Schubert stb = ui_out_stream_new (uiout); 7825796c8dcSSimon Schubert old_chain = make_cleanup_ui_out_stream_delete (stb); 7835796c8dcSSimon Schubert 784*c50c785cSJohn Marino find_frame_funname (frame, &funname, &funlang, &func); 7855796c8dcSSimon Schubert 7865796c8dcSSimon Schubert annotate_frame_begin (print_level ? frame_relative_level (frame) : 0, 787*c50c785cSJohn Marino gdbarch, pc); 7885796c8dcSSimon Schubert 7895796c8dcSSimon Schubert list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); 7905796c8dcSSimon Schubert 7915796c8dcSSimon Schubert if (print_level) 7925796c8dcSSimon Schubert { 7935796c8dcSSimon Schubert ui_out_text (uiout, "#"); 7945796c8dcSSimon Schubert ui_out_field_fmt_int (uiout, 2, ui_left, "level", 7955796c8dcSSimon Schubert frame_relative_level (frame)); 7965796c8dcSSimon Schubert } 7975796c8dcSSimon Schubert get_user_print_options (&opts); 7985796c8dcSSimon Schubert if (opts.addressprint) 799*c50c785cSJohn Marino if (!sal.symtab 800*c50c785cSJohn Marino || frame_show_address (frame, sal) 8015796c8dcSSimon Schubert || print_what == LOC_AND_ADDRESS) 8025796c8dcSSimon Schubert { 8035796c8dcSSimon Schubert annotate_frame_address (); 804*c50c785cSJohn Marino if (pc_p) 805*c50c785cSJohn Marino ui_out_field_core_addr (uiout, "addr", gdbarch, pc); 806*c50c785cSJohn Marino else 807*c50c785cSJohn Marino ui_out_field_string (uiout, "addr", "<unavailable>"); 8085796c8dcSSimon Schubert annotate_frame_address_end (); 8095796c8dcSSimon Schubert ui_out_text (uiout, " in "); 8105796c8dcSSimon Schubert } 8115796c8dcSSimon Schubert annotate_frame_function_name (); 8125796c8dcSSimon Schubert fprintf_symbol_filtered (stb->stream, funname ? funname : "??", 8135796c8dcSSimon Schubert funlang, DMGL_ANSI); 8145796c8dcSSimon Schubert ui_out_field_stream (uiout, "func", stb); 8155796c8dcSSimon Schubert ui_out_wrap_hint (uiout, " "); 8165796c8dcSSimon Schubert annotate_frame_args (); 8175796c8dcSSimon Schubert 8185796c8dcSSimon Schubert ui_out_text (uiout, " ("); 8195796c8dcSSimon Schubert if (print_args) 8205796c8dcSSimon Schubert { 8215796c8dcSSimon Schubert struct print_args_args args; 8225796c8dcSSimon Schubert struct cleanup *args_list_chain; 823cf7f2e2dSJohn Marino 8245796c8dcSSimon Schubert args.frame = frame; 825*c50c785cSJohn Marino args.func = func; 8265796c8dcSSimon Schubert args.stream = gdb_stdout; 8275796c8dcSSimon Schubert args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args"); 8285796c8dcSSimon Schubert catch_errors (print_args_stub, &args, "", RETURN_MASK_ERROR); 8295796c8dcSSimon Schubert /* FIXME: ARGS must be a list. If one argument is a string it 8305796c8dcSSimon Schubert will have " that will not be properly escaped. */ 8315796c8dcSSimon Schubert /* Invoke ui_out_tuple_end. */ 8325796c8dcSSimon Schubert do_cleanups (args_list_chain); 8335796c8dcSSimon Schubert QUIT; 8345796c8dcSSimon Schubert } 8355796c8dcSSimon Schubert ui_out_text (uiout, ")"); 8365796c8dcSSimon Schubert if (sal.symtab && sal.symtab->filename) 8375796c8dcSSimon Schubert { 8385796c8dcSSimon Schubert annotate_frame_source_begin (); 8395796c8dcSSimon Schubert ui_out_wrap_hint (uiout, " "); 8405796c8dcSSimon Schubert ui_out_text (uiout, " at "); 8415796c8dcSSimon Schubert annotate_frame_source_file (); 8425796c8dcSSimon Schubert ui_out_field_string (uiout, "file", sal.symtab->filename); 8435796c8dcSSimon Schubert if (ui_out_is_mi_like_p (uiout)) 8445796c8dcSSimon Schubert { 8455796c8dcSSimon Schubert const char *fullname = symtab_to_fullname (sal.symtab); 846cf7f2e2dSJohn Marino 8475796c8dcSSimon Schubert if (fullname != NULL) 8485796c8dcSSimon Schubert ui_out_field_string (uiout, "fullname", fullname); 8495796c8dcSSimon Schubert } 8505796c8dcSSimon Schubert annotate_frame_source_file_end (); 8515796c8dcSSimon Schubert ui_out_text (uiout, ":"); 8525796c8dcSSimon Schubert annotate_frame_source_line (); 8535796c8dcSSimon Schubert ui_out_field_int (uiout, "line", sal.line); 8545796c8dcSSimon Schubert annotate_frame_source_end (); 8555796c8dcSSimon Schubert } 8565796c8dcSSimon Schubert 857*c50c785cSJohn Marino if (pc_p && (!funname || (!sal.symtab || !sal.symtab->filename))) 8585796c8dcSSimon Schubert { 8595796c8dcSSimon Schubert #ifdef PC_SOLIB 8605796c8dcSSimon Schubert char *lib = PC_SOLIB (get_frame_pc (frame)); 8615796c8dcSSimon Schubert #else 862cf7f2e2dSJohn Marino char *lib = solib_name_from_address (get_frame_program_space (frame), 863cf7f2e2dSJohn Marino get_frame_pc (frame)); 8645796c8dcSSimon Schubert #endif 8655796c8dcSSimon Schubert if (lib) 8665796c8dcSSimon Schubert { 8675796c8dcSSimon Schubert annotate_frame_where (); 8685796c8dcSSimon Schubert ui_out_wrap_hint (uiout, " "); 8695796c8dcSSimon Schubert ui_out_text (uiout, " from "); 8705796c8dcSSimon Schubert ui_out_field_string (uiout, "from", lib); 8715796c8dcSSimon Schubert } 8725796c8dcSSimon Schubert } 8735796c8dcSSimon Schubert 8745796c8dcSSimon Schubert /* do_cleanups will call ui_out_tuple_end() for us. */ 8755796c8dcSSimon Schubert do_cleanups (list_chain); 8765796c8dcSSimon Schubert ui_out_text (uiout, "\n"); 8775796c8dcSSimon Schubert do_cleanups (old_chain); 8785796c8dcSSimon Schubert } 8795796c8dcSSimon Schubert 8805796c8dcSSimon Schubert 8815796c8dcSSimon Schubert /* Read a frame specification in whatever the appropriate format is 8825796c8dcSSimon Schubert from FRAME_EXP. Call error(), printing MESSAGE, if the 8835796c8dcSSimon Schubert specification is in any way invalid (so this function never returns 8845796c8dcSSimon Schubert NULL). When SEPECTED_P is non-NULL set its target to indicate that 8855796c8dcSSimon Schubert the default selected frame was used. */ 8865796c8dcSSimon Schubert 8875796c8dcSSimon Schubert static struct frame_info * 8885796c8dcSSimon Schubert parse_frame_specification_1 (const char *frame_exp, const char *message, 8895796c8dcSSimon Schubert int *selected_frame_p) 8905796c8dcSSimon Schubert { 8915796c8dcSSimon Schubert int numargs; 8925796c8dcSSimon Schubert struct value *args[4]; 8935796c8dcSSimon Schubert CORE_ADDR addrs[ARRAY_SIZE (args)]; 8945796c8dcSSimon Schubert 8955796c8dcSSimon Schubert if (frame_exp == NULL) 8965796c8dcSSimon Schubert numargs = 0; 8975796c8dcSSimon Schubert else 8985796c8dcSSimon Schubert { 8995796c8dcSSimon Schubert numargs = 0; 9005796c8dcSSimon Schubert while (1) 9015796c8dcSSimon Schubert { 9025796c8dcSSimon Schubert char *addr_string; 9035796c8dcSSimon Schubert struct cleanup *cleanup; 9045796c8dcSSimon Schubert const char *p; 9055796c8dcSSimon Schubert 9065796c8dcSSimon Schubert /* Skip leading white space, bail of EOL. */ 9075796c8dcSSimon Schubert while (isspace (*frame_exp)) 9085796c8dcSSimon Schubert frame_exp++; 9095796c8dcSSimon Schubert if (!*frame_exp) 9105796c8dcSSimon Schubert break; 9115796c8dcSSimon Schubert 9125796c8dcSSimon Schubert /* Parse the argument, extract it, save it. */ 9135796c8dcSSimon Schubert for (p = frame_exp; 9145796c8dcSSimon Schubert *p && !isspace (*p); 9155796c8dcSSimon Schubert p++); 9165796c8dcSSimon Schubert addr_string = savestring (frame_exp, p - frame_exp); 9175796c8dcSSimon Schubert frame_exp = p; 9185796c8dcSSimon Schubert cleanup = make_cleanup (xfree, addr_string); 9195796c8dcSSimon Schubert 9205796c8dcSSimon Schubert /* NOTE: Parse and evaluate expression, but do not use 9215796c8dcSSimon Schubert functions such as parse_and_eval_long or 9225796c8dcSSimon Schubert parse_and_eval_address to also extract the value. 9235796c8dcSSimon Schubert Instead value_as_long and value_as_address are used. 9245796c8dcSSimon Schubert This avoids problems with expressions that contain 9255796c8dcSSimon Schubert side-effects. */ 9265796c8dcSSimon Schubert if (numargs >= ARRAY_SIZE (args)) 9275796c8dcSSimon Schubert error (_("Too many args in frame specification")); 9285796c8dcSSimon Schubert args[numargs++] = parse_and_eval (addr_string); 9295796c8dcSSimon Schubert 9305796c8dcSSimon Schubert do_cleanups (cleanup); 9315796c8dcSSimon Schubert } 9325796c8dcSSimon Schubert } 9335796c8dcSSimon Schubert 9345796c8dcSSimon Schubert /* If no args, default to the selected frame. */ 9355796c8dcSSimon Schubert if (numargs == 0) 9365796c8dcSSimon Schubert { 9375796c8dcSSimon Schubert if (selected_frame_p != NULL) 9385796c8dcSSimon Schubert (*selected_frame_p) = 1; 9395796c8dcSSimon Schubert return get_selected_frame (message); 9405796c8dcSSimon Schubert } 9415796c8dcSSimon Schubert 9425796c8dcSSimon Schubert /* None of the remaining use the selected frame. */ 9435796c8dcSSimon Schubert if (selected_frame_p != NULL) 9445796c8dcSSimon Schubert (*selected_frame_p) = 0; 9455796c8dcSSimon Schubert 9465796c8dcSSimon Schubert /* Assume the single arg[0] is an integer, and try using that to 9475796c8dcSSimon Schubert select a frame relative to current. */ 9485796c8dcSSimon Schubert if (numargs == 1) 9495796c8dcSSimon Schubert { 9505796c8dcSSimon Schubert struct frame_info *fid; 9515796c8dcSSimon Schubert int level = value_as_long (args[0]); 952cf7f2e2dSJohn Marino 9535796c8dcSSimon Schubert fid = find_relative_frame (get_current_frame (), &level); 9545796c8dcSSimon Schubert if (level == 0) 955*c50c785cSJohn Marino /* find_relative_frame was successful. */ 9565796c8dcSSimon Schubert return fid; 9575796c8dcSSimon Schubert } 9585796c8dcSSimon Schubert 9595796c8dcSSimon Schubert /* Convert each value into a corresponding address. */ 9605796c8dcSSimon Schubert { 9615796c8dcSSimon Schubert int i; 962cf7f2e2dSJohn Marino 9635796c8dcSSimon Schubert for (i = 0; i < numargs; i++) 9645796c8dcSSimon Schubert addrs[i] = value_as_address (args[i]); 9655796c8dcSSimon Schubert } 9665796c8dcSSimon Schubert 9675796c8dcSSimon Schubert /* Assume that the single arg[0] is an address, use that to identify 9685796c8dcSSimon Schubert a frame with a matching ID. Should this also accept stack/pc or 9695796c8dcSSimon Schubert stack/pc/special. */ 9705796c8dcSSimon Schubert if (numargs == 1) 9715796c8dcSSimon Schubert { 9725796c8dcSSimon Schubert struct frame_id id = frame_id_build_wild (addrs[0]); 9735796c8dcSSimon Schubert struct frame_info *fid; 9745796c8dcSSimon Schubert 9755796c8dcSSimon Schubert /* If (s)he specifies the frame with an address, he deserves 9765796c8dcSSimon Schubert what (s)he gets. Still, give the highest one that matches. 9775796c8dcSSimon Schubert (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't 9785796c8dcSSimon Schubert know). */ 9795796c8dcSSimon Schubert for (fid = get_current_frame (); 9805796c8dcSSimon Schubert fid != NULL; 9815796c8dcSSimon Schubert fid = get_prev_frame (fid)) 9825796c8dcSSimon Schubert { 9835796c8dcSSimon Schubert if (frame_id_eq (id, get_frame_id (fid))) 9845796c8dcSSimon Schubert { 9855796c8dcSSimon Schubert struct frame_info *prev_frame; 9865796c8dcSSimon Schubert 9875796c8dcSSimon Schubert while (1) 9885796c8dcSSimon Schubert { 9895796c8dcSSimon Schubert prev_frame = get_prev_frame (fid); 9905796c8dcSSimon Schubert if (!prev_frame 9915796c8dcSSimon Schubert || !frame_id_eq (id, get_frame_id (prev_frame))) 9925796c8dcSSimon Schubert break; 9935796c8dcSSimon Schubert fid = prev_frame; 9945796c8dcSSimon Schubert } 9955796c8dcSSimon Schubert return fid; 9965796c8dcSSimon Schubert } 9975796c8dcSSimon Schubert } 9985796c8dcSSimon Schubert } 9995796c8dcSSimon Schubert 10005796c8dcSSimon Schubert /* We couldn't identify the frame as an existing frame, but 10015796c8dcSSimon Schubert perhaps we can create one with a single argument. */ 10025796c8dcSSimon Schubert if (numargs == 1) 10035796c8dcSSimon Schubert return create_new_frame (addrs[0], 0); 10045796c8dcSSimon Schubert else if (numargs == 2) 10055796c8dcSSimon Schubert return create_new_frame (addrs[0], addrs[1]); 10065796c8dcSSimon Schubert else 10075796c8dcSSimon Schubert error (_("Too many args in frame specification")); 10085796c8dcSSimon Schubert } 10095796c8dcSSimon Schubert 10105796c8dcSSimon Schubert static struct frame_info * 10115796c8dcSSimon Schubert parse_frame_specification (char *frame_exp) 10125796c8dcSSimon Schubert { 10135796c8dcSSimon Schubert return parse_frame_specification_1 (frame_exp, NULL, NULL); 10145796c8dcSSimon Schubert } 10155796c8dcSSimon Schubert 10165796c8dcSSimon Schubert /* Print verbosely the selected frame or the frame at address 10175796c8dcSSimon Schubert ADDR_EXP. Absolutely all information in the frame is printed. */ 10185796c8dcSSimon Schubert 10195796c8dcSSimon Schubert static void 10205796c8dcSSimon Schubert frame_info (char *addr_exp, int from_tty) 10215796c8dcSSimon Schubert { 10225796c8dcSSimon Schubert struct frame_info *fi; 10235796c8dcSSimon Schubert struct symtab_and_line sal; 10245796c8dcSSimon Schubert struct symbol *func; 10255796c8dcSSimon Schubert struct symtab *s; 10265796c8dcSSimon Schubert struct frame_info *calling_frame_info; 1027cf7f2e2dSJohn Marino int numregs; 10285796c8dcSSimon Schubert char *funname = 0; 10295796c8dcSSimon Schubert enum language funlang = language_unknown; 10305796c8dcSSimon Schubert const char *pc_regname; 10315796c8dcSSimon Schubert int selected_frame_p; 10325796c8dcSSimon Schubert struct gdbarch *gdbarch; 10335796c8dcSSimon Schubert struct cleanup *back_to = make_cleanup (null_cleanup, NULL); 1034*c50c785cSJohn Marino CORE_ADDR frame_pc; 1035*c50c785cSJohn Marino int frame_pc_p; 1036*c50c785cSJohn Marino CORE_ADDR caller_pc; 10375796c8dcSSimon Schubert 10385796c8dcSSimon Schubert fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p); 10395796c8dcSSimon Schubert gdbarch = get_frame_arch (fi); 10405796c8dcSSimon Schubert 10415796c8dcSSimon Schubert /* Name of the value returned by get_frame_pc(). Per comments, "pc" 10425796c8dcSSimon Schubert is not a good name. */ 10435796c8dcSSimon Schubert if (gdbarch_pc_regnum (gdbarch) >= 0) 10445796c8dcSSimon Schubert /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can 10455796c8dcSSimon Schubert easily not match that of the internal value returned by 10465796c8dcSSimon Schubert get_frame_pc(). */ 10475796c8dcSSimon Schubert pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch)); 10485796c8dcSSimon Schubert else 10495796c8dcSSimon Schubert /* But then, this is weird to. Even without gdbarch_pc_regnum, an 10505796c8dcSSimon Schubert architectures will often have a hardware register called "pc", 10515796c8dcSSimon Schubert and that register's value, again, can easily not match 10525796c8dcSSimon Schubert get_frame_pc(). */ 10535796c8dcSSimon Schubert pc_regname = "pc"; 10545796c8dcSSimon Schubert 1055*c50c785cSJohn Marino frame_pc_p = get_frame_pc_if_available (fi, &frame_pc); 10565796c8dcSSimon Schubert find_frame_sal (fi, &sal); 10575796c8dcSSimon Schubert func = get_frame_function (fi); 1058*c50c785cSJohn Marino s = sal.symtab; 10595796c8dcSSimon Schubert if (func) 10605796c8dcSSimon Schubert { 10615796c8dcSSimon Schubert funname = SYMBOL_PRINT_NAME (func); 10625796c8dcSSimon Schubert funlang = SYMBOL_LANGUAGE (func); 10635796c8dcSSimon Schubert if (funlang == language_cplus) 10645796c8dcSSimon Schubert { 10655796c8dcSSimon Schubert /* It seems appropriate to use SYMBOL_PRINT_NAME() here, 10665796c8dcSSimon Schubert to display the demangled name that we already have 10675796c8dcSSimon Schubert stored in the symbol table, but we stored a version 10685796c8dcSSimon Schubert with DMGL_PARAMS turned on, and here we don't want to 10695796c8dcSSimon Schubert display parameters. So remove the parameters. */ 10705796c8dcSSimon Schubert char *func_only = cp_remove_params (funname); 1071cf7f2e2dSJohn Marino 10725796c8dcSSimon Schubert if (func_only) 10735796c8dcSSimon Schubert { 10745796c8dcSSimon Schubert funname = func_only; 10755796c8dcSSimon Schubert make_cleanup (xfree, func_only); 10765796c8dcSSimon Schubert } 10775796c8dcSSimon Schubert } 10785796c8dcSSimon Schubert } 1079*c50c785cSJohn Marino else if (frame_pc_p) 10805796c8dcSSimon Schubert { 10815796c8dcSSimon Schubert struct minimal_symbol *msymbol; 10825796c8dcSSimon Schubert 1083*c50c785cSJohn Marino msymbol = lookup_minimal_symbol_by_pc (frame_pc); 10845796c8dcSSimon Schubert if (msymbol != NULL) 10855796c8dcSSimon Schubert { 10865796c8dcSSimon Schubert funname = SYMBOL_PRINT_NAME (msymbol); 10875796c8dcSSimon Schubert funlang = SYMBOL_LANGUAGE (msymbol); 10885796c8dcSSimon Schubert } 10895796c8dcSSimon Schubert } 10905796c8dcSSimon Schubert calling_frame_info = get_prev_frame (fi); 10915796c8dcSSimon Schubert 10925796c8dcSSimon Schubert if (selected_frame_p && frame_relative_level (fi) >= 0) 10935796c8dcSSimon Schubert { 10945796c8dcSSimon Schubert printf_filtered (_("Stack level %d, frame at "), 10955796c8dcSSimon Schubert frame_relative_level (fi)); 10965796c8dcSSimon Schubert } 10975796c8dcSSimon Schubert else 10985796c8dcSSimon Schubert { 10995796c8dcSSimon Schubert printf_filtered (_("Stack frame at ")); 11005796c8dcSSimon Schubert } 11015796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout); 11025796c8dcSSimon Schubert printf_filtered (":\n"); 11035796c8dcSSimon Schubert printf_filtered (" %s = ", pc_regname); 1104*c50c785cSJohn Marino if (frame_pc_p) 11055796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout); 1106*c50c785cSJohn Marino else 1107*c50c785cSJohn Marino fputs_filtered ("<unavailable>", gdb_stdout); 11085796c8dcSSimon Schubert 11095796c8dcSSimon Schubert wrap_here (" "); 11105796c8dcSSimon Schubert if (funname) 11115796c8dcSSimon Schubert { 11125796c8dcSSimon Schubert printf_filtered (" in "); 11135796c8dcSSimon Schubert fprintf_symbol_filtered (gdb_stdout, funname, funlang, 11145796c8dcSSimon Schubert DMGL_ANSI | DMGL_PARAMS); 11155796c8dcSSimon Schubert } 11165796c8dcSSimon Schubert wrap_here (" "); 11175796c8dcSSimon Schubert if (sal.symtab) 11185796c8dcSSimon Schubert printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line); 11195796c8dcSSimon Schubert puts_filtered ("; "); 11205796c8dcSSimon Schubert wrap_here (" "); 11215796c8dcSSimon Schubert printf_filtered ("saved %s ", pc_regname); 1122*c50c785cSJohn Marino if (frame_unwind_caller_pc_if_available (fi, &caller_pc)) 1123*c50c785cSJohn Marino fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout); 1124*c50c785cSJohn Marino else 1125*c50c785cSJohn Marino fputs_filtered ("<unavailable>", gdb_stdout); 11265796c8dcSSimon Schubert printf_filtered ("\n"); 11275796c8dcSSimon Schubert 11285796c8dcSSimon Schubert if (calling_frame_info == NULL) 11295796c8dcSSimon Schubert { 11305796c8dcSSimon Schubert enum unwind_stop_reason reason; 11315796c8dcSSimon Schubert 11325796c8dcSSimon Schubert reason = get_frame_unwind_stop_reason (fi); 11335796c8dcSSimon Schubert if (reason != UNWIND_NO_REASON) 11345796c8dcSSimon Schubert printf_filtered (_(" Outermost frame: %s\n"), 11355796c8dcSSimon Schubert frame_stop_reason_string (reason)); 11365796c8dcSSimon Schubert } 11375796c8dcSSimon Schubert else if (get_frame_type (fi) == INLINE_FRAME) 11385796c8dcSSimon Schubert printf_filtered (" inlined into frame %d", 11395796c8dcSSimon Schubert frame_relative_level (get_prev_frame (fi))); 11405796c8dcSSimon Schubert else 11415796c8dcSSimon Schubert { 11425796c8dcSSimon Schubert printf_filtered (" called by frame at "); 11435796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)), 11445796c8dcSSimon Schubert gdb_stdout); 11455796c8dcSSimon Schubert } 11465796c8dcSSimon Schubert if (get_next_frame (fi) && calling_frame_info) 11475796c8dcSSimon Schubert puts_filtered (","); 11485796c8dcSSimon Schubert wrap_here (" "); 11495796c8dcSSimon Schubert if (get_next_frame (fi)) 11505796c8dcSSimon Schubert { 11515796c8dcSSimon Schubert printf_filtered (" caller of frame at "); 11525796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))), 11535796c8dcSSimon Schubert gdb_stdout); 11545796c8dcSSimon Schubert } 11555796c8dcSSimon Schubert if (get_next_frame (fi) || calling_frame_info) 11565796c8dcSSimon Schubert puts_filtered ("\n"); 11575796c8dcSSimon Schubert 11585796c8dcSSimon Schubert if (s) 11595796c8dcSSimon Schubert printf_filtered (" source language %s.\n", 11605796c8dcSSimon Schubert language_str (s->language)); 11615796c8dcSSimon Schubert 11625796c8dcSSimon Schubert { 11635796c8dcSSimon Schubert /* Address of the argument list for this frame, or 0. */ 11645796c8dcSSimon Schubert CORE_ADDR arg_list = get_frame_args_address (fi); 11655796c8dcSSimon Schubert /* Number of args for this frame, or -1 if unknown. */ 11665796c8dcSSimon Schubert int numargs; 11675796c8dcSSimon Schubert 11685796c8dcSSimon Schubert if (arg_list == 0) 11695796c8dcSSimon Schubert printf_filtered (" Arglist at unknown address.\n"); 11705796c8dcSSimon Schubert else 11715796c8dcSSimon Schubert { 11725796c8dcSSimon Schubert printf_filtered (" Arglist at "); 11735796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout); 11745796c8dcSSimon Schubert printf_filtered (","); 11755796c8dcSSimon Schubert 11765796c8dcSSimon Schubert if (!gdbarch_frame_num_args_p (gdbarch)) 11775796c8dcSSimon Schubert { 11785796c8dcSSimon Schubert numargs = -1; 11795796c8dcSSimon Schubert puts_filtered (" args: "); 11805796c8dcSSimon Schubert } 11815796c8dcSSimon Schubert else 11825796c8dcSSimon Schubert { 11835796c8dcSSimon Schubert numargs = gdbarch_frame_num_args (gdbarch, fi); 11845796c8dcSSimon Schubert gdb_assert (numargs >= 0); 11855796c8dcSSimon Schubert if (numargs == 0) 11865796c8dcSSimon Schubert puts_filtered (" no args."); 11875796c8dcSSimon Schubert else if (numargs == 1) 11885796c8dcSSimon Schubert puts_filtered (" 1 arg: "); 11895796c8dcSSimon Schubert else 11905796c8dcSSimon Schubert printf_filtered (" %d args: ", numargs); 11915796c8dcSSimon Schubert } 11925796c8dcSSimon Schubert print_frame_args (func, fi, numargs, gdb_stdout); 11935796c8dcSSimon Schubert puts_filtered ("\n"); 11945796c8dcSSimon Schubert } 11955796c8dcSSimon Schubert } 11965796c8dcSSimon Schubert { 11975796c8dcSSimon Schubert /* Address of the local variables for this frame, or 0. */ 11985796c8dcSSimon Schubert CORE_ADDR arg_list = get_frame_locals_address (fi); 11995796c8dcSSimon Schubert 12005796c8dcSSimon Schubert if (arg_list == 0) 12015796c8dcSSimon Schubert printf_filtered (" Locals at unknown address,"); 12025796c8dcSSimon Schubert else 12035796c8dcSSimon Schubert { 12045796c8dcSSimon Schubert printf_filtered (" Locals at "); 12055796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout); 12065796c8dcSSimon Schubert printf_filtered (","); 12075796c8dcSSimon Schubert } 12085796c8dcSSimon Schubert } 12095796c8dcSSimon Schubert 12105796c8dcSSimon Schubert /* Print as much information as possible on the location of all the 12115796c8dcSSimon Schubert registers. */ 12125796c8dcSSimon Schubert { 12135796c8dcSSimon Schubert enum lval_type lval; 12145796c8dcSSimon Schubert int optimized; 1215*c50c785cSJohn Marino int unavailable; 12165796c8dcSSimon Schubert CORE_ADDR addr; 12175796c8dcSSimon Schubert int realnum; 12185796c8dcSSimon Schubert int count; 12195796c8dcSSimon Schubert int i; 12205796c8dcSSimon Schubert int need_nl = 1; 12215796c8dcSSimon Schubert 12225796c8dcSSimon Schubert /* The sp is special; what's displayed isn't the save address, but 12235796c8dcSSimon Schubert the value of the previous frame's sp. This is a legacy thing, 12245796c8dcSSimon Schubert at one stage the frame cached the previous frame's SP instead 12255796c8dcSSimon Schubert of its address, hence it was easiest to just display the cached 12265796c8dcSSimon Schubert value. */ 12275796c8dcSSimon Schubert if (gdbarch_sp_regnum (gdbarch) >= 0) 12285796c8dcSSimon Schubert { 12295796c8dcSSimon Schubert /* Find out the location of the saved stack pointer with out 12305796c8dcSSimon Schubert actually evaluating it. */ 12315796c8dcSSimon Schubert frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch), 1232*c50c785cSJohn Marino &optimized, &unavailable, &lval, &addr, 12335796c8dcSSimon Schubert &realnum, NULL); 1234*c50c785cSJohn Marino if (!optimized && !unavailable && lval == not_lval) 12355796c8dcSSimon Schubert { 12365796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 12375796c8dcSSimon Schubert int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch)); 12385796c8dcSSimon Schubert gdb_byte value[MAX_REGISTER_SIZE]; 12395796c8dcSSimon Schubert CORE_ADDR sp; 1240cf7f2e2dSJohn Marino 12415796c8dcSSimon Schubert frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch), 1242*c50c785cSJohn Marino &optimized, &unavailable, &lval, &addr, 12435796c8dcSSimon Schubert &realnum, value); 12445796c8dcSSimon Schubert /* NOTE: cagney/2003-05-22: This is assuming that the 12455796c8dcSSimon Schubert stack pointer was packed as an unsigned integer. That 12465796c8dcSSimon Schubert may or may not be valid. */ 12475796c8dcSSimon Schubert sp = extract_unsigned_integer (value, sp_size, byte_order); 12485796c8dcSSimon Schubert printf_filtered (" Previous frame's sp is "); 12495796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, sp), gdb_stdout); 12505796c8dcSSimon Schubert printf_filtered ("\n"); 12515796c8dcSSimon Schubert need_nl = 0; 12525796c8dcSSimon Schubert } 1253*c50c785cSJohn Marino else if (!optimized && !unavailable && lval == lval_memory) 12545796c8dcSSimon Schubert { 12555796c8dcSSimon Schubert printf_filtered (" Previous frame's sp at "); 12565796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), gdb_stdout); 12575796c8dcSSimon Schubert printf_filtered ("\n"); 12585796c8dcSSimon Schubert need_nl = 0; 12595796c8dcSSimon Schubert } 1260*c50c785cSJohn Marino else if (!optimized && !unavailable && lval == lval_register) 12615796c8dcSSimon Schubert { 12625796c8dcSSimon Schubert printf_filtered (" Previous frame's sp in %s\n", 12635796c8dcSSimon Schubert gdbarch_register_name (gdbarch, realnum)); 12645796c8dcSSimon Schubert need_nl = 0; 12655796c8dcSSimon Schubert } 12665796c8dcSSimon Schubert /* else keep quiet. */ 12675796c8dcSSimon Schubert } 12685796c8dcSSimon Schubert 12695796c8dcSSimon Schubert count = 0; 12705796c8dcSSimon Schubert numregs = gdbarch_num_regs (gdbarch) 12715796c8dcSSimon Schubert + gdbarch_num_pseudo_regs (gdbarch); 12725796c8dcSSimon Schubert for (i = 0; i < numregs; i++) 12735796c8dcSSimon Schubert if (i != gdbarch_sp_regnum (gdbarch) 12745796c8dcSSimon Schubert && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup)) 12755796c8dcSSimon Schubert { 12765796c8dcSSimon Schubert /* Find out the location of the saved register without 12775796c8dcSSimon Schubert fetching the corresponding value. */ 1278*c50c785cSJohn Marino frame_register_unwind (fi, i, &optimized, &unavailable, 1279*c50c785cSJohn Marino &lval, &addr, &realnum, NULL); 12805796c8dcSSimon Schubert /* For moment, only display registers that were saved on the 12815796c8dcSSimon Schubert stack. */ 1282*c50c785cSJohn Marino if (!optimized && !unavailable && lval == lval_memory) 12835796c8dcSSimon Schubert { 12845796c8dcSSimon Schubert if (count == 0) 12855796c8dcSSimon Schubert puts_filtered (" Saved registers:\n "); 12865796c8dcSSimon Schubert else 12875796c8dcSSimon Schubert puts_filtered (","); 12885796c8dcSSimon Schubert wrap_here (" "); 12895796c8dcSSimon Schubert printf_filtered (" %s at ", 12905796c8dcSSimon Schubert gdbarch_register_name (gdbarch, i)); 12915796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), gdb_stdout); 12925796c8dcSSimon Schubert count++; 12935796c8dcSSimon Schubert } 12945796c8dcSSimon Schubert } 12955796c8dcSSimon Schubert if (count || need_nl) 12965796c8dcSSimon Schubert puts_filtered ("\n"); 12975796c8dcSSimon Schubert } 12985796c8dcSSimon Schubert 12995796c8dcSSimon Schubert do_cleanups (back_to); 13005796c8dcSSimon Schubert } 13015796c8dcSSimon Schubert 13025796c8dcSSimon Schubert /* Print briefly all stack frames or just the innermost COUNT_EXP 13035796c8dcSSimon Schubert frames. */ 13045796c8dcSSimon Schubert 13055796c8dcSSimon Schubert static void 13065796c8dcSSimon Schubert backtrace_command_1 (char *count_exp, int show_locals, int from_tty) 13075796c8dcSSimon Schubert { 13085796c8dcSSimon Schubert struct frame_info *fi; 13095796c8dcSSimon Schubert int count; 13105796c8dcSSimon Schubert int i; 13115796c8dcSSimon Schubert struct frame_info *trailing; 13125796c8dcSSimon Schubert int trailing_level; 13135796c8dcSSimon Schubert 13145796c8dcSSimon Schubert if (!target_has_stack) 13155796c8dcSSimon Schubert error (_("No stack.")); 13165796c8dcSSimon Schubert 13175796c8dcSSimon Schubert /* The following code must do two things. First, it must set the 13185796c8dcSSimon Schubert variable TRAILING to the frame from which we should start 13195796c8dcSSimon Schubert printing. Second, it must set the variable count to the number 13205796c8dcSSimon Schubert of frames which we should print, or -1 if all of them. */ 13215796c8dcSSimon Schubert trailing = get_current_frame (); 13225796c8dcSSimon Schubert 13235796c8dcSSimon Schubert trailing_level = 0; 13245796c8dcSSimon Schubert if (count_exp) 13255796c8dcSSimon Schubert { 13265796c8dcSSimon Schubert count = parse_and_eval_long (count_exp); 13275796c8dcSSimon Schubert if (count < 0) 13285796c8dcSSimon Schubert { 13295796c8dcSSimon Schubert struct frame_info *current; 13305796c8dcSSimon Schubert 13315796c8dcSSimon Schubert count = -count; 13325796c8dcSSimon Schubert 13335796c8dcSSimon Schubert current = trailing; 13345796c8dcSSimon Schubert while (current && count--) 13355796c8dcSSimon Schubert { 13365796c8dcSSimon Schubert QUIT; 13375796c8dcSSimon Schubert current = get_prev_frame (current); 13385796c8dcSSimon Schubert } 13395796c8dcSSimon Schubert 13405796c8dcSSimon Schubert /* Will stop when CURRENT reaches the top of the stack. 13415796c8dcSSimon Schubert TRAILING will be COUNT below it. */ 13425796c8dcSSimon Schubert while (current) 13435796c8dcSSimon Schubert { 13445796c8dcSSimon Schubert QUIT; 13455796c8dcSSimon Schubert trailing = get_prev_frame (trailing); 13465796c8dcSSimon Schubert current = get_prev_frame (current); 13475796c8dcSSimon Schubert trailing_level++; 13485796c8dcSSimon Schubert } 13495796c8dcSSimon Schubert 13505796c8dcSSimon Schubert count = -1; 13515796c8dcSSimon Schubert } 13525796c8dcSSimon Schubert } 13535796c8dcSSimon Schubert else 13545796c8dcSSimon Schubert count = -1; 13555796c8dcSSimon Schubert 13565796c8dcSSimon Schubert if (info_verbose) 13575796c8dcSSimon Schubert { 13585796c8dcSSimon Schubert /* Read in symbols for all of the frames. Need to do this in a 13595796c8dcSSimon Schubert separate pass so that "Reading in symbols for xxx" messages 13605796c8dcSSimon Schubert don't screw up the appearance of the backtrace. Also if 13615796c8dcSSimon Schubert people have strong opinions against reading symbols for 13625796c8dcSSimon Schubert backtrace this may have to be an option. */ 13635796c8dcSSimon Schubert i = count; 13645796c8dcSSimon Schubert for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi)) 13655796c8dcSSimon Schubert { 1366cf7f2e2dSJohn Marino CORE_ADDR pc; 1367cf7f2e2dSJohn Marino 13685796c8dcSSimon Schubert QUIT; 1369cf7f2e2dSJohn Marino pc = get_frame_address_in_block (fi); 1370cf7f2e2dSJohn Marino find_pc_sect_symtab_via_partial (pc, find_pc_mapped_section (pc)); 13715796c8dcSSimon Schubert } 13725796c8dcSSimon Schubert } 13735796c8dcSSimon Schubert 13745796c8dcSSimon Schubert for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi)) 13755796c8dcSSimon Schubert { 13765796c8dcSSimon Schubert QUIT; 13775796c8dcSSimon Schubert 13785796c8dcSSimon Schubert /* Don't use print_stack_frame; if an error() occurs it probably 13795796c8dcSSimon Schubert means further attempts to backtrace would fail (on the other 13805796c8dcSSimon Schubert hand, perhaps the code does or could be fixed to make sure 13815796c8dcSSimon Schubert the frame->prev field gets set to NULL in that case). */ 13825796c8dcSSimon Schubert print_frame_info (fi, 1, LOCATION, 1); 13835796c8dcSSimon Schubert if (show_locals) 13845796c8dcSSimon Schubert print_frame_local_vars (fi, 1, gdb_stdout); 13855796c8dcSSimon Schubert 13865796c8dcSSimon Schubert /* Save the last frame to check for error conditions. */ 13875796c8dcSSimon Schubert trailing = fi; 13885796c8dcSSimon Schubert } 13895796c8dcSSimon Schubert 13905796c8dcSSimon Schubert /* If we've stopped before the end, mention that. */ 13915796c8dcSSimon Schubert if (fi && from_tty) 13925796c8dcSSimon Schubert printf_filtered (_("(More stack frames follow...)\n")); 13935796c8dcSSimon Schubert 13945796c8dcSSimon Schubert /* If we've run out of frames, and the reason appears to be an error 13955796c8dcSSimon Schubert condition, print it. */ 13965796c8dcSSimon Schubert if (fi == NULL && trailing != NULL) 13975796c8dcSSimon Schubert { 13985796c8dcSSimon Schubert enum unwind_stop_reason reason; 13995796c8dcSSimon Schubert 14005796c8dcSSimon Schubert reason = get_frame_unwind_stop_reason (trailing); 14015796c8dcSSimon Schubert if (reason > UNWIND_FIRST_ERROR) 14025796c8dcSSimon Schubert printf_filtered (_("Backtrace stopped: %s\n"), 14035796c8dcSSimon Schubert frame_stop_reason_string (reason)); 14045796c8dcSSimon Schubert } 14055796c8dcSSimon Schubert } 14065796c8dcSSimon Schubert 14075796c8dcSSimon Schubert struct backtrace_command_args 14085796c8dcSSimon Schubert { 14095796c8dcSSimon Schubert char *count_exp; 14105796c8dcSSimon Schubert int show_locals; 14115796c8dcSSimon Schubert int from_tty; 14125796c8dcSSimon Schubert }; 14135796c8dcSSimon Schubert 14145796c8dcSSimon Schubert /* Stub for catch_errors. */ 14155796c8dcSSimon Schubert 14165796c8dcSSimon Schubert static int 14175796c8dcSSimon Schubert backtrace_command_stub (void *data) 14185796c8dcSSimon Schubert { 14195796c8dcSSimon Schubert struct backtrace_command_args *args = data; 1420cf7f2e2dSJohn Marino 14215796c8dcSSimon Schubert backtrace_command_1 (args->count_exp, args->show_locals, args->from_tty); 14225796c8dcSSimon Schubert return 0; 14235796c8dcSSimon Schubert } 14245796c8dcSSimon Schubert 14255796c8dcSSimon Schubert static void 14265796c8dcSSimon Schubert backtrace_command (char *arg, int from_tty) 14275796c8dcSSimon Schubert { 14285796c8dcSSimon Schubert struct cleanup *old_chain = NULL; 14295796c8dcSSimon Schubert int fulltrace_arg = -1, arglen = 0, argc = 0; 14305796c8dcSSimon Schubert struct backtrace_command_args btargs; 14315796c8dcSSimon Schubert 14325796c8dcSSimon Schubert if (arg) 14335796c8dcSSimon Schubert { 14345796c8dcSSimon Schubert char **argv; 14355796c8dcSSimon Schubert int i; 14365796c8dcSSimon Schubert 14375796c8dcSSimon Schubert argv = gdb_buildargv (arg); 14385796c8dcSSimon Schubert old_chain = make_cleanup_freeargv (argv); 14395796c8dcSSimon Schubert argc = 0; 14405796c8dcSSimon Schubert for (i = 0; argv[i]; i++) 14415796c8dcSSimon Schubert { 14425796c8dcSSimon Schubert unsigned int j; 14435796c8dcSSimon Schubert 14445796c8dcSSimon Schubert for (j = 0; j < strlen (argv[i]); j++) 14455796c8dcSSimon Schubert argv[i][j] = tolower (argv[i][j]); 14465796c8dcSSimon Schubert 14475796c8dcSSimon Schubert if (fulltrace_arg < 0 && subset_compare (argv[i], "full")) 14485796c8dcSSimon Schubert fulltrace_arg = argc; 14495796c8dcSSimon Schubert else 14505796c8dcSSimon Schubert { 14515796c8dcSSimon Schubert arglen += strlen (argv[i]); 14525796c8dcSSimon Schubert argc++; 14535796c8dcSSimon Schubert } 14545796c8dcSSimon Schubert } 14555796c8dcSSimon Schubert arglen += argc; 14565796c8dcSSimon Schubert if (fulltrace_arg >= 0) 14575796c8dcSSimon Schubert { 14585796c8dcSSimon Schubert if (arglen > 0) 14595796c8dcSSimon Schubert { 14605796c8dcSSimon Schubert arg = xmalloc (arglen + 1); 14615796c8dcSSimon Schubert memset (arg, 0, arglen + 1); 14625796c8dcSSimon Schubert for (i = 0; i < (argc + 1); i++) 14635796c8dcSSimon Schubert { 14645796c8dcSSimon Schubert if (i != fulltrace_arg) 14655796c8dcSSimon Schubert { 14665796c8dcSSimon Schubert strcat (arg, argv[i]); 14675796c8dcSSimon Schubert strcat (arg, " "); 14685796c8dcSSimon Schubert } 14695796c8dcSSimon Schubert } 14705796c8dcSSimon Schubert } 14715796c8dcSSimon Schubert else 14725796c8dcSSimon Schubert arg = NULL; 14735796c8dcSSimon Schubert } 14745796c8dcSSimon Schubert } 14755796c8dcSSimon Schubert 14765796c8dcSSimon Schubert btargs.count_exp = arg; 14775796c8dcSSimon Schubert btargs.show_locals = (fulltrace_arg >= 0); 14785796c8dcSSimon Schubert btargs.from_tty = from_tty; 14795796c8dcSSimon Schubert catch_errors (backtrace_command_stub, &btargs, "", RETURN_MASK_ERROR); 14805796c8dcSSimon Schubert 14815796c8dcSSimon Schubert if (fulltrace_arg >= 0 && arglen > 0) 14825796c8dcSSimon Schubert xfree (arg); 14835796c8dcSSimon Schubert 14845796c8dcSSimon Schubert if (old_chain) 14855796c8dcSSimon Schubert do_cleanups (old_chain); 14865796c8dcSSimon Schubert } 14875796c8dcSSimon Schubert 14885796c8dcSSimon Schubert static void 14895796c8dcSSimon Schubert backtrace_full_command (char *arg, int from_tty) 14905796c8dcSSimon Schubert { 14915796c8dcSSimon Schubert struct backtrace_command_args btargs; 1492cf7f2e2dSJohn Marino 14935796c8dcSSimon Schubert btargs.count_exp = arg; 14945796c8dcSSimon Schubert btargs.show_locals = 1; 14955796c8dcSSimon Schubert btargs.from_tty = from_tty; 14965796c8dcSSimon Schubert catch_errors (backtrace_command_stub, &btargs, "", RETURN_MASK_ERROR); 14975796c8dcSSimon Schubert } 14985796c8dcSSimon Schubert 14995796c8dcSSimon Schubert 1500cf7f2e2dSJohn Marino /* Iterate over the local variables of a block B, calling CB with 1501cf7f2e2dSJohn Marino CB_DATA. */ 15025796c8dcSSimon Schubert 1503cf7f2e2dSJohn Marino static void 1504cf7f2e2dSJohn Marino iterate_over_block_locals (struct block *b, 1505cf7f2e2dSJohn Marino iterate_over_block_arg_local_vars_cb cb, 1506cf7f2e2dSJohn Marino void *cb_data) 15075796c8dcSSimon Schubert { 15085796c8dcSSimon Schubert struct dict_iterator iter; 15095796c8dcSSimon Schubert struct symbol *sym; 15105796c8dcSSimon Schubert 15115796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (b, iter, sym) 15125796c8dcSSimon Schubert { 15135796c8dcSSimon Schubert switch (SYMBOL_CLASS (sym)) 15145796c8dcSSimon Schubert { 15155796c8dcSSimon Schubert case LOC_LOCAL: 15165796c8dcSSimon Schubert case LOC_REGISTER: 15175796c8dcSSimon Schubert case LOC_STATIC: 15185796c8dcSSimon Schubert case LOC_COMPUTED: 15195796c8dcSSimon Schubert if (SYMBOL_IS_ARGUMENT (sym)) 15205796c8dcSSimon Schubert break; 1521cf7f2e2dSJohn Marino (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data); 15225796c8dcSSimon Schubert break; 15235796c8dcSSimon Schubert 15245796c8dcSSimon Schubert default: 15255796c8dcSSimon Schubert /* Ignore symbols which are not locals. */ 15265796c8dcSSimon Schubert break; 15275796c8dcSSimon Schubert } 15285796c8dcSSimon Schubert } 15295796c8dcSSimon Schubert } 15305796c8dcSSimon Schubert 1531cf7f2e2dSJohn Marino 15325796c8dcSSimon Schubert /* Same, but print labels. */ 15335796c8dcSSimon Schubert 1534cf7f2e2dSJohn Marino #if 0 1535cf7f2e2dSJohn Marino /* Commented out, as the code using this function has also been 1536cf7f2e2dSJohn Marino commented out. FIXME:brobecker/2009-01-13: Find out why the code 1537cf7f2e2dSJohn Marino was commented out in the first place. The discussion introducing 1538cf7f2e2dSJohn Marino this change (2007-12-04: Support lexical blocks and function bodies 1539cf7f2e2dSJohn Marino that occupy non-contiguous address ranges) did not explain why 1540cf7f2e2dSJohn Marino this change was made. */ 15415796c8dcSSimon Schubert static int 15425796c8dcSSimon Schubert print_block_frame_labels (struct gdbarch *gdbarch, struct block *b, 15435796c8dcSSimon Schubert int *have_default, struct ui_file *stream) 15445796c8dcSSimon Schubert { 15455796c8dcSSimon Schubert struct dict_iterator iter; 15465796c8dcSSimon Schubert struct symbol *sym; 15475796c8dcSSimon Schubert int values_printed = 0; 15485796c8dcSSimon Schubert 15495796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (b, iter, sym) 15505796c8dcSSimon Schubert { 15515796c8dcSSimon Schubert if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0) 15525796c8dcSSimon Schubert { 15535796c8dcSSimon Schubert if (*have_default) 15545796c8dcSSimon Schubert continue; 15555796c8dcSSimon Schubert *have_default = 1; 15565796c8dcSSimon Schubert } 15575796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) == LOC_LABEL) 15585796c8dcSSimon Schubert { 15595796c8dcSSimon Schubert struct symtab_and_line sal; 15605796c8dcSSimon Schubert struct value_print_options opts; 1561cf7f2e2dSJohn Marino 15625796c8dcSSimon Schubert sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); 15635796c8dcSSimon Schubert values_printed = 1; 15645796c8dcSSimon Schubert fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); 15655796c8dcSSimon Schubert get_user_print_options (&opts); 15665796c8dcSSimon Schubert if (opts.addressprint) 15675796c8dcSSimon Schubert { 15685796c8dcSSimon Schubert fprintf_filtered (stream, " "); 15695796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)), 15705796c8dcSSimon Schubert stream); 15715796c8dcSSimon Schubert } 15725796c8dcSSimon Schubert fprintf_filtered (stream, " in file %s, line %d\n", 15735796c8dcSSimon Schubert sal.symtab->filename, sal.line); 15745796c8dcSSimon Schubert } 15755796c8dcSSimon Schubert } 15765796c8dcSSimon Schubert 15775796c8dcSSimon Schubert return values_printed; 15785796c8dcSSimon Schubert } 1579cf7f2e2dSJohn Marino #endif 15805796c8dcSSimon Schubert 1581cf7f2e2dSJohn Marino /* Iterate over all the local variables in block B, including all its 1582cf7f2e2dSJohn Marino superblocks, stopping when the top-level block is reached. */ 15835796c8dcSSimon Schubert 1584cf7f2e2dSJohn Marino void 1585cf7f2e2dSJohn Marino iterate_over_block_local_vars (struct block *block, 1586cf7f2e2dSJohn Marino iterate_over_block_arg_local_vars_cb cb, 1587cf7f2e2dSJohn Marino void *cb_data) 1588cf7f2e2dSJohn Marino { 1589cf7f2e2dSJohn Marino while (block) 1590cf7f2e2dSJohn Marino { 1591cf7f2e2dSJohn Marino iterate_over_block_locals (block, cb, cb_data); 1592cf7f2e2dSJohn Marino /* After handling the function's top-level block, stop. Don't 1593cf7f2e2dSJohn Marino continue to its superblock, the block of per-file 1594cf7f2e2dSJohn Marino symbols. */ 1595cf7f2e2dSJohn Marino if (BLOCK_FUNCTION (block)) 1596cf7f2e2dSJohn Marino break; 1597cf7f2e2dSJohn Marino block = BLOCK_SUPERBLOCK (block); 1598cf7f2e2dSJohn Marino } 1599cf7f2e2dSJohn Marino } 1600cf7f2e2dSJohn Marino 1601cf7f2e2dSJohn Marino /* Data to be passed around in the calls to the locals and args 1602cf7f2e2dSJohn Marino iterators. */ 1603cf7f2e2dSJohn Marino 1604cf7f2e2dSJohn Marino struct print_variable_and_value_data 1605cf7f2e2dSJohn Marino { 1606cf7f2e2dSJohn Marino struct frame_info *frame; 1607cf7f2e2dSJohn Marino int num_tabs; 1608cf7f2e2dSJohn Marino struct ui_file *stream; 1609cf7f2e2dSJohn Marino int values_printed; 1610cf7f2e2dSJohn Marino }; 1611cf7f2e2dSJohn Marino 1612*c50c785cSJohn Marino /* The callback for the locals and args iterators. */ 1613cf7f2e2dSJohn Marino 1614cf7f2e2dSJohn Marino static void 1615cf7f2e2dSJohn Marino do_print_variable_and_value (const char *print_name, 1616cf7f2e2dSJohn Marino struct symbol *sym, 1617cf7f2e2dSJohn Marino void *cb_data) 1618cf7f2e2dSJohn Marino { 1619cf7f2e2dSJohn Marino struct print_variable_and_value_data *p = cb_data; 1620cf7f2e2dSJohn Marino 1621cf7f2e2dSJohn Marino print_variable_and_value (print_name, sym, 1622cf7f2e2dSJohn Marino p->frame, p->stream, p->num_tabs); 1623cf7f2e2dSJohn Marino p->values_printed = 1; 1624cf7f2e2dSJohn Marino } 16255796c8dcSSimon Schubert 16265796c8dcSSimon Schubert static void 16275796c8dcSSimon Schubert print_frame_local_vars (struct frame_info *frame, int num_tabs, 16285796c8dcSSimon Schubert struct ui_file *stream) 16295796c8dcSSimon Schubert { 1630cf7f2e2dSJohn Marino struct print_variable_and_value_data cb_data; 1631cf7f2e2dSJohn Marino struct block *block; 1632*c50c785cSJohn Marino CORE_ADDR pc; 1633*c50c785cSJohn Marino 1634*c50c785cSJohn Marino if (!get_frame_pc_if_available (frame, &pc)) 1635*c50c785cSJohn Marino { 1636*c50c785cSJohn Marino fprintf_filtered (stream, 1637*c50c785cSJohn Marino _("PC unavailable, cannot determine locals.\n")); 1638*c50c785cSJohn Marino return; 1639*c50c785cSJohn Marino } 16405796c8dcSSimon Schubert 1641cf7f2e2dSJohn Marino block = get_frame_block (frame, 0); 16425796c8dcSSimon Schubert if (block == 0) 16435796c8dcSSimon Schubert { 16445796c8dcSSimon Schubert fprintf_filtered (stream, "No symbol table info available.\n"); 16455796c8dcSSimon Schubert return; 16465796c8dcSSimon Schubert } 16475796c8dcSSimon Schubert 1648cf7f2e2dSJohn Marino cb_data.frame = frame; 1649cf7f2e2dSJohn Marino cb_data.num_tabs = 4 * num_tabs; 1650cf7f2e2dSJohn Marino cb_data.stream = stream; 1651cf7f2e2dSJohn Marino cb_data.values_printed = 0; 16525796c8dcSSimon Schubert 1653cf7f2e2dSJohn Marino iterate_over_block_local_vars (block, 1654cf7f2e2dSJohn Marino do_print_variable_and_value, 1655cf7f2e2dSJohn Marino &cb_data); 1656cf7f2e2dSJohn Marino 1657cf7f2e2dSJohn Marino if (!cb_data.values_printed) 16585796c8dcSSimon Schubert fprintf_filtered (stream, _("No locals.\n")); 16595796c8dcSSimon Schubert } 16605796c8dcSSimon Schubert 16615796c8dcSSimon Schubert /* Same, but print labels. */ 16625796c8dcSSimon Schubert 16635796c8dcSSimon Schubert static void 16645796c8dcSSimon Schubert print_frame_label_vars (struct frame_info *frame, int this_level_only, 16655796c8dcSSimon Schubert struct ui_file *stream) 16665796c8dcSSimon Schubert { 16675796c8dcSSimon Schubert #if 1 16685796c8dcSSimon Schubert fprintf_filtered (stream, "print_frame_label_vars disabled.\n"); 16695796c8dcSSimon Schubert #else 16705796c8dcSSimon Schubert struct blockvector *bl; 16715796c8dcSSimon Schubert struct block *block = get_frame_block (frame, 0); 16725796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 16735796c8dcSSimon Schubert int values_printed = 0; 16745796c8dcSSimon Schubert int index, have_default = 0; 16755796c8dcSSimon Schubert char *blocks_printed; 16765796c8dcSSimon Schubert CORE_ADDR pc = get_frame_pc (frame); 16775796c8dcSSimon Schubert 16785796c8dcSSimon Schubert if (block == 0) 16795796c8dcSSimon Schubert { 16805796c8dcSSimon Schubert fprintf_filtered (stream, "No symbol table info available.\n"); 16815796c8dcSSimon Schubert return; 16825796c8dcSSimon Schubert } 16835796c8dcSSimon Schubert 16845796c8dcSSimon Schubert bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); 16855796c8dcSSimon Schubert blocks_printed = alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); 16865796c8dcSSimon Schubert memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); 16875796c8dcSSimon Schubert 16885796c8dcSSimon Schubert while (block != 0) 16895796c8dcSSimon Schubert { 16905796c8dcSSimon Schubert CORE_ADDR end = BLOCK_END (block) - 4; 16915796c8dcSSimon Schubert int last_index; 16925796c8dcSSimon Schubert 16935796c8dcSSimon Schubert if (bl != blockvector_for_pc (end, &index)) 16945796c8dcSSimon Schubert error (_("blockvector blotch")); 16955796c8dcSSimon Schubert if (BLOCKVECTOR_BLOCK (bl, index) != block) 16965796c8dcSSimon Schubert error (_("blockvector botch")); 16975796c8dcSSimon Schubert last_index = BLOCKVECTOR_NBLOCKS (bl); 16985796c8dcSSimon Schubert index += 1; 16995796c8dcSSimon Schubert 17005796c8dcSSimon Schubert /* Don't print out blocks that have gone by. */ 17015796c8dcSSimon Schubert while (index < last_index 17025796c8dcSSimon Schubert && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) 17035796c8dcSSimon Schubert index++; 17045796c8dcSSimon Schubert 17055796c8dcSSimon Schubert while (index < last_index 17065796c8dcSSimon Schubert && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) 17075796c8dcSSimon Schubert { 17085796c8dcSSimon Schubert if (blocks_printed[index] == 0) 17095796c8dcSSimon Schubert { 17105796c8dcSSimon Schubert if (print_block_frame_labels (gdbarch, 17115796c8dcSSimon Schubert BLOCKVECTOR_BLOCK (bl, index), 17125796c8dcSSimon Schubert &have_default, stream)) 17135796c8dcSSimon Schubert values_printed = 1; 17145796c8dcSSimon Schubert blocks_printed[index] = 1; 17155796c8dcSSimon Schubert } 17165796c8dcSSimon Schubert index++; 17175796c8dcSSimon Schubert } 17185796c8dcSSimon Schubert if (have_default) 17195796c8dcSSimon Schubert return; 17205796c8dcSSimon Schubert if (values_printed && this_level_only) 17215796c8dcSSimon Schubert return; 17225796c8dcSSimon Schubert 17235796c8dcSSimon Schubert /* After handling the function's top-level block, stop. Don't 17245796c8dcSSimon Schubert continue to its superblock, the block of per-file symbols. 17255796c8dcSSimon Schubert Also do not continue to the containing function of an inlined 17265796c8dcSSimon Schubert function. */ 17275796c8dcSSimon Schubert if (BLOCK_FUNCTION (block)) 17285796c8dcSSimon Schubert break; 17295796c8dcSSimon Schubert block = BLOCK_SUPERBLOCK (block); 17305796c8dcSSimon Schubert } 17315796c8dcSSimon Schubert 17325796c8dcSSimon Schubert if (!values_printed && !this_level_only) 17335796c8dcSSimon Schubert fprintf_filtered (stream, _("No catches.\n")); 17345796c8dcSSimon Schubert #endif 17355796c8dcSSimon Schubert } 17365796c8dcSSimon Schubert 17375796c8dcSSimon Schubert void 17385796c8dcSSimon Schubert locals_info (char *args, int from_tty) 17395796c8dcSSimon Schubert { 17405796c8dcSSimon Schubert print_frame_local_vars (get_selected_frame (_("No frame selected.")), 17415796c8dcSSimon Schubert 0, gdb_stdout); 17425796c8dcSSimon Schubert } 17435796c8dcSSimon Schubert 17445796c8dcSSimon Schubert static void 17455796c8dcSSimon Schubert catch_info (char *ignore, int from_tty) 17465796c8dcSSimon Schubert { 17475796c8dcSSimon Schubert /* Assume g++ compiled code; old GDB 4.16 behaviour. */ 17485796c8dcSSimon Schubert print_frame_label_vars (get_selected_frame (_("No frame selected.")), 17495796c8dcSSimon Schubert 0, gdb_stdout); 17505796c8dcSSimon Schubert } 17515796c8dcSSimon Schubert 1752cf7f2e2dSJohn Marino /* Iterate over all the argument variables in block B. 1753cf7f2e2dSJohn Marino 1754cf7f2e2dSJohn Marino Returns 1 if any argument was walked; 0 otherwise. */ 1755cf7f2e2dSJohn Marino 1756cf7f2e2dSJohn Marino void 1757cf7f2e2dSJohn Marino iterate_over_block_arg_vars (struct block *b, 1758cf7f2e2dSJohn Marino iterate_over_block_arg_local_vars_cb cb, 1759cf7f2e2dSJohn Marino void *cb_data) 17605796c8dcSSimon Schubert { 17615796c8dcSSimon Schubert struct dict_iterator iter; 17625796c8dcSSimon Schubert struct symbol *sym, *sym2; 17635796c8dcSSimon Schubert 17645796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (b, iter, sym) 17655796c8dcSSimon Schubert { 17665796c8dcSSimon Schubert /* Don't worry about things which aren't arguments. */ 17675796c8dcSSimon Schubert if (SYMBOL_IS_ARGUMENT (sym)) 17685796c8dcSSimon Schubert { 17695796c8dcSSimon Schubert /* We have to look up the symbol because arguments can have 17705796c8dcSSimon Schubert two entries (one a parameter, one a local) and the one we 17715796c8dcSSimon Schubert want is the local, which lookup_symbol will find for us. 17725796c8dcSSimon Schubert This includes gcc1 (not gcc2) on the sparc when passing a 17735796c8dcSSimon Schubert small structure and gcc2 when the argument type is float 17745796c8dcSSimon Schubert and it is passed as a double and converted to float by 17755796c8dcSSimon Schubert the prologue (in the latter case the type of the LOC_ARG 17765796c8dcSSimon Schubert symbol is double and the type of the LOC_LOCAL symbol is 17775796c8dcSSimon Schubert float). There are also LOC_ARG/LOC_REGISTER pairs which 17785796c8dcSSimon Schubert are not combined in symbol-reading. */ 17795796c8dcSSimon Schubert 17805796c8dcSSimon Schubert sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), 17815796c8dcSSimon Schubert b, VAR_DOMAIN, NULL); 1782cf7f2e2dSJohn Marino (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data); 1783cf7f2e2dSJohn Marino } 17845796c8dcSSimon Schubert } 17855796c8dcSSimon Schubert } 17865796c8dcSSimon Schubert 1787cf7f2e2dSJohn Marino static void 1788cf7f2e2dSJohn Marino print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream) 1789cf7f2e2dSJohn Marino { 1790cf7f2e2dSJohn Marino struct print_variable_and_value_data cb_data; 1791cf7f2e2dSJohn Marino struct symbol *func; 1792*c50c785cSJohn Marino CORE_ADDR pc; 1793*c50c785cSJohn Marino 1794*c50c785cSJohn Marino if (!get_frame_pc_if_available (frame, &pc)) 1795*c50c785cSJohn Marino { 1796*c50c785cSJohn Marino fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n")); 1797*c50c785cSJohn Marino return; 1798*c50c785cSJohn Marino } 1799cf7f2e2dSJohn Marino 1800cf7f2e2dSJohn Marino func = get_frame_function (frame); 1801cf7f2e2dSJohn Marino if (func == NULL) 1802cf7f2e2dSJohn Marino { 1803cf7f2e2dSJohn Marino fprintf_filtered (stream, _("No symbol table info available.\n")); 1804cf7f2e2dSJohn Marino return; 1805cf7f2e2dSJohn Marino } 1806cf7f2e2dSJohn Marino 1807cf7f2e2dSJohn Marino cb_data.frame = frame; 1808cf7f2e2dSJohn Marino cb_data.num_tabs = 0; 1809cf7f2e2dSJohn Marino cb_data.stream = gdb_stdout; 1810cf7f2e2dSJohn Marino cb_data.values_printed = 0; 1811cf7f2e2dSJohn Marino 1812cf7f2e2dSJohn Marino iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func), 1813cf7f2e2dSJohn Marino do_print_variable_and_value, &cb_data); 1814cf7f2e2dSJohn Marino 1815cf7f2e2dSJohn Marino if (!cb_data.values_printed) 18165796c8dcSSimon Schubert fprintf_filtered (stream, _("No arguments.\n")); 18175796c8dcSSimon Schubert } 18185796c8dcSSimon Schubert 18195796c8dcSSimon Schubert void 18205796c8dcSSimon Schubert args_info (char *ignore, int from_tty) 18215796c8dcSSimon Schubert { 18225796c8dcSSimon Schubert print_frame_arg_vars (get_selected_frame (_("No frame selected.")), 18235796c8dcSSimon Schubert gdb_stdout); 18245796c8dcSSimon Schubert } 18255796c8dcSSimon Schubert 18265796c8dcSSimon Schubert 18275796c8dcSSimon Schubert static void 18285796c8dcSSimon Schubert args_plus_locals_info (char *ignore, int from_tty) 18295796c8dcSSimon Schubert { 18305796c8dcSSimon Schubert args_info (ignore, from_tty); 18315796c8dcSSimon Schubert locals_info (ignore, from_tty); 18325796c8dcSSimon Schubert } 18335796c8dcSSimon Schubert 18345796c8dcSSimon Schubert 18355796c8dcSSimon Schubert /* Select frame FRAME. Also print the stack frame and show the source 18365796c8dcSSimon Schubert if this is the tui version. */ 18375796c8dcSSimon Schubert static void 18385796c8dcSSimon Schubert select_and_print_frame (struct frame_info *frame) 18395796c8dcSSimon Schubert { 18405796c8dcSSimon Schubert select_frame (frame); 18415796c8dcSSimon Schubert if (frame) 18425796c8dcSSimon Schubert print_stack_frame (frame, 1, SRC_AND_LOC); 18435796c8dcSSimon Schubert } 18445796c8dcSSimon Schubert 18455796c8dcSSimon Schubert /* Return the symbol-block in which the selected frame is executing. 18465796c8dcSSimon Schubert Can return zero under various legitimate circumstances. 18475796c8dcSSimon Schubert 18485796c8dcSSimon Schubert If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant 18495796c8dcSSimon Schubert code address within the block returned. We use this to decide 18505796c8dcSSimon Schubert which macros are in scope. */ 18515796c8dcSSimon Schubert 18525796c8dcSSimon Schubert struct block * 18535796c8dcSSimon Schubert get_selected_block (CORE_ADDR *addr_in_block) 18545796c8dcSSimon Schubert { 18555796c8dcSSimon Schubert if (!has_stack_frames ()) 18565796c8dcSSimon Schubert return 0; 18575796c8dcSSimon Schubert 18585796c8dcSSimon Schubert return get_frame_block (get_selected_frame (NULL), addr_in_block); 18595796c8dcSSimon Schubert } 18605796c8dcSSimon Schubert 18615796c8dcSSimon Schubert /* Find a frame a certain number of levels away from FRAME. 18625796c8dcSSimon Schubert LEVEL_OFFSET_PTR points to an int containing the number of levels. 18635796c8dcSSimon Schubert Positive means go to earlier frames (up); negative, the reverse. 18645796c8dcSSimon Schubert The int that contains the number of levels is counted toward 18655796c8dcSSimon Schubert zero as the frames for those levels are found. 18665796c8dcSSimon Schubert If the top or bottom frame is reached, that frame is returned, 18675796c8dcSSimon Schubert but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates 18685796c8dcSSimon Schubert how much farther the original request asked to go. */ 18695796c8dcSSimon Schubert 18705796c8dcSSimon Schubert struct frame_info * 18715796c8dcSSimon Schubert find_relative_frame (struct frame_info *frame, int *level_offset_ptr) 18725796c8dcSSimon Schubert { 18735796c8dcSSimon Schubert /* Going up is simple: just call get_prev_frame enough times or 18745796c8dcSSimon Schubert until the initial frame is reached. */ 18755796c8dcSSimon Schubert while (*level_offset_ptr > 0) 18765796c8dcSSimon Schubert { 18775796c8dcSSimon Schubert struct frame_info *prev = get_prev_frame (frame); 1878cf7f2e2dSJohn Marino 18795796c8dcSSimon Schubert if (!prev) 18805796c8dcSSimon Schubert break; 18815796c8dcSSimon Schubert (*level_offset_ptr)--; 18825796c8dcSSimon Schubert frame = prev; 18835796c8dcSSimon Schubert } 18845796c8dcSSimon Schubert 18855796c8dcSSimon Schubert /* Going down is just as simple. */ 18865796c8dcSSimon Schubert while (*level_offset_ptr < 0) 18875796c8dcSSimon Schubert { 18885796c8dcSSimon Schubert struct frame_info *next = get_next_frame (frame); 1889cf7f2e2dSJohn Marino 18905796c8dcSSimon Schubert if (!next) 18915796c8dcSSimon Schubert break; 18925796c8dcSSimon Schubert (*level_offset_ptr)++; 18935796c8dcSSimon Schubert frame = next; 18945796c8dcSSimon Schubert } 18955796c8dcSSimon Schubert 18965796c8dcSSimon Schubert return frame; 18975796c8dcSSimon Schubert } 18985796c8dcSSimon Schubert 18995796c8dcSSimon Schubert /* The "select_frame" command. With no argument this is a NOP. 19005796c8dcSSimon Schubert Select the frame at level LEVEL_EXP if it is a valid level. 19015796c8dcSSimon Schubert Otherwise, treat LEVEL_EXP as an address expression and select it. 19025796c8dcSSimon Schubert 19035796c8dcSSimon Schubert See parse_frame_specification for more info on proper frame 19045796c8dcSSimon Schubert expressions. */ 19055796c8dcSSimon Schubert 19065796c8dcSSimon Schubert void 19075796c8dcSSimon Schubert select_frame_command (char *level_exp, int from_tty) 19085796c8dcSSimon Schubert { 19095796c8dcSSimon Schubert select_frame (parse_frame_specification_1 (level_exp, "No stack.", NULL)); 19105796c8dcSSimon Schubert } 19115796c8dcSSimon Schubert 19125796c8dcSSimon Schubert /* The "frame" command. With no argument, print the selected frame 19135796c8dcSSimon Schubert briefly. With an argument, behave like select_frame and then print 19145796c8dcSSimon Schubert the selected frame. */ 19155796c8dcSSimon Schubert 19165796c8dcSSimon Schubert static void 19175796c8dcSSimon Schubert frame_command (char *level_exp, int from_tty) 19185796c8dcSSimon Schubert { 19195796c8dcSSimon Schubert select_frame_command (level_exp, from_tty); 19205796c8dcSSimon Schubert print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC); 19215796c8dcSSimon Schubert } 19225796c8dcSSimon Schubert 19235796c8dcSSimon Schubert /* The XDB Compatibility command to print the current frame. */ 19245796c8dcSSimon Schubert 19255796c8dcSSimon Schubert static void 19265796c8dcSSimon Schubert current_frame_command (char *level_exp, int from_tty) 19275796c8dcSSimon Schubert { 19285796c8dcSSimon Schubert print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC); 19295796c8dcSSimon Schubert } 19305796c8dcSSimon Schubert 19315796c8dcSSimon Schubert /* Select the frame up one or COUNT_EXP stack levels from the 19325796c8dcSSimon Schubert previously selected frame, and print it briefly. */ 19335796c8dcSSimon Schubert 19345796c8dcSSimon Schubert static void 19355796c8dcSSimon Schubert up_silently_base (char *count_exp) 19365796c8dcSSimon Schubert { 19375796c8dcSSimon Schubert struct frame_info *frame; 19385796c8dcSSimon Schubert int count = 1; 19395796c8dcSSimon Schubert 19405796c8dcSSimon Schubert if (count_exp) 19415796c8dcSSimon Schubert count = parse_and_eval_long (count_exp); 19425796c8dcSSimon Schubert 19435796c8dcSSimon Schubert frame = find_relative_frame (get_selected_frame ("No stack."), &count); 19445796c8dcSSimon Schubert if (count != 0 && count_exp == NULL) 19455796c8dcSSimon Schubert error (_("Initial frame selected; you cannot go up.")); 19465796c8dcSSimon Schubert select_frame (frame); 19475796c8dcSSimon Schubert } 19485796c8dcSSimon Schubert 19495796c8dcSSimon Schubert static void 19505796c8dcSSimon Schubert up_silently_command (char *count_exp, int from_tty) 19515796c8dcSSimon Schubert { 19525796c8dcSSimon Schubert up_silently_base (count_exp); 19535796c8dcSSimon Schubert } 19545796c8dcSSimon Schubert 19555796c8dcSSimon Schubert static void 19565796c8dcSSimon Schubert up_command (char *count_exp, int from_tty) 19575796c8dcSSimon Schubert { 19585796c8dcSSimon Schubert up_silently_base (count_exp); 19595796c8dcSSimon Schubert print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC); 19605796c8dcSSimon Schubert } 19615796c8dcSSimon Schubert 19625796c8dcSSimon Schubert /* Select the frame down one or COUNT_EXP stack levels from the previously 19635796c8dcSSimon Schubert selected frame, and print it briefly. */ 19645796c8dcSSimon Schubert 19655796c8dcSSimon Schubert static void 19665796c8dcSSimon Schubert down_silently_base (char *count_exp) 19675796c8dcSSimon Schubert { 19685796c8dcSSimon Schubert struct frame_info *frame; 19695796c8dcSSimon Schubert int count = -1; 1970cf7f2e2dSJohn Marino 19715796c8dcSSimon Schubert if (count_exp) 19725796c8dcSSimon Schubert count = -parse_and_eval_long (count_exp); 19735796c8dcSSimon Schubert 19745796c8dcSSimon Schubert frame = find_relative_frame (get_selected_frame ("No stack."), &count); 19755796c8dcSSimon Schubert if (count != 0 && count_exp == NULL) 19765796c8dcSSimon Schubert { 19775796c8dcSSimon Schubert /* We only do this if COUNT_EXP is not specified. That way 19785796c8dcSSimon Schubert "down" means to really go down (and let me know if that is 19795796c8dcSSimon Schubert impossible), but "down 9999" can be used to mean go all the 19805796c8dcSSimon Schubert way down without getting an error. */ 19815796c8dcSSimon Schubert 19825796c8dcSSimon Schubert error (_("Bottom (innermost) frame selected; you cannot go down.")); 19835796c8dcSSimon Schubert } 19845796c8dcSSimon Schubert 19855796c8dcSSimon Schubert select_frame (frame); 19865796c8dcSSimon Schubert } 19875796c8dcSSimon Schubert 19885796c8dcSSimon Schubert static void 19895796c8dcSSimon Schubert down_silently_command (char *count_exp, int from_tty) 19905796c8dcSSimon Schubert { 19915796c8dcSSimon Schubert down_silently_base (count_exp); 19925796c8dcSSimon Schubert } 19935796c8dcSSimon Schubert 19945796c8dcSSimon Schubert static void 19955796c8dcSSimon Schubert down_command (char *count_exp, int from_tty) 19965796c8dcSSimon Schubert { 19975796c8dcSSimon Schubert down_silently_base (count_exp); 19985796c8dcSSimon Schubert print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC); 19995796c8dcSSimon Schubert } 20005796c8dcSSimon Schubert 20015796c8dcSSimon Schubert 20025796c8dcSSimon Schubert void 20035796c8dcSSimon Schubert return_command (char *retval_exp, int from_tty) 20045796c8dcSSimon Schubert { 20055796c8dcSSimon Schubert struct frame_info *thisframe; 20065796c8dcSSimon Schubert struct gdbarch *gdbarch; 20075796c8dcSSimon Schubert struct symbol *thisfun; 20085796c8dcSSimon Schubert struct value *return_value = NULL; 20095796c8dcSSimon Schubert const char *query_prefix = ""; 20105796c8dcSSimon Schubert 20115796c8dcSSimon Schubert thisframe = get_selected_frame ("No selected frame."); 20125796c8dcSSimon Schubert thisfun = get_frame_function (thisframe); 20135796c8dcSSimon Schubert gdbarch = get_frame_arch (thisframe); 20145796c8dcSSimon Schubert 20155796c8dcSSimon Schubert if (get_frame_type (get_current_frame ()) == INLINE_FRAME) 20165796c8dcSSimon Schubert error (_("Can not force return from an inlined function.")); 20175796c8dcSSimon Schubert 20185796c8dcSSimon Schubert /* Compute the return value. If the computation triggers an error, 20195796c8dcSSimon Schubert let it bail. If the return type can't be handled, set 20205796c8dcSSimon Schubert RETURN_VALUE to NULL, and QUERY_PREFIX to an informational 20215796c8dcSSimon Schubert message. */ 20225796c8dcSSimon Schubert if (retval_exp) 20235796c8dcSSimon Schubert { 20245796c8dcSSimon Schubert struct expression *retval_expr = parse_expression (retval_exp); 20255796c8dcSSimon Schubert struct cleanup *old_chain = make_cleanup (xfree, retval_expr); 20265796c8dcSSimon Schubert struct type *return_type = NULL; 20275796c8dcSSimon Schubert 20285796c8dcSSimon Schubert /* Compute the return value. Should the computation fail, this 20295796c8dcSSimon Schubert call throws an error. */ 20305796c8dcSSimon Schubert return_value = evaluate_expression (retval_expr); 20315796c8dcSSimon Schubert 20325796c8dcSSimon Schubert /* Cast return value to the return type of the function. Should 20335796c8dcSSimon Schubert the cast fail, this call throws an error. */ 20345796c8dcSSimon Schubert if (thisfun != NULL) 20355796c8dcSSimon Schubert return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun)); 20365796c8dcSSimon Schubert if (return_type == NULL) 20375796c8dcSSimon Schubert { 20385796c8dcSSimon Schubert if (retval_expr->elts[0].opcode != UNOP_CAST) 20395796c8dcSSimon Schubert error (_("Return value type not available for selected " 20405796c8dcSSimon Schubert "stack frame.\n" 20415796c8dcSSimon Schubert "Please use an explicit cast of the value to return.")); 20425796c8dcSSimon Schubert return_type = value_type (return_value); 20435796c8dcSSimon Schubert } 20445796c8dcSSimon Schubert do_cleanups (old_chain); 20455796c8dcSSimon Schubert CHECK_TYPEDEF (return_type); 20465796c8dcSSimon Schubert return_value = value_cast (return_type, return_value); 20475796c8dcSSimon Schubert 20485796c8dcSSimon Schubert /* Make sure the value is fully evaluated. It may live in the 20495796c8dcSSimon Schubert stack frame we're about to pop. */ 20505796c8dcSSimon Schubert if (value_lazy (return_value)) 20515796c8dcSSimon Schubert value_fetch_lazy (return_value); 20525796c8dcSSimon Schubert 20535796c8dcSSimon Schubert if (TYPE_CODE (return_type) == TYPE_CODE_VOID) 20545796c8dcSSimon Schubert /* If the return-type is "void", don't try to find the 20555796c8dcSSimon Schubert return-value's location. However, do still evaluate the 20565796c8dcSSimon Schubert return expression so that, even when the expression result 20575796c8dcSSimon Schubert is discarded, side effects such as "return i++" still 20585796c8dcSSimon Schubert occur. */ 20595796c8dcSSimon Schubert return_value = NULL; 20605796c8dcSSimon Schubert else if (thisfun != NULL 20615796c8dcSSimon Schubert && using_struct_return (gdbarch, 20625796c8dcSSimon Schubert SYMBOL_TYPE (thisfun), return_type)) 20635796c8dcSSimon Schubert { 2064*c50c785cSJohn Marino query_prefix = "The location at which to store the " 2065*c50c785cSJohn Marino "function's return value is unknown.\n" 2066*c50c785cSJohn Marino "If you continue, the return value " 2067*c50c785cSJohn Marino "that you specified will be ignored.\n"; 20685796c8dcSSimon Schubert return_value = NULL; 20695796c8dcSSimon Schubert } 20705796c8dcSSimon Schubert } 20715796c8dcSSimon Schubert 20725796c8dcSSimon Schubert /* Does an interactive user really want to do this? Include 20735796c8dcSSimon Schubert information, such as how well GDB can handle the return value, in 20745796c8dcSSimon Schubert the query message. */ 20755796c8dcSSimon Schubert if (from_tty) 20765796c8dcSSimon Schubert { 20775796c8dcSSimon Schubert int confirmed; 2078cf7f2e2dSJohn Marino 20795796c8dcSSimon Schubert if (thisfun == NULL) 20805796c8dcSSimon Schubert confirmed = query (_("%sMake selected stack frame return now? "), 20815796c8dcSSimon Schubert query_prefix); 20825796c8dcSSimon Schubert else 20835796c8dcSSimon Schubert confirmed = query (_("%sMake %s return now? "), query_prefix, 20845796c8dcSSimon Schubert SYMBOL_PRINT_NAME (thisfun)); 20855796c8dcSSimon Schubert if (!confirmed) 20865796c8dcSSimon Schubert error (_("Not confirmed")); 20875796c8dcSSimon Schubert } 20885796c8dcSSimon Schubert 20895796c8dcSSimon Schubert /* Discard the selected frame and all frames inner-to it. */ 20905796c8dcSSimon Schubert frame_pop (get_selected_frame (NULL)); 20915796c8dcSSimon Schubert 20925796c8dcSSimon Schubert /* Store RETURN_VALUE in the just-returned register set. */ 20935796c8dcSSimon Schubert if (return_value != NULL) 20945796c8dcSSimon Schubert { 20955796c8dcSSimon Schubert struct type *return_type = value_type (return_value); 20965796c8dcSSimon Schubert struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ()); 20975796c8dcSSimon Schubert struct type *func_type = thisfun == NULL ? NULL : SYMBOL_TYPE (thisfun); 20985796c8dcSSimon Schubert 20995796c8dcSSimon Schubert gdb_assert (gdbarch_return_value (gdbarch, func_type, return_type, NULL, 21005796c8dcSSimon Schubert NULL, NULL) 21015796c8dcSSimon Schubert == RETURN_VALUE_REGISTER_CONVENTION); 21025796c8dcSSimon Schubert gdbarch_return_value (gdbarch, func_type, return_type, 21035796c8dcSSimon Schubert get_current_regcache (), NULL /*read*/, 21045796c8dcSSimon Schubert value_contents (return_value) /*write*/); 21055796c8dcSSimon Schubert } 21065796c8dcSSimon Schubert 21075796c8dcSSimon Schubert /* If we are at the end of a call dummy now, pop the dummy frame 21085796c8dcSSimon Schubert too. */ 21095796c8dcSSimon Schubert if (get_frame_type (get_current_frame ()) == DUMMY_FRAME) 21105796c8dcSSimon Schubert frame_pop (get_current_frame ()); 21115796c8dcSSimon Schubert 21125796c8dcSSimon Schubert /* If interactive, print the frame that is now current. */ 21135796c8dcSSimon Schubert if (from_tty) 21145796c8dcSSimon Schubert frame_command ("0", 1); 21155796c8dcSSimon Schubert else 21165796c8dcSSimon Schubert select_frame_command ("0", 0); 21175796c8dcSSimon Schubert } 21185796c8dcSSimon Schubert 21195796c8dcSSimon Schubert /* Sets the scope to input function name, provided that the function 2120*c50c785cSJohn Marino is within the current stack frame. */ 21215796c8dcSSimon Schubert 21225796c8dcSSimon Schubert struct function_bounds 21235796c8dcSSimon Schubert { 21245796c8dcSSimon Schubert CORE_ADDR low, high; 21255796c8dcSSimon Schubert }; 21265796c8dcSSimon Schubert 21275796c8dcSSimon Schubert static void 21285796c8dcSSimon Schubert func_command (char *arg, int from_tty) 21295796c8dcSSimon Schubert { 21305796c8dcSSimon Schubert struct frame_info *frame; 21315796c8dcSSimon Schubert int found = 0; 21325796c8dcSSimon Schubert struct symtabs_and_lines sals; 21335796c8dcSSimon Schubert int i; 21345796c8dcSSimon Schubert int level = 1; 21355796c8dcSSimon Schubert struct function_bounds *func_bounds = NULL; 21365796c8dcSSimon Schubert 21375796c8dcSSimon Schubert if (arg != NULL) 21385796c8dcSSimon Schubert return; 21395796c8dcSSimon Schubert 21405796c8dcSSimon Schubert frame = parse_frame_specification ("0"); 21415796c8dcSSimon Schubert sals = decode_line_spec (arg, 1); 21425796c8dcSSimon Schubert func_bounds = (struct function_bounds *) xmalloc ( 21435796c8dcSSimon Schubert sizeof (struct function_bounds) * sals.nelts); 21445796c8dcSSimon Schubert for (i = 0; (i < sals.nelts && !found); i++) 21455796c8dcSSimon Schubert { 21465796c8dcSSimon Schubert if (sals.sals[i].pc == 0 21475796c8dcSSimon Schubert || find_pc_partial_function (sals.sals[i].pc, NULL, 21485796c8dcSSimon Schubert &func_bounds[i].low, 21495796c8dcSSimon Schubert &func_bounds[i].high) == 0) 21505796c8dcSSimon Schubert { 21515796c8dcSSimon Schubert func_bounds[i].low = func_bounds[i].high = 0; 21525796c8dcSSimon Schubert } 21535796c8dcSSimon Schubert } 21545796c8dcSSimon Schubert 21555796c8dcSSimon Schubert do 21565796c8dcSSimon Schubert { 21575796c8dcSSimon Schubert for (i = 0; (i < sals.nelts && !found); i++) 21585796c8dcSSimon Schubert found = (get_frame_pc (frame) >= func_bounds[i].low 21595796c8dcSSimon Schubert && get_frame_pc (frame) < func_bounds[i].high); 21605796c8dcSSimon Schubert if (!found) 21615796c8dcSSimon Schubert { 21625796c8dcSSimon Schubert level = 1; 21635796c8dcSSimon Schubert frame = find_relative_frame (frame, &level); 21645796c8dcSSimon Schubert } 21655796c8dcSSimon Schubert } 21665796c8dcSSimon Schubert while (!found && level == 0); 21675796c8dcSSimon Schubert 21685796c8dcSSimon Schubert if (func_bounds) 21695796c8dcSSimon Schubert xfree (func_bounds); 21705796c8dcSSimon Schubert 21715796c8dcSSimon Schubert if (!found) 21725796c8dcSSimon Schubert printf_filtered (_("'%s' not within current stack frame.\n"), arg); 21735796c8dcSSimon Schubert else if (frame != get_selected_frame (NULL)) 21745796c8dcSSimon Schubert select_and_print_frame (frame); 21755796c8dcSSimon Schubert } 21765796c8dcSSimon Schubert 21775796c8dcSSimon Schubert /* Gets the language of the current frame. */ 21785796c8dcSSimon Schubert 21795796c8dcSSimon Schubert enum language 21805796c8dcSSimon Schubert get_frame_language (void) 21815796c8dcSSimon Schubert { 21825796c8dcSSimon Schubert struct frame_info *frame = deprecated_safe_get_selected_frame (); 21835796c8dcSSimon Schubert 21845796c8dcSSimon Schubert if (frame) 21855796c8dcSSimon Schubert { 2186*c50c785cSJohn Marino volatile struct gdb_exception ex; 2187*c50c785cSJohn Marino CORE_ADDR pc = 0; 2188*c50c785cSJohn Marino struct symtab *s; 2189*c50c785cSJohn Marino 21905796c8dcSSimon Schubert /* We determine the current frame language by looking up its 21915796c8dcSSimon Schubert associated symtab. To retrieve this symtab, we use the frame 21925796c8dcSSimon Schubert PC. However we cannot use the frame PC as is, because it 21935796c8dcSSimon Schubert usually points to the instruction following the "call", which 21945796c8dcSSimon Schubert is sometimes the first instruction of another function. So 21955796c8dcSSimon Schubert we rely on get_frame_address_in_block(), it provides us with 21965796c8dcSSimon Schubert a PC that is guaranteed to be inside the frame's code 21975796c8dcSSimon Schubert block. */ 21985796c8dcSSimon Schubert 2199*c50c785cSJohn Marino TRY_CATCH (ex, RETURN_MASK_ERROR) 2200*c50c785cSJohn Marino { 2201*c50c785cSJohn Marino pc = get_frame_address_in_block (frame); 2202*c50c785cSJohn Marino } 2203*c50c785cSJohn Marino if (ex.reason < 0) 2204*c50c785cSJohn Marino { 2205*c50c785cSJohn Marino if (ex.error != NOT_AVAILABLE_ERROR) 2206*c50c785cSJohn Marino throw_exception (ex); 2207*c50c785cSJohn Marino } 2208*c50c785cSJohn Marino else 2209*c50c785cSJohn Marino { 2210*c50c785cSJohn Marino s = find_pc_symtab (pc); 2211*c50c785cSJohn Marino if (s != NULL) 22125796c8dcSSimon Schubert return s->language; 22135796c8dcSSimon Schubert } 2214*c50c785cSJohn Marino } 22155796c8dcSSimon Schubert 22165796c8dcSSimon Schubert return language_unknown; 22175796c8dcSSimon Schubert } 22185796c8dcSSimon Schubert 22195796c8dcSSimon Schubert 22205796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */ 22215796c8dcSSimon Schubert void _initialize_stack (void); 22225796c8dcSSimon Schubert 22235796c8dcSSimon Schubert void 22245796c8dcSSimon Schubert _initialize_stack (void) 22255796c8dcSSimon Schubert { 22265796c8dcSSimon Schubert add_com ("return", class_stack, return_command, _("\ 22275796c8dcSSimon Schubert Make selected stack frame return to its caller.\n\ 22285796c8dcSSimon Schubert Control remains in the debugger, but when you continue\n\ 22295796c8dcSSimon Schubert execution will resume in the frame above the one now selected.\n\ 22305796c8dcSSimon Schubert If an argument is given, it is an expression for the value to return.")); 22315796c8dcSSimon Schubert 22325796c8dcSSimon Schubert add_com ("up", class_stack, up_command, _("\ 22335796c8dcSSimon Schubert Select and print stack frame that called this one.\n\ 22345796c8dcSSimon Schubert An argument says how many frames up to go.")); 22355796c8dcSSimon Schubert add_com ("up-silently", class_support, up_silently_command, _("\ 22365796c8dcSSimon Schubert Same as the `up' command, but does not print anything.\n\ 22375796c8dcSSimon Schubert This is useful in command scripts.")); 22385796c8dcSSimon Schubert 22395796c8dcSSimon Schubert add_com ("down", class_stack, down_command, _("\ 22405796c8dcSSimon Schubert Select and print stack frame called by this one.\n\ 22415796c8dcSSimon Schubert An argument says how many frames down to go.")); 22425796c8dcSSimon Schubert add_com_alias ("do", "down", class_stack, 1); 22435796c8dcSSimon Schubert add_com_alias ("dow", "down", class_stack, 1); 22445796c8dcSSimon Schubert add_com ("down-silently", class_support, down_silently_command, _("\ 22455796c8dcSSimon Schubert Same as the `down' command, but does not print anything.\n\ 22465796c8dcSSimon Schubert This is useful in command scripts.")); 22475796c8dcSSimon Schubert 22485796c8dcSSimon Schubert add_com ("frame", class_stack, frame_command, _("\ 2249*c50c785cSJohn Marino Select and print a stack frame.\nWith no argument, \ 2250*c50c785cSJohn Marino print the selected stack frame. (See also \"info frame\").\n\ 22515796c8dcSSimon Schubert An argument specifies the frame to select.\n\ 22525796c8dcSSimon Schubert It can be a stack frame number or the address of the frame.\n\ 22535796c8dcSSimon Schubert With argument, nothing is printed if input is coming from\n\ 22545796c8dcSSimon Schubert a command file or a user-defined command.")); 22555796c8dcSSimon Schubert 22565796c8dcSSimon Schubert add_com_alias ("f", "frame", class_stack, 1); 22575796c8dcSSimon Schubert 22585796c8dcSSimon Schubert if (xdb_commands) 22595796c8dcSSimon Schubert { 22605796c8dcSSimon Schubert add_com ("L", class_stack, current_frame_command, 22615796c8dcSSimon Schubert _("Print the current stack frame.\n")); 22625796c8dcSSimon Schubert add_com_alias ("V", "frame", class_stack, 1); 22635796c8dcSSimon Schubert } 22645796c8dcSSimon Schubert add_com ("select-frame", class_stack, select_frame_command, _("\ 22655796c8dcSSimon Schubert Select a stack frame without printing anything.\n\ 22665796c8dcSSimon Schubert An argument specifies the frame to select.\n\ 22675796c8dcSSimon Schubert It can be a stack frame number or the address of the frame.\n")); 22685796c8dcSSimon Schubert 22695796c8dcSSimon Schubert add_com ("backtrace", class_stack, backtrace_command, _("\ 22705796c8dcSSimon Schubert Print backtrace of all stack frames, or innermost COUNT frames.\n\ 2271*c50c785cSJohn Marino With a negative argument, print outermost -COUNT frames.\nUse of the \ 2272*c50c785cSJohn Marino 'full' qualifier also prints the values of the local variables.\n")); 22735796c8dcSSimon Schubert add_com_alias ("bt", "backtrace", class_stack, 0); 22745796c8dcSSimon Schubert if (xdb_commands) 22755796c8dcSSimon Schubert { 22765796c8dcSSimon Schubert add_com_alias ("t", "backtrace", class_stack, 0); 22775796c8dcSSimon Schubert add_com ("T", class_stack, backtrace_full_command, _("\ 22785796c8dcSSimon Schubert Print backtrace of all stack frames, or innermost COUNT frames\n\ 22795796c8dcSSimon Schubert and the values of the local variables.\n\ 22805796c8dcSSimon Schubert With a negative argument, print outermost -COUNT frames.\n\ 22815796c8dcSSimon Schubert Usage: T <count>\n")); 22825796c8dcSSimon Schubert } 22835796c8dcSSimon Schubert 22845796c8dcSSimon Schubert add_com_alias ("where", "backtrace", class_alias, 0); 22855796c8dcSSimon Schubert add_info ("stack", backtrace_command, 22865796c8dcSSimon Schubert _("Backtrace of the stack, or innermost COUNT frames.")); 22875796c8dcSSimon Schubert add_info_alias ("s", "stack", 1); 22885796c8dcSSimon Schubert add_info ("frame", frame_info, 22895796c8dcSSimon Schubert _("All about selected stack frame, or frame at ADDR.")); 22905796c8dcSSimon Schubert add_info_alias ("f", "frame", 1); 22915796c8dcSSimon Schubert add_info ("locals", locals_info, 22925796c8dcSSimon Schubert _("Local variables of current stack frame.")); 22935796c8dcSSimon Schubert add_info ("args", args_info, 22945796c8dcSSimon Schubert _("Argument variables of current stack frame.")); 22955796c8dcSSimon Schubert if (xdb_commands) 22965796c8dcSSimon Schubert add_com ("l", class_info, args_plus_locals_info, 22975796c8dcSSimon Schubert _("Argument and local variables of current stack frame.")); 22985796c8dcSSimon Schubert 22995796c8dcSSimon Schubert if (dbx_commands) 23005796c8dcSSimon Schubert add_com ("func", class_stack, func_command, _("\ 23015796c8dcSSimon Schubert Select the stack frame that contains <func>.\n\ 23025796c8dcSSimon Schubert Usage: func <name>\n")); 23035796c8dcSSimon Schubert 23045796c8dcSSimon Schubert add_info ("catch", catch_info, 23055796c8dcSSimon Schubert _("Exceptions that can be caught in the current stack frame.")); 23065796c8dcSSimon Schubert 23075796c8dcSSimon Schubert add_setshow_enum_cmd ("frame-arguments", class_stack, 23085796c8dcSSimon Schubert print_frame_arguments_choices, &print_frame_arguments, 23095796c8dcSSimon Schubert _("Set printing of non-scalar frame arguments"), 23105796c8dcSSimon Schubert _("Show printing of non-scalar frame arguments"), 23115796c8dcSSimon Schubert NULL, NULL, NULL, &setprintlist, &showprintlist); 23125796c8dcSSimon Schubert 23135796c8dcSSimon Schubert add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack, 23145796c8dcSSimon Schubert &disassemble_next_line, _("\ 2315*c50c785cSJohn Marino Set whether to disassemble next source line or insn when execution stops."), 2316*c50c785cSJohn Marino _("\ 2317*c50c785cSJohn Marino Show whether to disassemble next source line or insn when execution stops."), 2318*c50c785cSJohn Marino _("\ 23195796c8dcSSimon Schubert If ON, GDB will display disassembly of the next source line, in addition\n\ 23205796c8dcSSimon Schubert to displaying the source line itself. If the next source line cannot\n\ 23215796c8dcSSimon Schubert be displayed (e.g., source is unavailable or there's no line info), GDB\n\ 23225796c8dcSSimon Schubert will display disassembly of next instruction instead of showing the\n\ 23235796c8dcSSimon Schubert source line.\n\ 23245796c8dcSSimon Schubert If AUTO, display disassembly of next instruction only if the source line\n\ 23255796c8dcSSimon Schubert cannot be displayed.\n\ 23265796c8dcSSimon Schubert If OFF (which is the default), never display the disassembly of the next\n\ 23275796c8dcSSimon Schubert source line."), 23285796c8dcSSimon Schubert NULL, 23295796c8dcSSimon Schubert show_disassemble_next_line, 23305796c8dcSSimon Schubert &setlist, &showlist); 23315796c8dcSSimon Schubert disassemble_next_line = AUTO_BOOLEAN_FALSE; 23325796c8dcSSimon Schubert } 2333