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