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