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