📄 blockframe.c
字号:
/* Get info from stack frames; convert between frames, blocks, functions and pc values. Copyright 1986, 1987, 1988, 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 "symtab.h"#include "bfd.h"#include "symfile.h"#include "objfiles.h"#include "frame.h"#include "gdbcore.h"#include "value.h" /* for read_register */#include "target.h" /* for target_has_stack */#include "inferior.h" /* for read_pc *//* Is ADDR inside the startup file? Note that if your machine has a way to detect the bottom of the stack, there is no need to call this function from FRAME_CHAIN_VALID; the reason for doing so is that some machines have no way of detecting bottom of stack. */intinside_entry_file (addr) CORE_ADDR addr;{ if (symfile_objfile == 0) return 0; return (addr >= symfile_objfile -> ei.entry_file_lowpc && addr < symfile_objfile -> ei.entry_file_highpc);}/* Test a specified PC value to see if it is in the range of addresses that correspond to the main() function. See comments above for why we might want to do this. Typically called from FRAME_CHAIN_VALID. */intinside_main_func (pc)CORE_ADDR pc;{ if (symfile_objfile == 0) return 0; return (symfile_objfile -> ei.main_func_lowpc <= pc && symfile_objfile -> ei.main_func_highpc > pc);}/* Test a specified PC value to see if it is in the range of addresses that correspond to the process entry point function. See comments in objfiles.h for why we might want to do this. Typically called from FRAME_CHAIN_VALID. */intinside_entry_func (pc)CORE_ADDR pc;{ if (symfile_objfile == 0) return 0; return (symfile_objfile -> ei.entry_func_lowpc <= pc && symfile_objfile -> ei.entry_func_highpc > pc);}/* Address of innermost stack frame (contents of FP register) */static FRAME current_frame;/* * Cache for frame addresses already read by gdb. Valid only while * inferior is stopped. Control variables for the frame cache should * be local to this module. */struct obstack frame_cache_obstack;/* Return the innermost (currently executing) stack frame. */FRAMEget_current_frame (){ /* We assume its address is kept in a general register; param.h says which register. */ return current_frame;}voidset_current_frame (frame) FRAME frame;{ current_frame = frame;}FRAMEcreate_new_frame (addr, pc) FRAME_ADDR addr; CORE_ADDR pc;{ struct frame_info *fci; /* Same type as FRAME */ fci = (struct frame_info *) obstack_alloc (&frame_cache_obstack, sizeof (struct frame_info)); /* Arbitrary frame */ fci->next = (struct frame_info *) 0; fci->prev = (struct frame_info *) 0; fci->frame = addr; fci->next_frame = 0; /* Since arbitrary */ fci->pc = pc;#ifdef INIT_EXTRA_FRAME_INFO INIT_EXTRA_FRAME_INFO (0, fci);#endif return fci;}/* Return the frame that called FRAME. If FRAME is the original frame (it has no caller), return 0. */FRAMEget_prev_frame (frame) FRAME frame;{ /* We're allowed to know that FRAME and "struct frame_info *" are the same */ return get_prev_frame_info (frame);}/* Return the frame that FRAME calls (0 if FRAME is the innermost frame). */FRAMEget_next_frame (frame) FRAME frame;{ /* We're allowed to know that FRAME and "struct frame_info *" are the same */ return frame->next;}/* * Flush the entire frame cache. */voidflush_cached_frames (){ /* Since we can't really be sure what the first object allocated was */ obstack_free (&frame_cache_obstack, 0); obstack_init (&frame_cache_obstack); current_frame = (struct frame_info *) 0; /* Invalidate cache */}/* Flush the frame cache, and start a new one if necessary. */voidreinit_frame_cache (){ FRAME fr = current_frame; flush_cached_frames (); if (fr) set_current_frame ( create_new_frame (read_register (FP_REGNUM), read_pc ()));}/* Return a structure containing various interesting information about a specified stack frame. *//* How do I justify including this function? Well, the FRAME identifier format has gone through several changes recently, and it's not completely inconceivable that it could happen again. If it does, have this routine around will help */struct frame_info *get_frame_info (frame) FRAME frame;{ return frame;}/* If a machine allows frameless functions, it should define a macro FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h. FI is the struct frame_info for the frame, and FRAMELESS should be set to nonzero if it represents a frameless function invocation. *//* Return nonzero if the function for this frame has a prologue. Many machines can define FRAMELESS_FUNCTION_INVOCATION to just call this function. */intframeless_look_for_prologue (frame) FRAME frame;{ CORE_ADDR func_start, after_prologue; func_start = (get_pc_function_start (frame->pc) + FUNCTION_START_OFFSET); if (func_start) { after_prologue = func_start;#ifdef SKIP_PROLOGUE_FRAMELESS_P /* This is faster, since only care whether there *is* a prologue, not how long it is. */ SKIP_PROLOGUE_FRAMELESS_P (after_prologue);#else SKIP_PROLOGUE (after_prologue);#endif return after_prologue == func_start; } else /* If we can't find the start of the function, we don't really know whether the function is frameless, but we should be able to get a reasonable (i.e. best we can do under the circumstances) backtrace by saying that it isn't. */ return 0;}/* Default a few macros that people seldom redefine. */#if !defined (INIT_FRAME_PC)#define INIT_FRAME_PC(fromleaf, prev) \ prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \ prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());#endif#ifndef FRAME_CHAIN_COMBINE#define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)#endif/* Return a structure containing various interesting information about the frame that called NEXT_FRAME. Returns NULL if there is no such frame. */struct frame_info *get_prev_frame_info (next_frame) FRAME next_frame;{ FRAME_ADDR address; struct frame_info *prev; int fromleaf = 0; /* If the requested entry is in the cache, return it. Otherwise, figure out what the address should be for the entry we're about to add to the cache. */ if (!next_frame) { if (!current_frame) { error ("You haven't set up a process's stack to examine."); } return current_frame; } /* If we have the prev one, return it */ if (next_frame->prev) return next_frame->prev; /* On some machines it is possible to call a function without setting up a stack frame for it. On these machines, we define this macro to take two args; a frameinfo pointer identifying a frame and a variable to set or clear if it is or isn't leafless. */#ifdef FRAMELESS_FUNCTION_INVOCATION /* Still don't want to worry about this except on the innermost frame. This macro will set FROMLEAF if NEXT_FRAME is a frameless function invocation. */ if (!(next_frame->next)) { FRAMELESS_FUNCTION_INVOCATION (next_frame, fromleaf); if (fromleaf) address = next_frame->frame; }#endif if (!fromleaf) { /* Two macros defined in tm.h specify the machine-dependent actions to be performed here. First, get the frame's chain-pointer. If that is zero, the frame is the outermost frame or a leaf called by the outermost frame. This means that if start calls main without a frame, we'll return 0 (which is fine anyway). Nope; there's a problem. This also returns when the current routine is a leaf of main. This is unacceptable. We move this to after the ffi test; I'd rather have backtraces from start go curfluy than have an abort called from main not show main. */ address = FRAME_CHAIN (next_frame); if (!FRAME_CHAIN_VALID (address, next_frame)) return 0; address = FRAME_CHAIN_COMBINE (address, next_frame); } if (address == 0) return 0; prev = (struct frame_info *) obstack_alloc (&frame_cache_obstack, sizeof (struct frame_info)); if (next_frame) next_frame->prev = prev; prev->next = next_frame; prev->prev = (struct frame_info *) 0; prev->frame = address; prev->next_frame = prev->next ? prev->next->frame : 0;/* This change should not be needed, FIXME! We should determine whether any targets *need* INIT_FRAME_PC to happen after INIT_EXTRA_FRAME_INFO and come up with a simple way to express what goes on here. INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame (where the PC is already set up) and here (where it isn't). INIT_FRAME_PC is only called from here, always after INIT_EXTRA_FRAME_INFO. The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC value (which hasn't been set yet). Some other machines appear to require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC. Phoo. We shouldn't need INIT_FRAME_PC_FIRST to add more complication to an already overcomplicated part of GDB. gnu@cygnus.com, 15Sep92. */#ifdef INIT_FRAME_PC_FIRST INIT_FRAME_PC_FIRST (fromleaf, prev);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -