1 /* Get info from stack frames; convert between frames, blocks,
2 functions and pc values.
4 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
5 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
32 #include "value.h" /* for read_register */
33 #include "target.h" /* for target_has_stack */
34 #include "inferior.h" /* for read_pc */
37 #include "gdb_assert.h"
38 #include "dummy-frame.h"
40 /* Prototypes for exported functions. */
42 static void frame_saved_regs_register_unwind (struct frame_info
*frame
,
52 void _initialize_blockframe (void);
54 /* A default FRAME_CHAIN_VALID, in the form that is suitable for most
55 targets. If FRAME_CHAIN_VALID returns zero it means that the given
56 frame is the outermost one and has no caller. */
59 file_frame_chain_valid (CORE_ADDR chain
, struct frame_info
*thisframe
)
62 && !inside_entry_file (FRAME_SAVED_PC (thisframe
)));
65 /* Use the alternate method of avoiding running up off the end of the
66 frame chain or following frames back into the startup code. See
67 the comments in objfiles.h. */
70 func_frame_chain_valid (CORE_ADDR chain
, struct frame_info
*thisframe
)
73 && !inside_main_func ((thisframe
)->pc
)
74 && !inside_entry_func ((thisframe
)->pc
));
77 /* A very simple method of determining a valid frame */
80 nonnull_frame_chain_valid (CORE_ADDR chain
, struct frame_info
*thisframe
)
82 return ((chain
) != 0);
85 /* Is ADDR inside the startup file? Note that if your machine
86 has a way to detect the bottom of the stack, there is no need
87 to call this function from FRAME_CHAIN_VALID; the reason for
88 doing so is that some machines have no way of detecting bottom
91 A PC of zero is always considered to be the bottom of the stack. */
94 inside_entry_file (CORE_ADDR addr
)
98 if (symfile_objfile
== 0)
100 if (CALL_DUMMY_LOCATION
== AT_ENTRY_POINT
)
102 /* Do not stop backtracing if the pc is in the call dummy
103 at the entry point. */
104 /* FIXME: Won't always work with zeros for the last two arguments */
105 if (PC_IN_CALL_DUMMY (addr
, 0, 0))
108 return (addr
>= symfile_objfile
->ei
.entry_file_lowpc
&&
109 addr
< symfile_objfile
->ei
.entry_file_highpc
);
112 /* Test a specified PC value to see if it is in the range of addresses
113 that correspond to the main() function. See comments above for why
114 we might want to do this.
116 Typically called from FRAME_CHAIN_VALID.
118 A PC of zero is always considered to be the bottom of the stack. */
121 inside_main_func (CORE_ADDR pc
)
125 if (symfile_objfile
== 0)
128 /* If the addr range is not set up at symbol reading time, set it up now.
129 This is for FRAME_CHAIN_VALID_ALTERNATE. I do this for coff, because
130 it is unable to set it up and symbol reading time. */
132 if (symfile_objfile
->ei
.main_func_lowpc
== INVALID_ENTRY_LOWPC
&&
133 symfile_objfile
->ei
.main_func_highpc
== INVALID_ENTRY_HIGHPC
)
135 struct symbol
*mainsym
;
137 mainsym
= lookup_symbol (main_name (), NULL
, VAR_NAMESPACE
, NULL
, NULL
);
138 if (mainsym
&& SYMBOL_CLASS (mainsym
) == LOC_BLOCK
)
140 symfile_objfile
->ei
.main_func_lowpc
=
141 BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym
));
142 symfile_objfile
->ei
.main_func_highpc
=
143 BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym
));
146 return (symfile_objfile
->ei
.main_func_lowpc
<= pc
&&
147 symfile_objfile
->ei
.main_func_highpc
> pc
);
150 /* Test a specified PC value to see if it is in the range of addresses
151 that correspond to the process entry point function. See comments
152 in objfiles.h for why we might want to do this.
154 Typically called from FRAME_CHAIN_VALID.
156 A PC of zero is always considered to be the bottom of the stack. */
159 inside_entry_func (CORE_ADDR pc
)
163 if (symfile_objfile
== 0)
165 if (CALL_DUMMY_LOCATION
== AT_ENTRY_POINT
)
167 /* Do not stop backtracing if the pc is in the call dummy
168 at the entry point. */
169 /* FIXME: Won't always work with zeros for the last two arguments */
170 if (PC_IN_CALL_DUMMY (pc
, 0, 0))
173 return (symfile_objfile
->ei
.entry_func_lowpc
<= pc
&&
174 symfile_objfile
->ei
.entry_func_highpc
> pc
);
177 /* Info about the innermost stack frame (contents of FP register) */
179 static struct frame_info
*current_frame
;
181 /* Cache for frame addresses already read by gdb. Valid only while
182 inferior is stopped. Control variables for the frame cache should
183 be local to this module. */
185 static struct obstack frame_cache_obstack
;
188 frame_obstack_alloc (unsigned long size
)
190 return obstack_alloc (&frame_cache_obstack
, size
);
194 frame_saved_regs_zalloc (struct frame_info
*fi
)
196 fi
->saved_regs
= (CORE_ADDR
*)
197 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS
);
198 memset (fi
->saved_regs
, 0, SIZEOF_FRAME_SAVED_REGS
);
202 /* Return the innermost (currently executing) stack frame. */
205 get_current_frame (void)
207 if (current_frame
== NULL
)
209 if (target_has_stack
)
210 current_frame
= create_new_frame (read_fp (), read_pc ());
214 return current_frame
;
218 set_current_frame (struct frame_info
*frame
)
220 current_frame
= frame
;
224 /* Using the PC, select a mechanism for unwinding a frame returning
225 the previous frame. The register unwind function should, on
226 demand, initialize the ->context object. */
229 set_unwind_by_pc (CORE_ADDR pc
, CORE_ADDR fp
,
230 frame_register_unwind_ftype
**unwind
)
232 if (!USE_GENERIC_DUMMY_FRAMES
)
233 /* Still need to set this to something. The ``info frame'' code
234 calls this function to find out where the saved registers are.
235 Hopefully this is robust enough to stop any core dumps and
236 return vaguely correct values.. */
237 *unwind
= frame_saved_regs_register_unwind
;
238 else if (PC_IN_CALL_DUMMY (pc
, fp
, fp
))
239 *unwind
= generic_call_dummy_register_unwind
;
241 *unwind
= frame_saved_regs_register_unwind
;
244 /* Create an arbitrary (i.e. address specified by user) or innermost frame.
245 Always returns a non-NULL value. */
248 create_new_frame (CORE_ADDR addr
, CORE_ADDR pc
)
250 struct frame_info
*fi
;
253 fi
= (struct frame_info
*)
254 obstack_alloc (&frame_cache_obstack
,
255 sizeof (struct frame_info
));
257 /* Zero all fields by default. */
258 memset (fi
, 0, sizeof (struct frame_info
));
262 find_pc_partial_function (pc
, &name
, (CORE_ADDR
*) NULL
, (CORE_ADDR
*) NULL
);
263 fi
->signal_handler_caller
= PC_IN_SIGTRAMP (fi
->pc
, name
);
265 if (INIT_EXTRA_FRAME_INFO_P ())
266 INIT_EXTRA_FRAME_INFO (0, fi
);
268 /* Select/initialize an unwind function. */
269 set_unwind_by_pc (fi
->pc
, fi
->frame
, &fi
->register_unwind
);
274 /* Return the frame that FRAME calls (NULL if FRAME is the innermost
278 get_next_frame (struct frame_info
*frame
)
283 /* Flush the entire frame cache. */
286 flush_cached_frames (void)
288 /* Since we can't really be sure what the first object allocated was */
289 obstack_free (&frame_cache_obstack
, 0);
290 obstack_init (&frame_cache_obstack
);
292 current_frame
= NULL
; /* Invalidate cache */
294 annotate_frames_invalid ();
297 /* Flush the frame cache, and start a new one if necessary. */
300 reinit_frame_cache (void)
302 flush_cached_frames ();
304 /* FIXME: The inferior_ptid test is wrong if there is a corefile. */
305 if (PIDGET (inferior_ptid
) != 0)
307 select_frame (get_current_frame ());
311 /* Return nonzero if the function for this frame lacks a prologue. Many
312 machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
316 frameless_look_for_prologue (struct frame_info
*frame
)
318 CORE_ADDR func_start
, after_prologue
;
320 func_start
= get_pc_function_start (frame
->pc
);
323 func_start
+= FUNCTION_START_OFFSET
;
324 /* This is faster, since only care whether there *is* a
325 prologue, not how long it is. */
326 return PROLOGUE_FRAMELESS_P (func_start
);
328 else if (frame
->pc
== 0)
329 /* A frame with a zero PC is usually created by dereferencing a
330 NULL function pointer, normally causing an immediate core dump
331 of the inferior. Mark function as frameless, as the inferior
332 has no chance of setting up a stack frame. */
335 /* If we can't find the start of the function, we don't really
336 know whether the function is frameless, but we should be able
337 to get a reasonable (i.e. best we can do under the
338 circumstances) backtrace by saying that it isn't. */
342 /* Return a structure containing various interesting information
343 about the frame that called NEXT_FRAME. Returns NULL
344 if there is no such frame. */
347 get_prev_frame (struct frame_info
*next_frame
)
349 CORE_ADDR address
= 0;
350 struct frame_info
*prev
;
354 /* If the requested entry is in the cache, return it.
355 Otherwise, figure out what the address should be for the entry
356 we're about to add to the cache. */
361 /* This screws value_of_variable, which just wants a nice clean
362 NULL return from block_innermost_frame if there are no frames.
363 I don't think I've ever seen this message happen otherwise.
364 And returning NULL here is a perfectly legitimate thing to do. */
367 error ("You haven't set up a process's stack to examine.");
371 return current_frame
;
374 /* If we have the prev one, return it */
375 if (next_frame
->prev
)
376 return next_frame
->prev
;
378 /* On some machines it is possible to call a function without
379 setting up a stack frame for it. On these machines, we
380 define this macro to take two args; a frameinfo pointer
381 identifying a frame and a variable to set or clear if it is
382 or isn't leafless. */
384 /* Still don't want to worry about this except on the innermost
385 frame. This macro will set FROMLEAF if NEXT_FRAME is a
386 frameless function invocation. */
387 if (!(next_frame
->next
))
389 fromleaf
= FRAMELESS_FUNCTION_INVOCATION (next_frame
);
391 address
= FRAME_FP (next_frame
);
396 /* Two macros defined in tm.h specify the machine-dependent
397 actions to be performed here.
398 First, get the frame's chain-pointer.
399 If that is zero, the frame is the outermost frame or a leaf
400 called by the outermost frame. This means that if start
401 calls main without a frame, we'll return 0 (which is fine
404 Nope; there's a problem. This also returns when the current
405 routine is a leaf of main. This is unacceptable. We move
406 this to after the ffi test; I'd rather have backtraces from
407 start go curfluy than have an abort called from main not show
409 address
= FRAME_CHAIN (next_frame
);
411 /* FIXME: cagney/2002-06-08: There should be two tests here.
412 The first would check for a valid frame chain based on a user
413 selectable policy. The default being ``stop at main'' (as
414 implemented by generic_func_frame_chain_valid()). Other
415 policies would be available - stop at NULL, .... The second
416 test, if provided by the target architecture, would check for
417 more exotic cases - most target architectures wouldn't bother
418 with this second case. */
419 if (!FRAME_CHAIN_VALID (address
, next_frame
))
425 prev
= (struct frame_info
*)
426 obstack_alloc (&frame_cache_obstack
,
427 sizeof (struct frame_info
));
429 /* Zero all fields by default. */
430 memset (prev
, 0, sizeof (struct frame_info
));
433 next_frame
->prev
= prev
;
434 prev
->next
= next_frame
;
435 prev
->frame
= address
;
436 prev
->level
= next_frame
->level
+ 1;
438 /* This change should not be needed, FIXME! We should
439 determine whether any targets *need* INIT_FRAME_PC to happen
440 after INIT_EXTRA_FRAME_INFO and come up with a simple way to
441 express what goes on here.
443 INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
444 (where the PC is already set up) and here (where it isn't).
445 INIT_FRAME_PC is only called from here, always after
446 INIT_EXTRA_FRAME_INFO.
448 The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC
449 value (which hasn't been set yet). Some other machines appear to
450 require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC. Phoo.
452 We shouldn't need INIT_FRAME_PC_FIRST to add more complication to
453 an already overcomplicated part of GDB. gnu@cygnus.com, 15Sep92.
455 Assuming that some machines need INIT_FRAME_PC after
456 INIT_EXTRA_FRAME_INFO, one possible scheme:
458 SETUP_INNERMOST_FRAME()
459 Default version is just create_new_frame (read_fp ()),
460 read_pc ()). Machines with extra frame info would do that (or the
461 local equivalent) and then set the extra fields.
462 SETUP_ARBITRARY_FRAME(argc, argv)
463 Only change here is that create_new_frame would no longer init extra
464 frame info; SETUP_ARBITRARY_FRAME would have to do that.
465 INIT_PREV_FRAME(fromleaf, prev)
466 Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC. This should
467 also return a flag saying whether to keep the new frame, or
468 whether to discard it, because on some machines (e.g. mips) it
469 is really awkward to have FRAME_CHAIN_VALID called *before*
470 INIT_EXTRA_FRAME_INFO (there is no good way to get information
471 deduced in FRAME_CHAIN_VALID into the extra fields of the new frame).
472 std_frame_pc(fromleaf, prev)
473 This is the default setting for INIT_PREV_FRAME. It just does what
474 the default INIT_FRAME_PC does. Some machines will call it from
475 INIT_PREV_FRAME (either at the beginning, the end, or in the middle).
476 Some machines won't use it.
477 kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */
479 INIT_FRAME_PC_FIRST (fromleaf
, prev
);
481 if (INIT_EXTRA_FRAME_INFO_P ())
482 INIT_EXTRA_FRAME_INFO (fromleaf
, prev
);
484 /* This entry is in the frame queue now, which is good since
485 FRAME_SAVED_PC may use that queue to figure out its value
486 (see tm-sparc.h). We want the pc saved in the inferior frame. */
487 INIT_FRAME_PC (fromleaf
, prev
);
489 /* If ->frame and ->pc are unchanged, we are in the process of getting
490 ourselves into an infinite backtrace. Some architectures check this
491 in FRAME_CHAIN or thereabouts, but it seems like there is no reason
492 this can't be an architecture-independent check. */
493 if (next_frame
!= NULL
)
495 if (prev
->frame
== next_frame
->frame
496 && prev
->pc
== next_frame
->pc
)
498 next_frame
->prev
= NULL
;
499 obstack_free (&frame_cache_obstack
, prev
);
504 /* Initialize the code used to unwind the frame PREV based on the PC
505 (and probably other architectural information). The PC lets you
506 check things like the debug info at that point (dwarf2cfi?) and
507 use that to decide how the frame should be unwound. */
508 set_unwind_by_pc (prev
->pc
, prev
->frame
, &prev
->register_unwind
);
510 find_pc_partial_function (prev
->pc
, &name
,
511 (CORE_ADDR
*) NULL
, (CORE_ADDR
*) NULL
);
512 if (PC_IN_SIGTRAMP (prev
->pc
, name
))
513 prev
->signal_handler_caller
= 1;
519 get_frame_pc (struct frame_info
*frame
)
524 /* return the address of the PC for the given FRAME, ie the current PC value
525 if FRAME is the innermost frame, or the address adjusted to point to the
526 call instruction if not. */
529 frame_address_in_block (struct frame_info
*frame
)
531 CORE_ADDR pc
= frame
->pc
;
533 /* If we are not in the innermost frame, and we are not interrupted
534 by a signal, frame->pc points to the instruction following the
535 call. As a consequence, we need to get the address of the previous
536 instruction. Unfortunately, this is not straightforward to do, so
537 we just use the address minus one, which is a good enough
539 if (frame
->next
!= 0 && frame
->next
->signal_handler_caller
== 0)
545 #ifdef FRAME_FIND_SAVED_REGS
546 /* XXX - deprecated. This is a compatibility function for targets
547 that do not yet implement FRAME_INIT_SAVED_REGS. */
548 /* Find the addresses in which registers are saved in FRAME. */
551 get_frame_saved_regs (struct frame_info
*frame
,
552 struct frame_saved_regs
*saved_regs_addr
)
554 if (frame
->saved_regs
== NULL
)
556 frame
->saved_regs
= (CORE_ADDR
*)
557 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS
);
559 if (saved_regs_addr
== NULL
)
561 struct frame_saved_regs saved_regs
;
562 FRAME_FIND_SAVED_REGS (frame
, saved_regs
);
563 memcpy (frame
->saved_regs
, &saved_regs
, SIZEOF_FRAME_SAVED_REGS
);
567 FRAME_FIND_SAVED_REGS (frame
, *saved_regs_addr
);
568 memcpy (frame
->saved_regs
, saved_regs_addr
, SIZEOF_FRAME_SAVED_REGS
);
573 /* Return the innermost lexical block in execution
574 in a specified stack frame. The frame address is assumed valid.
576 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the exact code
577 address we used to choose the block. We use this to find a source
578 line, to decide which macro definitions are in scope.
580 The value returned in *ADDR_IN_BLOCK isn't necessarily the frame's
581 PC, and may not really be a valid PC at all. For example, in the
582 caller of a function declared to never return, the code at the
583 return address will never be reached, so the call instruction may
584 be the very last instruction in the block. So the address we use
585 to choose the block is actually one byte before the return address
586 --- hopefully pointing us at the call instruction, or its delay
590 get_frame_block (struct frame_info
*frame
, CORE_ADDR
*addr_in_block
)
592 const CORE_ADDR pc
= frame_address_in_block (frame
);
597 return block_for_pc (pc
);
601 get_current_block (CORE_ADDR
*addr_in_block
)
603 CORE_ADDR pc
= read_pc ();
608 return block_for_pc (pc
);
612 get_pc_function_start (CORE_ADDR pc
)
614 register struct block
*bl
;
615 register struct symbol
*symbol
;
616 register struct minimal_symbol
*msymbol
;
619 if ((bl
= block_for_pc (pc
)) != NULL
&&
620 (symbol
= block_function (bl
)) != NULL
)
622 bl
= SYMBOL_BLOCK_VALUE (symbol
);
623 fstart
= BLOCK_START (bl
);
625 else if ((msymbol
= lookup_minimal_symbol_by_pc (pc
)) != NULL
)
627 fstart
= SYMBOL_VALUE_ADDRESS (msymbol
);
628 if (!find_pc_section (fstart
))
638 /* Return the symbol for the function executing in frame FRAME. */
641 get_frame_function (struct frame_info
*frame
)
643 register struct block
*bl
= get_frame_block (frame
, 0);
646 return block_function (bl
);
650 /* Return the blockvector immediately containing the innermost lexical block
651 containing the specified pc value and section, or 0 if there is none.
652 PINDEX is a pointer to the index value of the block. If PINDEX
653 is NULL, we don't pass this information back to the caller. */
656 blockvector_for_pc_sect (register CORE_ADDR pc
, struct sec
*section
,
657 int *pindex
, struct symtab
*symtab
)
659 register struct block
*b
;
660 register int bot
, top
, half
;
661 struct blockvector
*bl
;
663 if (symtab
== 0) /* if no symtab specified by caller */
665 /* First search all symtabs for one whose file contains our pc */
666 if ((symtab
= find_pc_sect_symtab (pc
, section
)) == 0)
670 bl
= BLOCKVECTOR (symtab
);
671 b
= BLOCKVECTOR_BLOCK (bl
, 0);
673 /* Then search that symtab for the smallest block that wins. */
674 /* Use binary search to find the last block that starts before PC. */
677 top
= BLOCKVECTOR_NBLOCKS (bl
);
679 while (top
- bot
> 1)
681 half
= (top
- bot
+ 1) >> 1;
682 b
= BLOCKVECTOR_BLOCK (bl
, bot
+ half
);
683 if (BLOCK_START (b
) <= pc
)
689 /* Now search backward for a block that ends after PC. */
693 b
= BLOCKVECTOR_BLOCK (bl
, bot
);
694 if (BLOCK_END (b
) > pc
)
705 /* Return the blockvector immediately containing the innermost lexical block
706 containing the specified pc value, or 0 if there is none.
707 Backward compatibility, no section. */
710 blockvector_for_pc (register CORE_ADDR pc
, int *pindex
)
712 return blockvector_for_pc_sect (pc
, find_pc_mapped_section (pc
),
716 /* Return the innermost lexical block containing the specified pc value
717 in the specified section, or 0 if there is none. */
720 block_for_pc_sect (register CORE_ADDR pc
, struct sec
*section
)
722 register struct blockvector
*bl
;
725 bl
= blockvector_for_pc_sect (pc
, section
, &index
, NULL
);
727 return BLOCKVECTOR_BLOCK (bl
, index
);
731 /* Return the innermost lexical block containing the specified pc value,
732 or 0 if there is none. Backward compatibility, no section. */
735 block_for_pc (register CORE_ADDR pc
)
737 return block_for_pc_sect (pc
, find_pc_mapped_section (pc
));
740 /* Return the function containing pc value PC in section SECTION.
741 Returns 0 if function is not known. */
744 find_pc_sect_function (CORE_ADDR pc
, struct sec
*section
)
746 register struct block
*b
= block_for_pc_sect (pc
, section
);
749 return block_function (b
);
752 /* Return the function containing pc value PC.
753 Returns 0 if function is not known. Backward compatibility, no section */
756 find_pc_function (CORE_ADDR pc
)
758 return find_pc_sect_function (pc
, find_pc_mapped_section (pc
));
761 /* These variables are used to cache the most recent result
762 * of find_pc_partial_function. */
764 static CORE_ADDR cache_pc_function_low
= 0;
765 static CORE_ADDR cache_pc_function_high
= 0;
766 static char *cache_pc_function_name
= 0;
767 static struct sec
*cache_pc_function_section
= NULL
;
769 /* Clear cache, e.g. when symbol table is discarded. */
772 clear_pc_function_cache (void)
774 cache_pc_function_low
= 0;
775 cache_pc_function_high
= 0;
776 cache_pc_function_name
= (char *) 0;
777 cache_pc_function_section
= NULL
;
780 /* Finds the "function" (text symbol) that is smaller than PC but
781 greatest of all of the potential text symbols in SECTION. Sets
782 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
783 If ENDADDR is non-null, then set *ENDADDR to be the end of the
784 function (exclusive), but passing ENDADDR as non-null means that
785 the function might cause symbols to be read. This function either
786 succeeds or fails (not halfway succeeds). If it succeeds, it sets
787 *NAME, *ADDRESS, and *ENDADDR to real information and returns 1.
788 If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero and
792 find_pc_sect_partial_function (CORE_ADDR pc
, asection
*section
, char **name
,
793 CORE_ADDR
*address
, CORE_ADDR
*endaddr
)
795 struct partial_symtab
*pst
;
797 struct minimal_symbol
*msymbol
;
798 struct partial_symbol
*psb
;
799 struct obj_section
*osect
;
803 mapped_pc
= overlay_mapped_address (pc
, section
);
805 if (mapped_pc
>= cache_pc_function_low
806 && mapped_pc
< cache_pc_function_high
807 && section
== cache_pc_function_section
)
808 goto return_cached_value
;
810 /* If sigtramp is in the u area, it counts as a function (especially
811 important for step_1). */
812 if (SIGTRAMP_START_P () && PC_IN_SIGTRAMP (mapped_pc
, (char *) NULL
))
814 cache_pc_function_low
= SIGTRAMP_START (mapped_pc
);
815 cache_pc_function_high
= SIGTRAMP_END (mapped_pc
);
816 cache_pc_function_name
= "<sigtramp>";
817 cache_pc_function_section
= section
;
818 goto return_cached_value
;
821 msymbol
= lookup_minimal_symbol_by_pc_section (mapped_pc
, section
);
822 pst
= find_pc_sect_psymtab (mapped_pc
, section
);
825 /* Need to read the symbols to get a good value for the end address. */
826 if (endaddr
!= NULL
&& !pst
->readin
)
828 /* Need to get the terminal in case symbol-reading produces
830 target_terminal_ours_for_output ();
831 PSYMTAB_TO_SYMTAB (pst
);
836 /* Checking whether the msymbol has a larger value is for the
837 "pathological" case mentioned in print_frame_info. */
838 f
= find_pc_sect_function (mapped_pc
, section
);
841 || (BLOCK_START (SYMBOL_BLOCK_VALUE (f
))
842 >= SYMBOL_VALUE_ADDRESS (msymbol
))))
844 cache_pc_function_low
= BLOCK_START (SYMBOL_BLOCK_VALUE (f
));
845 cache_pc_function_high
= BLOCK_END (SYMBOL_BLOCK_VALUE (f
));
846 cache_pc_function_name
= SYMBOL_NAME (f
);
847 cache_pc_function_section
= section
;
848 goto return_cached_value
;
853 /* Now that static symbols go in the minimal symbol table, perhaps
854 we could just ignore the partial symbols. But at least for now
855 we use the partial or minimal symbol, whichever is larger. */
856 psb
= find_pc_sect_psymbol (pst
, mapped_pc
, section
);
859 && (msymbol
== NULL
||
860 (SYMBOL_VALUE_ADDRESS (psb
)
861 >= SYMBOL_VALUE_ADDRESS (msymbol
))))
863 /* This case isn't being cached currently. */
865 *address
= SYMBOL_VALUE_ADDRESS (psb
);
867 *name
= SYMBOL_NAME (psb
);
868 /* endaddr non-NULL can't happen here. */
874 /* Not in the normal symbol tables, see if the pc is in a known section.
875 If it's not, then give up. This ensures that anything beyond the end
876 of the text seg doesn't appear to be part of the last function in the
879 osect
= find_pc_sect_section (mapped_pc
, section
);
884 /* Must be in the minimal symbol table. */
887 /* No available symbol. */
897 cache_pc_function_low
= SYMBOL_VALUE_ADDRESS (msymbol
);
898 cache_pc_function_name
= SYMBOL_NAME (msymbol
);
899 cache_pc_function_section
= section
;
901 /* Use the lesser of the next minimal symbol in the same section, or
902 the end of the section, as the end of the function. */
904 /* Step over other symbols at this same address, and symbols in
905 other sections, to find the next symbol in this section with
906 a different address. */
908 for (i
= 1; SYMBOL_NAME (msymbol
+ i
) != NULL
; i
++)
910 if (SYMBOL_VALUE_ADDRESS (msymbol
+ i
) != SYMBOL_VALUE_ADDRESS (msymbol
)
911 && SYMBOL_BFD_SECTION (msymbol
+ i
) == SYMBOL_BFD_SECTION (msymbol
))
915 if (SYMBOL_NAME (msymbol
+ i
) != NULL
916 && SYMBOL_VALUE_ADDRESS (msymbol
+ i
) < osect
->endaddr
)
917 cache_pc_function_high
= SYMBOL_VALUE_ADDRESS (msymbol
+ i
);
919 /* We got the start address from the last msymbol in the objfile.
920 So the end address is the end of the section. */
921 cache_pc_function_high
= osect
->endaddr
;
927 if (pc_in_unmapped_range (pc
, section
))
928 *address
= overlay_unmapped_address (cache_pc_function_low
, section
);
930 *address
= cache_pc_function_low
;
934 *name
= cache_pc_function_name
;
938 if (pc_in_unmapped_range (pc
, section
))
940 /* Because the high address is actually beyond the end of
941 the function (and therefore possibly beyond the end of
942 the overlay), we must actually convert (high - 1) and
943 then add one to that. */
945 *endaddr
= 1 + overlay_unmapped_address (cache_pc_function_high
- 1,
949 *endaddr
= cache_pc_function_high
;
955 /* Backward compatibility, no section argument. */
958 find_pc_partial_function (CORE_ADDR pc
, char **name
, CORE_ADDR
*address
,
963 section
= find_pc_overlay (pc
);
964 return find_pc_sect_partial_function (pc
, section
, name
, address
, endaddr
);
967 /* Return the innermost stack frame executing inside of BLOCK,
968 or NULL if there is no such frame. If BLOCK is NULL, just return NULL. */
971 block_innermost_frame (struct block
*block
)
973 struct frame_info
*frame
;
974 register CORE_ADDR start
;
975 register CORE_ADDR end
;
976 CORE_ADDR calling_pc
;
981 start
= BLOCK_START (block
);
982 end
= BLOCK_END (block
);
987 frame
= get_prev_frame (frame
);
990 calling_pc
= frame_address_in_block (frame
);
991 if (calling_pc
>= start
&& calling_pc
< end
)
996 /* Return the full FRAME which corresponds to the given CORE_ADDR
997 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
1000 find_frame_addr_in_frame_chain (CORE_ADDR frame_addr
)
1002 struct frame_info
*frame
= NULL
;
1004 if (frame_addr
== (CORE_ADDR
) 0)
1009 frame
= get_prev_frame (frame
);
1012 if (FRAME_FP (frame
) == frame_addr
)
1017 #ifdef SIGCONTEXT_PC_OFFSET
1018 /* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp. */
1021 sigtramp_saved_pc (struct frame_info
*frame
)
1023 CORE_ADDR sigcontext_addr
;
1025 int ptrbytes
= TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
1026 int sigcontext_offs
= (2 * TARGET_INT_BIT
) / TARGET_CHAR_BIT
;
1028 buf
= alloca (ptrbytes
);
1029 /* Get sigcontext address, it is the third parameter on the stack. */
1031 sigcontext_addr
= read_memory_typed_address
1032 (FRAME_ARGS_ADDRESS (frame
->next
) + FRAME_ARGS_SKIP
+ sigcontext_offs
,
1033 builtin_type_void_data_ptr
);
1035 sigcontext_addr
= read_memory_typed_address
1036 (read_register (SP_REGNUM
) + sigcontext_offs
, builtin_type_void_data_ptr
);
1038 /* Don't cause a memory_error when accessing sigcontext in case the stack
1039 layout has changed or the stack is corrupt. */
1040 target_read_memory (sigcontext_addr
+ SIGCONTEXT_PC_OFFSET
, buf
, ptrbytes
);
1041 return extract_typed_address (buf
, builtin_type_void_data_ptr
);
1043 #endif /* SIGCONTEXT_PC_OFFSET */
1046 /* Are we in a call dummy? The code below which allows DECR_PC_AFTER_BREAK
1047 below is for infrun.c, which may give the macro a pc without that
1050 extern CORE_ADDR text_end
;
1053 pc_in_call_dummy_before_text_end (CORE_ADDR pc
, CORE_ADDR sp
,
1054 CORE_ADDR frame_address
)
1056 return ((pc
) >= text_end
- CALL_DUMMY_LENGTH
1057 && (pc
) <= text_end
+ DECR_PC_AFTER_BREAK
);
1061 pc_in_call_dummy_after_text_end (CORE_ADDR pc
, CORE_ADDR sp
,
1062 CORE_ADDR frame_address
)
1064 return ((pc
) >= text_end
1065 && (pc
) <= text_end
+ CALL_DUMMY_LENGTH
+ DECR_PC_AFTER_BREAK
);
1068 /* Is the PC in a call dummy? SP and FRAME_ADDRESS are the bottom and
1069 top of the stack frame which we are checking, where "bottom" and
1070 "top" refer to some section of memory which contains the code for
1071 the call dummy. Calls to this macro assume that the contents of
1072 SP_REGNUM and FP_REGNUM (or the saved values thereof), respectively,
1073 are the things to pass.
1075 This won't work on the 29k, where SP_REGNUM and FP_REGNUM don't
1076 have that meaning, but the 29k doesn't use ON_STACK. This could be
1077 fixed by generalizing this scheme, perhaps by passing in a frame
1078 and adding a few fields, at least on machines which need them for
1081 Something simpler, like checking for the stack segment, doesn't work,
1082 since various programs (threads implementations, gcc nested function
1083 stubs, etc) may either allocate stack frames in another segment, or
1084 allocate other kinds of code on the stack. */
1087 pc_in_call_dummy_on_stack (CORE_ADDR pc
, CORE_ADDR sp
, CORE_ADDR frame_address
)
1089 return (INNER_THAN ((sp
), (pc
))
1090 && (frame_address
!= 0)
1091 && INNER_THAN ((pc
), (frame_address
)));
1095 pc_in_call_dummy_at_entry_point (CORE_ADDR pc
, CORE_ADDR sp
,
1096 CORE_ADDR frame_address
)
1098 return ((pc
) >= CALL_DUMMY_ADDRESS ()
1099 && (pc
) <= (CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK
));
1103 /* Function: frame_chain_valid
1104 Returns true for a user frame or a call_function_by_hand dummy frame,
1105 and false for the CRT0 start-up frame. Purpose is to terminate backtrace */
1108 generic_file_frame_chain_valid (CORE_ADDR fp
, struct frame_info
*fi
)
1110 if (PC_IN_CALL_DUMMY (FRAME_SAVED_PC (fi
), fp
, fp
))
1111 return 1; /* don't prune CALL_DUMMY frames */
1112 else /* fall back to default algorithm (see frame.h) */
1114 && (INNER_THAN (fi
->frame
, fp
) || fi
->frame
== fp
)
1115 && !inside_entry_file (FRAME_SAVED_PC (fi
)));
1119 generic_func_frame_chain_valid (CORE_ADDR fp
, struct frame_info
*fi
)
1121 if (USE_GENERIC_DUMMY_FRAMES
1122 && PC_IN_CALL_DUMMY ((fi
)->pc
, 0, 0))
1123 return 1; /* don't prune CALL_DUMMY frames */
1124 else /* fall back to default algorithm (see frame.h) */
1126 && (INNER_THAN (fi
->frame
, fp
) || fi
->frame
== fp
)
1127 && !inside_main_func ((fi
)->pc
)
1128 && !inside_entry_func ((fi
)->pc
));
1131 /* Return the register saved in the simplistic ``saved_regs'' cache.
1132 If the value isn't here AND a value is needed, try the next inner
1136 frame_saved_regs_register_unwind (struct frame_info
*frame
, void **cache
,
1137 int regnum
, int *optimizedp
,
1138 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1139 int *realnump
, void *bufferp
)
1141 /* There is always a frame at this point. And THIS is the frame
1142 we're interested in. */
1143 gdb_assert (frame
!= NULL
);
1144 /* If we're using generic dummy frames, we'd better not be in a call
1145 dummy. (generic_call_dummy_register_unwind ought to have been called
1147 gdb_assert (!(USE_GENERIC_DUMMY_FRAMES
1148 && PC_IN_CALL_DUMMY (frame
->pc
, frame
->frame
, frame
->frame
)));
1150 /* Load the saved_regs register cache. */
1151 if (frame
->saved_regs
== NULL
)
1152 FRAME_INIT_SAVED_REGS (frame
);
1154 if (frame
->saved_regs
!= NULL
1155 && frame
->saved_regs
[regnum
] != 0)
1157 if (regnum
== SP_REGNUM
)
1159 /* SP register treated specially. */
1164 if (bufferp
!= NULL
)
1165 store_address (bufferp
, REGISTER_RAW_SIZE (regnum
),
1166 frame
->saved_regs
[regnum
]);
1170 /* Any other register is saved in memory, fetch it but cache
1171 a local copy of its value. */
1173 *lvalp
= lval_memory
;
1174 *addrp
= frame
->saved_regs
[regnum
];
1176 if (bufferp
!= NULL
)
1179 /* Save each register value, as it is read in, in a
1180 frame based cache. */
1181 void **regs
= (*cache
);
1184 int sizeof_cache
= ((NUM_REGS
+ NUM_PSEUDO_REGS
)
1186 regs
= frame_obstack_alloc (sizeof_cache
);
1187 memset (regs
, 0, sizeof_cache
);
1190 if (regs
[regnum
] == NULL
)
1193 = frame_obstack_alloc (REGISTER_RAW_SIZE (regnum
));
1194 read_memory (frame
->saved_regs
[regnum
], regs
[regnum
],
1195 REGISTER_RAW_SIZE (regnum
));
1197 memcpy (bufferp
, regs
[regnum
], REGISTER_RAW_SIZE (regnum
));
1199 /* Read the value in from memory. */
1200 read_memory (frame
->saved_regs
[regnum
], bufferp
,
1201 REGISTER_RAW_SIZE (regnum
));
1208 /* No luck, assume this and the next frame have the same register
1209 value. If a value is needed, pass the request on down the chain;
1210 otherwise just return an indication that the value is in the same
1211 register as the next frame. */
1212 if (bufferp
== NULL
)
1215 *lvalp
= lval_register
;
1221 frame_register_unwind (frame
->next
, regnum
, optimizedp
, lvalp
, addrp
,
1226 /* Function: get_saved_register
1227 Find register number REGNUM relative to FRAME and put its (raw,
1228 target format) contents in *RAW_BUFFER.
1230 Set *OPTIMIZED if the variable was optimized out (and thus can't be
1231 fetched). Note that this is never set to anything other than zero
1232 in this implementation.
1234 Set *LVAL to lval_memory, lval_register, or not_lval, depending on
1235 whether the value was fetched from memory, from a register, or in a
1236 strange and non-modifiable way (e.g. a frame pointer which was
1237 calculated rather than fetched). We will use not_lval for values
1238 fetched from generic dummy frames.
1240 Set *ADDRP to the address, either in memory or as a REGISTER_BYTE
1241 offset into the registers array. If the value is stored in a dummy
1242 frame, set *ADDRP to zero.
1244 To use this implementation, define a function called
1245 "get_saved_register" in your target code, which simply passes all
1246 of its arguments to this function.
1248 The argument RAW_BUFFER must point to aligned memory. */
1251 deprecated_generic_get_saved_register (char *raw_buffer
, int *optimized
,
1253 struct frame_info
*frame
, int regnum
,
1254 enum lval_type
*lval
)
1256 if (!target_has_registers
)
1257 error ("No registers.");
1259 /* Normal systems don't optimize out things with register numbers. */
1260 if (optimized
!= NULL
)
1263 if (addrp
) /* default assumption: not found in memory */
1266 /* Note: since the current frame's registers could only have been
1267 saved by frames INTERIOR TO the current frame, we skip examining
1268 the current frame itself: otherwise, we would be getting the
1269 previous frame's registers which were saved by the current frame. */
1271 while (frame
&& ((frame
= frame
->next
) != NULL
))
1273 if (PC_IN_CALL_DUMMY (frame
->pc
, frame
->frame
, frame
->frame
))
1275 if (lval
) /* found it in a CALL_DUMMY frame */
1278 /* FIXME: cagney/2002-06-26: This should be via the
1279 gdbarch_register_read() method so that it, on the fly,
1280 constructs either a raw or pseudo register from the raw
1282 regcache_raw_read (generic_find_dummy_frame (frame
->pc
,
1284 regnum
, raw_buffer
);
1288 FRAME_INIT_SAVED_REGS (frame
);
1289 if (frame
->saved_regs
!= NULL
1290 && frame
->saved_regs
[regnum
] != 0)
1292 if (lval
) /* found it saved on the stack */
1293 *lval
= lval_memory
;
1294 if (regnum
== SP_REGNUM
)
1296 if (raw_buffer
) /* SP register treated specially */
1297 store_address (raw_buffer
, REGISTER_RAW_SIZE (regnum
),
1298 frame
->saved_regs
[regnum
]);
1302 if (addrp
) /* any other register */
1303 *addrp
= frame
->saved_regs
[regnum
];
1305 read_memory (frame
->saved_regs
[regnum
], raw_buffer
,
1306 REGISTER_RAW_SIZE (regnum
));
1312 /* If we get thru the loop to this point, it means the register was
1313 not saved in any frame. Return the actual live-register value. */
1315 if (lval
) /* found it in a live register */
1316 *lval
= lval_register
;
1318 *addrp
= REGISTER_BYTE (regnum
);
1320 deprecated_read_register_gen (regnum
, raw_buffer
);
1324 _initialize_blockframe (void)
1326 obstack_init (&frame_cache_obstack
);