home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / gdb / blockframe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-13  |  23.9 KB  |  867 lines

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