import gdb-1999-07-07 post reformat
[external/binutils.git] / gdb / blockframe.c
1 /* Get info from stack frames;
2    convert between frames, blocks, functions and pc values.
3    Copyright 1986, 87, 88, 89, 91, 94, 95, 96, 97, 1998
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "symtab.h"
25 #include "bfd.h"
26 #include "symfile.h"
27 #include "objfiles.h"
28 #include "frame.h"
29 #include "gdbcore.h"
30 #include "value.h"              /* for read_register */
31 #include "target.h"             /* for target_has_stack */
32 #include "inferior.h"           /* for read_pc */
33 #include "annotate.h"
34
35 /* Prototypes for exported functions. */
36
37 void _initialize_blockframe PARAMS ((void));
38
39 /* A default FRAME_CHAIN_VALID, in the form that is suitable for most
40    targets.  If FRAME_CHAIN_VALID returns zero it means that the given
41    frame is the outermost one and has no caller. */
42
43 int
44 default_frame_chain_valid (chain, thisframe)
45      CORE_ADDR chain;
46      struct frame_info *thisframe;
47 {
48   return ((chain) != 0
49           && !inside_main_func ((thisframe)->pc)
50           && !inside_entry_func ((thisframe)->pc));
51 }
52
53 /* Use the alternate method of avoiding running up off the end of the
54    frame chain or following frames back into the startup code.  See
55    the comments in objfiles.h. */
56
57 int
58 alternate_frame_chain_valid (chain, thisframe)
59      CORE_ADDR chain;
60      struct frame_info *thisframe;
61 {
62   return ((chain) != 0
63           && !inside_entry_file (FRAME_SAVED_PC (thisframe)));
64 }
65
66 /* A very simple method of determining a valid frame */
67
68 int
69 nonnull_frame_chain_valid (chain, thisframe)
70      CORE_ADDR chain;
71      struct frame_info *thisframe;
72 {
73   return ((chain) != 0);
74 }
75
76 /* Is ADDR inside the startup file?  Note that if your machine
77    has a way to detect the bottom of the stack, there is no need
78    to call this function from FRAME_CHAIN_VALID; the reason for
79    doing so is that some machines have no way of detecting bottom
80    of stack. 
81
82    A PC of zero is always considered to be the bottom of the stack. */
83
84 int
85 inside_entry_file (addr)
86      CORE_ADDR addr;
87 {
88   if (addr == 0)
89     return 1;
90   if (symfile_objfile == 0)
91     return 0;
92   if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
93     {
94       /* Do not stop backtracing if the pc is in the call dummy
95          at the entry point.  */
96       /* FIXME: Won't always work with zeros for the last two arguments */
97       if (PC_IN_CALL_DUMMY (addr, 0, 0))
98         return 0;
99     }
100   return (addr >= symfile_objfile->ei.entry_file_lowpc &&
101           addr < symfile_objfile->ei.entry_file_highpc);
102 }
103
104 /* Test a specified PC value to see if it is in the range of addresses
105    that correspond to the main() function.  See comments above for why
106    we might want to do this.
107
108    Typically called from FRAME_CHAIN_VALID.
109
110    A PC of zero is always considered to be the bottom of the stack. */
111
112 int
113 inside_main_func (pc)
114      CORE_ADDR pc;
115 {
116   if (pc == 0)
117     return 1;
118   if (symfile_objfile == 0)
119     return 0;
120
121   /* If the addr range is not set up at symbol reading time, set it up now.
122      This is for FRAME_CHAIN_VALID_ALTERNATE. I do this for coff, because
123      it is unable to set it up and symbol reading time. */
124
125   if (symfile_objfile->ei.main_func_lowpc == INVALID_ENTRY_LOWPC &&
126       symfile_objfile->ei.main_func_highpc == INVALID_ENTRY_HIGHPC)
127     {
128       struct symbol *mainsym;
129
130       mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL);
131       if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
132         {
133           symfile_objfile->ei.main_func_lowpc =
134             BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym));
135           symfile_objfile->ei.main_func_highpc =
136             BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym));
137         }
138     }
139   return (symfile_objfile->ei.main_func_lowpc <= pc &&
140           symfile_objfile->ei.main_func_highpc > pc);
141 }
142
143 /* Test a specified PC value to see if it is in the range of addresses
144    that correspond to the process entry point function.  See comments
145    in objfiles.h for why we might want to do this.
146
147    Typically called from FRAME_CHAIN_VALID.
148
149    A PC of zero is always considered to be the bottom of the stack. */
150
151 int
152 inside_entry_func (pc)
153      CORE_ADDR pc;
154 {
155   if (pc == 0)
156     return 1;
157   if (symfile_objfile == 0)
158     return 0;
159   if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
160     {
161       /* Do not stop backtracing if the pc is in the call dummy
162          at the entry point.  */
163       /* FIXME: Won't always work with zeros for the last two arguments */
164       if (PC_IN_CALL_DUMMY (pc, 0, 0))
165         return 0;
166     }
167   return (symfile_objfile->ei.entry_func_lowpc <= pc &&
168           symfile_objfile->ei.entry_func_highpc > pc);
169 }
170
171 /* Info about the innermost stack frame (contents of FP register) */
172
173 static struct frame_info *current_frame;
174
175 /* Cache for frame addresses already read by gdb.  Valid only while
176    inferior is stopped.  Control variables for the frame cache should
177    be local to this module.  */
178
179 static struct obstack frame_cache_obstack;
180
181 void *
182 frame_obstack_alloc (size)
183      unsigned long size;
184 {
185   return obstack_alloc (&frame_cache_obstack, size);
186 }
187
188 void
189 frame_saved_regs_zalloc (fi)
190      struct frame_info *fi;
191 {
192   fi->saved_regs = (CORE_ADDR *)
193     frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
194   memset (fi->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
195 }
196
197
198 /* Return the innermost (currently executing) stack frame.  */
199
200 struct frame_info *
201 get_current_frame ()
202 {
203   if (current_frame == NULL)
204     {
205       if (target_has_stack)
206         current_frame = create_new_frame (read_fp (), read_pc ());
207       else
208         error ("No stack.");
209     }
210   return current_frame;
211 }
212
213 void
214 set_current_frame (frame)
215      struct frame_info *frame;
216 {
217   current_frame = frame;
218 }
219
220 /* Create an arbitrary (i.e. address specified by user) or innermost frame.
221    Always returns a non-NULL value.  */
222
223 struct frame_info *
224 create_new_frame (addr, pc)
225      CORE_ADDR addr;
226      CORE_ADDR pc;
227 {
228   struct frame_info *fi;
229   char *name;
230
231   fi = (struct frame_info *)
232     obstack_alloc (&frame_cache_obstack,
233                    sizeof (struct frame_info));
234
235   /* Arbitrary frame */
236   fi->saved_regs = NULL;
237   fi->next = NULL;
238   fi->prev = NULL;
239   fi->frame = addr;
240   fi->pc = pc;
241   find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
242   fi->signal_handler_caller = IN_SIGTRAMP (fi->pc, name);
243
244 #ifdef INIT_EXTRA_FRAME_INFO
245   INIT_EXTRA_FRAME_INFO (0, fi);
246 #endif
247
248   return fi;
249 }
250
251 /* Return the frame that FRAME calls (NULL if FRAME is the innermost
252    frame).  */
253
254 struct frame_info *
255 get_next_frame (frame)
256      struct frame_info *frame;
257 {
258   return frame->next;
259 }
260
261 /* Flush the entire frame cache.  */
262
263 void
264 flush_cached_frames ()
265 {
266   /* Since we can't really be sure what the first object allocated was */
267   obstack_free (&frame_cache_obstack, 0);
268   obstack_init (&frame_cache_obstack);
269
270   current_frame = NULL;         /* Invalidate cache */
271   select_frame (NULL, -1);
272   annotate_frames_invalid ();
273 }
274
275 /* Flush the frame cache, and start a new one if necessary.  */
276
277 void
278 reinit_frame_cache ()
279 {
280   flush_cached_frames ();
281
282   /* FIXME: The inferior_pid test is wrong if there is a corefile.  */
283   if (inferior_pid != 0)
284     {
285       select_frame (get_current_frame (), 0);
286     }
287 }
288
289 /* If a machine allows frameless functions, it should define a macro
290    FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h.  FI is the struct
291    frame_info for the frame, and FRAMELESS should be set to nonzero
292    if it represents a frameless function invocation.  */
293
294 /* Return nonzero if the function for this frame lacks a prologue.  Many
295    machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
296    function.  */
297
298 int
299 frameless_look_for_prologue (frame)
300      struct frame_info *frame;
301 {
302   CORE_ADDR func_start, after_prologue;
303   func_start = get_pc_function_start (frame->pc);
304   if (func_start)
305     {
306       func_start += FUNCTION_START_OFFSET;
307       after_prologue = func_start;
308 #ifdef SKIP_PROLOGUE_FRAMELESS_P
309       /* This is faster, since only care whether there *is* a prologue,
310          not how long it is.  */
311       after_prologue = SKIP_PROLOGUE_FRAMELESS_P (after_prologue);
312 #else
313       after_prologue = SKIP_PROLOGUE (after_prologue);
314 #endif
315       return after_prologue == func_start;
316     }
317   else if (frame->pc == 0)
318     /* A frame with a zero PC is usually created by dereferencing a NULL
319        function pointer, normally causing an immediate core dump of the
320        inferior. Mark function as frameless, as the inferior has no chance
321        of setting up a stack frame.  */
322     return 1;
323   else
324     /* If we can't find the start of the function, we don't really
325        know whether the function is frameless, but we should be able
326        to get a reasonable (i.e. best we can do under the
327        circumstances) backtrace by saying that it isn't.  */
328     return 0;
329 }
330
331 /* Default a few macros that people seldom redefine.  */
332
333 #if !defined (INIT_FRAME_PC)
334 #define INIT_FRAME_PC(fromleaf, prev) \
335   prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
336               prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
337 #endif
338
339 #ifndef FRAME_CHAIN_COMBINE
340 #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
341 #endif
342
343 /* Return a structure containing various interesting information
344    about the frame that called NEXT_FRAME.  Returns NULL
345    if there is no such frame.  */
346
347 struct frame_info *
348 get_prev_frame (next_frame)
349      struct frame_info *next_frame;
350 {
351   CORE_ADDR address = 0;
352   struct frame_info *prev;
353   int fromleaf = 0;
354   char *name;
355
356   /* If the requested entry is in the cache, return it.
357      Otherwise, figure out what the address should be for the entry
358      we're about to add to the cache. */
359
360   if (!next_frame)
361     {
362 #if 0
363       /* This screws value_of_variable, which just wants a nice clean
364          NULL return from block_innermost_frame if there are no frames.
365          I don't think I've ever seen this message happen otherwise.
366          And returning NULL here is a perfectly legitimate thing to do.  */
367       if (!current_frame)
368         {
369           error ("You haven't set up a process's stack to examine.");
370         }
371 #endif
372
373       return current_frame;
374     }
375
376   /* If we have the prev one, return it */
377   if (next_frame->prev)
378     return next_frame->prev;
379
380   /* On some machines it is possible to call a function without
381      setting up a stack frame for it.  On these machines, we
382      define this macro to take two args; a frameinfo pointer
383      identifying a frame and a variable to set or clear if it is
384      or isn't leafless.  */
385
386   /* Still don't want to worry about this except on the innermost
387      frame.  This macro will set FROMLEAF if NEXT_FRAME is a
388      frameless function invocation.  */
389   if (!(next_frame->next))
390     {
391       fromleaf = FRAMELESS_FUNCTION_INVOCATION (next_frame);
392       if (fromleaf)
393         address = FRAME_FP (next_frame);
394     }
395
396   if (!fromleaf)
397     {
398       /* Two macros defined in tm.h specify the machine-dependent
399          actions to be performed here.
400          First, get the frame's chain-pointer.
401          If that is zero, the frame is the outermost frame or a leaf
402          called by the outermost frame.  This means that if start
403          calls main without a frame, we'll return 0 (which is fine
404          anyway).
405
406          Nope; there's a problem.  This also returns when the current
407          routine is a leaf of main.  This is unacceptable.  We move
408          this to after the ffi test; I'd rather have backtraces from
409          start go curfluy than have an abort called from main not show
410          main.  */
411       address = FRAME_CHAIN (next_frame);
412       if (!FRAME_CHAIN_VALID (address, next_frame))
413         return 0;
414       address = FRAME_CHAIN_COMBINE (address, next_frame);
415     }
416   if (address == 0)
417     return 0;
418
419   prev = (struct frame_info *)
420     obstack_alloc (&frame_cache_obstack,
421                    sizeof (struct frame_info));
422
423   prev->saved_regs = NULL;
424   if (next_frame)
425     next_frame->prev = prev;
426   prev->next = next_frame;
427   prev->prev = (struct frame_info *) 0;
428   prev->frame = address;
429   prev->signal_handler_caller = 0;
430
431 /* This change should not be needed, FIXME!  We should
432    determine whether any targets *need* INIT_FRAME_PC to happen
433    after INIT_EXTRA_FRAME_INFO and come up with a simple way to
434    express what goes on here.
435
436    INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
437    (where the PC is already set up) and here (where it isn't).
438    INIT_FRAME_PC is only called from here, always after
439    INIT_EXTRA_FRAME_INFO.
440
441    The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC
442    value (which hasn't been set yet).  Some other machines appear to
443    require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC.  Phoo.
444
445    We shouldn't need INIT_FRAME_PC_FIRST to add more complication to
446    an already overcomplicated part of GDB.   gnu@cygnus.com, 15Sep92.
447
448    Assuming that some machines need INIT_FRAME_PC after
449    INIT_EXTRA_FRAME_INFO, one possible scheme:
450
451    SETUP_INNERMOST_FRAME()
452    Default version is just create_new_frame (read_fp ()),
453    read_pc ()).  Machines with extra frame info would do that (or the
454    local equivalent) and then set the extra fields.
455    SETUP_ARBITRARY_FRAME(argc, argv)
456    Only change here is that create_new_frame would no longer init extra
457    frame info; SETUP_ARBITRARY_FRAME would have to do that.
458    INIT_PREV_FRAME(fromleaf, prev)
459    Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC.  This should
460    also return a flag saying whether to keep the new frame, or
461    whether to discard it, because on some machines (e.g.  mips) it
462    is really awkward to have FRAME_CHAIN_VALID called *before*
463    INIT_EXTRA_FRAME_INFO (there is no good way to get information
464    deduced in FRAME_CHAIN_VALID into the extra fields of the new frame).
465    std_frame_pc(fromleaf, prev)
466    This is the default setting for INIT_PREV_FRAME.  It just does what
467    the default INIT_FRAME_PC does.  Some machines will call it from
468    INIT_PREV_FRAME (either at the beginning, the end, or in the middle).
469    Some machines won't use it.
470    kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94.  */
471
472 #ifdef INIT_FRAME_PC_FIRST
473   INIT_FRAME_PC_FIRST (fromleaf, prev);
474 #endif
475
476 #ifdef INIT_EXTRA_FRAME_INFO
477   INIT_EXTRA_FRAME_INFO (fromleaf, prev);
478 #endif
479
480   /* This entry is in the frame queue now, which is good since
481      FRAME_SAVED_PC may use that queue to figure out its value
482      (see tm-sparc.h).  We want the pc saved in the inferior frame. */
483   INIT_FRAME_PC (fromleaf, prev);
484
485   /* If ->frame and ->pc are unchanged, we are in the process of getting
486      ourselves into an infinite backtrace.  Some architectures check this
487      in FRAME_CHAIN or thereabouts, but it seems like there is no reason
488      this can't be an architecture-independent check.  */
489   if (next_frame != NULL)
490     {
491       if (prev->frame == next_frame->frame
492           && prev->pc == next_frame->pc)
493         {
494           next_frame->prev = NULL;
495           obstack_free (&frame_cache_obstack, prev);
496           return NULL;
497         }
498     }
499
500   find_pc_partial_function (prev->pc, &name,
501                             (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
502   if (IN_SIGTRAMP (prev->pc, name))
503     prev->signal_handler_caller = 1;
504
505   return prev;
506 }
507
508 CORE_ADDR
509 get_frame_pc (frame)
510      struct frame_info *frame;
511 {
512   return frame->pc;
513 }
514
515
516 #ifdef FRAME_FIND_SAVED_REGS
517 /* XXX - deprecated.  This is a compatibility function for targets
518    that do not yet implement FRAME_INIT_SAVED_REGS.  */
519 /* Find the addresses in which registers are saved in FRAME.  */
520
521 void
522 get_frame_saved_regs (frame, saved_regs_addr)
523      struct frame_info *frame;
524      struct frame_saved_regs *saved_regs_addr;
525 {
526   if (frame->saved_regs == NULL)
527     {
528       frame->saved_regs = (CORE_ADDR *)
529         frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
530     }
531   if (saved_regs_addr == NULL)
532     {
533       struct frame_saved_regs saved_regs;
534       FRAME_FIND_SAVED_REGS (frame, saved_regs);
535       memcpy (frame->saved_regs, &saved_regs, SIZEOF_FRAME_SAVED_REGS);
536     }
537   else
538     {
539       FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr);
540       memcpy (frame->saved_regs, saved_regs_addr, SIZEOF_FRAME_SAVED_REGS);
541     }
542 }
543 #endif
544
545 /* Return the innermost lexical block in execution
546    in a specified stack frame.  The frame address is assumed valid.  */
547
548 struct block *
549 get_frame_block (frame)
550      struct frame_info *frame;
551 {
552   CORE_ADDR pc;
553
554   pc = frame->pc;
555   if (frame->next != 0 && frame->next->signal_handler_caller == 0)
556     /* We are not in the innermost frame and we were not interrupted
557        by a signal.  We need to subtract one to get the correct block,
558        in case the call instruction was the last instruction of the block.
559        If there are any machines on which the saved pc does not point to
560        after the call insn, we probably want to make frame->pc point after
561        the call insn anyway.  */
562     --pc;
563   return block_for_pc (pc);
564 }
565
566 struct block *
567 get_current_block ()
568 {
569   return block_for_pc (read_pc ());
570 }
571
572 CORE_ADDR
573 get_pc_function_start (pc)
574      CORE_ADDR pc;
575 {
576   register struct block *bl;
577   register struct symbol *symbol;
578   register struct minimal_symbol *msymbol;
579   CORE_ADDR fstart;
580
581   if ((bl = block_for_pc (pc)) != NULL &&
582       (symbol = block_function (bl)) != NULL)
583     {
584       bl = SYMBOL_BLOCK_VALUE (symbol);
585       fstart = BLOCK_START (bl);
586     }
587   else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL)
588     {
589       fstart = SYMBOL_VALUE_ADDRESS (msymbol);
590     }
591   else
592     {
593       fstart = 0;
594     }
595   return (fstart);
596 }
597
598 /* Return the symbol for the function executing in frame FRAME.  */
599
600 struct symbol *
601 get_frame_function (frame)
602      struct frame_info *frame;
603 {
604   register struct block *bl = get_frame_block (frame);
605   if (bl == 0)
606     return 0;
607   return block_function (bl);
608 }
609 \f
610
611 /* Return the blockvector immediately containing the innermost lexical block
612    containing the specified pc value and section, or 0 if there is none.
613    PINDEX is a pointer to the index value of the block.  If PINDEX
614    is NULL, we don't pass this information back to the caller.  */
615
616 struct blockvector *
617 blockvector_for_pc_sect (pc, section, pindex, symtab)
618      register CORE_ADDR pc;
619      struct sec *section;
620      int *pindex;
621      struct symtab *symtab;
622
623 {
624   register struct block *b;
625   register int bot, top, half;
626   struct blockvector *bl;
627
628   if (symtab == 0)              /* if no symtab specified by caller */
629     {
630       /* First search all symtabs for one whose file contains our pc */
631       if ((symtab = find_pc_sect_symtab (pc, section)) == 0)
632         return 0;
633     }
634
635   bl = BLOCKVECTOR (symtab);
636   b = BLOCKVECTOR_BLOCK (bl, 0);
637
638   /* Then search that symtab for the smallest block that wins.  */
639   /* Use binary search to find the last block that starts before PC.  */
640
641   bot = 0;
642   top = BLOCKVECTOR_NBLOCKS (bl);
643
644   while (top - bot > 1)
645     {
646       half = (top - bot + 1) >> 1;
647       b = BLOCKVECTOR_BLOCK (bl, bot + half);
648       if (BLOCK_START (b) <= pc)
649         bot += half;
650       else
651         top = bot + half;
652     }
653
654   /* Now search backward for a block that ends after PC.  */
655
656   while (bot >= 0)
657     {
658       b = BLOCKVECTOR_BLOCK (bl, bot);
659       if (BLOCK_END (b) >= pc)
660         {
661           if (pindex)
662             *pindex = bot;
663           return bl;
664         }
665       bot--;
666     }
667   return 0;
668 }
669
670 /* Return the blockvector immediately containing the innermost lexical block
671    containing the specified pc value, or 0 if there is none.
672    Backward compatibility, no section.  */
673
674 struct blockvector *
675 blockvector_for_pc (pc, pindex)
676      register CORE_ADDR pc;
677      int *pindex;
678 {
679   return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
680                                   pindex, NULL);
681 }
682
683 /* Return the innermost lexical block containing the specified pc value
684    in the specified section, or 0 if there is none.  */
685
686 struct block *
687 block_for_pc_sect (pc, section)
688      register CORE_ADDR pc;
689      struct sec *section;
690 {
691   register struct blockvector *bl;
692   int index;
693
694   bl = blockvector_for_pc_sect (pc, section, &index, NULL);
695   if (bl)
696     return BLOCKVECTOR_BLOCK (bl, index);
697   return 0;
698 }
699
700 /* Return the innermost lexical block containing the specified pc value,
701    or 0 if there is none.  Backward compatibility, no section.  */
702
703 struct block *
704 block_for_pc (pc)
705      register CORE_ADDR pc;
706 {
707   return block_for_pc_sect (pc, find_pc_mapped_section (pc));
708 }
709
710 /* Return the function containing pc value PC in section SECTION.
711    Returns 0 if function is not known.  */
712
713 struct symbol *
714 find_pc_sect_function (pc, section)
715      CORE_ADDR pc;
716      struct sec *section;
717 {
718   register struct block *b = block_for_pc_sect (pc, section);
719   if (b == 0)
720     return 0;
721   return block_function (b);
722 }
723
724 /* Return the function containing pc value PC.
725    Returns 0 if function is not known.  Backward compatibility, no section */
726
727 struct symbol *
728 find_pc_function (pc)
729      CORE_ADDR pc;
730 {
731   return find_pc_sect_function (pc, find_pc_mapped_section (pc));
732 }
733
734 /* These variables are used to cache the most recent result
735  * of find_pc_partial_function. */
736
737 static CORE_ADDR cache_pc_function_low = 0;
738 static CORE_ADDR cache_pc_function_high = 0;
739 static char *cache_pc_function_name = 0;
740 static struct sec *cache_pc_function_section = NULL;
741
742 /* Clear cache, e.g. when symbol table is discarded. */
743
744 void
745 clear_pc_function_cache ()
746 {
747   cache_pc_function_low = 0;
748   cache_pc_function_high = 0;
749   cache_pc_function_name = (char *) 0;
750   cache_pc_function_section = NULL;
751 }
752
753 /* Finds the "function" (text symbol) that is smaller than PC but
754    greatest of all of the potential text symbols in SECTION.  Sets
755    *NAME and/or *ADDRESS conditionally if that pointer is non-null.
756    If ENDADDR is non-null, then set *ENDADDR to be the end of the
757    function (exclusive), but passing ENDADDR as non-null means that
758    the function might cause symbols to be read.  This function either
759    succeeds or fails (not halfway succeeds).  If it succeeds, it sets
760    *NAME, *ADDRESS, and *ENDADDR to real information and returns 1.
761    If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero and
762    returns 0.  */
763
764 int
765 find_pc_sect_partial_function (pc, section, name, address, endaddr)
766      CORE_ADDR pc;
767      asection *section;
768      char **name;
769      CORE_ADDR *address;
770      CORE_ADDR *endaddr;
771 {
772   struct partial_symtab *pst;
773   struct symbol *f;
774   struct minimal_symbol *msymbol;
775   struct partial_symbol *psb;
776   struct obj_section *osect;
777   int i;
778   CORE_ADDR mapped_pc;
779
780   mapped_pc = overlay_mapped_address (pc, section);
781
782   if (mapped_pc >= cache_pc_function_low &&
783       mapped_pc < cache_pc_function_high &&
784       section == cache_pc_function_section)
785     goto return_cached_value;
786
787   /* If sigtramp is in the u area, it counts as a function (especially
788      important for step_1).  */
789 #if defined SIGTRAMP_START
790   if (IN_SIGTRAMP (mapped_pc, (char *) NULL))
791     {
792       cache_pc_function_low = SIGTRAMP_START (mapped_pc);
793       cache_pc_function_high = SIGTRAMP_END (mapped_pc);
794       cache_pc_function_name = "<sigtramp>";
795       cache_pc_function_section = section;
796       goto return_cached_value;
797     }
798 #endif
799
800   msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section);
801   pst = find_pc_sect_psymtab (mapped_pc, section);
802   if (pst)
803     {
804       /* Need to read the symbols to get a good value for the end address.  */
805       if (endaddr != NULL && !pst->readin)
806         {
807           /* Need to get the terminal in case symbol-reading produces
808              output.  */
809           target_terminal_ours_for_output ();
810           PSYMTAB_TO_SYMTAB (pst);
811         }
812
813       if (pst->readin)
814         {
815           /* Checking whether the msymbol has a larger value is for the
816              "pathological" case mentioned in print_frame_info.  */
817           f = find_pc_sect_function (mapped_pc, section);
818           if (f != NULL
819               && (msymbol == NULL
820                   || (BLOCK_START (SYMBOL_BLOCK_VALUE (f))
821                       >= SYMBOL_VALUE_ADDRESS (msymbol))))
822             {
823               cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
824               cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
825               cache_pc_function_name = SYMBOL_NAME (f);
826               cache_pc_function_section = section;
827               goto return_cached_value;
828             }
829         }
830       else
831         {
832           /* Now that static symbols go in the minimal symbol table, perhaps
833              we could just ignore the partial symbols.  But at least for now
834              we use the partial or minimal symbol, whichever is larger.  */
835           psb = find_pc_sect_psymbol (pst, mapped_pc, section);
836
837           if (psb
838               && (msymbol == NULL ||
839                   (SYMBOL_VALUE_ADDRESS (psb)
840                    >= SYMBOL_VALUE_ADDRESS (msymbol))))
841             {
842               /* This case isn't being cached currently. */
843               if (address)
844                 *address = SYMBOL_VALUE_ADDRESS (psb);
845               if (name)
846                 *name = SYMBOL_NAME (psb);
847               /* endaddr non-NULL can't happen here.  */
848               return 1;
849             }
850         }
851     }
852
853   /* Not in the normal symbol tables, see if the pc is in a known section.
854      If it's not, then give up.  This ensures that anything beyond the end
855      of the text seg doesn't appear to be part of the last function in the
856      text segment.  */
857
858   osect = find_pc_sect_section (mapped_pc, section);
859
860   if (!osect)
861     msymbol = NULL;
862
863   /* Must be in the minimal symbol table.  */
864   if (msymbol == NULL)
865     {
866       /* No available symbol.  */
867       if (name != NULL)
868         *name = 0;
869       if (address != NULL)
870         *address = 0;
871       if (endaddr != NULL)
872         *endaddr = 0;
873       return 0;
874     }
875
876   cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
877   cache_pc_function_name = SYMBOL_NAME (msymbol);
878   cache_pc_function_section = section;
879
880   /* Use the lesser of the next minimal symbol in the same section, or
881      the end of the section, as the end of the function.  */
882
883   /* Step over other symbols at this same address, and symbols in
884      other sections, to find the next symbol in this section with
885      a different address.  */
886
887   for (i = 1; SYMBOL_NAME (msymbol + i) != NULL; i++)
888     {
889       if (SYMBOL_VALUE_ADDRESS (msymbol + i) != SYMBOL_VALUE_ADDRESS (msymbol)
890         && SYMBOL_BFD_SECTION (msymbol + i) == SYMBOL_BFD_SECTION (msymbol))
891         break;
892     }
893
894   if (SYMBOL_NAME (msymbol + i) != NULL
895       && SYMBOL_VALUE_ADDRESS (msymbol + i) < osect->endaddr)
896     cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i);
897   else
898     /* We got the start address from the last msymbol in the objfile.
899        So the end address is the end of the section.  */
900     cache_pc_function_high = osect->endaddr;
901
902 return_cached_value:
903
904   if (address)
905     {
906       if (pc_in_unmapped_range (pc, section))
907         *address = overlay_unmapped_address (cache_pc_function_low, section);
908       else
909         *address = cache_pc_function_low;
910     }
911
912   if (name)
913     *name = cache_pc_function_name;
914
915   if (endaddr)
916     {
917       if (pc_in_unmapped_range (pc, section))
918         {
919           /* Because the high address is actually beyond the end of
920              the function (and therefore possibly beyond the end of
921              the overlay), we must actually convert (high - 1)
922              and then add one to that. */
923
924           *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1,
925                                                    section);
926         }
927       else
928         *endaddr = cache_pc_function_high;
929     }
930
931   return 1;
932 }
933
934 /* Backward compatibility, no section argument */
935
936 int
937 find_pc_partial_function (pc, name, address, endaddr)
938      CORE_ADDR pc;
939      char **name;
940      CORE_ADDR *address;
941      CORE_ADDR *endaddr;
942 {
943   asection *section;
944
945   section = find_pc_overlay (pc);
946   return find_pc_sect_partial_function (pc, section, name, address, endaddr);
947 }
948
949 /* Return the innermost stack frame executing inside of BLOCK,
950    or NULL if there is no such frame.  If BLOCK is NULL, just return NULL.  */
951
952 struct frame_info *
953 block_innermost_frame (block)
954      struct block *block;
955 {
956   struct frame_info *frame;
957   register CORE_ADDR start;
958   register CORE_ADDR end;
959
960   if (block == NULL)
961     return NULL;
962
963   start = BLOCK_START (block);
964   end = BLOCK_END (block);
965
966   frame = NULL;
967   while (1)
968     {
969       frame = get_prev_frame (frame);
970       if (frame == NULL)
971         return NULL;
972       if (frame->pc >= start && frame->pc < end)
973         return frame;
974     }
975 }
976
977 /* Return the full FRAME which corresponds to the given CORE_ADDR
978    or NULL if no FRAME on the chain corresponds to CORE_ADDR.  */
979
980 struct frame_info *
981 find_frame_addr_in_frame_chain (frame_addr)
982      CORE_ADDR frame_addr;
983 {
984   struct frame_info *frame = NULL;
985
986   if (frame_addr == (CORE_ADDR) 0)
987     return NULL;
988
989   while (1)
990     {
991       frame = get_prev_frame (frame);
992       if (frame == NULL)
993         return NULL;
994       if (FRAME_FP (frame) == frame_addr)
995         return frame;
996     }
997 }
998
999 #ifdef SIGCONTEXT_PC_OFFSET
1000 /* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp.  */
1001
1002 CORE_ADDR
1003 sigtramp_saved_pc (frame)
1004      struct frame_info *frame;
1005 {
1006   CORE_ADDR sigcontext_addr;
1007   char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
1008   int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
1009   int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
1010
1011   /* Get sigcontext address, it is the third parameter on the stack.  */
1012   if (frame->next)
1013     sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next)
1014                                            + FRAME_ARGS_SKIP
1015                                            + sigcontext_offs,
1016                                            ptrbytes);
1017   else
1018     sigcontext_addr = read_memory_integer (read_register (SP_REGNUM)
1019                                            + sigcontext_offs,
1020                                            ptrbytes);
1021
1022   /* Don't cause a memory_error when accessing sigcontext in case the stack
1023      layout has changed or the stack is corrupt.  */
1024   target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
1025   return extract_unsigned_integer (buf, ptrbytes);
1026 }
1027 #endif /* SIGCONTEXT_PC_OFFSET */
1028
1029
1030 /* Are we in a call dummy?  The code below which allows DECR_PC_AFTER_BREAK
1031    below is for infrun.c, which may give the macro a pc without that
1032    subtracted out.  */
1033
1034 extern CORE_ADDR text_end;
1035
1036 int
1037 pc_in_call_dummy_before_text_end (pc, sp, frame_address)
1038      CORE_ADDR pc;
1039      CORE_ADDR sp;
1040      CORE_ADDR frame_address;
1041 {
1042   return ((pc) >= text_end - CALL_DUMMY_LENGTH
1043           && (pc) <= text_end + DECR_PC_AFTER_BREAK);
1044 }
1045
1046 int
1047 pc_in_call_dummy_after_text_end (pc, sp, frame_address)
1048      CORE_ADDR pc;
1049      CORE_ADDR sp;
1050      CORE_ADDR frame_address;
1051 {
1052   return ((pc) >= text_end
1053           && (pc) <= text_end + CALL_DUMMY_LENGTH + DECR_PC_AFTER_BREAK);
1054 }
1055
1056 /* Is the PC in a call dummy?  SP and FRAME_ADDRESS are the bottom and
1057    top of the stack frame which we are checking, where "bottom" and
1058    "top" refer to some section of memory which contains the code for
1059    the call dummy.  Calls to this macro assume that the contents of
1060    SP_REGNUM and FP_REGNUM (or the saved values thereof), respectively,
1061    are the things to pass.
1062
1063    This won't work on the 29k, where SP_REGNUM and FP_REGNUM don't
1064    have that meaning, but the 29k doesn't use ON_STACK.  This could be
1065    fixed by generalizing this scheme, perhaps by passing in a frame
1066    and adding a few fields, at least on machines which need them for
1067    PC_IN_CALL_DUMMY.
1068
1069    Something simpler, like checking for the stack segment, doesn't work,
1070    since various programs (threads implementations, gcc nested function
1071    stubs, etc) may either allocate stack frames in another segment, or
1072    allocate other kinds of code on the stack.  */
1073
1074 int
1075 pc_in_call_dummy_on_stack (pc, sp, frame_address)
1076      CORE_ADDR pc;
1077      CORE_ADDR sp;
1078      CORE_ADDR frame_address;
1079 {
1080   return (INNER_THAN ((sp), (pc))
1081           && (frame_address != 0)
1082           && INNER_THAN ((pc), (frame_address)));
1083 }
1084
1085 int
1086 pc_in_call_dummy_at_entry_point (pc, sp, frame_address)
1087      CORE_ADDR pc;
1088      CORE_ADDR sp;
1089      CORE_ADDR frame_address;
1090 {
1091   return ((pc) >= CALL_DUMMY_ADDRESS ()
1092           && (pc) <= (CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK));
1093 }
1094
1095
1096 /*
1097  * GENERIC DUMMY FRAMES
1098  * 
1099  * The following code serves to maintain the dummy stack frames for
1100  * inferior function calls (ie. when gdb calls into the inferior via
1101  * call_function_by_hand).  This code saves the machine state before 
1102  * the call in host memory, so we must maintain an independant stack 
1103  * and keep it consistant etc.  I am attempting to make this code 
1104  * generic enough to be used by many targets.
1105  *
1106  * The cheapest and most generic way to do CALL_DUMMY on a new target
1107  * is probably to define CALL_DUMMY to be empty, CALL_DUMMY_LENGTH to
1108  * zero, and CALL_DUMMY_LOCATION to AT_ENTRY.  Then you must remember
1109  * to define PUSH_RETURN_ADDRESS, because no call instruction will be
1110  * being executed by the target.  Also FRAME_CHAIN_VALID as
1111  * generic_frame_chain_valid and FIX_CALL_DUMMY as
1112  * generic_fix_call_dummy.  */
1113
1114 /* Dummy frame.  This saves the processor state just prior to setting
1115    up the inferior function call.  Older targets save the registers
1116    target stack (but that really slows down function calls).  */
1117
1118 struct dummy_frame
1119 {
1120   struct dummy_frame *next;
1121
1122   CORE_ADDR pc;
1123   CORE_ADDR fp;
1124   CORE_ADDR sp;
1125   CORE_ADDR top;
1126   char *registers;
1127 };
1128
1129 static struct dummy_frame *dummy_frame_stack = NULL;
1130
1131 /* Function: find_dummy_frame(pc, fp, sp)
1132    Search the stack of dummy frames for one matching the given PC, FP and SP.
1133    This is the work-horse for pc_in_call_dummy and read_register_dummy     */
1134
1135 char *
1136 generic_find_dummy_frame (pc, fp)
1137      CORE_ADDR pc;
1138      CORE_ADDR fp;
1139 {
1140   struct dummy_frame *dummyframe;
1141
1142   if (pc != entry_point_address ())
1143     return 0;
1144
1145   for (dummyframe = dummy_frame_stack; dummyframe != NULL;
1146        dummyframe = dummyframe->next)
1147     if (fp == dummyframe->fp
1148         || fp == dummyframe->sp
1149         || fp == dummyframe->top)
1150       /* The frame in question lies between the saved fp and sp, inclusive */
1151       return dummyframe->registers;
1152
1153   return 0;
1154 }
1155
1156 /* Function: pc_in_call_dummy (pc, fp)
1157    Return true if this is a dummy frame created by gdb for an inferior call */
1158
1159 int
1160 generic_pc_in_call_dummy (pc, sp, fp)
1161      CORE_ADDR pc;
1162      CORE_ADDR sp;
1163      CORE_ADDR fp;
1164 {
1165   /* if find_dummy_frame succeeds, then PC is in a call dummy */
1166   /* Note: SP and not FP is passed on. */
1167   return (generic_find_dummy_frame (pc, sp) != 0);
1168 }
1169
1170 /* Function: read_register_dummy 
1171    Find a saved register from before GDB calls a function in the inferior */
1172
1173 CORE_ADDR
1174 generic_read_register_dummy (pc, fp, regno)
1175      CORE_ADDR pc;
1176      CORE_ADDR fp;
1177      int regno;
1178 {
1179   char *dummy_regs = generic_find_dummy_frame (pc, fp);
1180
1181   if (dummy_regs)
1182     return extract_address (&dummy_regs[REGISTER_BYTE (regno)],
1183                             REGISTER_RAW_SIZE (regno));
1184   else
1185     return 0;
1186 }
1187
1188 /* Save all the registers on the dummy frame stack.  Most ports save the
1189    registers on the target stack.  This results in lots of unnecessary memory
1190    references, which are slow when debugging via a serial line.  Instead, we
1191    save all the registers internally, and never write them to the stack.  The
1192    registers get restored when the called function returns to the entry point,
1193    where a breakpoint is laying in wait.  */
1194
1195 void
1196 generic_push_dummy_frame ()
1197 {
1198   struct dummy_frame *dummy_frame;
1199   CORE_ADDR fp = (get_current_frame ())->frame;
1200
1201   /* check to see if there are stale dummy frames, 
1202      perhaps left over from when a longjump took us out of a 
1203      function that was called by the debugger */
1204
1205   dummy_frame = dummy_frame_stack;
1206   while (dummy_frame)
1207     if (INNER_THAN (dummy_frame->fp, fp))       /* stale -- destroy! */
1208       {
1209         dummy_frame_stack = dummy_frame->next;
1210         free (dummy_frame->registers);
1211         free (dummy_frame);
1212         dummy_frame = dummy_frame_stack;
1213       }
1214     else
1215       dummy_frame = dummy_frame->next;
1216
1217   dummy_frame = xmalloc (sizeof (struct dummy_frame));
1218   dummy_frame->registers = xmalloc (REGISTER_BYTES);
1219
1220   dummy_frame->pc = read_register (PC_REGNUM);
1221   dummy_frame->sp = read_register (SP_REGNUM);
1222   dummy_frame->top = dummy_frame->sp;
1223   dummy_frame->fp = fp;
1224   read_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
1225   dummy_frame->next = dummy_frame_stack;
1226   dummy_frame_stack = dummy_frame;
1227 }
1228
1229 void
1230 generic_save_dummy_frame_tos (sp)
1231      CORE_ADDR sp;
1232 {
1233   dummy_frame_stack->top = sp;
1234 }
1235
1236 /* Function: pop_frame
1237    Restore the machine state from either the saved dummy stack or a
1238    real stack frame. */
1239
1240 void
1241 generic_pop_current_frame (pop)
1242      void (*pop) PARAMS ((struct frame_info * frame));
1243 {
1244   struct frame_info *frame = get_current_frame ();
1245   if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
1246     generic_pop_dummy_frame ();
1247   else
1248     pop (frame);
1249 }
1250
1251 /* Function: pop_dummy_frame
1252    Restore the machine state from a saved dummy stack frame. */
1253
1254 void
1255 generic_pop_dummy_frame ()
1256 {
1257   struct dummy_frame *dummy_frame = dummy_frame_stack;
1258
1259   /* FIXME: what if the first frame isn't the right one, eg..
1260      because one call-by-hand function has done a longjmp into another one? */
1261
1262   if (!dummy_frame)
1263     error ("Can't pop dummy frame!");
1264   dummy_frame_stack = dummy_frame->next;
1265   write_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
1266   flush_cached_frames ();
1267
1268   free (dummy_frame->registers);
1269   free (dummy_frame);
1270 }
1271
1272 /* Function: frame_chain_valid 
1273    Returns true for a user frame or a call_function_by_hand dummy frame,
1274    and false for the CRT0 start-up frame.  Purpose is to terminate backtrace */
1275
1276 int
1277 generic_frame_chain_valid (fp, fi)
1278      CORE_ADDR fp;
1279      struct frame_info *fi;
1280 {
1281   if (PC_IN_CALL_DUMMY (FRAME_SAVED_PC (fi), fp, fp))
1282     return 1;                   /* don't prune CALL_DUMMY frames */
1283   else                          /* fall back to default algorithm (see frame.h) */
1284     return (fp != 0
1285             && (INNER_THAN (fi->frame, fp) || fi->frame == fp)
1286             && !inside_entry_file (FRAME_SAVED_PC (fi)));
1287 }
1288
1289 /* Function: fix_call_dummy
1290    Stub function.  Generic dumy frames typically do not need to fix
1291    the frame being created */
1292
1293 void
1294 generic_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p)
1295      char *dummy;
1296      CORE_ADDR pc;
1297      CORE_ADDR fun;
1298      int nargs;
1299      struct value **args;
1300      struct type *type;
1301      int gcc_p;
1302 {
1303   return;
1304 }
1305
1306 /* Function: get_saved_register
1307    Find register number REGNUM relative to FRAME and put its (raw,
1308    target format) contents in *RAW_BUFFER.  
1309
1310    Set *OPTIMIZED if the variable was optimized out (and thus can't be
1311    fetched).  Note that this is never set to anything other than zero
1312    in this implementation.
1313
1314    Set *LVAL to lval_memory, lval_register, or not_lval, depending on
1315    whether the value was fetched from memory, from a register, or in a
1316    strange and non-modifiable way (e.g. a frame pointer which was
1317    calculated rather than fetched).  We will use not_lval for values
1318    fetched from generic dummy frames.
1319
1320    Set *ADDRP to the address, either in memory on as a REGISTER_BYTE
1321    offset into the registers array.  If the value is stored in a dummy
1322    frame, set *ADDRP to zero.
1323
1324    To use this implementation, define a function called
1325    "get_saved_register" in your target code, which simply passes all
1326    of its arguments to this function.
1327
1328    The argument RAW_BUFFER must point to aligned memory.  */
1329
1330 void
1331 generic_get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
1332      char *raw_buffer;
1333      int *optimized;
1334      CORE_ADDR *addrp;
1335      struct frame_info *frame;
1336      int regnum;
1337      enum lval_type *lval;
1338 {
1339   if (!target_has_registers)
1340     error ("No registers.");
1341
1342   /* Normal systems don't optimize out things with register numbers.  */
1343   if (optimized != NULL)
1344     *optimized = 0;
1345
1346   if (addrp)                    /* default assumption: not found in memory */
1347     *addrp = 0;
1348
1349   /* Note: since the current frame's registers could only have been
1350      saved by frames INTERIOR TO the current frame, we skip examining
1351      the current frame itself: otherwise, we would be getting the
1352      previous frame's registers which were saved by the current frame.  */
1353
1354   while (frame && ((frame = frame->next) != NULL))
1355     {
1356       if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
1357         {
1358           if (lval)             /* found it in a CALL_DUMMY frame */
1359             *lval = not_lval;
1360           if (raw_buffer)
1361             memcpy (raw_buffer,
1362                     generic_find_dummy_frame (frame->pc, frame->frame) +
1363                     REGISTER_BYTE (regnum),
1364                     REGISTER_RAW_SIZE (regnum));
1365           return;
1366         }
1367
1368       FRAME_INIT_SAVED_REGS (frame);
1369       if (frame->saved_regs != NULL
1370           && frame->saved_regs[regnum] != 0)
1371         {
1372           if (lval)             /* found it saved on the stack */
1373             *lval = lval_memory;
1374           if (regnum == SP_REGNUM)
1375             {
1376               if (raw_buffer)   /* SP register treated specially */
1377                 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
1378                                frame->saved_regs[regnum]);
1379             }
1380           else
1381             {
1382               if (addrp)        /* any other register */
1383                 *addrp = frame->saved_regs[regnum];
1384               if (raw_buffer)
1385                 read_memory (frame->saved_regs[regnum], raw_buffer,
1386                              REGISTER_RAW_SIZE (regnum));
1387             }
1388           return;
1389         }
1390     }
1391
1392   /* If we get thru the loop to this point, it means the register was
1393      not saved in any frame.  Return the actual live-register value.  */
1394
1395   if (lval)                     /* found it in a live register */
1396     *lval = lval_register;
1397   if (addrp)
1398     *addrp = REGISTER_BYTE (regnum);
1399   if (raw_buffer)
1400     read_register_gen (regnum, raw_buffer);
1401 }
1402
1403 void
1404 _initialize_blockframe ()
1405 {
1406   obstack_init (&frame_cache_obstack);
1407 }