*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / blockframe.c
CommitLineData
7cc19214
AC
1/* Get info from stack frames; convert between frames, blocks,
2 functions and pc values.
3
4 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
51603483 5 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7cc19214 6 Foundation, Inc.
c906108c 7
c5aa993b 8 This file is part of GDB.
c906108c 9
c5aa993b
JM
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.
c906108c 14
c5aa993b
JM
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.
c906108c 19
c5aa993b
JM
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. */
c906108c
SS
24
25#include "defs.h"
26#include "symtab.h"
27#include "bfd.h"
28#include "symfile.h"
29#include "objfiles.h"
30#include "frame.h"
31#include "gdbcore.h"
32#include "value.h" /* for read_register */
33#include "target.h" /* for target_has_stack */
34#include "inferior.h" /* for read_pc */
35#include "annotate.h"
4e052eda 36#include "regcache.h"
4f460812 37#include "gdb_assert.h"
9c1412c1 38#include "dummy-frame.h"
51603483
DJ
39#include "command.h"
40#include "gdbcmd.h"
c906108c 41
51603483 42/* Prototypes for exported functions. */
c5aa993b 43
51603483 44void _initialize_blockframe (void);
c906108c
SS
45
46/* Is ADDR inside the startup file? Note that if your machine
47 has a way to detect the bottom of the stack, there is no need
48 to call this function from FRAME_CHAIN_VALID; the reason for
49 doing so is that some machines have no way of detecting bottom
50 of stack.
51
52 A PC of zero is always considered to be the bottom of the stack. */
53
54int
fba45db2 55inside_entry_file (CORE_ADDR addr)
c906108c
SS
56{
57 if (addr == 0)
58 return 1;
59 if (symfile_objfile == 0)
60 return 0;
7a292a7a
SS
61 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
62 {
63 /* Do not stop backtracing if the pc is in the call dummy
c5aa993b 64 at the entry point. */
7a292a7a 65 /* FIXME: Won't always work with zeros for the last two arguments */
ae45cd16 66 if (DEPRECATED_PC_IN_CALL_DUMMY (addr, 0, 0))
7a292a7a
SS
67 return 0;
68 }
c5aa993b
JM
69 return (addr >= symfile_objfile->ei.entry_file_lowpc &&
70 addr < symfile_objfile->ei.entry_file_highpc);
c906108c
SS
71}
72
73/* Test a specified PC value to see if it is in the range of addresses
74 that correspond to the main() function. See comments above for why
75 we might want to do this.
76
77 Typically called from FRAME_CHAIN_VALID.
78
79 A PC of zero is always considered to be the bottom of the stack. */
80
81int
fba45db2 82inside_main_func (CORE_ADDR pc)
c906108c
SS
83{
84 if (pc == 0)
85 return 1;
86 if (symfile_objfile == 0)
87 return 0;
88
89 /* If the addr range is not set up at symbol reading time, set it up now.
90 This is for FRAME_CHAIN_VALID_ALTERNATE. I do this for coff, because
91 it is unable to set it up and symbol reading time. */
92
c5aa993b
JM
93 if (symfile_objfile->ei.main_func_lowpc == INVALID_ENTRY_LOWPC &&
94 symfile_objfile->ei.main_func_highpc == INVALID_ENTRY_HIGHPC)
c906108c
SS
95 {
96 struct symbol *mainsym;
97
51cc5b07 98 mainsym = lookup_symbol (main_name (), NULL, VAR_NAMESPACE, NULL, NULL);
c5aa993b
JM
99 if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
100 {
101 symfile_objfile->ei.main_func_lowpc =
c906108c 102 BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym));
c5aa993b 103 symfile_objfile->ei.main_func_highpc =
c906108c 104 BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym));
c5aa993b 105 }
c906108c 106 }
c5aa993b
JM
107 return (symfile_objfile->ei.main_func_lowpc <= pc &&
108 symfile_objfile->ei.main_func_highpc > pc);
c906108c
SS
109}
110
111/* Test a specified PC value to see if it is in the range of addresses
112 that correspond to the process entry point function. See comments
113 in objfiles.h for why we might want to do this.
114
115 Typically called from FRAME_CHAIN_VALID.
116
117 A PC of zero is always considered to be the bottom of the stack. */
118
119int
fba45db2 120inside_entry_func (CORE_ADDR pc)
c906108c
SS
121{
122 if (pc == 0)
123 return 1;
124 if (symfile_objfile == 0)
125 return 0;
7a292a7a
SS
126 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
127 {
128 /* Do not stop backtracing if the pc is in the call dummy
c5aa993b 129 at the entry point. */
7a292a7a 130 /* FIXME: Won't always work with zeros for the last two arguments */
ae45cd16 131 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
7a292a7a
SS
132 return 0;
133 }
c5aa993b
JM
134 return (symfile_objfile->ei.entry_func_lowpc <= pc &&
135 symfile_objfile->ei.entry_func_highpc > pc);
c906108c
SS
136}
137
c906108c
SS
138/* Return nonzero if the function for this frame lacks a prologue. Many
139 machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
140 function. */
141
142int
fba45db2 143frameless_look_for_prologue (struct frame_info *frame)
c906108c
SS
144{
145 CORE_ADDR func_start, after_prologue;
53a5351d 146
bdd78e62 147 func_start = get_pc_function_start (get_frame_pc (frame));
c906108c
SS
148 if (func_start)
149 {
150 func_start += FUNCTION_START_OFFSET;
53a5351d
JM
151 /* This is faster, since only care whether there *is* a
152 prologue, not how long it is. */
dad41f9a 153 return PROLOGUE_FRAMELESS_P (func_start);
c906108c 154 }
bdd78e62 155 else if (get_frame_pc (frame) == 0)
53a5351d
JM
156 /* A frame with a zero PC is usually created by dereferencing a
157 NULL function pointer, normally causing an immediate core dump
158 of the inferior. Mark function as frameless, as the inferior
159 has no chance of setting up a stack frame. */
c906108c
SS
160 return 1;
161 else
162 /* If we can't find the start of the function, we don't really
163 know whether the function is frameless, but we should be able
164 to get a reasonable (i.e. best we can do under the
165 circumstances) backtrace by saying that it isn't. */
166 return 0;
167}
168
42f99ac2
JB
169/* return the address of the PC for the given FRAME, ie the current PC value
170 if FRAME is the innermost frame, or the address adjusted to point to the
171 call instruction if not. */
172
173CORE_ADDR
174frame_address_in_block (struct frame_info *frame)
175{
bdd78e62 176 CORE_ADDR pc = get_frame_pc (frame);
42f99ac2
JB
177
178 /* If we are not in the innermost frame, and we are not interrupted
179 by a signal, frame->pc points to the instruction following the
180 call. As a consequence, we need to get the address of the previous
181 instruction. Unfortunately, this is not straightforward to do, so
182 we just use the address minus one, which is a good enough
183 approximation. */
5a203e44
AC
184 /* FIXME: cagney/2002-11-10: Should this instead test for
185 NORMAL_FRAME? A dummy frame (in fact all the abnormal frames)
186 save the PC value in the block. */
75e3c1f9
AC
187 if (get_next_frame (frame) != 0
188 && get_frame_type (get_next_frame (frame)) != SIGTRAMP_FRAME)
42f99ac2
JB
189 --pc;
190
191 return pc;
192}
c906108c 193
c906108c 194/* Return the innermost lexical block in execution
ae767bfb
JB
195 in a specified stack frame. The frame address is assumed valid.
196
197 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the exact code
198 address we used to choose the block. We use this to find a source
199 line, to decide which macro definitions are in scope.
200
201 The value returned in *ADDR_IN_BLOCK isn't necessarily the frame's
202 PC, and may not really be a valid PC at all. For example, in the
203 caller of a function declared to never return, the code at the
204 return address will never be reached, so the call instruction may
205 be the very last instruction in the block. So the address we use
206 to choose the block is actually one byte before the return address
207 --- hopefully pointing us at the call instruction, or its delay
208 slot instruction. */
c906108c
SS
209
210struct block *
ae767bfb 211get_frame_block (struct frame_info *frame, CORE_ADDR *addr_in_block)
c906108c 212{
42f99ac2 213 const CORE_ADDR pc = frame_address_in_block (frame);
ae767bfb
JB
214
215 if (addr_in_block)
216 *addr_in_block = pc;
217
c906108c
SS
218 return block_for_pc (pc);
219}
220
c906108c 221CORE_ADDR
fba45db2 222get_pc_function_start (CORE_ADDR pc)
c906108c
SS
223{
224 register struct block *bl;
225 register struct symbol *symbol;
226 register struct minimal_symbol *msymbol;
227 CORE_ADDR fstart;
228
229 if ((bl = block_for_pc (pc)) != NULL &&
230 (symbol = block_function (bl)) != NULL)
231 {
232 bl = SYMBOL_BLOCK_VALUE (symbol);
233 fstart = BLOCK_START (bl);
234 }
235 else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL)
236 {
237 fstart = SYMBOL_VALUE_ADDRESS (msymbol);
28a93f5a
PM
238 if (!find_pc_section (fstart))
239 return 0;
c906108c
SS
240 }
241 else
242 {
243 fstart = 0;
244 }
245 return (fstart);
246}
247
248/* Return the symbol for the function executing in frame FRAME. */
249
250struct symbol *
fba45db2 251get_frame_function (struct frame_info *frame)
c906108c 252{
ae767bfb 253 register struct block *bl = get_frame_block (frame, 0);
c906108c
SS
254 if (bl == 0)
255 return 0;
256 return block_function (bl);
257}
258\f
259
260/* Return the blockvector immediately containing the innermost lexical block
261 containing the specified pc value and section, or 0 if there is none.
262 PINDEX is a pointer to the index value of the block. If PINDEX
263 is NULL, we don't pass this information back to the caller. */
264
265struct blockvector *
fba45db2
KB
266blockvector_for_pc_sect (register CORE_ADDR pc, struct sec *section,
267 int *pindex, struct symtab *symtab)
c906108c
SS
268{
269 register struct block *b;
270 register int bot, top, half;
271 struct blockvector *bl;
272
c5aa993b 273 if (symtab == 0) /* if no symtab specified by caller */
c906108c
SS
274 {
275 /* First search all symtabs for one whose file contains our pc */
276 if ((symtab = find_pc_sect_symtab (pc, section)) == 0)
277 return 0;
278 }
279
280 bl = BLOCKVECTOR (symtab);
281 b = BLOCKVECTOR_BLOCK (bl, 0);
282
283 /* Then search that symtab for the smallest block that wins. */
284 /* Use binary search to find the last block that starts before PC. */
285
286 bot = 0;
287 top = BLOCKVECTOR_NBLOCKS (bl);
288
289 while (top - bot > 1)
290 {
291 half = (top - bot + 1) >> 1;
292 b = BLOCKVECTOR_BLOCK (bl, bot + half);
293 if (BLOCK_START (b) <= pc)
294 bot += half;
295 else
296 top = bot + half;
297 }
298
299 /* Now search backward for a block that ends after PC. */
300
301 while (bot >= 0)
302 {
303 b = BLOCKVECTOR_BLOCK (bl, bot);
43e526b9 304 if (BLOCK_END (b) > pc)
c906108c
SS
305 {
306 if (pindex)
307 *pindex = bot;
308 return bl;
309 }
310 bot--;
311 }
312 return 0;
313}
314
315/* Return the blockvector immediately containing the innermost lexical block
316 containing the specified pc value, or 0 if there is none.
317 Backward compatibility, no section. */
318
319struct blockvector *
fba45db2 320blockvector_for_pc (register CORE_ADDR pc, int *pindex)
c906108c
SS
321{
322 return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
323 pindex, NULL);
324}
325
326/* Return the innermost lexical block containing the specified pc value
327 in the specified section, or 0 if there is none. */
328
329struct block *
fba45db2 330block_for_pc_sect (register CORE_ADDR pc, struct sec *section)
c906108c
SS
331{
332 register struct blockvector *bl;
333 int index;
334
335 bl = blockvector_for_pc_sect (pc, section, &index, NULL);
336 if (bl)
337 return BLOCKVECTOR_BLOCK (bl, index);
338 return 0;
339}
340
341/* Return the innermost lexical block containing the specified pc value,
342 or 0 if there is none. Backward compatibility, no section. */
343
344struct block *
fba45db2 345block_for_pc (register CORE_ADDR pc)
c906108c
SS
346{
347 return block_for_pc_sect (pc, find_pc_mapped_section (pc));
348}
349
350/* Return the function containing pc value PC in section SECTION.
351 Returns 0 if function is not known. */
352
353struct symbol *
fba45db2 354find_pc_sect_function (CORE_ADDR pc, struct sec *section)
c906108c
SS
355{
356 register struct block *b = block_for_pc_sect (pc, section);
357 if (b == 0)
358 return 0;
359 return block_function (b);
360}
361
362/* Return the function containing pc value PC.
363 Returns 0 if function is not known. Backward compatibility, no section */
364
365struct symbol *
fba45db2 366find_pc_function (CORE_ADDR pc)
c906108c
SS
367{
368 return find_pc_sect_function (pc, find_pc_mapped_section (pc));
369}
370
371/* These variables are used to cache the most recent result
372 * of find_pc_partial_function. */
373
c5aa993b
JM
374static CORE_ADDR cache_pc_function_low = 0;
375static CORE_ADDR cache_pc_function_high = 0;
376static char *cache_pc_function_name = 0;
c906108c
SS
377static struct sec *cache_pc_function_section = NULL;
378
379/* Clear cache, e.g. when symbol table is discarded. */
380
381void
fba45db2 382clear_pc_function_cache (void)
c906108c
SS
383{
384 cache_pc_function_low = 0;
385 cache_pc_function_high = 0;
c5aa993b 386 cache_pc_function_name = (char *) 0;
c906108c
SS
387 cache_pc_function_section = NULL;
388}
389
390/* Finds the "function" (text symbol) that is smaller than PC but
391 greatest of all of the potential text symbols in SECTION. Sets
392 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
393 If ENDADDR is non-null, then set *ENDADDR to be the end of the
394 function (exclusive), but passing ENDADDR as non-null means that
395 the function might cause symbols to be read. This function either
396 succeeds or fails (not halfway succeeds). If it succeeds, it sets
397 *NAME, *ADDRESS, and *ENDADDR to real information and returns 1.
398 If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero and
399 returns 0. */
400
401int
fba45db2
KB
402find_pc_sect_partial_function (CORE_ADDR pc, asection *section, char **name,
403 CORE_ADDR *address, CORE_ADDR *endaddr)
c906108c
SS
404{
405 struct partial_symtab *pst;
c5aa993b 406 struct symbol *f;
c906108c
SS
407 struct minimal_symbol *msymbol;
408 struct partial_symbol *psb;
c5aa993b 409 struct obj_section *osect;
c906108c
SS
410 int i;
411 CORE_ADDR mapped_pc;
412
413 mapped_pc = overlay_mapped_address (pc, section);
414
247055de
MK
415 if (mapped_pc >= cache_pc_function_low
416 && mapped_pc < cache_pc_function_high
417 && section == cache_pc_function_section)
c906108c
SS
418 goto return_cached_value;
419
420 /* If sigtramp is in the u area, it counts as a function (especially
421 important for step_1). */
43156d82 422 if (SIGTRAMP_START_P () && PC_IN_SIGTRAMP (mapped_pc, (char *) NULL))
c906108c 423 {
c5aa993b
JM
424 cache_pc_function_low = SIGTRAMP_START (mapped_pc);
425 cache_pc_function_high = SIGTRAMP_END (mapped_pc);
426 cache_pc_function_name = "<sigtramp>";
c906108c
SS
427 cache_pc_function_section = section;
428 goto return_cached_value;
429 }
c906108c
SS
430
431 msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section);
432 pst = find_pc_sect_psymtab (mapped_pc, section);
433 if (pst)
434 {
435 /* Need to read the symbols to get a good value for the end address. */
436 if (endaddr != NULL && !pst->readin)
437 {
438 /* Need to get the terminal in case symbol-reading produces
439 output. */
440 target_terminal_ours_for_output ();
441 PSYMTAB_TO_SYMTAB (pst);
442 }
443
444 if (pst->readin)
445 {
446 /* Checking whether the msymbol has a larger value is for the
447 "pathological" case mentioned in print_frame_info. */
448 f = find_pc_sect_function (mapped_pc, section);
449 if (f != NULL
450 && (msymbol == NULL
451 || (BLOCK_START (SYMBOL_BLOCK_VALUE (f))
452 >= SYMBOL_VALUE_ADDRESS (msymbol))))
453 {
c5aa993b
JM
454 cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
455 cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
456 cache_pc_function_name = SYMBOL_NAME (f);
c906108c
SS
457 cache_pc_function_section = section;
458 goto return_cached_value;
459 }
460 }
461 else
462 {
463 /* Now that static symbols go in the minimal symbol table, perhaps
464 we could just ignore the partial symbols. But at least for now
465 we use the partial or minimal symbol, whichever is larger. */
466 psb = find_pc_sect_psymbol (pst, mapped_pc, section);
467
468 if (psb
469 && (msymbol == NULL ||
470 (SYMBOL_VALUE_ADDRESS (psb)
471 >= SYMBOL_VALUE_ADDRESS (msymbol))))
472 {
473 /* This case isn't being cached currently. */
474 if (address)
475 *address = SYMBOL_VALUE_ADDRESS (psb);
476 if (name)
477 *name = SYMBOL_NAME (psb);
478 /* endaddr non-NULL can't happen here. */
479 return 1;
480 }
481 }
482 }
483
484 /* Not in the normal symbol tables, see if the pc is in a known section.
485 If it's not, then give up. This ensures that anything beyond the end
486 of the text seg doesn't appear to be part of the last function in the
487 text segment. */
488
489 osect = find_pc_sect_section (mapped_pc, section);
490
491 if (!osect)
492 msymbol = NULL;
493
494 /* Must be in the minimal symbol table. */
495 if (msymbol == NULL)
496 {
497 /* No available symbol. */
498 if (name != NULL)
499 *name = 0;
500 if (address != NULL)
501 *address = 0;
502 if (endaddr != NULL)
503 *endaddr = 0;
504 return 0;
505 }
506
c5aa993b
JM
507 cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
508 cache_pc_function_name = SYMBOL_NAME (msymbol);
c906108c
SS
509 cache_pc_function_section = section;
510
511 /* Use the lesser of the next minimal symbol in the same section, or
512 the end of the section, as the end of the function. */
c5aa993b 513
c906108c
SS
514 /* Step over other symbols at this same address, and symbols in
515 other sections, to find the next symbol in this section with
516 a different address. */
517
c5aa993b 518 for (i = 1; SYMBOL_NAME (msymbol + i) != NULL; i++)
c906108c 519 {
c5aa993b 520 if (SYMBOL_VALUE_ADDRESS (msymbol + i) != SYMBOL_VALUE_ADDRESS (msymbol)
247055de 521 && SYMBOL_BFD_SECTION (msymbol + i) == SYMBOL_BFD_SECTION (msymbol))
c906108c
SS
522 break;
523 }
524
525 if (SYMBOL_NAME (msymbol + i) != NULL
526 && SYMBOL_VALUE_ADDRESS (msymbol + i) < osect->endaddr)
527 cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i);
528 else
529 /* We got the start address from the last msymbol in the objfile.
530 So the end address is the end of the section. */
531 cache_pc_function_high = osect->endaddr;
532
247055de 533 return_cached_value:
c906108c
SS
534
535 if (address)
536 {
537 if (pc_in_unmapped_range (pc, section))
c5aa993b 538 *address = overlay_unmapped_address (cache_pc_function_low, section);
c906108c 539 else
c5aa993b 540 *address = cache_pc_function_low;
c906108c 541 }
c5aa993b 542
c906108c
SS
543 if (name)
544 *name = cache_pc_function_name;
545
546 if (endaddr)
547 {
548 if (pc_in_unmapped_range (pc, section))
c5aa993b 549 {
c906108c
SS
550 /* Because the high address is actually beyond the end of
551 the function (and therefore possibly beyond the end of
247055de
MK
552 the overlay), we must actually convert (high - 1) and
553 then add one to that. */
c906108c 554
c5aa993b 555 *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1,
c906108c 556 section);
c5aa993b 557 }
c906108c 558 else
c5aa993b 559 *endaddr = cache_pc_function_high;
c906108c
SS
560 }
561
562 return 1;
563}
564
247055de 565/* Backward compatibility, no section argument. */
c906108c
SS
566
567int
fba45db2
KB
568find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
569 CORE_ADDR *endaddr)
c906108c 570{
c5aa993b 571 asection *section;
c906108c
SS
572
573 section = find_pc_overlay (pc);
574 return find_pc_sect_partial_function (pc, section, name, address, endaddr);
575}
576
577/* Return the innermost stack frame executing inside of BLOCK,
578 or NULL if there is no such frame. If BLOCK is NULL, just return NULL. */
579
580struct frame_info *
fba45db2 581block_innermost_frame (struct block *block)
c906108c
SS
582{
583 struct frame_info *frame;
584 register CORE_ADDR start;
585 register CORE_ADDR end;
42f99ac2 586 CORE_ADDR calling_pc;
c906108c
SS
587
588 if (block == NULL)
589 return NULL;
590
591 start = BLOCK_START (block);
592 end = BLOCK_END (block);
593
594 frame = NULL;
595 while (1)
596 {
597 frame = get_prev_frame (frame);
598 if (frame == NULL)
599 return NULL;
42f99ac2
JB
600 calling_pc = frame_address_in_block (frame);
601 if (calling_pc >= start && calling_pc < end)
c906108c
SS
602 return frame;
603 }
604}
605
7a292a7a
SS
606/* Are we in a call dummy? The code below which allows DECR_PC_AFTER_BREAK
607 below is for infrun.c, which may give the macro a pc without that
608 subtracted out. */
609
7a292a7a
SS
610/* Is the PC in a call dummy? SP and FRAME_ADDRESS are the bottom and
611 top of the stack frame which we are checking, where "bottom" and
612 "top" refer to some section of memory which contains the code for
613 the call dummy. Calls to this macro assume that the contents of
614 SP_REGNUM and FP_REGNUM (or the saved values thereof), respectively,
615 are the things to pass.
616
617 This won't work on the 29k, where SP_REGNUM and FP_REGNUM don't
618 have that meaning, but the 29k doesn't use ON_STACK. This could be
619 fixed by generalizing this scheme, perhaps by passing in a frame
620 and adding a few fields, at least on machines which need them for
ae45cd16 621 DEPRECATED_PC_IN_CALL_DUMMY.
7a292a7a
SS
622
623 Something simpler, like checking for the stack segment, doesn't work,
624 since various programs (threads implementations, gcc nested function
625 stubs, etc) may either allocate stack frames in another segment, or
626 allocate other kinds of code on the stack. */
627
628int
b4b88177
AC
629deprecated_pc_in_call_dummy_on_stack (CORE_ADDR pc, CORE_ADDR sp,
630 CORE_ADDR frame_address)
7a292a7a
SS
631{
632 return (INNER_THAN ((sp), (pc))
633 && (frame_address != 0)
634 && INNER_THAN ((pc), (frame_address)));
635}
636
637int
b4b88177
AC
638deprecated_pc_in_call_dummy_at_entry_point (CORE_ADDR pc, CORE_ADDR sp,
639 CORE_ADDR frame_address)
7a292a7a
SS
640{
641 return ((pc) >= CALL_DUMMY_ADDRESS ()
642 && (pc) <= (CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK));
643}
644
c906108c
SS
645/* Function: frame_chain_valid
646 Returns true for a user frame or a call_function_by_hand dummy frame,
51603483 647 and false for the CRT0 start-up frame. Purpose is to terminate backtrace. */
c5aa993b 648
c906108c 649int
51603483 650frame_chain_valid (CORE_ADDR fp, struct frame_info *fi)
c906108c 651{
51603483
DJ
652 /* Don't prune CALL_DUMMY frames. */
653 if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES
654 && DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), 0, 0))
655 return 1;
656
657 /* If the new frame pointer is zero, then it isn't valid. */
658 if (fp == 0)
659 return 0;
660
661 /* If the new frame would be inside (younger than) the previous frame,
662 then it isn't valid. */
663 if (INNER_THAN (fp, get_frame_base (fi)))
664 return 0;
665
666 /* If we're already inside the entry function for the main objfile, then it
667 isn't valid. */
668 if (inside_entry_func (get_frame_pc (fi)))
669 return 0;
670
671 /* If we're inside the entry file, it isn't valid. */
672 /* NOTE/drow 2002-12-25: should there be a way to disable this check? It
673 assumes a single small entry file, and the way some debug readers (e.g.
674 dbxread) figure out which object is the entry file is somewhat hokey. */
675 if (inside_entry_file (frame_pc_unwind (fi)))
676 return 0;
677
51603483
DJ
678 /* If the architecture has a custom FRAME_CHAIN_VALID, call it now. */
679 if (FRAME_CHAIN_VALID_P ())
680 return FRAME_CHAIN_VALID (fp, fi);
681
682 return 1;
c906108c 683}
This page took 0.23824 seconds and 4 git commands to generate.