home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / blockframe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-18  |  23.9 KB  |  855 lines

  1. /* Get info from stack frames;
  2.    convert between frames, blocks, functions and pc values.
  3.    Copyright 1986, 1987, 1988, 1989, 1991, 1994 Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include "symtab.h"
  23. #include "bfd.h"
  24. #include "symfile.h"
  25. #include "objfiles.h"
  26. #include "frame.h"
  27. #include "gdbcore.h"
  28. #include "value.h"        /* for read_register */
  29. #include "target.h"        /* for target_has_stack */
  30. #include "inferior.h"        /* for read_pc */
  31. #include "annotate.h"
  32.  
  33. /* Is ADDR inside the startup file?  Note that if your machine
  34.    has a way to detect the bottom of the stack, there is no need
  35.    to call this function from FRAME_CHAIN_VALID; the reason for
  36.    doing so is that some machines have no way of detecting bottom
  37.    of stack. 
  38.  
  39.    A PC of zero is always considered to be the bottom of the stack. */
  40.  
  41. int
  42. inside_entry_file (addr)
  43.      CORE_ADDR addr;
  44. {
  45.   if (addr == 0)
  46.     return 1;
  47.   if (symfile_objfile == 0)
  48.     return 0;
  49. #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT
  50.   /* Do not stop backtracing if the pc is in the call dummy
  51.      at the entry point.  */
  52.   if (PC_IN_CALL_DUMMY (addr, 0, 0))
  53.     return 0;
  54. #endif
  55.   return (addr >= symfile_objfile -> ei.entry_file_lowpc &&
  56.       addr <  symfile_objfile -> ei.entry_file_highpc);
  57. }
  58.  
  59. /* Test a specified PC value to see if it is in the range of addresses
  60.    that correspond to the main() function.  See comments above for why
  61.    we might want to do this.
  62.  
  63.    Typically called from FRAME_CHAIN_VALID.
  64.  
  65.    A PC of zero is always considered to be the bottom of the stack. */
  66.  
  67. int
  68. inside_main_func (pc)
  69. CORE_ADDR pc;
  70. {
  71.   if (pc == 0)
  72.     return 1;
  73.   if (symfile_objfile == 0)
  74.     return 0;
  75.   return (symfile_objfile -> ei.main_func_lowpc  <= pc &&
  76.       symfile_objfile -> ei.main_func_highpc > pc);
  77. }
  78.  
  79. /* Test a specified PC value to see if it is in the range of addresses
  80.    that correspond to the process entry point function.  See comments
  81.    in objfiles.h for why we might want to do this.
  82.  
  83.    Typically called from FRAME_CHAIN_VALID.
  84.  
  85.    A PC of zero is always considered to be the bottom of the stack. */
  86.  
  87. int
  88. inside_entry_func (pc)
  89. CORE_ADDR pc;
  90. {
  91.   if (pc == 0)
  92.     return 1;
  93.   if (symfile_objfile == 0)
  94.     return 0;
  95. #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT
  96.   /* Do not stop backtracing if the pc is in the call dummy
  97.      at the entry point.  */
  98.   if (PC_IN_CALL_DUMMY (pc, 0, 0))
  99.     return 0;
  100. #endif
  101.   return (symfile_objfile -> ei.entry_func_lowpc  <= pc &&
  102.       symfile_objfile -> ei.entry_func_highpc > pc);
  103. }
  104.  
  105. /* Info about the innermost stack frame (contents of FP register) */
  106.  
  107. static struct frame_info *current_frame;
  108.  
  109. /* Cache for frame addresses already read by gdb.  Valid only while
  110.    inferior is stopped.  Control variables for the frame cache should
  111.    be local to this module.  */
  112.  
  113. struct obstack frame_cache_obstack;
  114.  
  115. /* Return the innermost (currently executing) stack frame.  */
  116.  
  117. struct frame_info *
  118. get_current_frame ()
  119. {
  120.   if (current_frame == NULL)
  121.     {
  122.       if (target_has_stack)
  123.     current_frame = create_new_frame (read_fp (), read_pc ());
  124.       else
  125.     error ("No stack.");
  126.     }
  127.   return current_frame;
  128. }
  129.  
  130. void
  131. set_current_frame (frame)
  132.      struct frame_info *frame;
  133. {
  134.   current_frame = frame;
  135. }
  136.  
  137. /* Create an arbitrary (i.e. address specified by user) or innermost frame.
  138.    Always returns a non-NULL value.  */
  139.  
  140. struct frame_info *
  141. create_new_frame (addr, pc)
  142.      CORE_ADDR addr;
  143.      CORE_ADDR pc;
  144. {
  145.   struct frame_info *fi;
  146.   char *name;
  147.  
  148.   fi = (struct frame_info *)
  149.     obstack_alloc (&frame_cache_obstack,
  150.            sizeof (struct frame_info));
  151.  
  152.   /* Arbitrary frame */
  153.   fi->next = NULL;
  154.   fi->prev = NULL;
  155.   fi->frame = addr;
  156.   fi->pc = pc;
  157.   find_pc_partial_function (pc, &name, (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
  158.   fi->signal_handler_caller = IN_SIGTRAMP (fi->pc, name);
  159.  
  160. #ifdef INIT_EXTRA_FRAME_INFO
  161.   INIT_EXTRA_FRAME_INFO (0, fi);
  162. #endif
  163.  
  164.   return fi;
  165. }
  166.  
  167. /* Return the frame that called FI.
  168.    If FI is the original frame (it has no caller), return 0.  */
  169.  
  170. struct frame_info *
  171. get_prev_frame (frame)
  172.      struct frame_info *frame;
  173. {
  174.   return get_prev_frame_info (frame);
  175. }
  176.  
  177. /* Return the frame that FRAME calls (NULL if FRAME is the innermost
  178.    frame).  */
  179.  
  180. struct frame_info *
  181. get_next_frame (frame)
  182.      struct frame_info *frame;
  183. {
  184.   return frame->next;
  185. }
  186.  
  187. /* Flush the entire frame cache.  */
  188.  
  189. void
  190. flush_cached_frames ()
  191. {
  192.   /* Since we can't really be sure what the first object allocated was */
  193.   obstack_free (&frame_cache_obstack, 0);
  194.   obstack_init (&frame_cache_obstack);
  195.  
  196.   current_frame = NULL;  /* Invalidate cache */
  197.   select_frame (NULL, -1);
  198.   annotate_frames_invalid ();
  199. }
  200.  
  201. /* Flush the frame cache, and start a new one if necessary.  */
  202.  
  203. void
  204. reinit_frame_cache ()
  205. {
  206.   flush_cached_frames ();
  207.  
  208.   /* FIXME: The inferior_pid test is wrong if there is a corefile.  */
  209.   if (inferior_pid != 0)
  210.     {
  211.       select_frame (get_current_frame (), 0);
  212.     }
  213. }
  214.  
  215. /* If a machine allows frameless functions, it should define a macro
  216.    FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h.  FI is the struct
  217.    frame_info for the frame, and FRAMELESS should be set to nonzero
  218.    if it represents a frameless function invocation.  */
  219.  
  220. /* Return nonzero if the function for this frame lacks a prologue.  Many
  221.    machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
  222.    function.  */
  223.  
  224. int
  225. frameless_look_for_prologue (frame)
  226.      struct frame_info *frame;
  227. {
  228.   CORE_ADDR func_start, after_prologue;
  229.   func_start = (get_pc_function_start (frame->pc) + FUNCTION_START_OFFSET);
  230.   if (func_start)
  231.     {
  232.       after_prologue = func_start;
  233. #ifdef SKIP_PROLOGUE_FRAMELESS_P
  234.       /* This is faster, since only care whether there *is* a prologue,
  235.      not how long it is.  */
  236.       SKIP_PROLOGUE_FRAMELESS_P (after_prologue);
  237. #else
  238.       SKIP_PROLOGUE (after_prologue);
  239. #endif
  240.       return after_prologue == func_start;
  241.     }
  242.   else
  243.     /* If we can't find the start of the function, we don't really
  244.        know whether the function is frameless, but we should be able
  245.        to get a reasonable (i.e. best we can do under the
  246.        circumstances) backtrace by saying that it isn't.  */
  247.     return 0;
  248. }
  249.  
  250. /* Default a few macros that people seldom redefine.  */
  251.  
  252. #if !defined (INIT_FRAME_PC)
  253. #define INIT_FRAME_PC(fromleaf, prev) \
  254.   prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
  255.           prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
  256. #endif
  257.  
  258. #ifndef FRAME_CHAIN_COMBINE
  259. #define    FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
  260. #endif
  261.  
  262. /* Return a structure containing various interesting information
  263.    about the frame that called NEXT_FRAME.  Returns NULL
  264.    if there is no such frame.  */
  265.  
  266. struct frame_info *
  267. get_prev_frame_info (next_frame)
  268.      struct frame_info *next_frame;
  269. {
  270.   CORE_ADDR address = 0;
  271.   struct frame_info *prev;
  272.   int fromleaf = 0;
  273.   char *name;
  274.  
  275.   /* If the requested entry is in the cache, return it.
  276.      Otherwise, figure out what the address should be for the entry
  277.      we're about to add to the cache. */
  278.  
  279.   if (!next_frame)
  280.     {
  281. #if 0
  282.       /* This screws value_of_variable, which just wants a nice clean
  283.      NULL return from block_innermost_frame if there are no frames.
  284.      I don't think I've ever seen this message happen otherwise.
  285.      And returning NULL here is a perfectly legitimate thing to do.  */
  286.       if (!current_frame)
  287.     {
  288.       error ("You haven't set up a process's stack to examine.");
  289.     }
  290. #endif
  291.  
  292.       return current_frame;
  293.     }
  294.  
  295.   /* If we have the prev one, return it */
  296.   if (next_frame->prev)
  297.     return next_frame->prev;
  298.  
  299.   /* On some machines it is possible to call a function without
  300.      setting up a stack frame for it.  On these machines, we
  301.      define this macro to take two args; a frameinfo pointer
  302.      identifying a frame and a variable to set or clear if it is
  303.      or isn't leafless.  */
  304. #ifdef FRAMELESS_FUNCTION_INVOCATION
  305.   /* Still don't want to worry about this except on the innermost
  306.      frame.  This macro will set FROMLEAF if NEXT_FRAME is a
  307.      frameless function invocation.  */
  308.   if (!(next_frame->next))
  309.     {
  310.       FRAMELESS_FUNCTION_INVOCATION (next_frame, fromleaf);
  311.       if (fromleaf)
  312.     address = FRAME_FP (next_frame);
  313.     }
  314. #endif
  315.  
  316.   if (!fromleaf)
  317.     {
  318.       /* Two macros defined in tm.h specify the machine-dependent
  319.      actions to be performed here.
  320.      First, get the frame's chain-pointer.
  321.      If that is zero, the frame is the outermost frame or a leaf
  322.      called by the outermost frame.  This means that if start
  323.      calls main without a frame, we'll return 0 (which is fine
  324.      anyway).
  325.  
  326.      Nope; there's a problem.  This also returns when the current
  327.      routine is a leaf of main.  This is unacceptable.  We move
  328.      this to after the ffi test; I'd rather have backtraces from
  329.      start go curfluy than have an abort called from main not show
  330.      main.  */
  331.       address = FRAME_CHAIN (next_frame);
  332.       if (!FRAME_CHAIN_VALID (address, next_frame))
  333.     return 0;
  334.       address = FRAME_CHAIN_COMBINE (address, next_frame);
  335.     }
  336.   if (address == 0)
  337.     return 0;
  338.  
  339.   prev = (struct frame_info *)
  340.     obstack_alloc (&frame_cache_obstack,
  341.            sizeof (struct frame_info));
  342.  
  343.   if (next_frame)
  344.     next_frame->prev = prev;
  345.   prev->next = next_frame;
  346.   prev->prev = (struct frame_info *) 0;
  347.   prev->frame = address;
  348.   prev->signal_handler_caller = 0;
  349.  
  350. /* This change should not be needed, FIXME!  We should
  351.    determine whether any targets *need* INIT_FRAME_PC to happen
  352.    after INIT_EXTRA_FRAME_INFO and come up with a simple way to
  353.    express what goes on here.
  354.  
  355.       INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
  356.               (where the PC is already set up) and here (where it isn't).
  357.       INIT_FRAME_PC is only called from here, always after
  358.               INIT_EXTRA_FRAME_INFO.
  359.    
  360.    The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC
  361.    value (which hasn't been set yet).  Some other machines appear to
  362.    require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC.  Phoo.
  363.  
  364.    We shouldn't need INIT_FRAME_PC_FIRST to add more complication to
  365.    an already overcomplicated part of GDB.   gnu@cygnus.com, 15Sep92.
  366.  
  367.    Assuming that some machines need INIT_FRAME_PC after
  368.    INIT_EXTRA_FRAME_INFO, one possible scheme:
  369.  
  370.    SETUP_INNERMOST_FRAME()
  371.      Default version is just create_new_frame (read_fp ()),
  372.      read_pc ()).  Machines with extra frame info would do that (or the
  373.      local equivalent) and then set the extra fields.
  374.    SETUP_ARBITRARY_FRAME(argc, argv)
  375.      Only change here is that create_new_frame would no longer init extra
  376.      frame info; SETUP_ARBITRARY_FRAME would have to do that.
  377.    INIT_PREV_FRAME(fromleaf, prev)
  378.      Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC.  This should
  379.      also return a flag saying whether to keep the new frame, or
  380.      whether to discard it, because on some machines (e.g.  mips) it
  381.      is really awkward to have FRAME_CHAIN_VALID called *before*
  382.      INIT_EXTRA_FRAME_INFO (there is no good way to get information
  383.      deduced in FRAME_CHAIN_VALID into the extra fields of the new frame).
  384.    std_frame_pc(fromleaf, prev)
  385.      This is the default setting for INIT_PREV_FRAME.  It just does what
  386.      the default INIT_FRAME_PC does.  Some machines will call it from
  387.      INIT_PREV_FRAME (either at the beginning, the end, or in the middle).
  388.      Some machines won't use it.
  389.    kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94.  */
  390.  
  391. #ifdef INIT_FRAME_PC_FIRST
  392.   INIT_FRAME_PC_FIRST (fromleaf, prev);
  393. #endif
  394.  
  395. #ifdef INIT_EXTRA_FRAME_INFO
  396.   INIT_EXTRA_FRAME_INFO(fromleaf, prev);
  397. #endif
  398.  
  399.   /* This entry is in the frame queue now, which is good since
  400.      FRAME_SAVED_PC may use that queue to figure out its value
  401.      (see tm-sparc.h).  We want the pc saved in the inferior frame. */
  402.   INIT_FRAME_PC(fromleaf, prev);
  403.  
  404.   /* If ->frame and ->pc are unchanged, we are in the process of getting
  405.      ourselves into an infinite backtrace.  Some architectures check this
  406.      in FRAME_CHAIN or thereabouts, but it seems like there is no reason
  407.      this can't be an architecture-independent check.  */
  408.   if (next_frame != NULL)
  409.     {
  410.       if (prev->frame == next_frame->frame
  411.       && prev->pc == next_frame->pc)
  412.     {
  413.       next_frame->prev = NULL;
  414.       obstack_free (&frame_cache_obstack, prev);
  415.       return NULL;
  416.     }
  417.     }
  418.  
  419.   find_pc_partial_function (prev->pc, &name,
  420.                 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
  421.   if (IN_SIGTRAMP (prev->pc, name))
  422.     prev->signal_handler_caller = 1;
  423.  
  424.   return prev;
  425. }
  426.  
  427. CORE_ADDR
  428. get_frame_pc (frame)
  429.      struct frame_info *frame;
  430. {
  431.   return frame->pc;
  432. }
  433.  
  434. #if defined (FRAME_FIND_SAVED_REGS)
  435. /* Find the addresses in which registers are saved in FRAME.  */
  436.  
  437. void
  438. get_frame_saved_regs (frame, saved_regs_addr)
  439.      struct frame_info *frame;
  440.      struct frame_saved_regs *saved_regs_addr;
  441. {
  442.   FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr);
  443. }
  444. #endif
  445.  
  446. /* Return the innermost lexical block in execution
  447.    in a specified stack frame.  The frame address is assumed valid.  */
  448.  
  449. struct block *
  450. get_frame_block (frame)
  451.      struct frame_info *frame;
  452. {
  453.   CORE_ADDR pc;
  454.  
  455.   pc = frame->pc;
  456.   if (frame->next != 0 && frame->next->signal_handler_caller == 0)
  457.     /* We are not in the innermost frame and we were not interrupted
  458.        by a signal.  We need to subtract one to get the correct block,
  459.        in case the call instruction was the last instruction of the block.
  460.        If there are any machines on which the saved pc does not point to
  461.        after the call insn, we probably want to make frame->pc point after
  462.        the call insn anyway.  */
  463.     --pc;
  464.   return block_for_pc (pc);
  465. }
  466.  
  467. struct block *
  468. get_current_block ()
  469. {
  470.   return block_for_pc (read_pc ());
  471. }
  472.  
  473. CORE_ADDR
  474. get_pc_function_start (pc)
  475.      CORE_ADDR pc;
  476. {
  477.   register struct block *bl;
  478.   register struct symbol *symbol;
  479.   register struct minimal_symbol *msymbol;
  480.   CORE_ADDR fstart;
  481.  
  482.   if ((bl = block_for_pc (pc)) != NULL &&
  483.       (symbol = block_function (bl)) != NULL)
  484.     {
  485.       bl = SYMBOL_BLOCK_VALUE (symbol);
  486.       fstart = BLOCK_START (bl);
  487.     }
  488.   else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL)
  489.     {
  490.       fstart = SYMBOL_VALUE_ADDRESS (msymbol);
  491.     }
  492.   else
  493.     {
  494.       fstart = 0;
  495.     }
  496.   return (fstart);
  497. }
  498.  
  499. /* Return the symbol for the function executing in frame FRAME.  */
  500.  
  501. struct symbol *
  502. get_frame_function (frame)
  503.      struct frame_info *frame;
  504. {
  505.   register struct block *bl = get_frame_block (frame);
  506.   if (bl == 0)
  507.     return 0;
  508.   return block_function (bl);
  509. }
  510.  
  511. /* Return the blockvector immediately containing the innermost lexical block
  512.    containing the specified pc value, or 0 if there is none.
  513.    PINDEX is a pointer to the index value of the block.  If PINDEX
  514.    is NULL, we don't pass this information back to the caller.  */
  515.  
  516. struct blockvector *
  517. blockvector_for_pc (pc, pindex)
  518.      register CORE_ADDR pc;
  519.      int *pindex;
  520. {
  521.   register struct block *b;
  522.   register int bot, top, half;
  523.   register struct symtab *s;
  524.   struct blockvector *bl;
  525.  
  526.   /* First search all symtabs for one whose file contains our pc */
  527.   s = find_pc_symtab (pc);
  528.   if (s == 0)
  529.     return 0;
  530.  
  531.   bl = BLOCKVECTOR (s);
  532.   b = BLOCKVECTOR_BLOCK (bl, 0);
  533.  
  534.   /* Then search that symtab for the smallest block that wins.  */
  535.   /* Use binary search to find the last block that starts before PC.  */
  536.  
  537.   bot = 0;
  538.   top = BLOCKVECTOR_NBLOCKS (bl);
  539.  
  540.   while (top - bot > 1)
  541.     {
  542.       half = (top - bot + 1) >> 1;
  543.       b = BLOCKVECTOR_BLOCK (bl, bot + half);
  544.       if (BLOCK_START (b) <= pc)
  545.     bot += half;
  546.       else
  547.     top = bot + half;
  548.     }
  549.  
  550.   /* Now search backward for a block that ends after PC.  */
  551.  
  552.   while (bot >= 0)
  553.     {
  554.       b = BLOCKVECTOR_BLOCK (bl, bot);
  555.       if (BLOCK_END (b) > pc)
  556.     {
  557.       if (pindex)
  558.         *pindex = bot;
  559.       return bl;
  560.     }
  561.       bot--;
  562.     }
  563.  
  564.   return 0;
  565. }
  566.  
  567. /* Return the innermost lexical block containing the specified pc value,
  568.    or 0 if there is none.  */
  569.  
  570. struct block *
  571. block_for_pc (pc)
  572.      register CORE_ADDR pc;
  573. {
  574.   register struct blockvector *bl;
  575.   int index;
  576.  
  577.   bl = blockvector_for_pc (pc, &index);
  578.   if (bl)
  579.     return BLOCKVECTOR_BLOCK (bl, index);
  580.   return 0;
  581. }
  582.  
  583. /* Return the function containing pc value PC.
  584.    Returns 0 if function is not known.  */
  585.  
  586. struct symbol *
  587. find_pc_function (pc)
  588.      CORE_ADDR pc;
  589. {
  590.   register struct block *b = block_for_pc (pc);
  591.   if (b == 0)
  592.     return 0;
  593.   return block_function (b);
  594. }
  595.  
  596. /* These variables are used to cache the most recent result
  597.  * of find_pc_partial_function. */
  598.  
  599. static CORE_ADDR cache_pc_function_low = 0;
  600. static CORE_ADDR cache_pc_function_high = 0;
  601. static char *cache_pc_function_name = 0;
  602.  
  603. /* Clear cache, e.g. when symbol table is discarded. */
  604.  
  605. void
  606. clear_pc_function_cache()
  607. {
  608.   cache_pc_function_low = 0;
  609.   cache_pc_function_high = 0;
  610.   cache_pc_function_name = (char *)0;
  611. }
  612.  
  613. /* Finds the "function" (text symbol) that is smaller than PC but
  614.    greatest of all of the potential text symbols.  Sets *NAME and/or
  615.    *ADDRESS conditionally if that pointer is non-null.  If ENDADDR is
  616.    non-null, then set *ENDADDR to be the end of the function
  617.    (exclusive), but passing ENDADDR as non-null means that the
  618.    function might cause symbols to be read.  This function either
  619.    succeeds or fails (not halfway succeeds).  If it succeeds, it sets
  620.    *NAME, *ADDRESS, and *ENDADDR to real information and returns 1.
  621.    If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero
  622.    and returns 0.  */
  623.  
  624. int
  625. find_pc_partial_function (pc, name, address, endaddr)
  626.      CORE_ADDR pc;
  627.      char **name;
  628.      CORE_ADDR *address;
  629.      CORE_ADDR *endaddr;
  630. {
  631.   struct partial_symtab *pst;
  632.   struct symbol *f;
  633.   struct minimal_symbol *msymbol;
  634.   struct partial_symbol *psb;
  635.   struct obj_section *sec;
  636.  
  637.   if (pc >= cache_pc_function_low && pc < cache_pc_function_high)
  638.     goto return_cached_value;
  639.  
  640.   /* If sigtramp is in the u area, it counts as a function (especially
  641.      important for step_1).  */
  642. #if defined SIGTRAMP_START
  643.   if (IN_SIGTRAMP (pc, (char *)NULL))
  644.     {
  645.       cache_pc_function_low = SIGTRAMP_START;
  646.       cache_pc_function_high = SIGTRAMP_END;
  647.       cache_pc_function_name = "<sigtramp>";
  648.  
  649.       goto return_cached_value;
  650.     }
  651. #endif
  652.  
  653.   msymbol = lookup_minimal_symbol_by_pc (pc);
  654.   pst = find_pc_psymtab (pc);
  655.   if (pst)
  656.     {
  657.       /* Need to read the symbols to get a good value for the end address.  */
  658.       if (endaddr != NULL && !pst->readin)
  659.     {
  660.       /* Need to get the terminal in case symbol-reading produces
  661.          output.  */
  662.       target_terminal_ours_for_output ();
  663.       PSYMTAB_TO_SYMTAB (pst);
  664.     }
  665.  
  666.       if (pst->readin)
  667.     {
  668.       /* Checking whether the msymbol has a larger value is for the
  669.          "pathological" case mentioned in print_frame_info.  */
  670.       f = find_pc_function (pc);
  671.       if (f != NULL
  672.           && (msymbol == NULL
  673.           || (BLOCK_START (SYMBOL_BLOCK_VALUE (f))
  674.               >= SYMBOL_VALUE_ADDRESS (msymbol))))
  675.         {
  676.           cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
  677.           cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
  678.           cache_pc_function_name = SYMBOL_NAME (f);
  679.           goto return_cached_value;
  680.         }
  681.     }
  682.       else
  683.     {
  684.       /* Now that static symbols go in the minimal symbol table, perhaps
  685.          we could just ignore the partial symbols.  But at least for now
  686.          we use the partial or minimal symbol, whichever is larger.  */
  687.       psb = find_pc_psymbol (pst, pc);
  688.  
  689.       if (psb
  690.           && (msymbol == NULL ||
  691.           (SYMBOL_VALUE_ADDRESS (psb)
  692.            >= SYMBOL_VALUE_ADDRESS (msymbol))))
  693.         {
  694.           /* This case isn't being cached currently. */
  695.           if (address)
  696.         *address = SYMBOL_VALUE_ADDRESS (psb);
  697.           if (name)
  698.         *name = SYMBOL_NAME (psb);
  699.           /* endaddr non-NULL can't happen here.  */
  700.           return 1;
  701.         }
  702.     }
  703.     }
  704.  
  705.   /* Not in the normal symbol tables, see if the pc is in a known section.
  706.      If it's not, then give up.  This ensures that anything beyond the end
  707.      of the text seg doesn't appear to be part of the last function in the
  708.      text segment.  */
  709.  
  710.   sec = find_pc_section (pc);
  711.  
  712.   if (!sec)
  713.     msymbol = NULL;
  714.  
  715.   /* Must be in the minimal symbol table.  */
  716.   if (msymbol == NULL)
  717.     {
  718.       /* No available symbol.  */
  719.       if (name != NULL)
  720.     *name = 0;
  721.       if (address != NULL)
  722.     *address = 0;
  723.       if (endaddr != NULL)
  724.     *endaddr = 0;
  725.       return 0;
  726.     }
  727.  
  728.   /* See if we're in a transfer table for Sun shared libs.
  729.  
  730.      Note the hack for Sun shared library transfer tables creates
  731.      problems for single stepping through the return path from a shared
  732.      library call if the return path includes trampoline code.
  733.  
  734.      I don't really understand the reasoning behind the magic handling
  735.      for mst_trampoline symbols.  */
  736.  
  737. #ifdef INHIBIT_SUNSOLIB_TRANSFER_TABLE_HACK
  738.     cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
  739. #else
  740.   if (msymbol -> type == mst_text || msymbol -> type == mst_file_text)
  741.     cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
  742.   else
  743.     /* It is a transfer table for Sun shared libraries.  */
  744.     cache_pc_function_low = pc - FUNCTION_START_OFFSET;
  745. #endif
  746.  
  747.   cache_pc_function_name = SYMBOL_NAME (msymbol);
  748.  
  749.   /* Use the lesser of the next minimal symbol, or the end of the section, as
  750.      the end of the function.  */
  751.  
  752.   if (SYMBOL_NAME (msymbol + 1) != NULL
  753.       && SYMBOL_VALUE_ADDRESS (msymbol + 1) < sec->endaddr)
  754.     cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + 1);
  755.   else
  756.     /* We got the start address from the last msymbol in the objfile.
  757.        So the end address is the end of the section.  */
  758.     cache_pc_function_high = sec->endaddr;
  759.  
  760.  return_cached_value:
  761.   if (address)
  762.     *address = cache_pc_function_low;
  763.   if (name)
  764.     *name = cache_pc_function_name;
  765.   if (endaddr)
  766.     *endaddr = cache_pc_function_high;
  767.   return 1;
  768. }
  769.  
  770. /* Return the innermost stack frame executing inside of BLOCK,
  771.    or NULL if there is no such frame.  If BLOCK is NULL, just return NULL.  */
  772.  
  773. struct frame_info *
  774. block_innermost_frame (block)
  775.      struct block *block;
  776. {
  777.   struct frame_info *frame;
  778.   register CORE_ADDR start;
  779.   register CORE_ADDR end;
  780.  
  781.   if (block == NULL)
  782.     return NULL;
  783.  
  784.   start = BLOCK_START (block);
  785.   end = BLOCK_END (block);
  786.  
  787.   frame = NULL;
  788.   while (1)
  789.     {
  790.       frame = get_prev_frame (frame);
  791.       if (frame == NULL)
  792.     return NULL;
  793.       if (frame->pc >= start && frame->pc < end)
  794.     return frame;
  795.     }
  796. }
  797.  
  798. /* Return the full FRAME which corresponds to the given CORE_ADDR
  799.    or NULL if no FRAME on the chain corresponds to CORE_ADDR.  */
  800.  
  801. struct frame_info *
  802. find_frame_addr_in_frame_chain (frame_addr)
  803.      CORE_ADDR frame_addr;
  804. {
  805.   struct frame_info *frame = NULL;
  806.  
  807.   if (frame_addr == (CORE_ADDR)0)
  808.     return NULL;
  809.  
  810.   while (1)
  811.     {
  812.       frame = get_prev_frame (frame);
  813.       if (frame == NULL)
  814.     return NULL;
  815.       if (FRAME_FP (frame) == frame_addr)
  816.     return frame;
  817.     }
  818. }
  819.  
  820. #ifdef SIGCONTEXT_PC_OFFSET
  821. /* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp.  */
  822.  
  823. CORE_ADDR
  824. sigtramp_saved_pc (frame)
  825.      struct frame_info *frame;
  826. {
  827.   CORE_ADDR sigcontext_addr;
  828.   char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
  829.   int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
  830.   int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
  831.  
  832.   /* Get sigcontext address, it is the third parameter on the stack.  */
  833.   if (frame->next)
  834.     sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next)
  835.                        + FRAME_ARGS_SKIP
  836.                        + sigcontext_offs,
  837.                        ptrbytes);
  838.   else
  839.     sigcontext_addr = read_memory_integer (read_register (SP_REGNUM)
  840.                         + sigcontext_offs,
  841.                        ptrbytes);
  842.  
  843.   /* Don't cause a memory_error when accessing sigcontext in case the stack
  844.      layout has changed or the stack is corrupt.  */
  845.   target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
  846.   return extract_unsigned_integer (buf, ptrbytes);
  847. }
  848. #endif /* SIGCONTEXT_PC_OFFSET */
  849.  
  850. void
  851. _initialize_blockframe ()
  852. {
  853.   obstack_init (&frame_cache_obstack);
  854. }
  855.