2002-05-02 Pierre Muller <muller@ics.u-strasbg.fr>
[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,
5 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
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"
c906108c
SS
37
38/* Prototypes for exported functions. */
39
53a5351d 40void _initialize_blockframe (void);
c906108c
SS
41
42/* A default FRAME_CHAIN_VALID, in the form that is suitable for most
43 targets. If FRAME_CHAIN_VALID returns zero it means that the given
44 frame is the outermost one and has no caller. */
45
46int
fba45db2 47file_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe)
c906108c
SS
48{
49 return ((chain) != 0
c4093a6a 50 && !inside_entry_file (FRAME_SAVED_PC (thisframe)));
c906108c
SS
51}
52
53/* Use the alternate method of avoiding running up off the end of the
54 frame chain or following frames back into the startup code. See
55 the comments in objfiles.h. */
c5aa993b 56
c906108c 57int
fba45db2 58func_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe)
c906108c
SS
59{
60 return ((chain) != 0
c4093a6a
JM
61 && !inside_main_func ((thisframe)->pc)
62 && !inside_entry_func ((thisframe)->pc));
c906108c
SS
63}
64
65/* A very simple method of determining a valid frame */
c5aa993b 66
c906108c 67int
fba45db2 68nonnull_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe)
c906108c
SS
69{
70 return ((chain) != 0);
71}
72
73/* Is ADDR inside the startup file? Note that if your machine
74 has a way to detect the bottom of the stack, there is no need
75 to call this function from FRAME_CHAIN_VALID; the reason for
76 doing so is that some machines have no way of detecting bottom
77 of stack.
78
79 A PC of zero is always considered to be the bottom of the stack. */
80
81int
fba45db2 82inside_entry_file (CORE_ADDR addr)
c906108c
SS
83{
84 if (addr == 0)
85 return 1;
86 if (symfile_objfile == 0)
87 return 0;
7a292a7a
SS
88 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
89 {
90 /* Do not stop backtracing if the pc is in the call dummy
c5aa993b 91 at the entry point. */
7a292a7a 92 /* FIXME: Won't always work with zeros for the last two arguments */
c5aa993b 93 if (PC_IN_CALL_DUMMY (addr, 0, 0))
7a292a7a
SS
94 return 0;
95 }
c5aa993b
JM
96 return (addr >= symfile_objfile->ei.entry_file_lowpc &&
97 addr < symfile_objfile->ei.entry_file_highpc);
c906108c
SS
98}
99
100/* Test a specified PC value to see if it is in the range of addresses
101 that correspond to the main() function. See comments above for why
102 we might want to do this.
103
104 Typically called from FRAME_CHAIN_VALID.
105
106 A PC of zero is always considered to be the bottom of the stack. */
107
108int
fba45db2 109inside_main_func (CORE_ADDR pc)
c906108c
SS
110{
111 if (pc == 0)
112 return 1;
113 if (symfile_objfile == 0)
114 return 0;
115
116 /* If the addr range is not set up at symbol reading time, set it up now.
117 This is for FRAME_CHAIN_VALID_ALTERNATE. I do this for coff, because
118 it is unable to set it up and symbol reading time. */
119
c5aa993b
JM
120 if (symfile_objfile->ei.main_func_lowpc == INVALID_ENTRY_LOWPC &&
121 symfile_objfile->ei.main_func_highpc == INVALID_ENTRY_HIGHPC)
c906108c
SS
122 {
123 struct symbol *mainsym;
124
51cc5b07 125 mainsym = lookup_symbol (main_name (), NULL, VAR_NAMESPACE, NULL, NULL);
c5aa993b
JM
126 if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
127 {
128 symfile_objfile->ei.main_func_lowpc =
c906108c 129 BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym));
c5aa993b 130 symfile_objfile->ei.main_func_highpc =
c906108c 131 BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym));
c5aa993b 132 }
c906108c 133 }
c5aa993b
JM
134 return (symfile_objfile->ei.main_func_lowpc <= pc &&
135 symfile_objfile->ei.main_func_highpc > pc);
c906108c
SS
136}
137
138/* Test a specified PC value to see if it is in the range of addresses
139 that correspond to the process entry point function. See comments
140 in objfiles.h for why we might want to do this.
141
142 Typically called from FRAME_CHAIN_VALID.
143
144 A PC of zero is always considered to be the bottom of the stack. */
145
146int
fba45db2 147inside_entry_func (CORE_ADDR pc)
c906108c
SS
148{
149 if (pc == 0)
150 return 1;
151 if (symfile_objfile == 0)
152 return 0;
7a292a7a
SS
153 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
154 {
155 /* Do not stop backtracing if the pc is in the call dummy
c5aa993b 156 at the entry point. */
7a292a7a
SS
157 /* FIXME: Won't always work with zeros for the last two arguments */
158 if (PC_IN_CALL_DUMMY (pc, 0, 0))
159 return 0;
160 }
c5aa993b
JM
161 return (symfile_objfile->ei.entry_func_lowpc <= pc &&
162 symfile_objfile->ei.entry_func_highpc > pc);
c906108c
SS
163}
164
165/* Info about the innermost stack frame (contents of FP register) */
166
167static struct frame_info *current_frame;
168
169/* Cache for frame addresses already read by gdb. Valid only while
170 inferior is stopped. Control variables for the frame cache should
171 be local to this module. */
172
173static struct obstack frame_cache_obstack;
174
175void *
fba45db2 176frame_obstack_alloc (unsigned long size)
c906108c
SS
177{
178 return obstack_alloc (&frame_cache_obstack, size);
179}
180
181void
fba45db2 182frame_saved_regs_zalloc (struct frame_info *fi)
c906108c 183{
c5aa993b 184 fi->saved_regs = (CORE_ADDR *)
c906108c
SS
185 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
186 memset (fi->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
187}
188
189
190/* Return the innermost (currently executing) stack frame. */
191
192struct frame_info *
fba45db2 193get_current_frame (void)
c906108c
SS
194{
195 if (current_frame == NULL)
196 {
197 if (target_has_stack)
198 current_frame = create_new_frame (read_fp (), read_pc ());
199 else
200 error ("No stack.");
201 }
202 return current_frame;
203}
204
205void
fba45db2 206set_current_frame (struct frame_info *frame)
c906108c
SS
207{
208 current_frame = frame;
209}
210
211/* Create an arbitrary (i.e. address specified by user) or innermost frame.
212 Always returns a non-NULL value. */
213
214struct frame_info *
fba45db2 215create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
c906108c
SS
216{
217 struct frame_info *fi;
218 char *name;
219
220 fi = (struct frame_info *)
221 obstack_alloc (&frame_cache_obstack,
222 sizeof (struct frame_info));
223
736d0890
MS
224 /* Zero all fields by default. */
225 memset (fi, 0, sizeof (struct frame_info));
226
c906108c
SS
227 fi->frame = addr;
228 fi->pc = pc;
c5aa993b 229 find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
d7bd68ca 230 fi->signal_handler_caller = PC_IN_SIGTRAMP (fi->pc, name);
c906108c 231
5fdff426
AC
232 if (INIT_EXTRA_FRAME_INFO_P ())
233 INIT_EXTRA_FRAME_INFO (0, fi);
c906108c
SS
234
235 return fi;
236}
237
c906108c
SS
238/* Return the frame that FRAME calls (NULL if FRAME is the innermost
239 frame). */
240
241struct frame_info *
fba45db2 242get_next_frame (struct frame_info *frame)
c906108c
SS
243{
244 return frame->next;
245}
246
247/* Flush the entire frame cache. */
248
249void
fba45db2 250flush_cached_frames (void)
c906108c
SS
251{
252 /* Since we can't really be sure what the first object allocated was */
253 obstack_free (&frame_cache_obstack, 0);
254 obstack_init (&frame_cache_obstack);
255
c5aa993b 256 current_frame = NULL; /* Invalidate cache */
c906108c
SS
257 select_frame (NULL, -1);
258 annotate_frames_invalid ();
259}
260
261/* Flush the frame cache, and start a new one if necessary. */
262
263void
fba45db2 264reinit_frame_cache (void)
c906108c
SS
265{
266 flush_cached_frames ();
267
39f77062
KB
268 /* FIXME: The inferior_ptid test is wrong if there is a corefile. */
269 if (PIDGET (inferior_ptid) != 0)
c906108c
SS
270 {
271 select_frame (get_current_frame (), 0);
272 }
273}
274
c906108c
SS
275/* Return nonzero if the function for this frame lacks a prologue. Many
276 machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
277 function. */
278
279int
fba45db2 280frameless_look_for_prologue (struct frame_info *frame)
c906108c
SS
281{
282 CORE_ADDR func_start, after_prologue;
53a5351d 283
c906108c
SS
284 func_start = get_pc_function_start (frame->pc);
285 if (func_start)
286 {
287 func_start += FUNCTION_START_OFFSET;
53a5351d
JM
288 /* This is faster, since only care whether there *is* a
289 prologue, not how long it is. */
dad41f9a 290 return PROLOGUE_FRAMELESS_P (func_start);
c906108c
SS
291 }
292 else if (frame->pc == 0)
53a5351d
JM
293 /* A frame with a zero PC is usually created by dereferencing a
294 NULL function pointer, normally causing an immediate core dump
295 of the inferior. Mark function as frameless, as the inferior
296 has no chance of setting up a stack frame. */
c906108c
SS
297 return 1;
298 else
299 /* If we can't find the start of the function, we don't really
300 know whether the function is frameless, but we should be able
301 to get a reasonable (i.e. best we can do under the
302 circumstances) backtrace by saying that it isn't. */
303 return 0;
304}
305
c906108c
SS
306/* Return a structure containing various interesting information
307 about the frame that called NEXT_FRAME. Returns NULL
308 if there is no such frame. */
309
310struct frame_info *
fba45db2 311get_prev_frame (struct frame_info *next_frame)
c906108c
SS
312{
313 CORE_ADDR address = 0;
314 struct frame_info *prev;
315 int fromleaf = 0;
316 char *name;
317
318 /* If the requested entry is in the cache, return it.
319 Otherwise, figure out what the address should be for the entry
320 we're about to add to the cache. */
321
322 if (!next_frame)
323 {
324#if 0
325 /* This screws value_of_variable, which just wants a nice clean
c5aa993b
JM
326 NULL return from block_innermost_frame if there are no frames.
327 I don't think I've ever seen this message happen otherwise.
328 And returning NULL here is a perfectly legitimate thing to do. */
c906108c
SS
329 if (!current_frame)
330 {
331 error ("You haven't set up a process's stack to examine.");
332 }
333#endif
334
335 return current_frame;
336 }
337
338 /* If we have the prev one, return it */
339 if (next_frame->prev)
340 return next_frame->prev;
341
342 /* On some machines it is possible to call a function without
343 setting up a stack frame for it. On these machines, we
344 define this macro to take two args; a frameinfo pointer
345 identifying a frame and a variable to set or clear if it is
346 or isn't leafless. */
392a587b 347
c906108c
SS
348 /* Still don't want to worry about this except on the innermost
349 frame. This macro will set FROMLEAF if NEXT_FRAME is a
350 frameless function invocation. */
351 if (!(next_frame->next))
352 {
392a587b 353 fromleaf = FRAMELESS_FUNCTION_INVOCATION (next_frame);
c906108c
SS
354 if (fromleaf)
355 address = FRAME_FP (next_frame);
356 }
c906108c
SS
357
358 if (!fromleaf)
359 {
360 /* Two macros defined in tm.h specify the machine-dependent
c5aa993b
JM
361 actions to be performed here.
362 First, get the frame's chain-pointer.
363 If that is zero, the frame is the outermost frame or a leaf
364 called by the outermost frame. This means that if start
365 calls main without a frame, we'll return 0 (which is fine
366 anyway).
367
368 Nope; there's a problem. This also returns when the current
369 routine is a leaf of main. This is unacceptable. We move
370 this to after the ffi test; I'd rather have backtraces from
371 start go curfluy than have an abort called from main not show
372 main. */
c906108c
SS
373 address = FRAME_CHAIN (next_frame);
374 if (!FRAME_CHAIN_VALID (address, next_frame))
375 return 0;
c906108c
SS
376 }
377 if (address == 0)
378 return 0;
379
380 prev = (struct frame_info *)
381 obstack_alloc (&frame_cache_obstack,
382 sizeof (struct frame_info));
383
bb30608f 384 /* Zero all fields by default. */
0c8053b6 385 memset (prev, 0, sizeof (struct frame_info));
bb30608f 386
c906108c
SS
387 if (next_frame)
388 next_frame->prev = prev;
389 prev->next = next_frame;
c906108c 390 prev->frame = address;
7cc19214 391 prev->level = next_frame->level + 1;
c906108c
SS
392
393/* This change should not be needed, FIXME! We should
394 determine whether any targets *need* INIT_FRAME_PC to happen
395 after INIT_EXTRA_FRAME_INFO and come up with a simple way to
396 express what goes on here.
397
c5aa993b
JM
398 INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
399 (where the PC is already set up) and here (where it isn't).
400 INIT_FRAME_PC is only called from here, always after
401 INIT_EXTRA_FRAME_INFO.
402
c906108c
SS
403 The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC
404 value (which hasn't been set yet). Some other machines appear to
405 require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC. Phoo.
406
407 We shouldn't need INIT_FRAME_PC_FIRST to add more complication to
408 an already overcomplicated part of GDB. gnu@cygnus.com, 15Sep92.
409
410 Assuming that some machines need INIT_FRAME_PC after
411 INIT_EXTRA_FRAME_INFO, one possible scheme:
412
413 SETUP_INNERMOST_FRAME()
c5aa993b
JM
414 Default version is just create_new_frame (read_fp ()),
415 read_pc ()). Machines with extra frame info would do that (or the
416 local equivalent) and then set the extra fields.
c906108c 417 SETUP_ARBITRARY_FRAME(argc, argv)
c5aa993b
JM
418 Only change here is that create_new_frame would no longer init extra
419 frame info; SETUP_ARBITRARY_FRAME would have to do that.
c906108c 420 INIT_PREV_FRAME(fromleaf, prev)
c5aa993b
JM
421 Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC. This should
422 also return a flag saying whether to keep the new frame, or
423 whether to discard it, because on some machines (e.g. mips) it
424 is really awkward to have FRAME_CHAIN_VALID called *before*
425 INIT_EXTRA_FRAME_INFO (there is no good way to get information
426 deduced in FRAME_CHAIN_VALID into the extra fields of the new frame).
c906108c 427 std_frame_pc(fromleaf, prev)
c5aa993b
JM
428 This is the default setting for INIT_PREV_FRAME. It just does what
429 the default INIT_FRAME_PC does. Some machines will call it from
430 INIT_PREV_FRAME (either at the beginning, the end, or in the middle).
431 Some machines won't use it.
c906108c
SS
432 kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */
433
c906108c 434 INIT_FRAME_PC_FIRST (fromleaf, prev);
c906108c 435
e6b47f07
AC
436 if (INIT_EXTRA_FRAME_INFO_P ())
437 INIT_EXTRA_FRAME_INFO (fromleaf, prev);
c906108c
SS
438
439 /* This entry is in the frame queue now, which is good since
440 FRAME_SAVED_PC may use that queue to figure out its value
441 (see tm-sparc.h). We want the pc saved in the inferior frame. */
c5aa993b 442 INIT_FRAME_PC (fromleaf, prev);
c906108c
SS
443
444 /* If ->frame and ->pc are unchanged, we are in the process of getting
445 ourselves into an infinite backtrace. Some architectures check this
446 in FRAME_CHAIN or thereabouts, but it seems like there is no reason
447 this can't be an architecture-independent check. */
448 if (next_frame != NULL)
449 {
450 if (prev->frame == next_frame->frame
451 && prev->pc == next_frame->pc)
452 {
453 next_frame->prev = NULL;
454 obstack_free (&frame_cache_obstack, prev);
455 return NULL;
456 }
457 }
458
459 find_pc_partial_function (prev->pc, &name,
c5aa993b 460 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
d7bd68ca 461 if (PC_IN_SIGTRAMP (prev->pc, name))
c906108c
SS
462 prev->signal_handler_caller = 1;
463
464 return prev;
465}
466
467CORE_ADDR
fba45db2 468get_frame_pc (struct frame_info *frame)
c906108c
SS
469{
470 return frame->pc;
471}
472
473
474#ifdef FRAME_FIND_SAVED_REGS
475/* XXX - deprecated. This is a compatibility function for targets
476 that do not yet implement FRAME_INIT_SAVED_REGS. */
477/* Find the addresses in which registers are saved in FRAME. */
478
479void
fba45db2
KB
480get_frame_saved_regs (struct frame_info *frame,
481 struct frame_saved_regs *saved_regs_addr)
c906108c
SS
482{
483 if (frame->saved_regs == NULL)
484 {
c5aa993b 485 frame->saved_regs = (CORE_ADDR *)
c906108c
SS
486 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
487 }
488 if (saved_regs_addr == NULL)
489 {
490 struct frame_saved_regs saved_regs;
491 FRAME_FIND_SAVED_REGS (frame, saved_regs);
492 memcpy (frame->saved_regs, &saved_regs, SIZEOF_FRAME_SAVED_REGS);
493 }
494 else
495 {
496 FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr);
497 memcpy (frame->saved_regs, saved_regs_addr, SIZEOF_FRAME_SAVED_REGS);
498 }
499}
500#endif
501
502/* Return the innermost lexical block in execution
ae767bfb
JB
503 in a specified stack frame. The frame address is assumed valid.
504
505 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the exact code
506 address we used to choose the block. We use this to find a source
507 line, to decide which macro definitions are in scope.
508
509 The value returned in *ADDR_IN_BLOCK isn't necessarily the frame's
510 PC, and may not really be a valid PC at all. For example, in the
511 caller of a function declared to never return, the code at the
512 return address will never be reached, so the call instruction may
513 be the very last instruction in the block. So the address we use
514 to choose the block is actually one byte before the return address
515 --- hopefully pointing us at the call instruction, or its delay
516 slot instruction. */
c906108c
SS
517
518struct block *
ae767bfb 519get_frame_block (struct frame_info *frame, CORE_ADDR *addr_in_block)
c906108c
SS
520{
521 CORE_ADDR pc;
522
523 pc = frame->pc;
524 if (frame->next != 0 && frame->next->signal_handler_caller == 0)
525 /* We are not in the innermost frame and we were not interrupted
526 by a signal. We need to subtract one to get the correct block,
527 in case the call instruction was the last instruction of the block.
528 If there are any machines on which the saved pc does not point to
529 after the call insn, we probably want to make frame->pc point after
530 the call insn anyway. */
531 --pc;
ae767bfb
JB
532
533 if (addr_in_block)
534 *addr_in_block = pc;
535
c906108c
SS
536 return block_for_pc (pc);
537}
538
539struct block *
ae767bfb 540get_current_block (CORE_ADDR *addr_in_block)
c906108c 541{
ae767bfb
JB
542 CORE_ADDR pc = read_pc ();
543
544 if (addr_in_block)
545 *addr_in_block = pc;
546
547 return block_for_pc (pc);
c906108c
SS
548}
549
550CORE_ADDR
fba45db2 551get_pc_function_start (CORE_ADDR pc)
c906108c
SS
552{
553 register struct block *bl;
554 register struct symbol *symbol;
555 register struct minimal_symbol *msymbol;
556 CORE_ADDR fstart;
557
558 if ((bl = block_for_pc (pc)) != NULL &&
559 (symbol = block_function (bl)) != NULL)
560 {
561 bl = SYMBOL_BLOCK_VALUE (symbol);
562 fstart = BLOCK_START (bl);
563 }
564 else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL)
565 {
566 fstart = SYMBOL_VALUE_ADDRESS (msymbol);
567 }
568 else
569 {
570 fstart = 0;
571 }
572 return (fstart);
573}
574
575/* Return the symbol for the function executing in frame FRAME. */
576
577struct symbol *
fba45db2 578get_frame_function (struct frame_info *frame)
c906108c 579{
ae767bfb 580 register struct block *bl = get_frame_block (frame, 0);
c906108c
SS
581 if (bl == 0)
582 return 0;
583 return block_function (bl);
584}
585\f
586
587/* Return the blockvector immediately containing the innermost lexical block
588 containing the specified pc value and section, or 0 if there is none.
589 PINDEX is a pointer to the index value of the block. If PINDEX
590 is NULL, we don't pass this information back to the caller. */
591
592struct blockvector *
fba45db2
KB
593blockvector_for_pc_sect (register CORE_ADDR pc, struct sec *section,
594 int *pindex, struct symtab *symtab)
c906108c
SS
595{
596 register struct block *b;
597 register int bot, top, half;
598 struct blockvector *bl;
599
c5aa993b 600 if (symtab == 0) /* if no symtab specified by caller */
c906108c
SS
601 {
602 /* First search all symtabs for one whose file contains our pc */
603 if ((symtab = find_pc_sect_symtab (pc, section)) == 0)
604 return 0;
605 }
606
607 bl = BLOCKVECTOR (symtab);
608 b = BLOCKVECTOR_BLOCK (bl, 0);
609
610 /* Then search that symtab for the smallest block that wins. */
611 /* Use binary search to find the last block that starts before PC. */
612
613 bot = 0;
614 top = BLOCKVECTOR_NBLOCKS (bl);
615
616 while (top - bot > 1)
617 {
618 half = (top - bot + 1) >> 1;
619 b = BLOCKVECTOR_BLOCK (bl, bot + half);
620 if (BLOCK_START (b) <= pc)
621 bot += half;
622 else
623 top = bot + half;
624 }
625
626 /* Now search backward for a block that ends after PC. */
627
628 while (bot >= 0)
629 {
630 b = BLOCKVECTOR_BLOCK (bl, bot);
43e526b9 631 if (BLOCK_END (b) > pc)
c906108c
SS
632 {
633 if (pindex)
634 *pindex = bot;
635 return bl;
636 }
637 bot--;
638 }
639 return 0;
640}
641
642/* Return the blockvector immediately containing the innermost lexical block
643 containing the specified pc value, or 0 if there is none.
644 Backward compatibility, no section. */
645
646struct blockvector *
fba45db2 647blockvector_for_pc (register CORE_ADDR pc, int *pindex)
c906108c
SS
648{
649 return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
650 pindex, NULL);
651}
652
653/* Return the innermost lexical block containing the specified pc value
654 in the specified section, or 0 if there is none. */
655
656struct block *
fba45db2 657block_for_pc_sect (register CORE_ADDR pc, struct sec *section)
c906108c
SS
658{
659 register struct blockvector *bl;
660 int index;
661
662 bl = blockvector_for_pc_sect (pc, section, &index, NULL);
663 if (bl)
664 return BLOCKVECTOR_BLOCK (bl, index);
665 return 0;
666}
667
668/* Return the innermost lexical block containing the specified pc value,
669 or 0 if there is none. Backward compatibility, no section. */
670
671struct block *
fba45db2 672block_for_pc (register CORE_ADDR pc)
c906108c
SS
673{
674 return block_for_pc_sect (pc, find_pc_mapped_section (pc));
675}
676
677/* Return the function containing pc value PC in section SECTION.
678 Returns 0 if function is not known. */
679
680struct symbol *
fba45db2 681find_pc_sect_function (CORE_ADDR pc, struct sec *section)
c906108c
SS
682{
683 register struct block *b = block_for_pc_sect (pc, section);
684 if (b == 0)
685 return 0;
686 return block_function (b);
687}
688
689/* Return the function containing pc value PC.
690 Returns 0 if function is not known. Backward compatibility, no section */
691
692struct symbol *
fba45db2 693find_pc_function (CORE_ADDR pc)
c906108c
SS
694{
695 return find_pc_sect_function (pc, find_pc_mapped_section (pc));
696}
697
698/* These variables are used to cache the most recent result
699 * of find_pc_partial_function. */
700
c5aa993b
JM
701static CORE_ADDR cache_pc_function_low = 0;
702static CORE_ADDR cache_pc_function_high = 0;
703static char *cache_pc_function_name = 0;
c906108c
SS
704static struct sec *cache_pc_function_section = NULL;
705
706/* Clear cache, e.g. when symbol table is discarded. */
707
708void
fba45db2 709clear_pc_function_cache (void)
c906108c
SS
710{
711 cache_pc_function_low = 0;
712 cache_pc_function_high = 0;
c5aa993b 713 cache_pc_function_name = (char *) 0;
c906108c
SS
714 cache_pc_function_section = NULL;
715}
716
717/* Finds the "function" (text symbol) that is smaller than PC but
718 greatest of all of the potential text symbols in SECTION. Sets
719 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
720 If ENDADDR is non-null, then set *ENDADDR to be the end of the
721 function (exclusive), but passing ENDADDR as non-null means that
722 the function might cause symbols to be read. This function either
723 succeeds or fails (not halfway succeeds). If it succeeds, it sets
724 *NAME, *ADDRESS, and *ENDADDR to real information and returns 1.
725 If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero and
726 returns 0. */
727
728int
fba45db2
KB
729find_pc_sect_partial_function (CORE_ADDR pc, asection *section, char **name,
730 CORE_ADDR *address, CORE_ADDR *endaddr)
c906108c
SS
731{
732 struct partial_symtab *pst;
c5aa993b 733 struct symbol *f;
c906108c
SS
734 struct minimal_symbol *msymbol;
735 struct partial_symbol *psb;
c5aa993b 736 struct obj_section *osect;
c906108c
SS
737 int i;
738 CORE_ADDR mapped_pc;
739
740 mapped_pc = overlay_mapped_address (pc, section);
741
c5aa993b 742 if (mapped_pc >= cache_pc_function_low &&
c906108c
SS
743 mapped_pc < cache_pc_function_high &&
744 section == cache_pc_function_section)
745 goto return_cached_value;
746
747 /* If sigtramp is in the u area, it counts as a function (especially
748 important for step_1). */
749#if defined SIGTRAMP_START
d7bd68ca 750 if (PC_IN_SIGTRAMP (mapped_pc, (char *) NULL))
c906108c 751 {
c5aa993b
JM
752 cache_pc_function_low = SIGTRAMP_START (mapped_pc);
753 cache_pc_function_high = SIGTRAMP_END (mapped_pc);
754 cache_pc_function_name = "<sigtramp>";
c906108c
SS
755 cache_pc_function_section = section;
756 goto return_cached_value;
757 }
758#endif
759
760 msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section);
761 pst = find_pc_sect_psymtab (mapped_pc, section);
762 if (pst)
763 {
764 /* Need to read the symbols to get a good value for the end address. */
765 if (endaddr != NULL && !pst->readin)
766 {
767 /* Need to get the terminal in case symbol-reading produces
768 output. */
769 target_terminal_ours_for_output ();
770 PSYMTAB_TO_SYMTAB (pst);
771 }
772
773 if (pst->readin)
774 {
775 /* Checking whether the msymbol has a larger value is for the
776 "pathological" case mentioned in print_frame_info. */
777 f = find_pc_sect_function (mapped_pc, section);
778 if (f != NULL
779 && (msymbol == NULL
780 || (BLOCK_START (SYMBOL_BLOCK_VALUE (f))
781 >= SYMBOL_VALUE_ADDRESS (msymbol))))
782 {
c5aa993b
JM
783 cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
784 cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
785 cache_pc_function_name = SYMBOL_NAME (f);
c906108c
SS
786 cache_pc_function_section = section;
787 goto return_cached_value;
788 }
789 }
790 else
791 {
792 /* Now that static symbols go in the minimal symbol table, perhaps
793 we could just ignore the partial symbols. But at least for now
794 we use the partial or minimal symbol, whichever is larger. */
795 psb = find_pc_sect_psymbol (pst, mapped_pc, section);
796
797 if (psb
798 && (msymbol == NULL ||
799 (SYMBOL_VALUE_ADDRESS (psb)
800 >= SYMBOL_VALUE_ADDRESS (msymbol))))
801 {
802 /* This case isn't being cached currently. */
803 if (address)
804 *address = SYMBOL_VALUE_ADDRESS (psb);
805 if (name)
806 *name = SYMBOL_NAME (psb);
807 /* endaddr non-NULL can't happen here. */
808 return 1;
809 }
810 }
811 }
812
813 /* Not in the normal symbol tables, see if the pc is in a known section.
814 If it's not, then give up. This ensures that anything beyond the end
815 of the text seg doesn't appear to be part of the last function in the
816 text segment. */
817
818 osect = find_pc_sect_section (mapped_pc, section);
819
820 if (!osect)
821 msymbol = NULL;
822
823 /* Must be in the minimal symbol table. */
824 if (msymbol == NULL)
825 {
826 /* No available symbol. */
827 if (name != NULL)
828 *name = 0;
829 if (address != NULL)
830 *address = 0;
831 if (endaddr != NULL)
832 *endaddr = 0;
833 return 0;
834 }
835
c5aa993b
JM
836 cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
837 cache_pc_function_name = SYMBOL_NAME (msymbol);
c906108c
SS
838 cache_pc_function_section = section;
839
840 /* Use the lesser of the next minimal symbol in the same section, or
841 the end of the section, as the end of the function. */
c5aa993b 842
c906108c
SS
843 /* Step over other symbols at this same address, and symbols in
844 other sections, to find the next symbol in this section with
845 a different address. */
846
c5aa993b 847 for (i = 1; SYMBOL_NAME (msymbol + i) != NULL; i++)
c906108c 848 {
c5aa993b
JM
849 if (SYMBOL_VALUE_ADDRESS (msymbol + i) != SYMBOL_VALUE_ADDRESS (msymbol)
850 && SYMBOL_BFD_SECTION (msymbol + i) == SYMBOL_BFD_SECTION (msymbol))
c906108c
SS
851 break;
852 }
853
854 if (SYMBOL_NAME (msymbol + i) != NULL
855 && SYMBOL_VALUE_ADDRESS (msymbol + i) < osect->endaddr)
856 cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i);
857 else
858 /* We got the start address from the last msymbol in the objfile.
859 So the end address is the end of the section. */
860 cache_pc_function_high = osect->endaddr;
861
c5aa993b 862return_cached_value:
c906108c
SS
863
864 if (address)
865 {
866 if (pc_in_unmapped_range (pc, section))
c5aa993b 867 *address = overlay_unmapped_address (cache_pc_function_low, section);
c906108c 868 else
c5aa993b 869 *address = cache_pc_function_low;
c906108c 870 }
c5aa993b 871
c906108c
SS
872 if (name)
873 *name = cache_pc_function_name;
874
875 if (endaddr)
876 {
877 if (pc_in_unmapped_range (pc, section))
c5aa993b 878 {
c906108c
SS
879 /* Because the high address is actually beyond the end of
880 the function (and therefore possibly beyond the end of
881 the overlay), we must actually convert (high - 1)
882 and then add one to that. */
883
c5aa993b 884 *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1,
c906108c 885 section);
c5aa993b 886 }
c906108c 887 else
c5aa993b 888 *endaddr = cache_pc_function_high;
c906108c
SS
889 }
890
891 return 1;
892}
893
894/* Backward compatibility, no section argument */
895
896int
fba45db2
KB
897find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
898 CORE_ADDR *endaddr)
c906108c 899{
c5aa993b 900 asection *section;
c906108c
SS
901
902 section = find_pc_overlay (pc);
903 return find_pc_sect_partial_function (pc, section, name, address, endaddr);
904}
905
906/* Return the innermost stack frame executing inside of BLOCK,
907 or NULL if there is no such frame. If BLOCK is NULL, just return NULL. */
908
909struct frame_info *
fba45db2 910block_innermost_frame (struct block *block)
c906108c
SS
911{
912 struct frame_info *frame;
913 register CORE_ADDR start;
914 register CORE_ADDR end;
915
916 if (block == NULL)
917 return NULL;
918
919 start = BLOCK_START (block);
920 end = BLOCK_END (block);
921
922 frame = NULL;
923 while (1)
924 {
925 frame = get_prev_frame (frame);
926 if (frame == NULL)
927 return NULL;
928 if (frame->pc >= start && frame->pc < end)
929 return frame;
930 }
931}
932
933/* Return the full FRAME which corresponds to the given CORE_ADDR
934 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
935
936struct frame_info *
fba45db2 937find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
c906108c
SS
938{
939 struct frame_info *frame = NULL;
940
c5aa993b 941 if (frame_addr == (CORE_ADDR) 0)
c906108c
SS
942 return NULL;
943
944 while (1)
945 {
946 frame = get_prev_frame (frame);
947 if (frame == NULL)
948 return NULL;
949 if (FRAME_FP (frame) == frame_addr)
950 return frame;
951 }
952}
953
954#ifdef SIGCONTEXT_PC_OFFSET
955/* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp. */
956
957CORE_ADDR
fba45db2 958sigtramp_saved_pc (struct frame_info *frame)
c906108c
SS
959{
960 CORE_ADDR sigcontext_addr;
35fc8285 961 char *buf;
c906108c
SS
962 int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
963 int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
964
35fc8285 965 buf = alloca (ptrbytes);
c906108c
SS
966 /* Get sigcontext address, it is the third parameter on the stack. */
967 if (frame->next)
968 sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next)
969 + FRAME_ARGS_SKIP
970 + sigcontext_offs,
971 ptrbytes);
972 else
973 sigcontext_addr = read_memory_integer (read_register (SP_REGNUM)
c5aa993b 974 + sigcontext_offs,
c906108c
SS
975 ptrbytes);
976
977 /* Don't cause a memory_error when accessing sigcontext in case the stack
978 layout has changed or the stack is corrupt. */
979 target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
980 return extract_unsigned_integer (buf, ptrbytes);
981}
982#endif /* SIGCONTEXT_PC_OFFSET */
983
7a292a7a
SS
984
985/* Are we in a call dummy? The code below which allows DECR_PC_AFTER_BREAK
986 below is for infrun.c, which may give the macro a pc without that
987 subtracted out. */
988
989extern CORE_ADDR text_end;
990
991int
fba45db2
KB
992pc_in_call_dummy_before_text_end (CORE_ADDR pc, CORE_ADDR sp,
993 CORE_ADDR frame_address)
7a292a7a
SS
994{
995 return ((pc) >= text_end - CALL_DUMMY_LENGTH
996 && (pc) <= text_end + DECR_PC_AFTER_BREAK);
997}
998
999int
fba45db2
KB
1000pc_in_call_dummy_after_text_end (CORE_ADDR pc, CORE_ADDR sp,
1001 CORE_ADDR frame_address)
7a292a7a
SS
1002{
1003 return ((pc) >= text_end
1004 && (pc) <= text_end + CALL_DUMMY_LENGTH + DECR_PC_AFTER_BREAK);
1005}
1006
1007/* Is the PC in a call dummy? SP and FRAME_ADDRESS are the bottom and
1008 top of the stack frame which we are checking, where "bottom" and
1009 "top" refer to some section of memory which contains the code for
1010 the call dummy. Calls to this macro assume that the contents of
1011 SP_REGNUM and FP_REGNUM (or the saved values thereof), respectively,
1012 are the things to pass.
1013
1014 This won't work on the 29k, where SP_REGNUM and FP_REGNUM don't
1015 have that meaning, but the 29k doesn't use ON_STACK. This could be
1016 fixed by generalizing this scheme, perhaps by passing in a frame
1017 and adding a few fields, at least on machines which need them for
1018 PC_IN_CALL_DUMMY.
1019
1020 Something simpler, like checking for the stack segment, doesn't work,
1021 since various programs (threads implementations, gcc nested function
1022 stubs, etc) may either allocate stack frames in another segment, or
1023 allocate other kinds of code on the stack. */
1024
1025int
fba45db2 1026pc_in_call_dummy_on_stack (CORE_ADDR pc, CORE_ADDR sp, CORE_ADDR frame_address)
7a292a7a
SS
1027{
1028 return (INNER_THAN ((sp), (pc))
1029 && (frame_address != 0)
1030 && INNER_THAN ((pc), (frame_address)));
1031}
1032
1033int
fba45db2
KB
1034pc_in_call_dummy_at_entry_point (CORE_ADDR pc, CORE_ADDR sp,
1035 CORE_ADDR frame_address)
7a292a7a
SS
1036{
1037 return ((pc) >= CALL_DUMMY_ADDRESS ()
1038 && (pc) <= (CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK));
1039}
1040
c906108c
SS
1041
1042/*
1043 * GENERIC DUMMY FRAMES
1044 *
1045 * The following code serves to maintain the dummy stack frames for
1046 * inferior function calls (ie. when gdb calls into the inferior via
1047 * call_function_by_hand). This code saves the machine state before
b7d6b182 1048 * the call in host memory, so we must maintain an independent stack
c906108c
SS
1049 * and keep it consistant etc. I am attempting to make this code
1050 * generic enough to be used by many targets.
1051 *
1052 * The cheapest and most generic way to do CALL_DUMMY on a new target
1053 * is probably to define CALL_DUMMY to be empty, CALL_DUMMY_LENGTH to
1054 * zero, and CALL_DUMMY_LOCATION to AT_ENTRY. Then you must remember
1055 * to define PUSH_RETURN_ADDRESS, because no call instruction will be
1056 * being executed by the target. Also FRAME_CHAIN_VALID as
c4093a6a 1057 * generic_{file,func}_frame_chain_valid and FIX_CALL_DUMMY as
cce74817 1058 * generic_fix_call_dummy. */
c906108c 1059
7a292a7a
SS
1060/* Dummy frame. This saves the processor state just prior to setting
1061 up the inferior function call. Older targets save the registers
72229eb7 1062 on the target stack (but that really slows down function calls). */
7a292a7a
SS
1063
1064struct dummy_frame
1065{
1066 struct dummy_frame *next;
1067
1068 CORE_ADDR pc;
1069 CORE_ADDR fp;
1070 CORE_ADDR sp;
43ff13b4 1071 CORE_ADDR top;
7a292a7a 1072 char *registers;
6096c27a
AC
1073
1074 /* Address range of the call dummy code. Look for PC in the range
1075 [LO..HI) (after allowing for DECR_PC_AFTER_BREAK). */
1076 CORE_ADDR call_lo;
1077 CORE_ADDR call_hi;
7a292a7a
SS
1078};
1079
c906108c
SS
1080static struct dummy_frame *dummy_frame_stack = NULL;
1081
1082/* Function: find_dummy_frame(pc, fp, sp)
6096c27a
AC
1083
1084 Search the stack of dummy frames for one matching the given PC, FP
1085 and SP. Unlike PC_IN_CALL_DUMMY, this function doesn't need to
1086 adjust for DECR_PC_AFTER_BREAK. This is because it is only legal
1087 to call this function after the PC has been adjusted. */
c906108c 1088
c5aa993b 1089char *
fba45db2 1090generic_find_dummy_frame (CORE_ADDR pc, CORE_ADDR fp)
c906108c 1091{
c5aa993b 1092 struct dummy_frame *dummyframe;
c906108c 1093
c906108c
SS
1094 for (dummyframe = dummy_frame_stack; dummyframe != NULL;
1095 dummyframe = dummyframe->next)
6096c27a
AC
1096 if ((pc >= dummyframe->call_lo && pc < dummyframe->call_hi)
1097 && (fp == dummyframe->fp
1098 || fp == dummyframe->sp
1099 || fp == dummyframe->top))
c906108c 1100 /* The frame in question lies between the saved fp and sp, inclusive */
7a292a7a 1101 return dummyframe->registers;
c906108c
SS
1102
1103 return 0;
1104}
1105
6096c27a
AC
1106/* Function: pc_in_call_dummy (pc, sp, fp)
1107
1108 Return true if the PC falls in a dummy frame created by gdb for an
1109 inferior call. The code below which allows DECR_PC_AFTER_BREAK is
1110 for infrun.c, which may give the function a PC without that
1111 subtracted out. */
c906108c
SS
1112
1113int
fba45db2 1114generic_pc_in_call_dummy (CORE_ADDR pc, CORE_ADDR sp, CORE_ADDR fp)
c906108c 1115{
6096c27a
AC
1116 struct dummy_frame *dummyframe;
1117 for (dummyframe = dummy_frame_stack;
1118 dummyframe != NULL;
1119 dummyframe = dummyframe->next)
1120 {
1121 if ((pc >= dummyframe->call_lo)
1122 && (pc < dummyframe->call_hi + DECR_PC_AFTER_BREAK))
1123 return 1;
1124 }
1125 return 0;
c906108c
SS
1126}
1127
1128/* Function: read_register_dummy
1129 Find a saved register from before GDB calls a function in the inferior */
1130
1131CORE_ADDR
fba45db2 1132generic_read_register_dummy (CORE_ADDR pc, CORE_ADDR fp, int regno)
c906108c
SS
1133{
1134 char *dummy_regs = generic_find_dummy_frame (pc, fp);
1135
1136 if (dummy_regs)
1137 return extract_address (&dummy_regs[REGISTER_BYTE (regno)],
c5aa993b 1138 REGISTER_RAW_SIZE (regno));
c906108c
SS
1139 else
1140 return 0;
1141}
1142
1143/* Save all the registers on the dummy frame stack. Most ports save the
1144 registers on the target stack. This results in lots of unnecessary memory
1145 references, which are slow when debugging via a serial line. Instead, we
1146 save all the registers internally, and never write them to the stack. The
1147 registers get restored when the called function returns to the entry point,
1148 where a breakpoint is laying in wait. */
1149
1150void
fba45db2 1151generic_push_dummy_frame (void)
c906108c
SS
1152{
1153 struct dummy_frame *dummy_frame;
1154 CORE_ADDR fp = (get_current_frame ())->frame;
1155
1156 /* check to see if there are stale dummy frames,
1157 perhaps left over from when a longjump took us out of a
1158 function that was called by the debugger */
1159
1160 dummy_frame = dummy_frame_stack;
1161 while (dummy_frame)
1162 if (INNER_THAN (dummy_frame->fp, fp)) /* stale -- destroy! */
1163 {
1164 dummy_frame_stack = dummy_frame->next;
b8c9b27d
KB
1165 xfree (dummy_frame->registers);
1166 xfree (dummy_frame);
c906108c
SS
1167 dummy_frame = dummy_frame_stack;
1168 }
1169 else
1170 dummy_frame = dummy_frame->next;
1171
1172 dummy_frame = xmalloc (sizeof (struct dummy_frame));
7a292a7a
SS
1173 dummy_frame->registers = xmalloc (REGISTER_BYTES);
1174
4478b372
JB
1175 dummy_frame->pc = read_pc ();
1176 dummy_frame->sp = read_sp ();
c5aa993b
JM
1177 dummy_frame->top = dummy_frame->sp;
1178 dummy_frame->fp = fp;
7a292a7a 1179 read_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
c906108c
SS
1180 dummy_frame->next = dummy_frame_stack;
1181 dummy_frame_stack = dummy_frame;
1182}
1183
43ff13b4 1184void
fba45db2 1185generic_save_dummy_frame_tos (CORE_ADDR sp)
43ff13b4
JM
1186{
1187 dummy_frame_stack->top = sp;
1188}
1189
6096c27a
AC
1190/* Record the upper/lower bounds on the address of the call dummy. */
1191
1192void
1193generic_save_call_dummy_addr (CORE_ADDR lo, CORE_ADDR hi)
1194{
1195 dummy_frame_stack->call_lo = lo;
1196 dummy_frame_stack->call_hi = hi;
1197}
1198
ed9a39eb 1199/* Restore the machine state from either the saved dummy stack or a
c906108c
SS
1200 real stack frame. */
1201
1202void
ed9a39eb 1203generic_pop_current_frame (void (*popper) (struct frame_info * frame))
c906108c
SS
1204{
1205 struct frame_info *frame = get_current_frame ();
ed9a39eb 1206
c5aa993b 1207 if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
c906108c
SS
1208 generic_pop_dummy_frame ();
1209 else
ed9a39eb 1210 (*popper) (frame);
c906108c
SS
1211}
1212
1213/* Function: pop_dummy_frame
1214 Restore the machine state from a saved dummy stack frame. */
1215
1216void
fba45db2 1217generic_pop_dummy_frame (void)
c906108c
SS
1218{
1219 struct dummy_frame *dummy_frame = dummy_frame_stack;
1220
1221 /* FIXME: what if the first frame isn't the right one, eg..
1222 because one call-by-hand function has done a longjmp into another one? */
1223
1224 if (!dummy_frame)
1225 error ("Can't pop dummy frame!");
1226 dummy_frame_stack = dummy_frame->next;
7a292a7a 1227 write_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
c906108c 1228 flush_cached_frames ();
7a292a7a 1229
b8c9b27d
KB
1230 xfree (dummy_frame->registers);
1231 xfree (dummy_frame);
c906108c
SS
1232}
1233
1234/* Function: frame_chain_valid
1235 Returns true for a user frame or a call_function_by_hand dummy frame,
1236 and false for the CRT0 start-up frame. Purpose is to terminate backtrace */
c5aa993b 1237
c906108c 1238int
fba45db2 1239generic_file_frame_chain_valid (CORE_ADDR fp, struct frame_info *fi)
c906108c 1240{
c5aa993b
JM
1241 if (PC_IN_CALL_DUMMY (FRAME_SAVED_PC (fi), fp, fp))
1242 return 1; /* don't prune CALL_DUMMY frames */
1243 else /* fall back to default algorithm (see frame.h) */
c906108c
SS
1244 return (fp != 0
1245 && (INNER_THAN (fi->frame, fp) || fi->frame == fp)
c5aa993b 1246 && !inside_entry_file (FRAME_SAVED_PC (fi)));
c906108c 1247}
c5aa993b 1248
c4093a6a 1249int
fba45db2 1250generic_func_frame_chain_valid (CORE_ADDR fp, struct frame_info *fi)
c4093a6a
JM
1251{
1252 if (PC_IN_CALL_DUMMY ((fi)->pc, fp, fp))
1253 return 1; /* don't prune CALL_DUMMY frames */
1254 else /* fall back to default algorithm (see frame.h) */
1255 return (fp != 0
1256 && (INNER_THAN (fi->frame, fp) || fi->frame == fp)
1257 && !inside_main_func ((fi)->pc)
1258 && !inside_entry_func ((fi)->pc));
1259}
1260
cce74817 1261/* Function: fix_call_dummy
c570663e 1262 Stub function. Generic dummy frames typically do not need to fix
cce74817
JM
1263 the frame being created */
1264
1265void
fba45db2
KB
1266generic_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
1267 struct value **args, struct type *type, int gcc_p)
cce74817
JM
1268{
1269 return;
1270}
1271
c906108c
SS
1272/* Function: get_saved_register
1273 Find register number REGNUM relative to FRAME and put its (raw,
1274 target format) contents in *RAW_BUFFER.
1275
1276 Set *OPTIMIZED if the variable was optimized out (and thus can't be
1277 fetched). Note that this is never set to anything other than zero
1278 in this implementation.
1279
1280 Set *LVAL to lval_memory, lval_register, or not_lval, depending on
1281 whether the value was fetched from memory, from a register, or in a
1282 strange and non-modifiable way (e.g. a frame pointer which was
1283 calculated rather than fetched). We will use not_lval for values
1284 fetched from generic dummy frames.
1285
7036d6ce 1286 Set *ADDRP to the address, either in memory or as a REGISTER_BYTE
c906108c
SS
1287 offset into the registers array. If the value is stored in a dummy
1288 frame, set *ADDRP to zero.
1289
1290 To use this implementation, define a function called
1291 "get_saved_register" in your target code, which simply passes all
1292 of its arguments to this function.
1293
1294 The argument RAW_BUFFER must point to aligned memory. */
1295
1296void
fba45db2
KB
1297generic_get_saved_register (char *raw_buffer, int *optimized, CORE_ADDR *addrp,
1298 struct frame_info *frame, int regnum,
1299 enum lval_type *lval)
c906108c
SS
1300{
1301 if (!target_has_registers)
1302 error ("No registers.");
1303
1304 /* Normal systems don't optimize out things with register numbers. */
1305 if (optimized != NULL)
1306 *optimized = 0;
1307
c5aa993b 1308 if (addrp) /* default assumption: not found in memory */
c906108c
SS
1309 *addrp = 0;
1310
1311 /* Note: since the current frame's registers could only have been
1312 saved by frames INTERIOR TO the current frame, we skip examining
1313 the current frame itself: otherwise, we would be getting the
1314 previous frame's registers which were saved by the current frame. */
1315
1316 while (frame && ((frame = frame->next) != NULL))
1317 {
1318 if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
1319 {
c5aa993b 1320 if (lval) /* found it in a CALL_DUMMY frame */
c906108c
SS
1321 *lval = not_lval;
1322 if (raw_buffer)
c5aa993b
JM
1323 memcpy (raw_buffer,
1324 generic_find_dummy_frame (frame->pc, frame->frame) +
c906108c
SS
1325 REGISTER_BYTE (regnum),
1326 REGISTER_RAW_SIZE (regnum));
c5aa993b 1327 return;
c906108c
SS
1328 }
1329
1330 FRAME_INIT_SAVED_REGS (frame);
1331 if (frame->saved_regs != NULL
1332 && frame->saved_regs[regnum] != 0)
1333 {
c5aa993b 1334 if (lval) /* found it saved on the stack */
c906108c
SS
1335 *lval = lval_memory;
1336 if (regnum == SP_REGNUM)
1337 {
c5aa993b
JM
1338 if (raw_buffer) /* SP register treated specially */
1339 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
c906108c
SS
1340 frame->saved_regs[regnum]);
1341 }
1342 else
1343 {
c5aa993b 1344 if (addrp) /* any other register */
c906108c
SS
1345 *addrp = frame->saved_regs[regnum];
1346 if (raw_buffer)
c5aa993b 1347 read_memory (frame->saved_regs[regnum], raw_buffer,
c906108c
SS
1348 REGISTER_RAW_SIZE (regnum));
1349 }
1350 return;
1351 }
1352 }
1353
1354 /* If we get thru the loop to this point, it means the register was
1355 not saved in any frame. Return the actual live-register value. */
1356
c5aa993b 1357 if (lval) /* found it in a live register */
c906108c
SS
1358 *lval = lval_register;
1359 if (addrp)
1360 *addrp = REGISTER_BYTE (regnum);
1361 if (raw_buffer)
1362 read_register_gen (regnum, raw_buffer);
1363}
c906108c
SS
1364
1365void
53a5351d 1366_initialize_blockframe (void)
c906108c
SS
1367{
1368 obstack_init (&frame_cache_obstack);
1369}
This page took 0.207772 seconds and 4 git commands to generate.