1130803Smarcel/* Get info from stack frames; convert between frames, blocks, 2130803Smarcel functions and pc values. 319370Spst 4130803Smarcel Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 5130803Smarcel 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 6130803Smarcel Free Software Foundation, Inc. 7130803Smarcel 898944Sobrien This file is part of GDB. 919370Spst 1098944Sobrien This program is free software; you can redistribute it and/or modify 1198944Sobrien it under the terms of the GNU General Public License as published by 1298944Sobrien the Free Software Foundation; either version 2 of the License, or 1398944Sobrien (at your option) any later version. 1419370Spst 1598944Sobrien This program is distributed in the hope that it will be useful, 1698944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1798944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1898944Sobrien GNU General Public License for more details. 1919370Spst 2098944Sobrien You should have received a copy of the GNU General Public License 2198944Sobrien along with this program; if not, write to the Free Software 2298944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2398944Sobrien Boston, MA 02111-1307, USA. */ 2419370Spst 2519370Spst#include "defs.h" 2619370Spst#include "symtab.h" 2719370Spst#include "bfd.h" 2819370Spst#include "objfiles.h" 2919370Spst#include "frame.h" 3019370Spst#include "gdbcore.h" 3119370Spst#include "value.h" /* for read_register */ 3219370Spst#include "target.h" /* for target_has_stack */ 3319370Spst#include "inferior.h" /* for read_pc */ 3419370Spst#include "annotate.h" 3598944Sobrien#include "regcache.h" 36130803Smarcel#include "gdb_assert.h" 37130803Smarcel#include "dummy-frame.h" 38130803Smarcel#include "command.h" 39130803Smarcel#include "gdbcmd.h" 40130803Smarcel#include "block.h" 4119370Spst 4246283Sdfr/* Prototypes for exported functions. */ 4346283Sdfr 4498944Sobrienvoid _initialize_blockframe (void); 4546283Sdfr 46130803Smarcel/* Is ADDR inside the startup file? Note that if your machine has a 47130803Smarcel way to detect the bottom of the stack, there is no need to call 48130803Smarcel this function from DEPRECATED_FRAME_CHAIN_VALID; the reason for 49130803Smarcel doing so is that some machines have no way of detecting bottom of 50130803Smarcel stack. 5146283Sdfr 5219370Spst A PC of zero is always considered to be the bottom of the stack. */ 5319370Spst 5419370Spstint 55130803Smarceldeprecated_inside_entry_file (CORE_ADDR addr) 5619370Spst{ 5719370Spst if (addr == 0) 5819370Spst return 1; 5919370Spst if (symfile_objfile == 0) 6019370Spst return 0; 61130803Smarcel if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT 62130803Smarcel || CALL_DUMMY_LOCATION == AT_SYMBOL) 6398944Sobrien { 6498944Sobrien /* Do not stop backtracing if the pc is in the call dummy 6598944Sobrien at the entry point. */ 6698944Sobrien /* FIXME: Won't always work with zeros for the last two arguments */ 67130803Smarcel if (DEPRECATED_PC_IN_CALL_DUMMY (addr, 0, 0)) 6898944Sobrien return 0; 6998944Sobrien } 70130803Smarcel return (addr >= symfile_objfile->ei.deprecated_entry_file_lowpc && 71130803Smarcel addr < symfile_objfile->ei.deprecated_entry_file_highpc); 7219370Spst} 7319370Spst 74130803Smarcel/* Test whether PC is in the range of addresses that corresponds to 75130803Smarcel the "main" function. */ 7619370Spst 7719370Spstint 7898944Sobrieninside_main_func (CORE_ADDR pc) 7919370Spst{ 80130803Smarcel struct minimal_symbol *msymbol; 81130803Smarcel 8219370Spst if (symfile_objfile == 0) 8319370Spst return 0; 8419370Spst 85130803Smarcel msymbol = lookup_minimal_symbol (main_name (), NULL, symfile_objfile); 8619370Spst 87130803Smarcel /* If the address range hasn't been set up at symbol reading time, 88130803Smarcel set it up now. */ 89130803Smarcel 90130803Smarcel if (msymbol != NULL 91130803Smarcel && symfile_objfile->ei.main_func_lowpc == INVALID_ENTRY_LOWPC 92130803Smarcel && symfile_objfile->ei.main_func_highpc == INVALID_ENTRY_HIGHPC) 9319370Spst { 94130803Smarcel /* brobecker/2003-10-10: We used to rely on lookup_symbol() to 95130803Smarcel search the symbol associated to the "main" function. 96130803Smarcel Unfortunately, lookup_symbol() uses the current-language 97130803Smarcel la_lookup_symbol_nonlocal function to do the global symbol 98130803Smarcel search. Depending on the language, this can introduce 99130803Smarcel certain side-effects, because certain languages, for instance 100130803Smarcel Ada, may find more than one match. Therefore we prefer to 101130803Smarcel search the "main" function symbol using its address rather 102130803Smarcel than its name. */ 103130803Smarcel struct symbol *mainsym = 104130803Smarcel find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol)); 10546283Sdfr 10698944Sobrien if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK) 10798944Sobrien { 10898944Sobrien symfile_objfile->ei.main_func_lowpc = 10946283Sdfr BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym)); 11098944Sobrien symfile_objfile->ei.main_func_highpc = 11146283Sdfr BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym)); 11298944Sobrien } 11319370Spst } 11419370Spst 115130803Smarcel /* Not in the normal symbol tables, see if "main" is in the partial 116130803Smarcel symbol table. If it's not, then give up. */ 117130803Smarcel if (msymbol != NULL && MSYMBOL_TYPE (msymbol) == mst_text) 11898944Sobrien { 119130803Smarcel CORE_ADDR maddr = SYMBOL_VALUE_ADDRESS (msymbol); 120130803Smarcel asection *msect = SYMBOL_BFD_SECTION (msymbol); 121130803Smarcel struct obj_section *osect = find_pc_sect_section (maddr, msect); 12219370Spst 123130803Smarcel if (osect != NULL) 124130803Smarcel { 125130803Smarcel int i; 12619370Spst 127130803Smarcel /* Step over other symbols at this same address, and symbols 128130803Smarcel in other sections, to find the next symbol in this 129130803Smarcel section with a different address. */ 130130803Smarcel for (i = 1; SYMBOL_LINKAGE_NAME (msymbol + i) != NULL; i++) 131130803Smarcel { 132130803Smarcel if (SYMBOL_VALUE_ADDRESS (msymbol + i) != maddr 133130803Smarcel && SYMBOL_BFD_SECTION (msymbol + i) == msect) 134130803Smarcel break; 135130803Smarcel } 13619370Spst 137130803Smarcel symfile_objfile->ei.main_func_lowpc = maddr; 13819370Spst 139130803Smarcel /* Use the lesser of the next minimal symbol in the same 140130803Smarcel section, or the end of the section, as the end of the 141130803Smarcel function. */ 142130803Smarcel if (SYMBOL_LINKAGE_NAME (msymbol + i) != NULL 143130803Smarcel && SYMBOL_VALUE_ADDRESS (msymbol + i) < osect->endaddr) 144130803Smarcel symfile_objfile->ei.main_func_highpc = 145130803Smarcel SYMBOL_VALUE_ADDRESS (msymbol + i); 146130803Smarcel else 147130803Smarcel /* We got the start address from the last msymbol in the 148130803Smarcel objfile. So the end address is the end of the 149130803Smarcel section. */ 150130803Smarcel symfile_objfile->ei.main_func_highpc = osect->endaddr; 151130803Smarcel } 15219370Spst } 15319370Spst 154130803Smarcel return (symfile_objfile->ei.main_func_lowpc <= pc 155130803Smarcel && symfile_objfile->ei.main_func_highpc > pc); 15619370Spst} 15719370Spst 158130803Smarcel/* Test whether THIS_FRAME is inside the process entry point function. */ 15919370Spst 160130803Smarcelint 161130803Smarcelinside_entry_func (struct frame_info *this_frame) 16219370Spst{ 163130803Smarcel return (get_frame_func (this_frame) == entry_point_address ()); 16419370Spst} 16519370Spst 166130803Smarcel/* Similar to inside_entry_func, but accomodating legacy frame code. */ 16719370Spst 168130803Smarcelstatic int 169130803Smarcellegacy_inside_entry_func (CORE_ADDR pc) 17019370Spst{ 171130803Smarcel if (symfile_objfile == 0) 172130803Smarcel return 0; 17319370Spst 174130803Smarcel if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT) 17519370Spst { 176130803Smarcel /* Do not stop backtracing if the program counter is in the call 177130803Smarcel dummy at the entry point. */ 178130803Smarcel /* FIXME: This won't always work with zeros for the last two 179130803Smarcel arguments. */ 180130803Smarcel if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0)) 181130803Smarcel return 0; 18219370Spst } 183130803Smarcel 184130803Smarcel return (symfile_objfile->ei.entry_func_lowpc <= pc 185130803Smarcel && symfile_objfile->ei.entry_func_highpc > pc); 18619370Spst} 18719370Spst 188130803Smarcel/* Return nonzero if the function for this frame lacks a prologue. 189130803Smarcel Many machines can define DEPRECATED_FRAMELESS_FUNCTION_INVOCATION 190130803Smarcel to just call this function. */ 19119370Spst 19219370Spstint 193130803Smarcellegacy_frameless_look_for_prologue (struct frame_info *frame) 19419370Spst{ 195130803Smarcel CORE_ADDR func_start; 19698944Sobrien 197130803Smarcel func_start = get_frame_func (frame); 19819370Spst if (func_start) 19919370Spst { 20046283Sdfr func_start += FUNCTION_START_OFFSET; 201130803Smarcel /* NOTE: cagney/2004-02-09: Eliminated per-architecture 202130803Smarcel PROLOGUE_FRAMELESS_P call as architectures with custom 203130803Smarcel implementations had all been deleted. Eventually even this 204130803Smarcel function can go - GDB no longer tries to differentiate 205130803Smarcel between framed, frameless and stackless functions. They are 206130803Smarcel all now considered equally evil :-^. */ 207130803Smarcel /* If skipping the prologue ends up skips nothing, there must be 208130803Smarcel no prologue and hence no code creating a frame. There for 209130803Smarcel the function is "frameless" :-/. */ 210130803Smarcel return func_start == SKIP_PROLOGUE (func_start); 21119370Spst } 212130803Smarcel else if (get_frame_pc (frame) == 0) 21398944Sobrien /* A frame with a zero PC is usually created by dereferencing a 21498944Sobrien NULL function pointer, normally causing an immediate core dump 21598944Sobrien of the inferior. Mark function as frameless, as the inferior 21698944Sobrien has no chance of setting up a stack frame. */ 21746283Sdfr return 1; 21819370Spst else 21919370Spst /* If we can't find the start of the function, we don't really 22019370Spst know whether the function is frameless, but we should be able 22119370Spst to get a reasonable (i.e. best we can do under the 22219370Spst circumstances) backtrace by saying that it isn't. */ 22319370Spst return 0; 22419370Spst} 22519370Spst 226130803Smarcel/* Return the innermost lexical block in execution 227130803Smarcel in a specified stack frame. The frame address is assumed valid. 22819370Spst 229130803Smarcel If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the exact code 230130803Smarcel address we used to choose the block. We use this to find a source 231130803Smarcel line, to decide which macro definitions are in scope. 23219370Spst 233130803Smarcel The value returned in *ADDR_IN_BLOCK isn't necessarily the frame's 234130803Smarcel PC, and may not really be a valid PC at all. For example, in the 235130803Smarcel caller of a function declared to never return, the code at the 236130803Smarcel return address will never be reached, so the call instruction may 237130803Smarcel be the very last instruction in the block. So the address we use 238130803Smarcel to choose the block is actually one byte before the return address 239130803Smarcel --- hopefully pointing us at the call instruction, or its delay 240130803Smarcel slot instruction. */ 24119370Spst 242130803Smarcelstruct block * 243130803Smarcelget_frame_block (struct frame_info *frame, CORE_ADDR *addr_in_block) 24419370Spst{ 245130803Smarcel const CORE_ADDR pc = get_frame_address_in_block (frame); 24619370Spst 247130803Smarcel if (addr_in_block) 248130803Smarcel *addr_in_block = pc; 24919370Spst 250130803Smarcel return block_for_pc (pc); 251130803Smarcel} 25219370Spst 253130803SmarcelCORE_ADDR 254130803Smarcelget_pc_function_start (CORE_ADDR pc) 255130803Smarcel{ 256130803Smarcel struct block *bl; 257130803Smarcel struct minimal_symbol *msymbol; 25819370Spst 259130803Smarcel bl = block_for_pc (pc); 260130803Smarcel if (bl) 26119370Spst { 262130803Smarcel struct symbol *symbol = block_function (bl); 26319370Spst 264130803Smarcel if (symbol) 26519370Spst { 266130803Smarcel bl = SYMBOL_BLOCK_VALUE (symbol); 267130803Smarcel return BLOCK_START (bl); 26819370Spst } 26919370Spst } 27019370Spst 271130803Smarcel msymbol = lookup_minimal_symbol_by_pc (pc); 272130803Smarcel if (msymbol) 273130803Smarcel { 274130803Smarcel CORE_ADDR fstart = SYMBOL_VALUE_ADDRESS (msymbol); 27519370Spst 276130803Smarcel if (find_pc_section (fstart)) 277130803Smarcel return fstart; 27846283Sdfr } 27919370Spst 280130803Smarcel return 0; 28119370Spst} 28219370Spst 28319370Spst/* Return the symbol for the function executing in frame FRAME. */ 28419370Spst 28519370Spststruct symbol * 28698944Sobrienget_frame_function (struct frame_info *frame) 28719370Spst{ 288130803Smarcel struct block *bl = get_frame_block (frame, 0); 28919370Spst if (bl == 0) 29019370Spst return 0; 29119370Spst return block_function (bl); 29219370Spst} 29319370Spst 29446283Sdfr 29546283Sdfr/* Return the function containing pc value PC in section SECTION. 29619370Spst Returns 0 if function is not known. */ 29719370Spst 29819370Spststruct symbol * 299130803Smarcelfind_pc_sect_function (CORE_ADDR pc, struct bfd_section *section) 30019370Spst{ 301130803Smarcel struct block *b = block_for_pc_sect (pc, section); 30219370Spst if (b == 0) 30319370Spst return 0; 30419370Spst return block_function (b); 30519370Spst} 30619370Spst 30746283Sdfr/* Return the function containing pc value PC. 30846283Sdfr Returns 0 if function is not known. Backward compatibility, no section */ 30946283Sdfr 31046283Sdfrstruct symbol * 31198944Sobrienfind_pc_function (CORE_ADDR pc) 31246283Sdfr{ 31346283Sdfr return find_pc_sect_function (pc, find_pc_mapped_section (pc)); 31446283Sdfr} 31546283Sdfr 31619370Spst/* These variables are used to cache the most recent result 31719370Spst * of find_pc_partial_function. */ 31819370Spst 31998944Sobrienstatic CORE_ADDR cache_pc_function_low = 0; 32098944Sobrienstatic CORE_ADDR cache_pc_function_high = 0; 32198944Sobrienstatic char *cache_pc_function_name = 0; 322130803Smarcelstatic struct bfd_section *cache_pc_function_section = NULL; 32319370Spst 32419370Spst/* Clear cache, e.g. when symbol table is discarded. */ 32519370Spst 32619370Spstvoid 32798944Sobrienclear_pc_function_cache (void) 32819370Spst{ 32919370Spst cache_pc_function_low = 0; 33019370Spst cache_pc_function_high = 0; 33198944Sobrien cache_pc_function_name = (char *) 0; 33246283Sdfr cache_pc_function_section = NULL; 33319370Spst} 33419370Spst 33519370Spst/* Finds the "function" (text symbol) that is smaller than PC but 33646283Sdfr greatest of all of the potential text symbols in SECTION. Sets 33746283Sdfr *NAME and/or *ADDRESS conditionally if that pointer is non-null. 33846283Sdfr If ENDADDR is non-null, then set *ENDADDR to be the end of the 33946283Sdfr function (exclusive), but passing ENDADDR as non-null means that 34046283Sdfr the function might cause symbols to be read. This function either 34119370Spst succeeds or fails (not halfway succeeds). If it succeeds, it sets 34219370Spst *NAME, *ADDRESS, and *ENDADDR to real information and returns 1. 34346283Sdfr If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero and 34446283Sdfr returns 0. */ 34519370Spst 34619370Spstint 34798944Sobrienfind_pc_sect_partial_function (CORE_ADDR pc, asection *section, char **name, 34898944Sobrien CORE_ADDR *address, CORE_ADDR *endaddr) 34919370Spst{ 35019370Spst struct partial_symtab *pst; 35198944Sobrien struct symbol *f; 35219370Spst struct minimal_symbol *msymbol; 35319370Spst struct partial_symbol *psb; 35498944Sobrien struct obj_section *osect; 35546283Sdfr int i; 35646283Sdfr CORE_ADDR mapped_pc; 35719370Spst 35846283Sdfr mapped_pc = overlay_mapped_address (pc, section); 35946283Sdfr 360130803Smarcel if (mapped_pc >= cache_pc_function_low 361130803Smarcel && mapped_pc < cache_pc_function_high 362130803Smarcel && section == cache_pc_function_section) 36319370Spst goto return_cached_value; 36419370Spst 36519370Spst /* If sigtramp is in the u area, it counts as a function (especially 36619370Spst important for step_1). */ 367130803Smarcel if (SIGTRAMP_START_P () && PC_IN_SIGTRAMP (mapped_pc, (char *) NULL)) 36819370Spst { 36998944Sobrien cache_pc_function_low = SIGTRAMP_START (mapped_pc); 37098944Sobrien cache_pc_function_high = SIGTRAMP_END (mapped_pc); 37198944Sobrien cache_pc_function_name = "<sigtramp>"; 37246283Sdfr cache_pc_function_section = section; 37319370Spst goto return_cached_value; 37419370Spst } 37519370Spst 37646283Sdfr msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section); 37746283Sdfr pst = find_pc_sect_psymtab (mapped_pc, section); 37819370Spst if (pst) 37919370Spst { 38019370Spst /* Need to read the symbols to get a good value for the end address. */ 38119370Spst if (endaddr != NULL && !pst->readin) 38219370Spst { 38319370Spst /* Need to get the terminal in case symbol-reading produces 38419370Spst output. */ 38519370Spst target_terminal_ours_for_output (); 38619370Spst PSYMTAB_TO_SYMTAB (pst); 38719370Spst } 38819370Spst 38919370Spst if (pst->readin) 39019370Spst { 39119370Spst /* Checking whether the msymbol has a larger value is for the 39219370Spst "pathological" case mentioned in print_frame_info. */ 39346283Sdfr f = find_pc_sect_function (mapped_pc, section); 39419370Spst if (f != NULL 39519370Spst && (msymbol == NULL 39619370Spst || (BLOCK_START (SYMBOL_BLOCK_VALUE (f)) 39719370Spst >= SYMBOL_VALUE_ADDRESS (msymbol)))) 39819370Spst { 39998944Sobrien cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f)); 40098944Sobrien cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f)); 401130803Smarcel cache_pc_function_name = DEPRECATED_SYMBOL_NAME (f); 40246283Sdfr cache_pc_function_section = section; 40319370Spst goto return_cached_value; 40419370Spst } 40519370Spst } 40619370Spst else 40719370Spst { 40819370Spst /* Now that static symbols go in the minimal symbol table, perhaps 40919370Spst we could just ignore the partial symbols. But at least for now 41019370Spst we use the partial or minimal symbol, whichever is larger. */ 41146283Sdfr psb = find_pc_sect_psymbol (pst, mapped_pc, section); 41219370Spst 41319370Spst if (psb 41419370Spst && (msymbol == NULL || 41519370Spst (SYMBOL_VALUE_ADDRESS (psb) 41619370Spst >= SYMBOL_VALUE_ADDRESS (msymbol)))) 41719370Spst { 41819370Spst /* This case isn't being cached currently. */ 41919370Spst if (address) 42019370Spst *address = SYMBOL_VALUE_ADDRESS (psb); 42119370Spst if (name) 422130803Smarcel *name = DEPRECATED_SYMBOL_NAME (psb); 42319370Spst /* endaddr non-NULL can't happen here. */ 42419370Spst return 1; 42519370Spst } 42619370Spst } 42719370Spst } 42819370Spst 42919370Spst /* Not in the normal symbol tables, see if the pc is in a known section. 43019370Spst If it's not, then give up. This ensures that anything beyond the end 43119370Spst of the text seg doesn't appear to be part of the last function in the 43219370Spst text segment. */ 43319370Spst 43446283Sdfr osect = find_pc_sect_section (mapped_pc, section); 43519370Spst 43646283Sdfr if (!osect) 43719370Spst msymbol = NULL; 43819370Spst 43919370Spst /* Must be in the minimal symbol table. */ 44019370Spst if (msymbol == NULL) 44119370Spst { 44219370Spst /* No available symbol. */ 44319370Spst if (name != NULL) 44419370Spst *name = 0; 44519370Spst if (address != NULL) 44619370Spst *address = 0; 44719370Spst if (endaddr != NULL) 44819370Spst *endaddr = 0; 44919370Spst return 0; 45019370Spst } 45119370Spst 45298944Sobrien cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol); 453130803Smarcel cache_pc_function_name = DEPRECATED_SYMBOL_NAME (msymbol); 45446283Sdfr cache_pc_function_section = section; 45519370Spst 45646283Sdfr /* Use the lesser of the next minimal symbol in the same section, or 45746283Sdfr the end of the section, as the end of the function. */ 45898944Sobrien 45946283Sdfr /* Step over other symbols at this same address, and symbols in 46046283Sdfr other sections, to find the next symbol in this section with 46146283Sdfr a different address. */ 46219370Spst 463130803Smarcel for (i = 1; DEPRECATED_SYMBOL_NAME (msymbol + i) != NULL; i++) 46446283Sdfr { 46598944Sobrien if (SYMBOL_VALUE_ADDRESS (msymbol + i) != SYMBOL_VALUE_ADDRESS (msymbol) 466130803Smarcel && SYMBOL_BFD_SECTION (msymbol + i) == SYMBOL_BFD_SECTION (msymbol)) 46746283Sdfr break; 46846283Sdfr } 46946283Sdfr 470130803Smarcel if (DEPRECATED_SYMBOL_NAME (msymbol + i) != NULL 47146283Sdfr && SYMBOL_VALUE_ADDRESS (msymbol + i) < osect->endaddr) 47246283Sdfr cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i); 47319370Spst else 47419370Spst /* We got the start address from the last msymbol in the objfile. 47519370Spst So the end address is the end of the section. */ 47646283Sdfr cache_pc_function_high = osect->endaddr; 47719370Spst 478130803Smarcel return_cached_value: 47946283Sdfr 48019370Spst if (address) 48146283Sdfr { 48246283Sdfr if (pc_in_unmapped_range (pc, section)) 48398944Sobrien *address = overlay_unmapped_address (cache_pc_function_low, section); 48446283Sdfr else 48598944Sobrien *address = cache_pc_function_low; 48646283Sdfr } 48798944Sobrien 48819370Spst if (name) 48919370Spst *name = cache_pc_function_name; 49046283Sdfr 49119370Spst if (endaddr) 49246283Sdfr { 49346283Sdfr if (pc_in_unmapped_range (pc, section)) 49498944Sobrien { 49546283Sdfr /* Because the high address is actually beyond the end of 49646283Sdfr the function (and therefore possibly beyond the end of 497130803Smarcel the overlay), we must actually convert (high - 1) and 498130803Smarcel then add one to that. */ 49946283Sdfr 50098944Sobrien *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1, 50146283Sdfr section); 50298944Sobrien } 50346283Sdfr else 50498944Sobrien *endaddr = cache_pc_function_high; 50546283Sdfr } 50646283Sdfr 50719370Spst return 1; 50819370Spst} 50919370Spst 510130803Smarcel/* Backward compatibility, no section argument. */ 51146283Sdfr 51246283Sdfrint 51398944Sobrienfind_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address, 51498944Sobrien CORE_ADDR *endaddr) 51546283Sdfr{ 516130803Smarcel struct bfd_section *bfd_section; 51746283Sdfr 518130803Smarcel /* To ensure that the symbol returned belongs to the correct setion 519130803Smarcel (and that the last [random] symbol from the previous section 520130803Smarcel isn't returned) try to find the section containing PC. First try 521130803Smarcel the overlay code (which by default returns NULL); and second try 522130803Smarcel the normal section code (which almost always succeeds). */ 523130803Smarcel bfd_section = find_pc_overlay (pc); 524130803Smarcel if (bfd_section == NULL) 525130803Smarcel { 526130803Smarcel struct obj_section *obj_section = find_pc_section (pc); 527130803Smarcel if (obj_section == NULL) 528130803Smarcel bfd_section = NULL; 529130803Smarcel else 530130803Smarcel bfd_section = obj_section->the_bfd_section; 531130803Smarcel } 532130803Smarcel return find_pc_sect_partial_function (pc, bfd_section, name, address, 533130803Smarcel endaddr); 53446283Sdfr} 53546283Sdfr 53619370Spst/* Return the innermost stack frame executing inside of BLOCK, 53719370Spst or NULL if there is no such frame. If BLOCK is NULL, just return NULL. */ 53819370Spst 53919370Spststruct frame_info * 54098944Sobrienblock_innermost_frame (struct block *block) 54119370Spst{ 54219370Spst struct frame_info *frame; 543130803Smarcel CORE_ADDR start; 544130803Smarcel CORE_ADDR end; 545130803Smarcel CORE_ADDR calling_pc; 54619370Spst 54719370Spst if (block == NULL) 54819370Spst return NULL; 54919370Spst 55019370Spst start = BLOCK_START (block); 55119370Spst end = BLOCK_END (block); 55219370Spst 55319370Spst frame = NULL; 55419370Spst while (1) 55519370Spst { 55619370Spst frame = get_prev_frame (frame); 55719370Spst if (frame == NULL) 55819370Spst return NULL; 559130803Smarcel calling_pc = get_frame_address_in_block (frame); 560130803Smarcel if (calling_pc >= start && calling_pc < end) 56119370Spst return frame; 56219370Spst } 56319370Spst} 56419370Spst 56598944Sobrien/* Are we in a call dummy? The code below which allows DECR_PC_AFTER_BREAK 56698944Sobrien below is for infrun.c, which may give the macro a pc without that 56798944Sobrien subtracted out. */ 56898944Sobrien 56998944Sobrien/* Is the PC in a call dummy? SP and FRAME_ADDRESS are the bottom and 57098944Sobrien top of the stack frame which we are checking, where "bottom" and 57198944Sobrien "top" refer to some section of memory which contains the code for 57298944Sobrien the call dummy. Calls to this macro assume that the contents of 573130803Smarcel SP_REGNUM and DEPRECATED_FP_REGNUM (or the saved values thereof), 574130803Smarcel respectively, are the things to pass. 57598944Sobrien 576130803Smarcel This won't work on the 29k, where SP_REGNUM and 577130803Smarcel DEPRECATED_FP_REGNUM don't have that meaning, but the 29k doesn't 578130803Smarcel use ON_STACK. This could be fixed by generalizing this scheme, 579130803Smarcel perhaps by passing in a frame and adding a few fields, at least on 580130803Smarcel machines which need them for DEPRECATED_PC_IN_CALL_DUMMY. 58198944Sobrien 58298944Sobrien Something simpler, like checking for the stack segment, doesn't work, 58398944Sobrien since various programs (threads implementations, gcc nested function 58498944Sobrien stubs, etc) may either allocate stack frames in another segment, or 58598944Sobrien allocate other kinds of code on the stack. */ 58698944Sobrien 58798944Sobrienint 588130803Smarceldeprecated_pc_in_call_dummy_on_stack (CORE_ADDR pc, CORE_ADDR sp, 589130803Smarcel CORE_ADDR frame_address) 59098944Sobrien{ 59198944Sobrien return (INNER_THAN ((sp), (pc)) 59298944Sobrien && (frame_address != 0) 59398944Sobrien && INNER_THAN ((pc), (frame_address))); 59498944Sobrien} 59598944Sobrien 59698944Sobrienint 597130803Smarceldeprecated_pc_in_call_dummy_at_entry_point (CORE_ADDR pc, CORE_ADDR sp, 598130803Smarcel CORE_ADDR frame_address) 59998944Sobrien{ 600130803Smarcel CORE_ADDR addr = entry_point_address (); 601130803Smarcel return ((pc) >= addr && (pc) <= (addr + DECR_PC_AFTER_BREAK)); 60298944Sobrien} 60398944Sobrien 604130803Smarcel/* Returns true for a user frame or a call_function_by_hand dummy 605130803Smarcel frame, and false for the CRT0 start-up frame. Purpose is to 606130803Smarcel terminate backtrace. */ 60798944Sobrien 608130803Smarcelint 609130803Smarcellegacy_frame_chain_valid (CORE_ADDR fp, struct frame_info *fi) 61098944Sobrien{ 611130803Smarcel /* Don't prune CALL_DUMMY frames. */ 612130803Smarcel if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES 613130803Smarcel && DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), 0, 0)) 614130803Smarcel return 1; 61598944Sobrien 616130803Smarcel /* If the new frame pointer is zero, then it isn't valid. */ 617130803Smarcel if (fp == 0) 61846283Sdfr return 0; 619130803Smarcel 620130803Smarcel /* If the new frame would be inside (younger than) the previous frame, 621130803Smarcel then it isn't valid. */ 622130803Smarcel if (INNER_THAN (fp, get_frame_base (fi))) 623130803Smarcel return 0; 624130803Smarcel 625130803Smarcel /* If the architecture has a custom DEPRECATED_FRAME_CHAIN_VALID, 626130803Smarcel call it now. */ 627130803Smarcel if (DEPRECATED_FRAME_CHAIN_VALID_P ()) 628130803Smarcel return DEPRECATED_FRAME_CHAIN_VALID (fp, fi); 62946283Sdfr 630130803Smarcel /* If we're already inside the entry function for the main objfile, then it 631130803Smarcel isn't valid. */ 632130803Smarcel if (legacy_inside_entry_func (get_frame_pc (fi))) 63346283Sdfr return 0; 63446283Sdfr 635130803Smarcel /* If we're inside the entry file, it isn't valid. */ 636130803Smarcel /* NOTE/drow 2002-12-25: should there be a way to disable this check? It 637130803Smarcel assumes a single small entry file, and the way some debug readers (e.g. 638130803Smarcel dbxread) figure out which object is the entry file is somewhat hokey. */ 639130803Smarcel if (deprecated_inside_entry_file (frame_pc_unwind (fi))) 640130803Smarcel return 0; 64146283Sdfr 642130803Smarcel return 1; 64346283Sdfr} 644