* source.c (openp): Squelch warning about "filename".
[deliverable/binutils-gdb.git] / gdb / blockframe.c
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,
5 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
6 Foundation, Inc.
7
8 This file is part of GDB.
9
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.
14
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.
19
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. */
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"
36 #include "regcache.h"
37 #include "gdb_assert.h"
38 #include "dummy-frame.h"
39 #include "command.h"
40 #include "gdbcmd.h"
41
42 /* Flag to indicate whether backtraces should stop at main. */
43
44 static int backtrace_below_main;
45
46 /* Prototypes for exported functions. */
47
48 void _initialize_blockframe (void);
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
58 int
59 inside_entry_file (CORE_ADDR addr)
60 {
61 if (addr == 0)
62 return 1;
63 if (symfile_objfile == 0)
64 return 0;
65 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
66 {
67 /* Do not stop backtracing if the pc is in the call dummy
68 at the entry point. */
69 /* FIXME: Won't always work with zeros for the last two arguments */
70 if (DEPRECATED_PC_IN_CALL_DUMMY (addr, 0, 0))
71 return 0;
72 }
73 return (addr >= symfile_objfile->ei.entry_file_lowpc &&
74 addr < symfile_objfile->ei.entry_file_highpc);
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
85 int
86 inside_main_func (CORE_ADDR pc)
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
97 if (symfile_objfile->ei.main_func_lowpc == INVALID_ENTRY_LOWPC &&
98 symfile_objfile->ei.main_func_highpc == INVALID_ENTRY_HIGHPC)
99 {
100 struct symbol *mainsym;
101
102 mainsym = lookup_symbol (main_name (), NULL, VAR_NAMESPACE, NULL, NULL);
103 if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
104 {
105 symfile_objfile->ei.main_func_lowpc =
106 BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym));
107 symfile_objfile->ei.main_func_highpc =
108 BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym));
109 }
110 }
111 return (symfile_objfile->ei.main_func_lowpc <= pc &&
112 symfile_objfile->ei.main_func_highpc > pc);
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
123 int
124 inside_entry_func (CORE_ADDR pc)
125 {
126 if (pc == 0)
127 return 1;
128 if (symfile_objfile == 0)
129 return 0;
130 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
131 {
132 /* Do not stop backtracing if the pc is in the call dummy
133 at the entry point. */
134 /* FIXME: Won't always work with zeros for the last two arguments */
135 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
136 return 0;
137 }
138 return (symfile_objfile->ei.entry_func_lowpc <= pc &&
139 symfile_objfile->ei.entry_func_highpc > pc);
140 }
141
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
146 int
147 frameless_look_for_prologue (struct frame_info *frame)
148 {
149 CORE_ADDR func_start, after_prologue;
150
151 func_start = get_pc_function_start (get_frame_pc (frame));
152 if (func_start)
153 {
154 func_start += FUNCTION_START_OFFSET;
155 /* This is faster, since only care whether there *is* a
156 prologue, not how long it is. */
157 return PROLOGUE_FRAMELESS_P (func_start);
158 }
159 else if (get_frame_pc (frame) == 0)
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. */
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
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
177 CORE_ADDR
178 frame_address_in_block (struct frame_info *frame)
179 {
180 CORE_ADDR pc = get_frame_pc (frame);
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. */
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. */
191 if (get_next_frame (frame) != 0
192 && get_frame_type (get_next_frame (frame)) != SIGTRAMP_FRAME)
193 --pc;
194
195 return pc;
196 }
197
198 /* Return the innermost lexical block in execution
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. */
213
214 struct block *
215 get_frame_block (struct frame_info *frame, CORE_ADDR *addr_in_block)
216 {
217 const CORE_ADDR pc = frame_address_in_block (frame);
218
219 if (addr_in_block)
220 *addr_in_block = pc;
221
222 return block_for_pc (pc);
223 }
224
225 CORE_ADDR
226 get_pc_function_start (CORE_ADDR pc)
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);
242 if (!find_pc_section (fstart))
243 return 0;
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
254 struct symbol *
255 get_frame_function (struct frame_info *frame)
256 {
257 register struct block *bl = get_frame_block (frame, 0);
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
269 struct blockvector *
270 blockvector_for_pc_sect (register CORE_ADDR pc, struct sec *section,
271 int *pindex, struct symtab *symtab)
272 {
273 register struct block *b;
274 register int bot, top, half;
275 struct blockvector *bl;
276
277 if (symtab == 0) /* if no symtab specified by caller */
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);
308 if (BLOCK_END (b) > pc)
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
323 struct blockvector *
324 blockvector_for_pc (register CORE_ADDR pc, int *pindex)
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
333 struct block *
334 block_for_pc_sect (register CORE_ADDR pc, struct sec *section)
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
348 struct block *
349 block_for_pc (register CORE_ADDR pc)
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
357 struct symbol *
358 find_pc_sect_function (CORE_ADDR pc, struct sec *section)
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
369 struct symbol *
370 find_pc_function (CORE_ADDR pc)
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
378 static CORE_ADDR cache_pc_function_low = 0;
379 static CORE_ADDR cache_pc_function_high = 0;
380 static char *cache_pc_function_name = 0;
381 static struct sec *cache_pc_function_section = NULL;
382
383 /* Clear cache, e.g. when symbol table is discarded. */
384
385 void
386 clear_pc_function_cache (void)
387 {
388 cache_pc_function_low = 0;
389 cache_pc_function_high = 0;
390 cache_pc_function_name = (char *) 0;
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
405 int
406 find_pc_sect_partial_function (CORE_ADDR pc, asection *section, char **name,
407 CORE_ADDR *address, CORE_ADDR *endaddr)
408 {
409 struct partial_symtab *pst;
410 struct symbol *f;
411 struct minimal_symbol *msymbol;
412 struct partial_symbol *psb;
413 struct obj_section *osect;
414 int i;
415 CORE_ADDR mapped_pc;
416
417 mapped_pc = overlay_mapped_address (pc, section);
418
419 if (mapped_pc >= cache_pc_function_low
420 && mapped_pc < cache_pc_function_high
421 && section == cache_pc_function_section)
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). */
426 if (SIGTRAMP_START_P () && PC_IN_SIGTRAMP (mapped_pc, (char *) NULL))
427 {
428 cache_pc_function_low = SIGTRAMP_START (mapped_pc);
429 cache_pc_function_high = SIGTRAMP_END (mapped_pc);
430 cache_pc_function_name = "<sigtramp>";
431 cache_pc_function_section = section;
432 goto return_cached_value;
433 }
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 {
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);
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
511 cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
512 cache_pc_function_name = SYMBOL_NAME (msymbol);
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. */
517
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
522 for (i = 1; SYMBOL_NAME (msymbol + i) != NULL; i++)
523 {
524 if (SYMBOL_VALUE_ADDRESS (msymbol + i) != SYMBOL_VALUE_ADDRESS (msymbol)
525 && SYMBOL_BFD_SECTION (msymbol + i) == SYMBOL_BFD_SECTION (msymbol))
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
537 return_cached_value:
538
539 if (address)
540 {
541 if (pc_in_unmapped_range (pc, section))
542 *address = overlay_unmapped_address (cache_pc_function_low, section);
543 else
544 *address = cache_pc_function_low;
545 }
546
547 if (name)
548 *name = cache_pc_function_name;
549
550 if (endaddr)
551 {
552 if (pc_in_unmapped_range (pc, section))
553 {
554 /* Because the high address is actually beyond the end of
555 the function (and therefore possibly beyond the end of
556 the overlay), we must actually convert (high - 1) and
557 then add one to that. */
558
559 *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1,
560 section);
561 }
562 else
563 *endaddr = cache_pc_function_high;
564 }
565
566 return 1;
567 }
568
569 /* Backward compatibility, no section argument. */
570
571 int
572 find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
573 CORE_ADDR *endaddr)
574 {
575 asection *section;
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
584 struct frame_info *
585 block_innermost_frame (struct block *block)
586 {
587 struct frame_info *frame;
588 register CORE_ADDR start;
589 register CORE_ADDR end;
590 CORE_ADDR calling_pc;
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;
604 calling_pc = frame_address_in_block (frame);
605 if (calling_pc >= start && calling_pc < end)
606 return frame;
607 }
608 }
609
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
614 extern CORE_ADDR text_end;
615
616 int
617 deprecated_pc_in_call_dummy_before_text_end (CORE_ADDR pc, CORE_ADDR sp,
618 CORE_ADDR frame_address)
619 {
620 return ((pc) >= text_end - CALL_DUMMY_LENGTH
621 && (pc) <= text_end + DECR_PC_AFTER_BREAK);
622 }
623
624 int
625 deprecated_pc_in_call_dummy_after_text_end (CORE_ADDR pc, CORE_ADDR sp,
626 CORE_ADDR frame_address)
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
643 DEPRECATED_PC_IN_CALL_DUMMY.
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
650 int
651 deprecated_pc_in_call_dummy_on_stack (CORE_ADDR pc, CORE_ADDR sp,
652 CORE_ADDR frame_address)
653 {
654 return (INNER_THAN ((sp), (pc))
655 && (frame_address != 0)
656 && INNER_THAN ((pc), (frame_address)));
657 }
658
659 int
660 deprecated_pc_in_call_dummy_at_entry_point (CORE_ADDR pc, CORE_ADDR sp,
661 CORE_ADDR frame_address)
662 {
663 return ((pc) >= CALL_DUMMY_ADDRESS ()
664 && (pc) <= (CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK));
665 }
666
667 /* Function: frame_chain_valid
668 Returns true for a user frame or a call_function_by_hand dummy frame,
669 and false for the CRT0 start-up frame. Purpose is to terminate backtrace. */
670
671 int
672 frame_chain_valid (CORE_ADDR fp, struct frame_info *fi)
673 {
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;
710 }
711
712 void
713 do_flush_frames_sfunc (char *args, int from_tty, struct cmd_list_element *c)
714 {
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);
733 }
734
735 void
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.045163 seconds and 4 git commands to generate.