119370Spst/* Print and select stack frames for GDB, the GNU debugger. 219370Spst 398944Sobrien Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 4130803Smarcel 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free 5130803Smarcel Software Foundation, Inc. 619370Spst 798944Sobrien This file is part of GDB. 819370Spst 998944Sobrien This program is free software; you can redistribute it and/or modify 1098944Sobrien it under the terms of the GNU General Public License as published by 1198944Sobrien the Free Software Foundation; either version 2 of the License, or 1298944Sobrien (at your option) any later version. 1319370Spst 1498944Sobrien This program is distributed in the hope that it will be useful, 1598944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1698944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1798944Sobrien GNU General Public License for more details. 1819370Spst 1998944Sobrien You should have received a copy of the GNU General Public License 2098944Sobrien along with this program; if not, write to the Free Software 2198944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2298944Sobrien Boston, MA 02111-1307, USA. */ 2398944Sobrien 2446283Sdfr#include <ctype.h> 2519370Spst#include "defs.h" 2619370Spst#include "gdb_string.h" 2719370Spst#include "value.h" 2819370Spst#include "symtab.h" 2919370Spst#include "gdbtypes.h" 3019370Spst#include "expression.h" 3119370Spst#include "language.h" 3219370Spst#include "frame.h" 3319370Spst#include "gdbcmd.h" 3419370Spst#include "gdbcore.h" 3519370Spst#include "target.h" 36130803Smarcel#include "source.h" 3719370Spst#include "breakpoint.h" 3819370Spst#include "demangle.h" 3919370Spst#include "inferior.h" 4019370Spst#include "annotate.h" 4198944Sobrien#include "ui-out.h" 42130803Smarcel#include "block.h" 43130803Smarcel#include "stack.h" 44130803Smarcel#include "gdb_assert.h" 45130803Smarcel#include "dictionary.h" 46130803Smarcel#include "reggroups.h" 47130803Smarcel#include "regcache.h" 4819370Spst 4946283Sdfr/* Prototypes for exported functions. */ 5046283Sdfr 5198944Sobrienvoid args_info (char *, int); 5246283Sdfr 5398944Sobrienvoid locals_info (char *, int); 5446283Sdfr 5598944Sobrienvoid (*selected_frame_level_changed_hook) (int); 5646283Sdfr 5798944Sobrienvoid _initialize_stack (void); 5846283Sdfr 5946283Sdfr/* Prototypes for local functions. */ 6046283Sdfr 6198944Sobrienstatic void down_command (char *, int); 6219370Spst 6398944Sobrienstatic void down_silently_base (char *); 6446283Sdfr 6598944Sobrienstatic void down_silently_command (char *, int); 6619370Spst 6798944Sobrienstatic void up_command (char *, int); 6819370Spst 6998944Sobrienstatic void up_silently_base (char *); 7046283Sdfr 7198944Sobrienstatic void up_silently_command (char *, int); 7219370Spst 7398944Sobrienvoid frame_command (char *, int); 7419370Spst 7598944Sobrienstatic void current_frame_command (char *, int); 7619370Spst 7798944Sobrienstatic void print_frame_arg_vars (struct frame_info *, struct ui_file *); 7819370Spst 7998944Sobrienstatic void catch_info (char *, int); 8019370Spst 8198944Sobrienstatic void args_plus_locals_info (char *, int); 8219370Spst 8398944Sobrienstatic void print_frame_label_vars (struct frame_info *, int, 8498944Sobrien struct ui_file *); 8519370Spst 8698944Sobrienstatic void print_frame_local_vars (struct frame_info *, int, 8798944Sobrien struct ui_file *); 8819370Spst 8998944Sobrienstatic int print_block_frame_labels (struct block *, int *, 9098944Sobrien struct ui_file *); 9119370Spst 9298944Sobrienstatic int print_block_frame_locals (struct block *, 9398944Sobrien struct frame_info *, 9498944Sobrien int, 9598944Sobrien struct ui_file *); 9646283Sdfr 9798944Sobrienstatic void print_frame (struct frame_info *fi, 9898944Sobrien int level, 9998944Sobrien int source, 10098944Sobrien int args, 10198944Sobrien struct symtab_and_line sal); 10219370Spst 10398944Sobrienstatic void backtrace_command (char *, int); 10498944Sobrien 10598944Sobrienstruct frame_info *parse_frame_specification (char *); 10698944Sobrien 10798944Sobrienstatic void frame_info (char *, int); 10898944Sobrien 10919370Spstextern int addressprint; /* Print addresses, or stay symbolic only? */ 11019370Spst 11119370Spst/* Zero means do things normally; we are interacting directly with the 11219370Spst user. One means print the full filename and linenumber when a 11319370Spst frame is printed, and do so in a format emacs18/emacs19.22 can 11419370Spst parse. Two means print similar annotations, but in many more 11519370Spst cases and in a slightly different syntax. */ 11619370Spst 11719370Spstint annotation_level = 0; 11819370Spst 11919370Spst 12098944Sobrienstruct print_stack_frame_args 12198944Sobrien { 12298944Sobrien struct frame_info *fi; 12398944Sobrien int level; 12498944Sobrien int source; 12598944Sobrien int args; 12698944Sobrien }; 12719370Spst 12846283Sdfr/* Show or print the frame arguments. 12946283Sdfr Pass the args the way catch_errors wants them. */ 13098944Sobrienstatic int print_stack_frame_stub (void *args); 13146283Sdfrstatic int 13298944Sobrienprint_stack_frame_stub (void *args) 13346283Sdfr{ 13498944Sobrien struct print_stack_frame_args *p = (struct print_stack_frame_args *) args; 13546283Sdfr 136130803Smarcel print_frame_info (p->fi, p->level, p->source, p->args); 13746283Sdfr return 0; 13846283Sdfr} 13946283Sdfr 140130803Smarcel/* Show or print a stack frame briefly. FRAME_INFI should be the frame info 14119370Spst and LEVEL should be its level in the stack (or -1 for level not defined). 14219370Spst This prints the level, the function executing, the arguments, 14319370Spst and the file name and line number. 14419370Spst If the pc is not at the beginning of the source line, 14519370Spst the actual pc is printed at the beginning. 14619370Spst 14719370Spst If SOURCE is 1, print the source line as well. 14819370Spst If SOURCE is -1, print ONLY the source line. */ 14919370Spst 150130803Smarcelvoid 151130803Smarcelprint_stack_frame (struct frame_info *fi, int level, int source) 15246283Sdfr{ 15346283Sdfr struct print_stack_frame_args args; 15446283Sdfr 15546283Sdfr args.fi = fi; 15646283Sdfr args.level = level; 15746283Sdfr args.source = source; 15846283Sdfr args.args = 1; 15946283Sdfr 160130803Smarcel catch_errors (print_stack_frame_stub, (char *) &args, "", RETURN_MASK_ALL); 161130803Smarcel} 162130803Smarcel 163130803Smarcelstruct print_args_args 164130803Smarcel{ 165130803Smarcel struct symbol *func; 166130803Smarcel struct frame_info *fi; 167130803Smarcel struct ui_file *stream; 168130803Smarcel}; 169130803Smarcel 170130803Smarcelstatic int print_args_stub (void *); 171130803Smarcel 172130803Smarcel/* Print nameless args on STREAM. 173130803Smarcel FI is the frameinfo for this frame, START is the offset 174130803Smarcel of the first nameless arg, and NUM is the number of nameless args to 175130803Smarcel print. FIRST is nonzero if this is the first argument (not just 176130803Smarcel the first nameless arg). */ 177130803Smarcel 178130803Smarcelstatic void 179130803Smarcelprint_frame_nameless_args (struct frame_info *fi, long start, int num, 180130803Smarcel int first, struct ui_file *stream) 181130803Smarcel{ 182130803Smarcel int i; 183130803Smarcel CORE_ADDR argsaddr; 184130803Smarcel long arg_value; 185130803Smarcel 186130803Smarcel for (i = 0; i < num; i++) 187130803Smarcel { 188130803Smarcel QUIT; 189130803Smarcel argsaddr = get_frame_args_address (fi); 190130803Smarcel if (!argsaddr) 191130803Smarcel return; 192130803Smarcel arg_value = read_memory_integer (argsaddr + start, sizeof (int)); 193130803Smarcel if (!first) 194130803Smarcel fprintf_filtered (stream, ", "); 195130803Smarcel fprintf_filtered (stream, "%ld", arg_value); 196130803Smarcel first = 0; 197130803Smarcel start += sizeof (int); 198130803Smarcel } 19946283Sdfr} 20046283Sdfr 201130803Smarcel/* Print the arguments of a stack frame, given the function FUNC 202130803Smarcel running in that frame (as a symbol), the info on the frame, 203130803Smarcel and the number of args according to the stack frame (or -1 if unknown). */ 20446283Sdfr 205130803Smarcel/* References here and elsewhere to "number of args according to the 206130803Smarcel stack frame" appear in all cases to refer to "number of ints of args 207130803Smarcel according to the stack frame". At least for VAX, i386, isi. */ 20846283Sdfr 209130803Smarcelstatic void 210130803Smarcelprint_frame_args (struct symbol *func, struct frame_info *fi, int num, 211130803Smarcel struct ui_file *stream) 21246283Sdfr{ 213130803Smarcel struct block *b = NULL; 214130803Smarcel int first = 1; 215130803Smarcel struct dict_iterator iter; 216130803Smarcel struct symbol *sym; 217130803Smarcel struct value *val; 218130803Smarcel /* Offset of next stack argument beyond the one we have seen that is 219130803Smarcel at the highest offset. 220130803Smarcel -1 if we haven't come to a stack argument yet. */ 221130803Smarcel long highest_offset = -1; 222130803Smarcel int arg_size; 223130803Smarcel /* Number of ints of arguments that we have printed so far. */ 224130803Smarcel int args_printed = 0; 225130803Smarcel struct cleanup *old_chain, *list_chain; 226130803Smarcel struct ui_stream *stb; 22746283Sdfr 228130803Smarcel stb = ui_out_stream_new (uiout); 229130803Smarcel old_chain = make_cleanup_ui_out_stream_delete (stb); 23046283Sdfr 231130803Smarcel if (func) 232130803Smarcel { 233130803Smarcel b = SYMBOL_BLOCK_VALUE (func); 23446283Sdfr 235130803Smarcel ALL_BLOCK_SYMBOLS (b, iter, sym) 236130803Smarcel { 237130803Smarcel QUIT; 23846283Sdfr 239130803Smarcel /* Keep track of the highest stack argument offset seen, and 240130803Smarcel skip over any kinds of symbols we don't care about. */ 24146283Sdfr 242130803Smarcel switch (SYMBOL_CLASS (sym)) 243130803Smarcel { 244130803Smarcel case LOC_ARG: 245130803Smarcel case LOC_REF_ARG: 246130803Smarcel { 247130803Smarcel long current_offset = SYMBOL_VALUE (sym); 248130803Smarcel arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym)); 24946283Sdfr 250130803Smarcel /* Compute address of next argument by adding the size of 251130803Smarcel this argument and rounding to an int boundary. */ 252130803Smarcel current_offset = 253130803Smarcel ((current_offset + arg_size + sizeof (int) - 1) 254130803Smarcel & ~(sizeof (int) - 1)); 25519370Spst 256130803Smarcel /* If this is the highest offset seen yet, set highest_offset. */ 257130803Smarcel if (highest_offset == -1 258130803Smarcel || (current_offset > highest_offset)) 259130803Smarcel highest_offset = current_offset; 26019370Spst 261130803Smarcel /* Add the number of ints we're about to print to args_printed. */ 262130803Smarcel args_printed += (arg_size + sizeof (int) - 1) / sizeof (int); 263130803Smarcel } 26419370Spst 265130803Smarcel /* We care about types of symbols, but don't need to keep track of 266130803Smarcel stack offsets in them. */ 267130803Smarcel case LOC_REGPARM: 268130803Smarcel case LOC_REGPARM_ADDR: 269130803Smarcel case LOC_LOCAL_ARG: 270130803Smarcel case LOC_BASEREG_ARG: 271130803Smarcel case LOC_COMPUTED_ARG: 272130803Smarcel break; 27346283Sdfr 274130803Smarcel /* Other types of symbols we just skip over. */ 275130803Smarcel default: 276130803Smarcel continue; 277130803Smarcel } 27846283Sdfr 279130803Smarcel /* We have to look up the symbol because arguments can have 280130803Smarcel two entries (one a parameter, one a local) and the one we 281130803Smarcel want is the local, which lookup_symbol will find for us. 282130803Smarcel This includes gcc1 (not gcc2) on the sparc when passing a 283130803Smarcel small structure and gcc2 when the argument type is float 284130803Smarcel and it is passed as a double and converted to float by 285130803Smarcel the prologue (in the latter case the type of the LOC_ARG 286130803Smarcel symbol is double and the type of the LOC_LOCAL symbol is 287130803Smarcel float). */ 288130803Smarcel /* But if the parameter name is null, don't try it. 289130803Smarcel Null parameter names occur on the RS/6000, for traceback tables. 290130803Smarcel FIXME, should we even print them? */ 29146283Sdfr 292130803Smarcel if (*DEPRECATED_SYMBOL_NAME (sym)) 293130803Smarcel { 294130803Smarcel struct symbol *nsym; 295130803Smarcel nsym = lookup_symbol 296130803Smarcel (DEPRECATED_SYMBOL_NAME (sym), 297130803Smarcel b, VAR_DOMAIN, (int *) NULL, (struct symtab **) NULL); 298130803Smarcel if (SYMBOL_CLASS (nsym) == LOC_REGISTER) 299130803Smarcel { 300130803Smarcel /* There is a LOC_ARG/LOC_REGISTER pair. This means that 301130803Smarcel it was passed on the stack and loaded into a register, 302130803Smarcel or passed in a register and stored in a stack slot. 303130803Smarcel GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER. 30446283Sdfr 305130803Smarcel Reasons for using the LOC_ARG: 306130803Smarcel (1) because find_saved_registers may be slow for remote 307130803Smarcel debugging, 308130803Smarcel (2) because registers are often re-used and stack slots 309130803Smarcel rarely (never?) are. Therefore using the stack slot is 310130803Smarcel much less likely to print garbage. 31146283Sdfr 312130803Smarcel Reasons why we might want to use the LOC_REGISTER: 313130803Smarcel (1) So that the backtrace prints the same value as 314130803Smarcel "print foo". I see no compelling reason why this needs 315130803Smarcel to be the case; having the backtrace print the value which 316130803Smarcel was passed in, and "print foo" print the value as modified 317130803Smarcel within the called function, makes perfect sense to me. 31819370Spst 319130803Smarcel Additional note: It might be nice if "info args" displayed 320130803Smarcel both values. 321130803Smarcel One more note: There is a case with sparc structure passing 322130803Smarcel where we need to use the LOC_REGISTER, but this is dealt with 323130803Smarcel by creating a single LOC_REGPARM in symbol reading. */ 32419370Spst 325130803Smarcel /* Leave sym (the LOC_ARG) alone. */ 326130803Smarcel ; 327130803Smarcel } 328130803Smarcel else 329130803Smarcel sym = nsym; 330130803Smarcel } 331130803Smarcel 332130803Smarcel /* Print the current arg. */ 333130803Smarcel if (!first) 334130803Smarcel ui_out_text (uiout, ", "); 335130803Smarcel ui_out_wrap_hint (uiout, " "); 336130803Smarcel 337130803Smarcel annotate_arg_begin (); 338130803Smarcel 339130803Smarcel list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); 340130803Smarcel fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (sym), 341130803Smarcel SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI); 342130803Smarcel ui_out_field_stream (uiout, "name", stb); 343130803Smarcel annotate_arg_name_end (); 344130803Smarcel ui_out_text (uiout, "="); 345130803Smarcel 346130803Smarcel /* Avoid value_print because it will deref ref parameters. We just 347130803Smarcel want to print their addresses. Print ??? for args whose address 348130803Smarcel we do not know. We pass 2 as "recurse" to val_print because our 349130803Smarcel standard indentation here is 4 spaces, and val_print indents 350130803Smarcel 2 for each recurse. */ 351130803Smarcel val = read_var_value (sym, fi); 352130803Smarcel 353130803Smarcel annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val)); 354130803Smarcel 355130803Smarcel if (val) 356130803Smarcel { 357242936Semaste common_val_print (val, stb->stream, 0, 0, 2, Val_no_prettyprint); 358130803Smarcel ui_out_field_stream (uiout, "value", stb); 359130803Smarcel } 360130803Smarcel else 361130803Smarcel ui_out_text (uiout, "???"); 362130803Smarcel 363130803Smarcel /* Invoke ui_out_tuple_end. */ 364130803Smarcel do_cleanups (list_chain); 365130803Smarcel 366130803Smarcel annotate_arg_end (); 367130803Smarcel 368130803Smarcel first = 0; 369130803Smarcel } 370130803Smarcel } 371130803Smarcel 372130803Smarcel /* Don't print nameless args in situations where we don't know 373130803Smarcel enough about the stack to find them. */ 374130803Smarcel if (num != -1) 375130803Smarcel { 376130803Smarcel long start; 377130803Smarcel 378130803Smarcel if (highest_offset == -1) 379130803Smarcel start = FRAME_ARGS_SKIP; 380130803Smarcel else 381130803Smarcel start = highest_offset; 382130803Smarcel 383130803Smarcel print_frame_nameless_args (fi, start, num - args_printed, 384130803Smarcel first, stream); 385130803Smarcel } 386130803Smarcel do_cleanups (old_chain); 387130803Smarcel} 388130803Smarcel 38919370Spst/* Pass the args the way catch_errors wants them. */ 39019370Spst 39119370Spststatic int 392130803Smarcelprint_args_stub (void *args) 39319370Spst{ 39419370Spst int numargs; 39598944Sobrien struct print_args_args *p = (struct print_args_args *) args; 39619370Spst 397130803Smarcel if (FRAME_NUM_ARGS_P ()) 398130803Smarcel { 399130803Smarcel numargs = FRAME_NUM_ARGS (p->fi); 400130803Smarcel gdb_assert (numargs >= 0); 401130803Smarcel } 402130803Smarcel else 403130803Smarcel numargs = -1; 40498944Sobrien print_frame_args (p->func, p->fi, numargs, p->stream); 40519370Spst return 0; 40619370Spst} 40719370Spst 40846283Sdfr/* Print information about a frame for frame "fi" at level "level". 40998944Sobrien Used in "where" output, also used to emit breakpoint or step 41098944Sobrien messages. 41198944Sobrien LEVEL is the level of the frame, or -1 if it is the 41298944Sobrien innermost frame but we don't want to print the level. 41398944Sobrien The meaning of the SOURCE argument is: 41498944Sobrien SRC_LINE: Print only source line 41598944Sobrien LOCATION: Print only location 41698944Sobrien LOC_AND_SRC: Print location and source line. */ 41719370Spst 418130803Smarcelvoid 419130803Smarcelprint_frame_info (struct frame_info *fi, int level, int source, int args) 42019370Spst{ 42119370Spst struct symtab_and_line sal; 42298944Sobrien int source_print; 42398944Sobrien int location_print; 42419370Spst 425130803Smarcel if (get_frame_type (fi) == DUMMY_FRAME 426130803Smarcel || get_frame_type (fi) == SIGTRAMP_FRAME) 427130803Smarcel { 428130803Smarcel struct cleanup *uiout_cleanup 429130803Smarcel = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); 43019370Spst 431130803Smarcel annotate_frame_begin (level == -1 ? 0 : level, get_frame_pc (fi)); 43219370Spst 43319370Spst /* Do this regardless of SOURCE because we don't have any source 43498944Sobrien to list for this frame. */ 43519370Spst if (level >= 0) 436130803Smarcel { 437130803Smarcel ui_out_text (uiout, "#"); 438130803Smarcel ui_out_field_fmt_int (uiout, 2, ui_left, "level", level); 439130803Smarcel } 440130803Smarcel if (ui_out_is_mi_like_p (uiout)) 441130803Smarcel { 442130803Smarcel annotate_frame_address (); 443130803Smarcel ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi)); 444130803Smarcel annotate_frame_address_end (); 445130803Smarcel } 446130803Smarcel 447130803Smarcel if (get_frame_type (fi) == DUMMY_FRAME) 448130803Smarcel { 449130803Smarcel annotate_function_call (); 450130803Smarcel ui_out_field_string (uiout, "func", "<function called from gdb>"); 451130803Smarcel } 452130803Smarcel else if (get_frame_type (fi) == SIGTRAMP_FRAME) 453130803Smarcel { 454130803Smarcel annotate_signal_handler_caller (); 455130803Smarcel ui_out_field_string (uiout, "func", "<signal handler called>"); 456130803Smarcel } 457130803Smarcel ui_out_text (uiout, "\n"); 45819370Spst annotate_frame_end (); 45919370Spst 460130803Smarcel do_cleanups (uiout_cleanup); 46119370Spst return; 46219370Spst } 46319370Spst 46419370Spst /* If fi is not the innermost frame, that normally means that fi->pc 465130803Smarcel points to *after* the call instruction, and we want to get the 466130803Smarcel line containing the call, never the next line. But if the next 467130803Smarcel frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame 468130803Smarcel was not entered as the result of a call, and we want to get the 469130803Smarcel line containing fi->pc. */ 470130803Smarcel find_frame_sal (fi, &sal); 47119370Spst 47298944Sobrien location_print = (source == LOCATION 47398944Sobrien || source == LOC_AND_ADDRESS 47498944Sobrien || source == SRC_AND_LOC); 47598944Sobrien 47698944Sobrien if (location_print || !sal.symtab) 47798944Sobrien print_frame (fi, level, source, args, sal); 47898944Sobrien 47998944Sobrien source_print = (source == SRC_LINE || source == SRC_AND_LOC); 48098944Sobrien 481130803Smarcel if (sal.symtab) 482130803Smarcel set_current_source_symtab_and_line (&sal); 483130803Smarcel 48498944Sobrien if (source_print && sal.symtab) 48598944Sobrien { 486130803Smarcel struct symtab_and_line cursal; 48798944Sobrien int done = 0; 488130803Smarcel int mid_statement = (source == SRC_LINE) && (get_frame_pc (fi) != sal.pc); 48998944Sobrien 49098944Sobrien if (annotation_level) 49198944Sobrien done = identify_source_line (sal.symtab, sal.line, mid_statement, 492130803Smarcel get_frame_pc (fi)); 49398944Sobrien if (!done) 49498944Sobrien { 49598944Sobrien if (print_frame_info_listing_hook) 496130803Smarcel print_frame_info_listing_hook (sal.symtab, sal.line, sal.line + 1, 0); 49798944Sobrien else 49898944Sobrien { 49998944Sobrien /* We used to do this earlier, but that is clearly 50098944Sobrien wrong. This function is used by many different 50198944Sobrien parts of gdb, including normal_stop in infrun.c, 50298944Sobrien which uses this to print out the current PC 50398944Sobrien when we stepi/nexti into the middle of a source 50498944Sobrien line. Only the command line really wants this 50598944Sobrien behavior. Other UIs probably would like the 50698944Sobrien ability to decide for themselves if it is desired. */ 50798944Sobrien if (addressprint && mid_statement) 50898944Sobrien { 509130803Smarcel ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi)); 51098944Sobrien ui_out_text (uiout, "\t"); 51198944Sobrien } 51298944Sobrien 51398944Sobrien print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); 51498944Sobrien } 51598944Sobrien } 516130803Smarcel /* Make sure we have at least a default source file */ 517130803Smarcel set_default_source_symtab_and_line (); 518130803Smarcel cursal = get_current_source_symtab_and_line (); 519130803Smarcel cursal.line = max (sal.line - get_lines_to_list () / 2, 1); 520130803Smarcel set_current_source_symtab_and_line (&cursal); 52198944Sobrien } 52298944Sobrien 52398944Sobrien if (source != 0) 524130803Smarcel set_default_breakpoint (1, get_frame_pc (fi), sal.symtab, sal.line); 52598944Sobrien 52698944Sobrien annotate_frame_end (); 52798944Sobrien 52898944Sobrien gdb_flush (gdb_stdout); 52998944Sobrien} 53098944Sobrien 53198944Sobrienstatic void 53298944Sobrienprint_frame (struct frame_info *fi, 53398944Sobrien int level, 53498944Sobrien int source, 53598944Sobrien int args, 53698944Sobrien struct symtab_and_line sal) 53798944Sobrien{ 53898944Sobrien struct symbol *func; 539130803Smarcel char *funname = 0; 54098944Sobrien enum language funlang = language_unknown; 54198944Sobrien struct ui_stream *stb; 54298944Sobrien struct cleanup *old_chain; 54398944Sobrien struct cleanup *list_chain; 54498944Sobrien 54598944Sobrien stb = ui_out_stream_new (uiout); 54698944Sobrien old_chain = make_cleanup_ui_out_stream_delete (stb); 54798944Sobrien 548130803Smarcel func = find_pc_function (get_frame_address_in_block (fi)); 54919370Spst if (func) 55019370Spst { 55119370Spst /* In certain pathological cases, the symtabs give the wrong 55298944Sobrien function (when we are in the first function in a file which 55398944Sobrien is compiled without debugging symbols, the previous function 55498944Sobrien is compiled with debugging symbols, and the "foo.o" symbol 55598944Sobrien that is supposed to tell us where the file with debugging symbols 55698944Sobrien ends has been truncated by ar because it is longer than 15 55798944Sobrien characters). This also occurs if the user uses asm() to create 55898944Sobrien a function but not stabs for it (in a file compiled -g). 55919370Spst 56098944Sobrien So look in the minimal symbol tables as well, and if it comes 56198944Sobrien up with a larger address for the function use that instead. 56298944Sobrien I don't think this can ever cause any problems; there shouldn't 56398944Sobrien be any minimal symbols in the middle of a function; if this is 56498944Sobrien ever changed many parts of GDB will need to be changed (and we'll 56598944Sobrien create a find_pc_minimal_function or some such). */ 56619370Spst 567130803Smarcel struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi)); 56819370Spst if (msymbol != NULL 56998944Sobrien && (SYMBOL_VALUE_ADDRESS (msymbol) 57019370Spst > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) 57119370Spst { 57219370Spst#if 0 57319370Spst /* There is no particular reason to think the line number 57419370Spst information is wrong. Someone might have just put in 57519370Spst a label with asm() but left the line numbers alone. */ 57619370Spst /* In this case we have no way of knowing the source file 57719370Spst and line number, so don't print them. */ 57819370Spst sal.symtab = 0; 57919370Spst#endif 58019370Spst /* We also don't know anything about the function besides 58119370Spst its address and name. */ 58219370Spst func = 0; 583130803Smarcel funname = DEPRECATED_SYMBOL_NAME (msymbol); 58419370Spst funlang = SYMBOL_LANGUAGE (msymbol); 58519370Spst } 58619370Spst else 58719370Spst { 588130803Smarcel /* I'd like to use SYMBOL_PRINT_NAME() here, to display the 58998944Sobrien demangled name that we already have stored in the symbol 59098944Sobrien table, but we stored a version with DMGL_PARAMS turned 59198944Sobrien on, and here we don't want to display parameters. So call 59298944Sobrien the demangler again, with DMGL_ANSI only. (Yes, I know 59398944Sobrien that printf_symbol_filtered() will again try to demangle 59498944Sobrien the name on the fly, but the issue is that if 59598944Sobrien cplus_demangle() fails here, it'll fail there too. So we 59698944Sobrien want to catch the failure ("demangled==NULL" case below) 59798944Sobrien here, while we still have our hands on the function 59898944Sobrien symbol.) */ 59998944Sobrien char *demangled; 600130803Smarcel funname = DEPRECATED_SYMBOL_NAME (func); 60119370Spst funlang = SYMBOL_LANGUAGE (func); 60298944Sobrien if (funlang == language_cplus) 60398944Sobrien { 60498944Sobrien demangled = cplus_demangle (funname, DMGL_ANSI); 60598944Sobrien if (demangled == NULL) 60698944Sobrien /* If the demangler fails, try the demangled name from 60798944Sobrien the symbol table. This'll have parameters, but 60898944Sobrien that's preferable to diplaying a mangled name. */ 609130803Smarcel funname = SYMBOL_PRINT_NAME (func); 61098944Sobrien } 61119370Spst } 61219370Spst } 61319370Spst else 61419370Spst { 615130803Smarcel struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi)); 61646283Sdfr if (msymbol != NULL) 61719370Spst { 618130803Smarcel funname = DEPRECATED_SYMBOL_NAME (msymbol); 61946283Sdfr funlang = SYMBOL_LANGUAGE (msymbol); 62019370Spst } 62119370Spst } 62219370Spst 623130803Smarcel annotate_frame_begin (level == -1 ? 0 : level, get_frame_pc (fi)); 62419370Spst 62598944Sobrien list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); 62619370Spst 62798944Sobrien if (level >= 0) 62898944Sobrien { 62998944Sobrien ui_out_text (uiout, "#"); 630130803Smarcel ui_out_field_fmt_int (uiout, 2, ui_left, "level", level); 63119370Spst } 63298944Sobrien if (addressprint) 633130803Smarcel if (get_frame_pc (fi) != sal.pc 634130803Smarcel || !sal.symtab 635130803Smarcel || source == LOC_AND_ADDRESS) 63698944Sobrien { 63798944Sobrien annotate_frame_address (); 638130803Smarcel ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi)); 63998944Sobrien annotate_frame_address_end (); 64098944Sobrien ui_out_text (uiout, " in "); 64198944Sobrien } 64298944Sobrien annotate_frame_function_name (); 64398944Sobrien fprintf_symbol_filtered (stb->stream, funname ? funname : "??", funlang, 64498944Sobrien DMGL_ANSI); 64598944Sobrien ui_out_field_stream (uiout, "func", stb); 64698944Sobrien ui_out_wrap_hint (uiout, " "); 64798944Sobrien annotate_frame_args (); 64898944Sobrien 64998944Sobrien ui_out_text (uiout, " ("); 65098944Sobrien if (args) 65198944Sobrien { 65298944Sobrien struct print_args_args args; 65398944Sobrien struct cleanup *args_list_chain; 65498944Sobrien args.fi = fi; 65598944Sobrien args.func = func; 65698944Sobrien args.stream = gdb_stdout; 65798944Sobrien args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args"); 65898944Sobrien catch_errors (print_args_stub, &args, "", RETURN_MASK_ALL); 65998944Sobrien /* FIXME: args must be a list. If one argument is a string it will 66098944Sobrien have " that will not be properly escaped. */ 66198944Sobrien /* Invoke ui_out_tuple_end. */ 66298944Sobrien do_cleanups (args_list_chain); 66398944Sobrien QUIT; 66498944Sobrien } 66598944Sobrien ui_out_text (uiout, ")"); 66698944Sobrien if (sal.symtab && sal.symtab->filename) 66798944Sobrien { 66898944Sobrien annotate_frame_source_begin (); 66998944Sobrien ui_out_wrap_hint (uiout, " "); 67098944Sobrien ui_out_text (uiout, " at "); 67198944Sobrien annotate_frame_source_file (); 67298944Sobrien ui_out_field_string (uiout, "file", sal.symtab->filename); 67398944Sobrien annotate_frame_source_file_end (); 67498944Sobrien ui_out_text (uiout, ":"); 67598944Sobrien annotate_frame_source_line (); 67698944Sobrien ui_out_field_int (uiout, "line", sal.line); 67798944Sobrien annotate_frame_source_end (); 67898944Sobrien } 67919370Spst 68098944Sobrien#ifdef PC_SOLIB 68198944Sobrien if (!funname || (!sal.symtab || !sal.symtab->filename)) 68219370Spst { 683130803Smarcel char *lib = PC_SOLIB (get_frame_pc (fi)); 68498944Sobrien if (lib) 68519370Spst { 68698944Sobrien annotate_frame_where (); 68798944Sobrien ui_out_wrap_hint (uiout, " "); 68898944Sobrien ui_out_text (uiout, " from "); 68998944Sobrien ui_out_field_string (uiout, "from", lib); 69019370Spst } 69119370Spst } 69298944Sobrien#endif /* PC_SOLIB */ 69319370Spst 69498944Sobrien /* do_cleanups will call ui_out_tuple_end() for us. */ 69598944Sobrien do_cleanups (list_chain); 69698944Sobrien ui_out_text (uiout, "\n"); 69798944Sobrien do_cleanups (old_chain); 69819370Spst} 69946283Sdfr 70046283Sdfr/* Show the frame info. If this is the tui, it will be shown in 70146283Sdfr the source display otherwise, nothing is done */ 70246283Sdfrvoid 70398944Sobrienshow_stack_frame (struct frame_info *fi) 70446283Sdfr{ 70546283Sdfr} 70698944Sobrien 70746283Sdfr 70819370Spst/* Read a frame specification in whatever the appropriate format is. 70919370Spst Call error() if the specification is in any way invalid (i.e. 71019370Spst this function never returns NULL). */ 71119370Spst 71246283Sdfrstruct frame_info * 71398944Sobrienparse_frame_specification (char *frame_exp) 71419370Spst{ 71519370Spst int numargs = 0; 71619370Spst#define MAXARGS 4 71719370Spst CORE_ADDR args[MAXARGS]; 71898944Sobrien int level; 71998944Sobrien 72019370Spst if (frame_exp) 72119370Spst { 72219370Spst char *addr_string, *p; 72319370Spst struct cleanup *tmp_cleanup; 72419370Spst 72598944Sobrien while (*frame_exp == ' ') 72698944Sobrien frame_exp++; 72719370Spst 72819370Spst while (*frame_exp) 72919370Spst { 73019370Spst if (numargs > MAXARGS) 73119370Spst error ("Too many args in frame specification"); 73219370Spst /* Parse an argument. */ 73398944Sobrien for (p = frame_exp; *p && *p != ' '; p++) 73419370Spst ; 73598944Sobrien addr_string = savestring (frame_exp, p - frame_exp); 73619370Spst 73719370Spst { 73898944Sobrien struct value *vp; 73998944Sobrien 74098944Sobrien tmp_cleanup = make_cleanup (xfree, addr_string); 74198944Sobrien 74298944Sobrien /* NOTE: we call parse_and_eval and then both 74398944Sobrien value_as_long and value_as_address rather than calling 74498944Sobrien parse_and_eval_long and parse_and_eval_address because 74598944Sobrien of the issue of potential side effects from evaluating 74698944Sobrien the expression. */ 74798944Sobrien vp = parse_and_eval (addr_string); 74898944Sobrien if (numargs == 0) 74998944Sobrien level = value_as_long (vp); 75098944Sobrien 75198944Sobrien args[numargs++] = value_as_address (vp); 75219370Spst do_cleanups (tmp_cleanup); 75319370Spst } 75419370Spst 75519370Spst /* Skip spaces, move to possible next arg. */ 75698944Sobrien while (*p == ' ') 75798944Sobrien p++; 75819370Spst frame_exp = p; 75919370Spst } 76019370Spst } 76119370Spst 76219370Spst switch (numargs) 76319370Spst { 76419370Spst case 0: 765130803Smarcel if (deprecated_selected_frame == NULL) 76619370Spst error ("No selected frame."); 767130803Smarcel return deprecated_selected_frame; 76819370Spst /* NOTREACHED */ 76919370Spst case 1: 77019370Spst { 77119370Spst struct frame_info *fid = 77298944Sobrien find_relative_frame (get_current_frame (), &level); 77319370Spst struct frame_info *tfid; 77419370Spst 77519370Spst if (level == 0) 77619370Spst /* find_relative_frame was successful */ 77719370Spst return fid; 77819370Spst 77919370Spst /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications 78019370Spst take at least 2 addresses. It is important to detect this case 78119370Spst here so that "frame 100" does not give a confusing error message 78219370Spst like "frame specification requires two addresses". This of course 78319370Spst does not solve the "frame 100" problem for machines on which 78419370Spst a frame specification can be made with one address. To solve 78519370Spst that, we need a new syntax for a specifying a frame by address. 78619370Spst I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for 78719370Spst two args, etc.), but people might think that is too much typing, 78819370Spst so I guess *0x23,0x45 would be a possible alternative (commas 78919370Spst really should be used instead of spaces to delimit; using spaces 79019370Spst normally works in an expression). */ 79119370Spst#ifdef SETUP_ARBITRARY_FRAME 792130803Smarcel error ("No frame %s", paddr_d (args[0])); 79319370Spst#endif 79419370Spst 79519370Spst /* If (s)he specifies the frame with an address, he deserves what 79619370Spst (s)he gets. Still, give the highest one that matches. */ 79719370Spst 79819370Spst for (fid = get_current_frame (); 799130803Smarcel fid && get_frame_base (fid) != args[0]; 80019370Spst fid = get_prev_frame (fid)) 80119370Spst ; 80219370Spst 80319370Spst if (fid) 80419370Spst while ((tfid = get_prev_frame (fid)) && 805130803Smarcel (get_frame_base (tfid) == args[0])) 80619370Spst fid = tfid; 80798944Sobrien 80819370Spst /* We couldn't identify the frame as an existing frame, but 80919370Spst perhaps we can create one with a single argument. */ 81019370Spst } 81119370Spst 81298944Sobrien default: 81319370Spst#ifdef SETUP_ARBITRARY_FRAME 81419370Spst return SETUP_ARBITRARY_FRAME (numargs, args); 81519370Spst#else 81619370Spst /* Usual case. Do it here rather than have everyone supply 81798944Sobrien a SETUP_ARBITRARY_FRAME that does this. */ 81819370Spst if (numargs == 1) 81919370Spst return create_new_frame (args[0], 0); 82019370Spst error ("Too many args in frame specification"); 82119370Spst#endif 82219370Spst /* NOTREACHED */ 82319370Spst } 82419370Spst /* NOTREACHED */ 82519370Spst} 82619370Spst 82719370Spst/* Print verbosely the selected frame or the frame at address ADDR. 82819370Spst This means absolutely all information in the frame is printed. */ 82919370Spst 83019370Spststatic void 83198944Sobrienframe_info (char *addr_exp, int from_tty) 83219370Spst{ 83319370Spst struct frame_info *fi; 83419370Spst struct symtab_and_line sal; 83519370Spst struct symbol *func; 83619370Spst struct symtab *s; 83719370Spst struct frame_info *calling_frame_info; 83819370Spst int i, count, numregs; 83919370Spst char *funname = 0; 84019370Spst enum language funlang = language_unknown; 841130803Smarcel const char *pc_regname; 84219370Spst 84319370Spst if (!target_has_stack) 84419370Spst error ("No stack."); 84519370Spst 846130803Smarcel /* Name of the value returned by get_frame_pc(). Per comments, "pc" 847130803Smarcel is not a good name. */ 848130803Smarcel if (PC_REGNUM >= 0) 849130803Smarcel /* OK, this is weird. The PC_REGNUM hardware register's value can 850130803Smarcel easily not match that of the internal value returned by 851130803Smarcel get_frame_pc(). */ 852130803Smarcel pc_regname = REGISTER_NAME (PC_REGNUM); 853130803Smarcel else 854130803Smarcel /* But then, this is weird to. Even without PC_REGNUM, an 855130803Smarcel architectures will often have a hardware register called "pc", 856130803Smarcel and that register's value, again, can easily not match 857130803Smarcel get_frame_pc(). */ 858130803Smarcel pc_regname = "pc"; 859130803Smarcel 86019370Spst fi = parse_frame_specification (addr_exp); 86119370Spst if (fi == NULL) 86219370Spst error ("Invalid frame specified."); 86319370Spst 864130803Smarcel find_frame_sal (fi, &sal); 86519370Spst func = get_frame_function (fi); 866130803Smarcel /* FIXME: cagney/2002-11-28: Why bother? Won't sal.symtab contain 867130803Smarcel the same value. */ 868130803Smarcel s = find_pc_symtab (get_frame_pc (fi)); 86919370Spst if (func) 87019370Spst { 871130803Smarcel /* I'd like to use SYMBOL_PRINT_NAME() here, to display 87246283Sdfr * the demangled name that we already have stored in 87346283Sdfr * the symbol table, but we stored a version with 87446283Sdfr * DMGL_PARAMS turned on, and here we don't want 87546283Sdfr * to display parameters. So call the demangler again, 87646283Sdfr * with DMGL_ANSI only. RT 87746283Sdfr * (Yes, I know that printf_symbol_filtered() will 87846283Sdfr * again try to demangle the name on the fly, but 87946283Sdfr * the issue is that if cplus_demangle() fails here, 88046283Sdfr * it'll fail there too. So we want to catch the failure 88146283Sdfr * ("demangled==NULL" case below) here, while we still 88246283Sdfr * have our hands on the function symbol.) 88346283Sdfr */ 88498944Sobrien char *demangled; 885130803Smarcel funname = DEPRECATED_SYMBOL_NAME (func); 88698944Sobrien funlang = SYMBOL_LANGUAGE (func); 88798944Sobrien if (funlang == language_cplus) 88898944Sobrien { 88998944Sobrien demangled = cplus_demangle (funname, DMGL_ANSI); 89098944Sobrien /* If the demangler fails, try the demangled name 89198944Sobrien * from the symbol table. This'll have parameters, 89298944Sobrien * but that's preferable to diplaying a mangled name. 89398944Sobrien */ 89498944Sobrien if (demangled == NULL) 895130803Smarcel funname = SYMBOL_PRINT_NAME (func); 89698944Sobrien } 89719370Spst } 89819370Spst else 89919370Spst { 900130803Smarcel struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_pc (fi)); 90119370Spst if (msymbol != NULL) 90219370Spst { 903130803Smarcel funname = DEPRECATED_SYMBOL_NAME (msymbol); 90419370Spst funlang = SYMBOL_LANGUAGE (msymbol); 90519370Spst } 90619370Spst } 90719370Spst calling_frame_info = get_prev_frame (fi); 90819370Spst 909130803Smarcel if (!addr_exp && frame_relative_level (deprecated_selected_frame) >= 0) 91019370Spst { 911130803Smarcel printf_filtered ("Stack level %d, frame at ", 912130803Smarcel frame_relative_level (deprecated_selected_frame)); 913130803Smarcel print_address_numeric (get_frame_base (fi), 1, gdb_stdout); 91419370Spst printf_filtered (":\n"); 91519370Spst } 91619370Spst else 91719370Spst { 91819370Spst printf_filtered ("Stack frame at "); 919130803Smarcel print_address_numeric (get_frame_base (fi), 1, gdb_stdout); 92019370Spst printf_filtered (":\n"); 92119370Spst } 922130803Smarcel printf_filtered (" %s = ", pc_regname); 923130803Smarcel print_address_numeric (get_frame_pc (fi), 1, gdb_stdout); 92419370Spst 92519370Spst wrap_here (" "); 92619370Spst if (funname) 92719370Spst { 92819370Spst printf_filtered (" in "); 92919370Spst fprintf_symbol_filtered (gdb_stdout, funname, funlang, 93019370Spst DMGL_ANSI | DMGL_PARAMS); 93119370Spst } 93219370Spst wrap_here (" "); 93319370Spst if (sal.symtab) 93419370Spst printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line); 93519370Spst puts_filtered ("; "); 93619370Spst wrap_here (" "); 937130803Smarcel printf_filtered ("saved %s ", pc_regname); 938130803Smarcel print_address_numeric (frame_pc_unwind (fi), 1, gdb_stdout); 93919370Spst printf_filtered ("\n"); 94019370Spst 94119370Spst { 94298944Sobrien int frameless; 943130803Smarcel frameless = (DEPRECATED_FRAMELESS_FUNCTION_INVOCATION_P () 944130803Smarcel && DEPRECATED_FRAMELESS_FUNCTION_INVOCATION (fi)); 94519370Spst if (frameless) 94619370Spst printf_filtered (" (FRAMELESS),"); 94719370Spst } 94819370Spst 94919370Spst if (calling_frame_info) 95019370Spst { 95119370Spst printf_filtered (" called by frame at "); 952130803Smarcel print_address_numeric (get_frame_base (calling_frame_info), 953130803Smarcel 1, gdb_stdout); 95419370Spst } 955130803Smarcel if (get_next_frame (fi) && calling_frame_info) 95619370Spst puts_filtered (","); 95719370Spst wrap_here (" "); 958130803Smarcel if (get_next_frame (fi)) 95919370Spst { 96019370Spst printf_filtered (" caller of frame at "); 961130803Smarcel print_address_numeric (get_frame_base (get_next_frame (fi)), 1, 962130803Smarcel gdb_stdout); 96319370Spst } 964130803Smarcel if (get_next_frame (fi) || calling_frame_info) 96519370Spst puts_filtered ("\n"); 96619370Spst if (s) 967130803Smarcel printf_filtered (" source language %s.\n", 968130803Smarcel language_str (s->language)); 96919370Spst 97019370Spst { 97119370Spst /* Address of the argument list for this frame, or 0. */ 972130803Smarcel CORE_ADDR arg_list = get_frame_args_address (fi); 97319370Spst /* Number of args for this frame, or -1 if unknown. */ 97419370Spst int numargs; 97519370Spst 97619370Spst if (arg_list == 0) 97719370Spst printf_filtered (" Arglist at unknown address.\n"); 97819370Spst else 97919370Spst { 98019370Spst printf_filtered (" Arglist at "); 98119370Spst print_address_numeric (arg_list, 1, gdb_stdout); 98219370Spst printf_filtered (","); 98319370Spst 984130803Smarcel if (!FRAME_NUM_ARGS_P ()) 985130803Smarcel { 986130803Smarcel numargs = -1; 987130803Smarcel puts_filtered (" args: "); 988130803Smarcel } 98919370Spst else 990130803Smarcel { 991130803Smarcel numargs = FRAME_NUM_ARGS (fi); 992130803Smarcel gdb_assert (numargs >= 0); 993130803Smarcel if (numargs == 0) 994130803Smarcel puts_filtered (" no args."); 995130803Smarcel else if (numargs == 1) 996130803Smarcel puts_filtered (" 1 arg: "); 997130803Smarcel else 998130803Smarcel printf_filtered (" %d args: ", numargs); 999130803Smarcel } 100019370Spst print_frame_args (func, fi, numargs, gdb_stdout); 100119370Spst puts_filtered ("\n"); 100219370Spst } 100319370Spst } 100419370Spst { 100519370Spst /* Address of the local variables for this frame, or 0. */ 1006130803Smarcel CORE_ADDR arg_list = get_frame_locals_address (fi); 100719370Spst 100819370Spst if (arg_list == 0) 100919370Spst printf_filtered (" Locals at unknown address,"); 101019370Spst else 101119370Spst { 101219370Spst printf_filtered (" Locals at "); 101319370Spst print_address_numeric (arg_list, 1, gdb_stdout); 101419370Spst printf_filtered (","); 101519370Spst } 101619370Spst } 101719370Spst 1018130803Smarcel if (DEPRECATED_FRAME_INIT_SAVED_REGS_P () 1019130803Smarcel && deprecated_get_frame_saved_regs (fi) == NULL) 1020130803Smarcel DEPRECATED_FRAME_INIT_SAVED_REGS (fi); 1021130803Smarcel /* Print as much information as possible on the location of all the 1022130803Smarcel registers. */ 1023130803Smarcel { 1024130803Smarcel enum lval_type lval; 1025130803Smarcel int optimized; 1026130803Smarcel CORE_ADDR addr; 1027130803Smarcel int realnum; 1028130803Smarcel int count; 1029130803Smarcel int i; 1030130803Smarcel int need_nl = 1; 1031130803Smarcel 1032130803Smarcel /* The sp is special; what's displayed isn't the save address, but 1033130803Smarcel the value of the previous frame's sp. This is a legacy thing, 1034130803Smarcel at one stage the frame cached the previous frame's SP instead 1035130803Smarcel of its address, hence it was easiest to just display the cached 1036130803Smarcel value. */ 1037130803Smarcel if (SP_REGNUM >= 0) 1038130803Smarcel { 1039130803Smarcel /* Find out the location of the saved stack pointer with out 1040130803Smarcel actually evaluating it. */ 1041130803Smarcel frame_register_unwind (fi, SP_REGNUM, &optimized, &lval, &addr, 1042130803Smarcel &realnum, NULL); 1043130803Smarcel if (!optimized && lval == not_lval) 104446283Sdfr { 1045130803Smarcel char value[MAX_REGISTER_SIZE]; 1046130803Smarcel CORE_ADDR sp; 1047130803Smarcel frame_register_unwind (fi, SP_REGNUM, &optimized, &lval, &addr, 1048130803Smarcel &realnum, value); 1049130803Smarcel /* NOTE: cagney/2003-05-22: This is assuming that the 1050130803Smarcel stack pointer was packed as an unsigned integer. That 1051130803Smarcel may or may not be valid. */ 1052130803Smarcel sp = extract_unsigned_integer (value, DEPRECATED_REGISTER_RAW_SIZE (SP_REGNUM)); 1053130803Smarcel printf_filtered (" Previous frame's sp is "); 1054130803Smarcel print_address_numeric (sp, 1, gdb_stdout); 1055130803Smarcel printf_filtered ("\n"); 1056130803Smarcel need_nl = 0; 105746283Sdfr } 1058130803Smarcel else if (!optimized && lval == lval_memory) 1059130803Smarcel { 1060130803Smarcel printf_filtered (" Previous frame's sp at "); 1061130803Smarcel print_address_numeric (addr, 1, gdb_stdout); 1062130803Smarcel printf_filtered ("\n"); 1063130803Smarcel need_nl = 0; 1064130803Smarcel } 1065130803Smarcel else if (!optimized && lval == lval_register) 1066130803Smarcel { 1067130803Smarcel printf_filtered (" Previous frame's sp in %s\n", 1068130803Smarcel REGISTER_NAME (realnum)); 1069130803Smarcel need_nl = 0; 1070130803Smarcel } 1071130803Smarcel /* else keep quiet. */ 1072130803Smarcel } 1073130803Smarcel 1074130803Smarcel count = 0; 1075130803Smarcel numregs = NUM_REGS + NUM_PSEUDO_REGS; 1076130803Smarcel for (i = 0; i < numregs; i++) 1077130803Smarcel if (i != SP_REGNUM 1078130803Smarcel && gdbarch_register_reggroup_p (current_gdbarch, i, all_reggroup)) 1079130803Smarcel { 1080130803Smarcel /* Find out the location of the saved register without 1081130803Smarcel fetching the corresponding value. */ 1082130803Smarcel frame_register_unwind (fi, i, &optimized, &lval, &addr, &realnum, 1083130803Smarcel NULL); 1084130803Smarcel /* For moment, only display registers that were saved on the 1085130803Smarcel stack. */ 1086130803Smarcel if (!optimized && lval == lval_memory) 1087130803Smarcel { 1088130803Smarcel if (count == 0) 1089130803Smarcel puts_filtered (" Saved registers:\n "); 1090130803Smarcel else 1091130803Smarcel puts_filtered (","); 1092130803Smarcel wrap_here (" "); 1093130803Smarcel printf_filtered (" %s at ", REGISTER_NAME (i)); 1094130803Smarcel print_address_numeric (addr, 1, gdb_stdout); 1095130803Smarcel count++; 1096130803Smarcel } 1097130803Smarcel } 1098130803Smarcel if (count || need_nl) 109946283Sdfr puts_filtered ("\n"); 1100130803Smarcel } 110119370Spst} 110219370Spst 110319370Spst#if 0 110419370Spst/* Set a limit on the number of frames printed by default in a 110519370Spst backtrace. */ 110619370Spst 110719370Spststatic int backtrace_limit; 110819370Spst 110919370Spststatic void 111098944Sobrienset_backtrace_limit_command (char *count_exp, int from_tty) 111119370Spst{ 111298944Sobrien int count = parse_and_eval_long (count_exp); 111319370Spst 111419370Spst if (count < 0) 111519370Spst error ("Negative argument not meaningful as backtrace limit."); 111619370Spst 111719370Spst backtrace_limit = count; 111819370Spst} 111919370Spst 112019370Spststatic void 112198944Sobrienbacktrace_limit_info (char *arg, int from_tty) 112219370Spst{ 112319370Spst if (arg) 112419370Spst error ("\"Info backtrace-limit\" takes no arguments."); 112519370Spst 112619370Spst printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit); 112719370Spst} 112819370Spst#endif 112919370Spst 113019370Spst/* Print briefly all stack frames or just the innermost COUNT frames. */ 113119370Spst 113298944Sobrienstatic void backtrace_command_1 (char *count_exp, int show_locals, 113398944Sobrien int from_tty); 113419370Spststatic void 113598944Sobrienbacktrace_command_1 (char *count_exp, int show_locals, int from_tty) 113619370Spst{ 113719370Spst struct frame_info *fi; 1138130803Smarcel int count; 1139130803Smarcel int i; 1140130803Smarcel struct frame_info *trailing; 1141130803Smarcel int trailing_level; 114219370Spst 114319370Spst if (!target_has_stack) 114419370Spst error ("No stack."); 114519370Spst 114619370Spst /* The following code must do two things. First, it must 114719370Spst set the variable TRAILING to the frame from which we should start 114819370Spst printing. Second, it must set the variable count to the number 114919370Spst of frames which we should print, or -1 if all of them. */ 115019370Spst trailing = get_current_frame (); 115198944Sobrien 115298944Sobrien /* The target can be in a state where there is no valid frames 115398944Sobrien (e.g., just connected). */ 115498944Sobrien if (trailing == NULL) 115598944Sobrien error ("No stack."); 115698944Sobrien 115719370Spst trailing_level = 0; 115819370Spst if (count_exp) 115919370Spst { 116098944Sobrien count = parse_and_eval_long (count_exp); 116119370Spst if (count < 0) 116219370Spst { 116319370Spst struct frame_info *current; 116419370Spst 116519370Spst count = -count; 116619370Spst 116719370Spst current = trailing; 116819370Spst while (current && count--) 116919370Spst { 117019370Spst QUIT; 117119370Spst current = get_prev_frame (current); 117219370Spst } 117398944Sobrien 117419370Spst /* Will stop when CURRENT reaches the top of the stack. TRAILING 117519370Spst will be COUNT below it. */ 117619370Spst while (current) 117719370Spst { 117819370Spst QUIT; 117919370Spst trailing = get_prev_frame (trailing); 118019370Spst current = get_prev_frame (current); 118119370Spst trailing_level++; 118219370Spst } 118398944Sobrien 118419370Spst count = -1; 118519370Spst } 118619370Spst } 118719370Spst else 118819370Spst count = -1; 118919370Spst 119019370Spst if (info_verbose) 119119370Spst { 119219370Spst struct partial_symtab *ps; 119398944Sobrien 119419370Spst /* Read in symbols for all of the frames. Need to do this in 119598944Sobrien a separate pass so that "Reading in symbols for xxx" messages 119698944Sobrien don't screw up the appearance of the backtrace. Also 119798944Sobrien if people have strong opinions against reading symbols for 119898944Sobrien backtrace this may have to be an option. */ 119919370Spst i = count; 120019370Spst for (fi = trailing; 120119370Spst fi != NULL && i--; 120219370Spst fi = get_prev_frame (fi)) 120319370Spst { 120419370Spst QUIT; 1205130803Smarcel ps = find_pc_psymtab (get_frame_address_in_block (fi)); 120619370Spst if (ps) 120719370Spst PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */ 120819370Spst } 120919370Spst } 121019370Spst 121119370Spst for (i = 0, fi = trailing; 121219370Spst fi && count--; 121319370Spst i++, fi = get_prev_frame (fi)) 121419370Spst { 121519370Spst QUIT; 121619370Spst 121719370Spst /* Don't use print_stack_frame; if an error() occurs it probably 121898944Sobrien means further attempts to backtrace would fail (on the other 121998944Sobrien hand, perhaps the code does or could be fixed to make sure 122098944Sobrien the frame->prev field gets set to NULL in that case). */ 1221130803Smarcel print_frame_info (fi, trailing_level + i, 0, 1); 122246283Sdfr if (show_locals) 122398944Sobrien print_frame_local_vars (fi, 1, gdb_stdout); 122419370Spst } 122519370Spst 122619370Spst /* If we've stopped before the end, mention that. */ 122719370Spst if (fi && from_tty) 122819370Spst printf_filtered ("(More stack frames follow...)\n"); 122919370Spst} 123046283Sdfr 1231194061Savgstruct backtrace_command_args 1232194061Savg { 1233194061Savg char *count_exp; 1234194061Savg int show_locals; 1235194061Savg int from_tty; 1236194061Savg }; 1237194061Savg 1238194061Savg/* Stub to call backtrace_command_1 by way of an error catcher. */ 1239194061Savgstatic int 1240194061Savgbacktrace_command_stub (void *data) 1241194061Savg{ 1242194061Savg struct backtrace_command_args *args = (struct backtrace_command_args *)data; 1243194061Savg backtrace_command_1 (args->count_exp, args->show_locals, args->from_tty); 1244194061Savg return 0; 1245194061Savg} 1246194061Savg 124746283Sdfrstatic void 124898944Sobrienbacktrace_command (char *arg, int from_tty) 124946283Sdfr{ 125098944Sobrien struct cleanup *old_chain = (struct cleanup *) NULL; 125198944Sobrien char **argv = (char **) NULL; 125298944Sobrien int argIndicatingFullTrace = (-1), totArgLen = 0, argc = 0; 125398944Sobrien char *argPtr = arg; 1254194061Savg struct backtrace_command_args btargs; 125546283Sdfr 125698944Sobrien if (arg != (char *) NULL) 125746283Sdfr { 125846283Sdfr int i; 125946283Sdfr 126098944Sobrien argv = buildargv (arg); 126198944Sobrien old_chain = make_cleanup_freeargv (argv); 126246283Sdfr argc = 0; 126398944Sobrien for (i = 0; (argv[i] != (char *) NULL); i++) 126498944Sobrien { 126598944Sobrien unsigned int j; 126646283Sdfr 126798944Sobrien for (j = 0; (j < strlen (argv[i])); j++) 126898944Sobrien argv[i][j] = tolower (argv[i][j]); 126946283Sdfr 127098944Sobrien if (argIndicatingFullTrace < 0 && subset_compare (argv[i], "full")) 127198944Sobrien argIndicatingFullTrace = argc; 127298944Sobrien else 127398944Sobrien { 127498944Sobrien argc++; 127598944Sobrien totArgLen += strlen (argv[i]); 127698944Sobrien } 127798944Sobrien } 127846283Sdfr totArgLen += argc; 127946283Sdfr if (argIndicatingFullTrace >= 0) 128098944Sobrien { 128198944Sobrien if (totArgLen > 0) 128298944Sobrien { 128398944Sobrien argPtr = (char *) xmalloc (totArgLen + 1); 128498944Sobrien if (!argPtr) 128598944Sobrien nomem (0); 128698944Sobrien else 128798944Sobrien { 128898944Sobrien memset (argPtr, 0, totArgLen + 1); 128998944Sobrien for (i = 0; (i < (argc + 1)); i++) 129098944Sobrien { 129198944Sobrien if (i != argIndicatingFullTrace) 129298944Sobrien { 129398944Sobrien strcat (argPtr, argv[i]); 129498944Sobrien strcat (argPtr, " "); 129598944Sobrien } 129698944Sobrien } 129798944Sobrien } 129898944Sobrien } 129998944Sobrien else 130098944Sobrien argPtr = (char *) NULL; 130198944Sobrien } 130246283Sdfr } 130346283Sdfr 1304194061Savg btargs.count_exp = argPtr; 1305194061Savg btargs.show_locals = (argIndicatingFullTrace >= 0); 1306194061Savg btargs.from_tty = from_tty; 1307194061Savg catch_errors (backtrace_command_stub, (char *)&btargs, "", RETURN_MASK_ERROR); 130846283Sdfr 130946283Sdfr if (argIndicatingFullTrace >= 0 && totArgLen > 0) 131098944Sobrien xfree (argPtr); 131146283Sdfr 131246283Sdfr if (old_chain) 131398944Sobrien do_cleanups (old_chain); 131446283Sdfr} 131546283Sdfr 131698944Sobrienstatic void backtrace_full_command (char *arg, int from_tty); 131746283Sdfrstatic void 131898944Sobrienbacktrace_full_command (char *arg, int from_tty) 131946283Sdfr{ 1320194061Savg struct backtrace_command_args btargs; 1321194061Savg btargs.count_exp = arg; 1322194061Savg btargs.show_locals = 1; 1323194061Savg btargs.from_tty = from_tty; 1324194061Savg catch_errors (backtrace_command_stub, (char *)&btargs, "", RETURN_MASK_ERROR); 132546283Sdfr} 132698944Sobrien 132746283Sdfr 132819370Spst/* Print the local variables of a block B active in FRAME. 132919370Spst Return 1 if any variables were printed; 0 otherwise. */ 133019370Spst 133119370Spststatic int 1332130803Smarcelprint_block_frame_locals (struct block *b, struct frame_info *fi, 1333130803Smarcel int num_tabs, struct ui_file *stream) 133419370Spst{ 1335130803Smarcel struct dict_iterator iter; 1336130803Smarcel int j; 1337130803Smarcel struct symbol *sym; 1338130803Smarcel int values_printed = 0; 133919370Spst 1340130803Smarcel ALL_BLOCK_SYMBOLS (b, iter, sym) 134119370Spst { 134219370Spst switch (SYMBOL_CLASS (sym)) 134319370Spst { 134419370Spst case LOC_LOCAL: 134519370Spst case LOC_REGISTER: 134619370Spst case LOC_STATIC: 134719370Spst case LOC_BASEREG: 1348130803Smarcel case LOC_COMPUTED: 134919370Spst values_printed = 1; 135046283Sdfr for (j = 0; j < num_tabs; j++) 135198944Sobrien fputs_filtered ("\t", stream); 1352130803Smarcel fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); 135319370Spst fputs_filtered (" = ", stream); 135419370Spst print_variable_value (sym, fi, stream); 135519370Spst fprintf_filtered (stream, "\n"); 135619370Spst break; 135719370Spst 135819370Spst default: 135919370Spst /* Ignore symbols which are not locals. */ 136019370Spst break; 136119370Spst } 136219370Spst } 136319370Spst return values_printed; 136419370Spst} 136519370Spst 136619370Spst/* Same, but print labels. */ 136719370Spst 136819370Spststatic int 136998944Sobrienprint_block_frame_labels (struct block *b, int *have_default, 1370130803Smarcel struct ui_file *stream) 137119370Spst{ 1372130803Smarcel struct dict_iterator iter; 1373130803Smarcel struct symbol *sym; 1374130803Smarcel int values_printed = 0; 137519370Spst 1376130803Smarcel ALL_BLOCK_SYMBOLS (b, iter, sym) 137719370Spst { 1378130803Smarcel if (DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (sym), "default")) 137919370Spst { 138019370Spst if (*have_default) 138119370Spst continue; 138219370Spst *have_default = 1; 138319370Spst } 138419370Spst if (SYMBOL_CLASS (sym) == LOC_LABEL) 138519370Spst { 138619370Spst struct symtab_and_line sal; 138719370Spst sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); 138819370Spst values_printed = 1; 1389130803Smarcel fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); 139019370Spst if (addressprint) 139119370Spst { 139219370Spst fprintf_filtered (stream, " "); 139319370Spst print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream); 139419370Spst } 139519370Spst fprintf_filtered (stream, " in file %s, line %d\n", 139619370Spst sal.symtab->filename, sal.line); 139719370Spst } 139819370Spst } 139919370Spst return values_printed; 140019370Spst} 140119370Spst 140219370Spst/* Print on STREAM all the local variables in frame FRAME, 140319370Spst including all the blocks active in that frame 140419370Spst at its current pc. 140519370Spst 140619370Spst Returns 1 if the job was done, 140719370Spst or 0 if nothing was printed because we have no info 140819370Spst on the function running in FRAME. */ 140919370Spst 141019370Spststatic void 1411130803Smarcelprint_frame_local_vars (struct frame_info *fi, int num_tabs, 1412130803Smarcel struct ui_file *stream) 141319370Spst{ 1414130803Smarcel struct block *block = get_frame_block (fi, 0); 1415130803Smarcel int values_printed = 0; 141619370Spst 141719370Spst if (block == 0) 141819370Spst { 141919370Spst fprintf_filtered (stream, "No symbol table info available.\n"); 142019370Spst return; 142119370Spst } 142298944Sobrien 142319370Spst while (block != 0) 142419370Spst { 142546283Sdfr if (print_block_frame_locals (block, fi, num_tabs, stream)) 142619370Spst values_printed = 1; 142719370Spst /* After handling the function's top-level block, stop. 142898944Sobrien Don't continue to its superblock, the block of 142998944Sobrien per-file symbols. */ 143019370Spst if (BLOCK_FUNCTION (block)) 143119370Spst break; 143219370Spst block = BLOCK_SUPERBLOCK (block); 143319370Spst } 143419370Spst 143519370Spst if (!values_printed) 143619370Spst { 143719370Spst fprintf_filtered (stream, "No locals.\n"); 143819370Spst } 143919370Spst} 144019370Spst 144119370Spst/* Same, but print labels. */ 144219370Spst 144319370Spststatic void 1444130803Smarcelprint_frame_label_vars (struct frame_info *fi, int this_level_only, 1445130803Smarcel struct ui_file *stream) 144619370Spst{ 1447130803Smarcel struct blockvector *bl; 1448130803Smarcel struct block *block = get_frame_block (fi, 0); 1449130803Smarcel int values_printed = 0; 145019370Spst int index, have_default = 0; 145119370Spst char *blocks_printed; 1452130803Smarcel CORE_ADDR pc = get_frame_pc (fi); 145319370Spst 145419370Spst if (block == 0) 145519370Spst { 145619370Spst fprintf_filtered (stream, "No symbol table info available.\n"); 145719370Spst return; 145819370Spst } 145919370Spst 146019370Spst bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); 146119370Spst blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); 146219370Spst memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); 146319370Spst 146419370Spst while (block != 0) 146519370Spst { 146619370Spst CORE_ADDR end = BLOCK_END (block) - 4; 146719370Spst int last_index; 146819370Spst 146919370Spst if (bl != blockvector_for_pc (end, &index)) 147019370Spst error ("blockvector blotch"); 147119370Spst if (BLOCKVECTOR_BLOCK (bl, index) != block) 147219370Spst error ("blockvector botch"); 147319370Spst last_index = BLOCKVECTOR_NBLOCKS (bl); 147419370Spst index += 1; 147519370Spst 147619370Spst /* Don't print out blocks that have gone by. */ 147719370Spst while (index < last_index 147819370Spst && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) 147919370Spst index++; 148019370Spst 148119370Spst while (index < last_index 148219370Spst && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) 148319370Spst { 148419370Spst if (blocks_printed[index] == 0) 148519370Spst { 148619370Spst if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream)) 148719370Spst values_printed = 1; 148819370Spst blocks_printed[index] = 1; 148919370Spst } 149019370Spst index++; 149119370Spst } 149219370Spst if (have_default) 149319370Spst return; 149419370Spst if (values_printed && this_level_only) 149519370Spst return; 149619370Spst 149719370Spst /* After handling the function's top-level block, stop. 149898944Sobrien Don't continue to its superblock, the block of 149998944Sobrien per-file symbols. */ 150019370Spst if (BLOCK_FUNCTION (block)) 150119370Spst break; 150219370Spst block = BLOCK_SUPERBLOCK (block); 150319370Spst } 150419370Spst 150519370Spst if (!values_printed && !this_level_only) 150619370Spst { 150719370Spst fprintf_filtered (stream, "No catches.\n"); 150819370Spst } 150919370Spst} 151019370Spst 151146283Sdfrvoid 151298944Sobrienlocals_info (char *args, int from_tty) 151319370Spst{ 1514130803Smarcel if (!deprecated_selected_frame) 151519370Spst error ("No frame selected."); 1516130803Smarcel print_frame_local_vars (deprecated_selected_frame, 0, gdb_stdout); 151719370Spst} 151819370Spst 151919370Spststatic void 152098944Sobriencatch_info (char *ignore, int from_tty) 152119370Spst{ 152298944Sobrien struct symtab_and_line *sal; 152346283Sdfr 152498944Sobrien /* Check for target support for exception handling */ 152546283Sdfr sal = target_enable_exception_callback (EX_EVENT_CATCH, 1); 152646283Sdfr if (sal) 152746283Sdfr { 152846283Sdfr /* Currently not handling this */ 152946283Sdfr /* Ideally, here we should interact with the C++ runtime 153046283Sdfr system to find the list of active handlers, etc. */ 153146283Sdfr fprintf_filtered (gdb_stdout, "Info catch not supported with this target/compiler combination.\n"); 153246283Sdfr#if 0 1533130803Smarcel if (!deprecated_selected_frame) 153498944Sobrien error ("No frame selected."); 153546283Sdfr#endif 153646283Sdfr } 153746283Sdfr else 153846283Sdfr { 153998944Sobrien /* Assume g++ compiled code -- old v 4.16 behaviour */ 1540130803Smarcel if (!deprecated_selected_frame) 154198944Sobrien error ("No frame selected."); 154298944Sobrien 1543130803Smarcel print_frame_label_vars (deprecated_selected_frame, 0, gdb_stdout); 154446283Sdfr } 154519370Spst} 154619370Spst 154719370Spststatic void 1548130803Smarcelprint_frame_arg_vars (struct frame_info *fi, 1549130803Smarcel struct ui_file *stream) 155019370Spst{ 155119370Spst struct symbol *func = get_frame_function (fi); 1552130803Smarcel struct block *b; 1553130803Smarcel struct dict_iterator iter; 1554130803Smarcel struct symbol *sym, *sym2; 1555130803Smarcel int values_printed = 0; 155619370Spst 155719370Spst if (func == 0) 155819370Spst { 155919370Spst fprintf_filtered (stream, "No symbol table info available.\n"); 156019370Spst return; 156119370Spst } 156219370Spst 156319370Spst b = SYMBOL_BLOCK_VALUE (func); 1564130803Smarcel ALL_BLOCK_SYMBOLS (b, iter, sym) 156519370Spst { 156619370Spst switch (SYMBOL_CLASS (sym)) 156719370Spst { 156819370Spst case LOC_ARG: 156919370Spst case LOC_LOCAL_ARG: 157019370Spst case LOC_REF_ARG: 157119370Spst case LOC_REGPARM: 157219370Spst case LOC_REGPARM_ADDR: 157319370Spst case LOC_BASEREG_ARG: 1574130803Smarcel case LOC_COMPUTED_ARG: 157519370Spst values_printed = 1; 1576130803Smarcel fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); 157719370Spst fputs_filtered (" = ", stream); 157819370Spst 157919370Spst /* We have to look up the symbol because arguments can have 158019370Spst two entries (one a parameter, one a local) and the one we 158119370Spst want is the local, which lookup_symbol will find for us. 158219370Spst This includes gcc1 (not gcc2) on the sparc when passing a 158319370Spst small structure and gcc2 when the argument type is float 158419370Spst and it is passed as a double and converted to float by 158519370Spst the prologue (in the latter case the type of the LOC_ARG 158619370Spst symbol is double and the type of the LOC_LOCAL symbol is 158719370Spst float). There are also LOC_ARG/LOC_REGISTER pairs which 158819370Spst are not combined in symbol-reading. */ 158919370Spst 1590130803Smarcel sym2 = lookup_symbol (DEPRECATED_SYMBOL_NAME (sym), 1591130803Smarcel b, VAR_DOMAIN, (int *) NULL, (struct symtab **) NULL); 159219370Spst print_variable_value (sym2, fi, stream); 159319370Spst fprintf_filtered (stream, "\n"); 159419370Spst break; 159519370Spst 159619370Spst default: 159719370Spst /* Don't worry about things which aren't arguments. */ 159819370Spst break; 159919370Spst } 160019370Spst } 160119370Spst if (!values_printed) 160219370Spst { 160319370Spst fprintf_filtered (stream, "No arguments.\n"); 160419370Spst } 160519370Spst} 160619370Spst 160746283Sdfrvoid 160898944Sobrienargs_info (char *ignore, int from_tty) 160919370Spst{ 1610130803Smarcel if (!deprecated_selected_frame) 161119370Spst error ("No frame selected."); 1612130803Smarcel print_frame_arg_vars (deprecated_selected_frame, gdb_stdout); 161319370Spst} 161446283Sdfr 161546283Sdfr 161646283Sdfrstatic void 161798944Sobrienargs_plus_locals_info (char *ignore, int from_tty) 161846283Sdfr{ 161998944Sobrien args_info (ignore, from_tty); 162098944Sobrien locals_info (ignore, from_tty); 162146283Sdfr} 162298944Sobrien 162346283Sdfr 1624130803Smarcel/* Select frame FI. Also print the stack frame and show the source if 1625130803Smarcel this is the tui version. */ 1626130803Smarcelstatic void 1627130803Smarcelselect_and_print_frame (struct frame_info *fi) 162819370Spst{ 1629130803Smarcel select_frame (fi); 163019370Spst if (fi) 163198944Sobrien { 1632130803Smarcel print_stack_frame (fi, frame_relative_level (fi), 1); 163319370Spst } 163419370Spst} 163598944Sobrien 1636130803Smarcel/* Return the symbol-block in which the selected frame is executing. 1637130803Smarcel Can return zero under various legitimate circumstances. 163819370Spst 1639130803Smarcel If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant 1640130803Smarcel code address within the block returned. We use this to decide 1641130803Smarcel which macros are in scope. */ 164246283Sdfr 164319370Spststruct block * 1644130803Smarcelget_selected_block (CORE_ADDR *addr_in_block) 164519370Spst{ 164619370Spst if (!target_has_stack) 164719370Spst return 0; 164819370Spst 1649130803Smarcel /* NOTE: cagney/2002-11-28: Why go to all this effort to not create 1650130803Smarcel a selected/current frame? Perhaphs this function is called, 1651130803Smarcel indirectly, by WFI in "infrun.c" where avoiding the creation of 1652130803Smarcel an inner most frame is very important (it slows down single 1653130803Smarcel step). I suspect, though that this was true in the deep dark 1654130803Smarcel past but is no longer the case. A mindless look at all the 1655130803Smarcel callers tends to support this theory. I think we should be able 1656130803Smarcel to assume that there is always a selcted frame. */ 1657130803Smarcel /* gdb_assert (deprecated_selected_frame != NULL); So, do you feel 1658130803Smarcel lucky? */ 1659130803Smarcel if (!deprecated_selected_frame) 1660130803Smarcel { 1661130803Smarcel CORE_ADDR pc = read_pc (); 1662130803Smarcel if (addr_in_block != NULL) 1663130803Smarcel *addr_in_block = pc; 1664130803Smarcel return block_for_pc (pc); 1665130803Smarcel } 1666130803Smarcel return get_frame_block (deprecated_selected_frame, addr_in_block); 166719370Spst} 166819370Spst 166919370Spst/* Find a frame a certain number of levels away from FRAME. 167019370Spst LEVEL_OFFSET_PTR points to an int containing the number of levels. 167119370Spst Positive means go to earlier frames (up); negative, the reverse. 167219370Spst The int that contains the number of levels is counted toward 167319370Spst zero as the frames for those levels are found. 167419370Spst If the top or bottom frame is reached, that frame is returned, 167519370Spst but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates 167619370Spst how much farther the original request asked to go. */ 167719370Spst 167819370Spststruct frame_info * 1679130803Smarcelfind_relative_frame (struct frame_info *frame, 1680130803Smarcel int *level_offset_ptr) 168119370Spst{ 1682130803Smarcel struct frame_info *prev; 1683130803Smarcel struct frame_info *frame1; 168419370Spst 168519370Spst /* Going up is simple: just do get_prev_frame enough times 168619370Spst or until initial frame is reached. */ 168719370Spst while (*level_offset_ptr > 0) 168819370Spst { 168919370Spst prev = get_prev_frame (frame); 169019370Spst if (prev == 0) 169119370Spst break; 169219370Spst (*level_offset_ptr)--; 169319370Spst frame = prev; 169419370Spst } 169519370Spst /* Going down is just as simple. */ 169619370Spst if (*level_offset_ptr < 0) 169719370Spst { 169898944Sobrien while (*level_offset_ptr < 0) 169998944Sobrien { 170098944Sobrien frame1 = get_next_frame (frame); 170198944Sobrien if (!frame1) 170298944Sobrien break; 170398944Sobrien frame = frame1; 170498944Sobrien (*level_offset_ptr)++; 170598944Sobrien } 170619370Spst } 170719370Spst return frame; 170819370Spst} 170919370Spst 171019370Spst/* The "select_frame" command. With no arg, NOP. 171119370Spst With arg LEVEL_EXP, select the frame at level LEVEL if it is a 171219370Spst valid level. Otherwise, treat level_exp as an address expression 171319370Spst and select it. See parse_frame_specification for more info on proper 171419370Spst frame expressions. */ 171519370Spst 171698944Sobrienvoid 171798944Sobrienselect_frame_command (char *level_exp, int from_tty) 171819370Spst{ 1719130803Smarcel struct frame_info *frame; 1720130803Smarcel int level = frame_relative_level (deprecated_selected_frame); 172119370Spst 172219370Spst if (!target_has_stack) 172319370Spst error ("No stack."); 172419370Spst 172519370Spst frame = parse_frame_specification (level_exp); 172619370Spst 1727130803Smarcel select_frame (frame); 1728130803Smarcel if (level != frame_relative_level (deprecated_selected_frame)) 1729130803Smarcel selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame)); 173019370Spst} 173119370Spst 173219370Spst/* The "frame" command. With no arg, print selected frame briefly. 173319370Spst With arg, behaves like select_frame and then prints the selected 173419370Spst frame. */ 173519370Spst 173646283Sdfrvoid 173798944Sobrienframe_command (char *level_exp, int from_tty) 173819370Spst{ 173919370Spst select_frame_command (level_exp, from_tty); 1740130803Smarcel print_stack_frame (deprecated_selected_frame, 1741130803Smarcel frame_relative_level (deprecated_selected_frame), 1); 174219370Spst} 174319370Spst 174446283Sdfr/* The XDB Compatibility command to print the current frame. */ 174546283Sdfr 174698944Sobrienstatic void 174798944Sobriencurrent_frame_command (char *level_exp, int from_tty) 174846283Sdfr{ 1749130803Smarcel if (target_has_stack == 0 || deprecated_selected_frame == 0) 175098944Sobrien error ("No stack."); 1751130803Smarcel print_stack_frame (deprecated_selected_frame, 1752130803Smarcel frame_relative_level (deprecated_selected_frame), 1); 175398944Sobrien} 175446283Sdfr 175519370Spst/* Select the frame up one or COUNT stack levels 175619370Spst from the previously selected frame, and print it briefly. */ 175719370Spst 175819370Spststatic void 175998944Sobrienup_silently_base (char *count_exp) 176019370Spst{ 1761130803Smarcel struct frame_info *fi; 176219370Spst int count = 1, count1; 176319370Spst if (count_exp) 176498944Sobrien count = parse_and_eval_long (count_exp); 176519370Spst count1 = count; 176698944Sobrien 1767130803Smarcel if (target_has_stack == 0 || deprecated_selected_frame == 0) 176819370Spst error ("No stack."); 176919370Spst 1770130803Smarcel fi = find_relative_frame (deprecated_selected_frame, &count1); 177119370Spst if (count1 != 0 && count_exp == 0) 177219370Spst error ("Initial frame selected; you cannot go up."); 1773130803Smarcel select_frame (fi); 1774130803Smarcel selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame)); 177519370Spst} 177619370Spst 177719370Spststatic void 177898944Sobrienup_silently_command (char *count_exp, int from_tty) 177946283Sdfr{ 178098944Sobrien up_silently_base (count_exp); 178146283Sdfr} 178246283Sdfr 178346283Sdfrstatic void 178498944Sobrienup_command (char *count_exp, int from_tty) 178519370Spst{ 178646283Sdfr up_silently_base (count_exp); 1787130803Smarcel print_stack_frame (deprecated_selected_frame, 1788130803Smarcel frame_relative_level (deprecated_selected_frame), 1); 178919370Spst} 179019370Spst 179119370Spst/* Select the frame down one or COUNT stack levels 179219370Spst from the previously selected frame, and print it briefly. */ 179319370Spst 179419370Spststatic void 179598944Sobriendown_silently_base (char *count_exp) 179619370Spst{ 1797130803Smarcel struct frame_info *frame; 179819370Spst int count = -1, count1; 179919370Spst if (count_exp) 180098944Sobrien count = -parse_and_eval_long (count_exp); 180119370Spst count1 = count; 180298944Sobrien 1803130803Smarcel if (target_has_stack == 0 || deprecated_selected_frame == 0) 180419370Spst error ("No stack."); 180519370Spst 1806130803Smarcel frame = find_relative_frame (deprecated_selected_frame, &count1); 180719370Spst if (count1 != 0 && count_exp == 0) 180819370Spst { 180919370Spst 181019370Spst /* We only do this if count_exp is not specified. That way "down" 181198944Sobrien means to really go down (and let me know if that is 181298944Sobrien impossible), but "down 9999" can be used to mean go all the way 181398944Sobrien down without getting an error. */ 181419370Spst 181519370Spst error ("Bottom (i.e., innermost) frame selected; you cannot go down."); 181619370Spst } 181719370Spst 1818130803Smarcel select_frame (frame); 1819130803Smarcel selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame)); 182019370Spst} 182119370Spst 182246283Sdfrstatic void 182398944Sobriendown_silently_command (char *count_exp, int from_tty) 182446283Sdfr{ 182546283Sdfr down_silently_base (count_exp); 182646283Sdfr} 182719370Spst 182819370Spststatic void 182998944Sobriendown_command (char *count_exp, int from_tty) 183019370Spst{ 183146283Sdfr down_silently_base (count_exp); 1832130803Smarcel print_stack_frame (deprecated_selected_frame, 1833130803Smarcel frame_relative_level (deprecated_selected_frame), 1); 183419370Spst} 183519370Spst 183698944Sobrienvoid 183798944Sobrienreturn_command (char *retval_exp, int from_tty) 183819370Spst{ 183919370Spst struct symbol *thisfun; 184098944Sobrien struct value *return_value = NULL; 1841130803Smarcel const char *query_prefix = ""; 184219370Spst 1843130803Smarcel /* FIXME: cagney/2003-10-20: Perform a minimal existance test on the 1844130803Smarcel target. If that fails, error out. For the moment don't rely on 1845130803Smarcel get_selected_frame as it's error message is the the singularly 1846130803Smarcel obscure "No registers". */ 1847130803Smarcel if (!target_has_registers) 184819370Spst error ("No selected frame."); 1849130803Smarcel thisfun = get_frame_function (get_selected_frame ()); 185019370Spst 1851130803Smarcel /* Compute the return value. If the computation triggers an error, 1852130803Smarcel let it bail. If the return type can't be handled, set 1853130803Smarcel RETURN_VALUE to NULL, and QUERY_PREFIX to an informational 1854130803Smarcel message. */ 185519370Spst if (retval_exp) 185619370Spst { 185719370Spst struct type *return_type = NULL; 185819370Spst 1859130803Smarcel /* Compute the return value. Should the computation fail, this 1860130803Smarcel call throws an error. */ 186119370Spst return_value = parse_and_eval (retval_exp); 186219370Spst 1863130803Smarcel /* Cast return value to the return type of the function. Should 1864130803Smarcel the cast fail, this call throws an error. */ 186519370Spst if (thisfun != NULL) 186619370Spst return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun)); 186719370Spst if (return_type == NULL) 186819370Spst return_type = builtin_type_int; 186919370Spst return_value = value_cast (return_type, return_value); 187019370Spst 1871130803Smarcel /* Make sure the value is fully evaluated. It may live in the 1872130803Smarcel stack frame we're about to pop. */ 187319370Spst if (VALUE_LAZY (return_value)) 187419370Spst value_fetch_lazy (return_value); 1875130803Smarcel 1876130803Smarcel if (TYPE_CODE (return_type) == TYPE_CODE_VOID) 1877130803Smarcel /* If the return-type is "void", don't try to find the 1878130803Smarcel return-value's location. However, do still evaluate the 1879130803Smarcel return expression so that, even when the expression result 1880130803Smarcel is discarded, side effects such as "return i++" still 1881130803Smarcel occure. */ 1882130803Smarcel return_value = NULL; 1883130803Smarcel /* FIXME: cagney/2004-01-17: If the architecture implements both 1884130803Smarcel return_value and extract_returned_value_address, should allow 1885130803Smarcel "return" to work - don't set return_value to NULL. */ 1886130803Smarcel else if (!gdbarch_return_value_p (current_gdbarch) 1887130803Smarcel && (TYPE_CODE (return_type) == TYPE_CODE_STRUCT 1888130803Smarcel || TYPE_CODE (return_type) == TYPE_CODE_UNION)) 1889130803Smarcel { 1890130803Smarcel /* NOTE: cagney/2003-10-20: Compatibility hack for legacy 1891130803Smarcel code. Old architectures don't expect STORE_RETURN_VALUE 1892130803Smarcel to be called with with a small struct that needs to be 1893130803Smarcel stored in registers. Don't start doing it now. */ 1894130803Smarcel query_prefix = "\ 1895130803SmarcelA structure or union return type is not supported by this architecture.\n\ 1896130803SmarcelIf you continue, the return value that you specified will be ignored.\n"; 1897130803Smarcel return_value = NULL; 1898130803Smarcel } 1899130803Smarcel else if (using_struct_return (return_type, 0)) 1900130803Smarcel { 1901130803Smarcel query_prefix = "\ 1902130803SmarcelThe location at which to store the function's return value is unknown.\n\ 1903130803SmarcelIf you continue, the return value that you specified will be ignored.\n"; 1904130803Smarcel return_value = NULL; 1905130803Smarcel } 190619370Spst } 190719370Spst 1908130803Smarcel /* Does an interactive user really want to do this? Include 1909130803Smarcel information, such as how well GDB can handle the return value, in 1910130803Smarcel the query message. */ 191119370Spst if (from_tty) 191219370Spst { 1913130803Smarcel int confirmed; 1914130803Smarcel if (thisfun == NULL) 1915130803Smarcel confirmed = query ("%sMake selected stack frame return now? ", 1916130803Smarcel query_prefix); 1917130803Smarcel else 1918130803Smarcel confirmed = query ("%sMake %s return now? ", query_prefix, 1919130803Smarcel SYMBOL_PRINT_NAME (thisfun)); 1920130803Smarcel if (!confirmed) 1921130803Smarcel error ("Not confirmed"); 192219370Spst } 192319370Spst 1924130803Smarcel /* NOTE: cagney/2003-01-18: Is this silly? Rather than pop each 1925130803Smarcel frame in turn, should this code just go straight to the relevant 1926130803Smarcel frame and pop that? */ 192719370Spst 1928130803Smarcel /* First discard all frames inner-to the selected frame (making the 1929130803Smarcel selected frame current). */ 1930130803Smarcel { 1931130803Smarcel struct frame_id selected_id = get_frame_id (get_selected_frame ()); 1932130803Smarcel while (!frame_id_eq (selected_id, get_frame_id (get_current_frame ()))) 1933130803Smarcel { 1934130803Smarcel if (frame_id_inner (selected_id, get_frame_id (get_current_frame ()))) 1935130803Smarcel /* Caught in the safety net, oops! We've gone way past the 1936130803Smarcel selected frame. */ 1937130803Smarcel error ("Problem while popping stack frames (corrupt stack?)"); 1938130803Smarcel frame_pop (get_current_frame ()); 1939130803Smarcel } 1940130803Smarcel } 194119370Spst 1942130803Smarcel /* Second discard the selected frame (which is now also the current 1943130803Smarcel frame). */ 1944130803Smarcel frame_pop (get_current_frame ()); 194519370Spst 1946130803Smarcel /* Store RETURN_VAUE in the just-returned register set. */ 1947130803Smarcel if (return_value != NULL) 1948130803Smarcel { 1949130803Smarcel struct type *return_type = VALUE_TYPE (return_value); 1950130803Smarcel if (!gdbarch_return_value_p (current_gdbarch)) 1951130803Smarcel { 1952130803Smarcel STORE_RETURN_VALUE (return_type, current_regcache, 1953130803Smarcel VALUE_CONTENTS (return_value)); 1954130803Smarcel } 1955130803Smarcel /* FIXME: cagney/2004-01-17: If extract_returned_value_address 1956130803Smarcel is available and the function is using 1957130803Smarcel RETURN_VALUE_STRUCT_CONVENTION, should use it to find the 1958130803Smarcel address of the returned value so that it can be assigned. */ 1959130803Smarcel else 1960130803Smarcel { 1961130803Smarcel gdb_assert (gdbarch_return_value (current_gdbarch, return_type, 1962130803Smarcel NULL, NULL, NULL) 1963130803Smarcel == RETURN_VALUE_REGISTER_CONVENTION); 1964130803Smarcel gdbarch_return_value (current_gdbarch, return_type, 1965130803Smarcel current_regcache, NULL /*read*/, 1966130803Smarcel VALUE_CONTENTS (return_value) /*write*/); 1967130803Smarcel } 1968130803Smarcel } 196919370Spst 1970130803Smarcel /* If we are at the end of a call dummy now, pop the dummy frame 1971130803Smarcel too. */ 1972130803Smarcel /* NOTE: cagney/2003-01-18: Is this silly? Instead of popping all 1973130803Smarcel the frames in sequence, should this code just pop the dummy frame 1974130803Smarcel directly? */ 1975130803Smarcel#ifdef DEPRECATED_CALL_DUMMY_HAS_COMPLETED 1976130803Smarcel /* Since all up-to-date architectures return direct to the dummy 1977130803Smarcel breakpoint address, a dummy frame has, by definition, always 1978130803Smarcel completed. Hence this method is no longer needed. */ 1979130803Smarcel if (DEPRECATED_CALL_DUMMY_HAS_COMPLETED (read_pc(), read_sp (), 1980130803Smarcel get_frame_base (get_current_frame ()))) 1981130803Smarcel frame_pop (get_current_frame ()); 1982130803Smarcel#else 1983130803Smarcel if (get_frame_type (get_current_frame ()) == DUMMY_FRAME) 1984130803Smarcel frame_pop (get_current_frame ()); 1985130803Smarcel#endif 198619370Spst 198719370Spst /* If interactive, print the frame that is now current. */ 198819370Spst if (from_tty) 198919370Spst frame_command ("0", 1); 199019370Spst else 199119370Spst select_frame_command ("0", 0); 199219370Spst} 199319370Spst 199446283Sdfr/* Sets the scope to input function name, provided that the 199546283Sdfr function is within the current stack frame */ 199646283Sdfr 199746283Sdfrstruct function_bounds 199846283Sdfr{ 199946283Sdfr CORE_ADDR low, high; 200046283Sdfr}; 200146283Sdfr 200298944Sobrienstatic void func_command (char *arg, int from_tty); 200346283Sdfrstatic void 200498944Sobrienfunc_command (char *arg, int from_tty) 200546283Sdfr{ 200646283Sdfr struct frame_info *fp; 200746283Sdfr int found = 0; 200846283Sdfr struct symtabs_and_lines sals; 200946283Sdfr int i; 201046283Sdfr int level = 1; 201146283Sdfr struct function_bounds *func_bounds = (struct function_bounds *) NULL; 201246283Sdfr 201346283Sdfr if (arg != (char *) NULL) 201446283Sdfr return; 201546283Sdfr 201646283Sdfr fp = parse_frame_specification ("0"); 201746283Sdfr sals = decode_line_spec (arg, 1); 201846283Sdfr func_bounds = (struct function_bounds *) xmalloc ( 201946283Sdfr sizeof (struct function_bounds) * sals.nelts); 202046283Sdfr for (i = 0; (i < sals.nelts && !found); i++) 202146283Sdfr { 202246283Sdfr if (sals.sals[i].pc == (CORE_ADDR) 0 || 202346283Sdfr find_pc_partial_function (sals.sals[i].pc, 202446283Sdfr (char **) NULL, 202546283Sdfr &func_bounds[i].low, 202646283Sdfr &func_bounds[i].high) == 0) 202746283Sdfr { 202846283Sdfr func_bounds[i].low = 202946283Sdfr func_bounds[i].high = (CORE_ADDR) NULL; 203046283Sdfr } 203146283Sdfr } 203246283Sdfr 203346283Sdfr do 203446283Sdfr { 203546283Sdfr for (i = 0; (i < sals.nelts && !found); i++) 2036130803Smarcel found = (get_frame_pc (fp) >= func_bounds[i].low && 2037130803Smarcel get_frame_pc (fp) < func_bounds[i].high); 203846283Sdfr if (!found) 203946283Sdfr { 204046283Sdfr level = 1; 204146283Sdfr fp = find_relative_frame (fp, &level); 204246283Sdfr } 204346283Sdfr } 204446283Sdfr while (!found && level == 0); 204546283Sdfr 204646283Sdfr if (func_bounds) 204798944Sobrien xfree (func_bounds); 204846283Sdfr 204946283Sdfr if (!found) 205046283Sdfr printf_filtered ("'%s' not within current stack frame.\n", arg); 2051130803Smarcel else if (fp != deprecated_selected_frame) 2052130803Smarcel select_and_print_frame (fp); 205346283Sdfr} 205446283Sdfr 205519370Spst/* Gets the language of the current frame. */ 205619370Spst 205719370Spstenum language 205898944Sobrienget_frame_language (void) 205919370Spst{ 2060130803Smarcel struct symtab *s; 206119370Spst enum language flang; /* The language of the current frame */ 206298944Sobrien 2063130803Smarcel if (deprecated_selected_frame) 206419370Spst { 2065130803Smarcel /* We determine the current frame language by looking up its 2066130803Smarcel associated symtab. To retrieve this symtab, we use the frame PC. 2067130803Smarcel However we cannot use the frame pc as is, because it usually points 2068130803Smarcel to the instruction following the "call", which is sometimes the first 2069130803Smarcel instruction of another function. So we rely on 2070130803Smarcel get_frame_address_in_block(), it provides us with a PC which is 2071130803Smarcel guaranteed to be inside the frame's code block. */ 2072130803Smarcel s = find_pc_symtab (get_frame_address_in_block (deprecated_selected_frame)); 207319370Spst if (s) 207419370Spst flang = s->language; 207519370Spst else 207619370Spst flang = language_unknown; 207719370Spst } 207819370Spst else 207919370Spst flang = language_unknown; 208019370Spst 208119370Spst return flang; 208219370Spst} 208319370Spst 208419370Spstvoid 208598944Sobrien_initialize_stack (void) 208619370Spst{ 208798944Sobrien#if 0 208819370Spst backtrace_limit = 30; 208919370Spst#endif 209019370Spst 209119370Spst add_com ("return", class_stack, return_command, 209219370Spst "Make selected stack frame return to its caller.\n\ 209319370SpstControl remains in the debugger, but when you continue\n\ 209419370Spstexecution will resume in the frame above the one now selected.\n\ 209519370SpstIf an argument is given, it is an expression for the value to return."); 209619370Spst 209719370Spst add_com ("up", class_stack, up_command, 209819370Spst "Select and print stack frame that called this one.\n\ 209919370SpstAn argument says how many frames up to go."); 210019370Spst add_com ("up-silently", class_support, up_silently_command, 210119370Spst "Same as the `up' command, but does not print anything.\n\ 210219370SpstThis is useful in command scripts."); 210319370Spst 210419370Spst add_com ("down", class_stack, down_command, 210519370Spst "Select and print stack frame called by this one.\n\ 210619370SpstAn argument says how many frames down to go."); 210719370Spst add_com_alias ("do", "down", class_stack, 1); 210819370Spst add_com_alias ("dow", "down", class_stack, 1); 210919370Spst add_com ("down-silently", class_support, down_silently_command, 211019370Spst "Same as the `down' command, but does not print anything.\n\ 211119370SpstThis is useful in command scripts."); 211219370Spst 211319370Spst add_com ("frame", class_stack, frame_command, 211419370Spst "Select and print a stack frame.\n\ 211519370SpstWith no argument, print the selected stack frame. (See also \"info frame\").\n\ 211619370SpstAn argument specifies the frame to select.\n\ 211719370SpstIt can be a stack frame number or the address of the frame.\n\ 211819370SpstWith argument, nothing is printed if input is coming from\n\ 211919370Spsta command file or a user-defined command."); 212019370Spst 212119370Spst add_com_alias ("f", "frame", class_stack, 1); 212219370Spst 212346283Sdfr if (xdb_commands) 212446283Sdfr { 212598944Sobrien add_com ("L", class_stack, current_frame_command, 212698944Sobrien "Print the current stack frame.\n"); 212746283Sdfr add_com_alias ("V", "frame", class_stack, 1); 212846283Sdfr } 212919370Spst add_com ("select-frame", class_stack, select_frame_command, 213019370Spst "Select a stack frame without printing anything.\n\ 213119370SpstAn argument specifies the frame to select.\n\ 213219370SpstIt can be a stack frame number or the address of the frame.\n"); 213319370Spst 213419370Spst add_com ("backtrace", class_stack, backtrace_command, 213519370Spst "Print backtrace of all stack frames, or innermost COUNT frames.\n\ 213646283SdfrWith a negative argument, print outermost -COUNT frames.\n\ 213746283SdfrUse of the 'full' qualifier also prints the values of the local variables.\n"); 213819370Spst add_com_alias ("bt", "backtrace", class_stack, 0); 213946283Sdfr if (xdb_commands) 214046283Sdfr { 214146283Sdfr add_com_alias ("t", "backtrace", class_stack, 0); 214246283Sdfr add_com ("T", class_stack, backtrace_full_command, 214398944Sobrien "Print backtrace of all stack frames, or innermost COUNT frames \n\ 214446283Sdfrand the values of the local variables.\n\ 214546283SdfrWith a negative argument, print outermost -COUNT frames.\n\ 214646283SdfrUsage: T <count>\n"); 214746283Sdfr } 214846283Sdfr 214919370Spst add_com_alias ("where", "backtrace", class_alias, 0); 215019370Spst add_info ("stack", backtrace_command, 215119370Spst "Backtrace of the stack, or innermost COUNT frames."); 215219370Spst add_info_alias ("s", "stack", 1); 215319370Spst add_info ("frame", frame_info, 215419370Spst "All about selected stack frame, or frame at ADDR."); 215519370Spst add_info_alias ("f", "frame", 1); 215619370Spst add_info ("locals", locals_info, 215719370Spst "Local variables of current stack frame."); 215819370Spst add_info ("args", args_info, 215919370Spst "Argument variables of current stack frame."); 216046283Sdfr if (xdb_commands) 216198944Sobrien add_com ("l", class_info, args_plus_locals_info, 216298944Sobrien "Argument and local variables of current stack frame."); 216346283Sdfr 216446283Sdfr if (dbx_commands) 216598944Sobrien add_com ("func", class_stack, func_command, 216698944Sobrien "Select the stack frame that contains <func>.\nUsage: func <name>\n"); 216746283Sdfr 216819370Spst add_info ("catch", catch_info, 216919370Spst "Exceptions that can be caught in the current stack frame."); 217019370Spst 217119370Spst#if 0 217298944Sobrien add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command, 217398944Sobrien "Specify maximum number of frames for \"backtrace\" to print by default.", 217419370Spst &setlist); 217519370Spst add_info ("backtrace-limit", backtrace_limit_info, 217698944Sobrien "The maximum number of frames for \"backtrace\" to print by default."); 217719370Spst#endif 217819370Spst} 2179