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