📄 stack.c
字号:
/* Print and select stack frames for GDB, the GNU debugger. Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.This file is part of GDB.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "defs.h"#include "value.h"#include "symtab.h"#include "gdbtypes.h"#include "expression.h"#include "language.h"#include "frame.h"#include "gdbcmd.h"#include "gdbcore.h"#include "target.h"#include "breakpoint.h"#include "demangle.h"static voidreturn_command PARAMS ((char *, int));static voiddown_command PARAMS ((char *, int));static voiddown_silently_command PARAMS ((char *, int));static voidup_command PARAMS ((char *, int));static voidup_silently_command PARAMS ((char *, int));static voidframe_command PARAMS ((char *, int));static voidselect_frame_command PARAMS ((char *, int));static voidargs_info PARAMS ((char *, int));static voidprint_frame_arg_vars PARAMS ((FRAME, FILE *));static voidcatch_info PARAMS ((char *, int));static voidlocals_info PARAMS ((char *, int));static voidprint_frame_label_vars PARAMS ((FRAME, int, FILE *));static voidprint_frame_local_vars PARAMS ((FRAME, FILE *));static intprint_block_frame_labels PARAMS ((struct block *, int *, FILE *));static intprint_block_frame_locals PARAMS ((struct block *, FRAME, FILE *));static voidbacktrace_command PARAMS ((char *, int));static FRAMEparse_frame_specification PARAMS ((char *));static voidframe_info PARAMS ((char *, int));extern int addressprint; /* Print addresses, or stay symbolic only? */extern int info_verbose; /* Verbosity of symbol reading msgs */extern int lines_to_list; /* # of lines "list" command shows by default *//* The "selected" stack frame is used by default for local and arg access. May be zero, for no selected frame. */FRAME selected_frame;/* Level of the selected frame: 0 for innermost, 1 for its caller, ... or -1 for frame specified by address with no defined level. */int selected_frame_level;/* Nonzero means print the full filename and linenumber when a frame is printed, and do so in a format programs can parse. */int frame_file_full_name = 0;/* Negative says don't print source line in print_frame_info if SOURCE argument is -1. (Useful for a 'stepi' replacement that does "x/i $pc" or when running xgdb.) */int print_source_at_stop;static int info_printsource;/* Print a stack frame briefly. FRAME should be the frame id and LEVEL should be its level in the stack (or -1 for level not defined). This prints the level, the function executing, the arguments, and the file name and line number. If the pc is not at the beginning of the source line, the actual pc is printed at the beginning. If SOURCE is 1, print the source line as well. If SOURCE is -1, print ONLY the source line. */voidprint_stack_frame (frame, level, source) FRAME frame; int level; int source;{ struct frame_info *fi; fi = get_frame_info (frame); print_frame_info (fi, level, source, 1);}voidprint_frame_info (fi, level, source, args) struct frame_info *fi; register int level; int source; int args;{ struct symtab_and_line sal; struct symbol *func; register char *funname = 0; int numargs;#if 0 /* Symbol reading is fast enough now */ struct partial_symtab *pst; /* Don't give very much information if we haven't readin the symbol table yet. */ pst = find_pc_psymtab (fi->pc); if (pst && !pst->readin) { /* Abbreviated information. */ char *fname; if (!find_pc_partial_function (fi->pc, &fname, 0)) fname = "??"; printf_filtered ("#%-2d ", level); if (addressprint) printf_filtered ("%s in ", local_hex_string(fi->pc)); fputs_demangled (fname, stdout, 0); fputs_filtered (" (...)\n", stdout); return; }#endif#ifdef CORE_NEEDS_RELOCATION CORE_NEEDS_RELOCATION(fi->pc);#endif sal = find_pc_line (fi->pc, fi->next_frame); func = find_pc_function (fi->pc); if (func) { /* In certain pathological cases, the symtabs give the wrong function (when we are in the first function in a file which is compiled without debugging symbols, the previous function is compiled with debugging symbols, and the "foo.o" symbol that is supposed to tell us where the file with debugging symbols ends has been truncated by ar because it is longer than 15 characters). So look in the minimal symbol tables as well, and if it comes up with a larger address for the function use that instead. I don't think this can ever cause any problems; there shouldn't be any minimal symbols in the middle of a function. FIXME: (Not necessarily true. What about text labels) */ struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); if (msymbol != NULL && (msymbol -> address > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) { /* In this case we have no way of knowing the source file and line number, so don't print them. */ sal.symtab = 0; /* We also don't know anything about the function besides its address and name. */ func = 0; funname = msymbol -> name; } else funname = SYMBOL_NAME (func); } else { register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); if (msymbol != NULL) funname = msymbol -> name; } if (source >= 0 || !sal.symtab) { if (level >= 0) printf_filtered ("#%-2d ", level); if (addressprint) if (fi->pc != sal.pc || !sal.symtab) printf_filtered ("%s in ", local_hex_string(fi->pc)); fputs_demangled (funname ? funname : "??", stdout, 0);#ifdef notdef /* Steve McCanne doesn't like this. */ wrap_here (" ");#endif fputs_filtered (" (", stdout); if (args) { FRAME_NUM_ARGS (numargs, fi); print_frame_args (func, fi, numargs, stdout); } printf_filtered (")"); if (sal.symtab && sal.symtab->filename) { wrap_here (" "); printf_filtered (" at %s:%d", sal.symtab->filename, sal.line); }#ifdef PC_LOAD_SEGMENT /* If we couldn't print out function name but if can figure out what load segment this pc value is from, at least print out some info about its load segment. */ if (!funname) { wrap_here (" "); printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc)); }#endif printf_filtered ("\n"); } if ((source != 0) && sal.symtab) { if (source > 0 || print_source_at_stop >= 0) { int done = 0; int mid_statement = source < 0 && fi->pc != sal.pc; if (frame_file_full_name) done = identify_source_line (sal.symtab, sal.line, mid_statement); if (!done) { if (addressprint && mid_statement) printf_filtered ("%s\t", local_hex_string(fi->pc)); print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); } } current_source_line = max (sal.line - lines_to_list/2, 1); } if (source != 0) set_default_breakpoint (1, fi->pc, sal.symtab, sal.line); fflush (stdout);}#ifdef FRAME_SPECIFICATION_DYADICextern FRAME setup_arbitrary_frame ();#endif/* * Read a frame specification in whatever the appropriate format is. * Call error() if the specification is in any way invalid (i.e. * this function never returns NULL). */static FRAMEparse_frame_specification (frame_exp) char *frame_exp;{ int numargs = 0; int arg1, arg2; if (frame_exp) { char *addr_string, *p; struct cleanup *tmp_cleanup; while (*frame_exp == ' ') frame_exp++; for (p = frame_exp; *p && *p != ' '; p++) ; if (*frame_exp) { numargs = 1; addr_string = savestring(frame_exp, p - frame_exp); { tmp_cleanup = make_cleanup (free, addr_string); arg1 = parse_and_eval_address (addr_string); do_cleanups (tmp_cleanup); } while (*p == ' ') p++; if (*p) { numargs = 2; arg2 = parse_and_eval_address (p); } } } switch (numargs) { case 0: if (selected_frame == NULL) error ("No selected frame."); return selected_frame; /* NOTREACHED */ case 1: { int level = arg1; FRAME fid = find_relative_frame (get_current_frame (), &level); FRAME tfid; if (level == 0) /* find_relative_frame was successful */ return fid; /* If (s)he specifies the frame with an address, he deserves what (s)he gets. Still, give the highest one that matches. */ for (fid = get_current_frame (); fid && FRAME_FP (fid) != arg1; fid = get_prev_frame (fid)) ; if (fid) while ((tfid = get_prev_frame (fid)) && (FRAME_FP (tfid) == arg1)) fid = tfid; #ifdef FRAME_SPECIFICATION_DYADIC if (!fid) error ("Incorrect number of args in frame specification"); return fid;#else return create_new_frame (arg1, 0);#endif } /* NOTREACHED */ case 2: /* Must be addresses */#ifndef FRAME_SPECIFICATION_DYADIC error ("Incorrect number of args in frame specification");#else return setup_arbitrary_frame (arg1, arg2);#endif /* NOTREACHED */ } fatal ("Internal: Error in parsing in parse_frame_specification"); /* NOTREACHED */}/* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except that if it is unsure about the answer, it returns 0 instead of guessing (this happens on the VAX and i960, for example). On most machines, we never have to guess about the args address, so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */#if !defined (FRAME_ARGS_ADDRESS_CORRECT)#define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS#endif/* Print verbosely the selected frame or the frame at address ADDR. This means absolutely all information in the frame is printed. */static voidframe_info (addr_exp, from_tty) char *addr_exp; int from_tty;{ FRAME frame; struct frame_info *fi; struct frame_saved_regs fsr; struct symtab_and_line sal; struct symbol *func; struct symtab *s; FRAME calling_frame; int i, count; char *funname = 0; if (!target_has_stack) error ("No inferior or core file."); frame = parse_frame_specification (addr_exp); if (!frame) error ("Invalid frame specified."); fi = get_frame_info (frame); sal = find_pc_line (fi->pc, fi->next_frame); func = get_frame_function (frame); s = find_pc_symtab(fi->pc); if (func) funname = SYMBOL_NAME (func); else { register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); if (msymbol != NULL) funname = msymbol -> name; } calling_frame = get_prev_frame (frame); if (!addr_exp && selected_frame_level >= 0) { printf_filtered ("Stack level %d, frame at %s:\n", selected_frame_level, local_hex_string(FRAME_FP(frame))); } else { printf_filtered ("Stack frame at %s:\n", local_hex_string(FRAME_FP(frame))); } printf_filtered (" %s = %s", reg_names[PC_REGNUM], local_hex_string(fi->pc)); wrap_here (" ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -