]>
Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Get info from stack frames; |
2 | convert between frames, blocks, functions and pc values. | |
15cb042b | 3 | Copyright 1986, 1987, 1988, 1989, 1991, 1994, 1995, 1996, 1997 |
dc1b349d | 4 | Free Software Foundation, Inc. |
bd5635a1 RP |
5 | |
6 | This file is part of GDB. | |
7 | ||
5259796b | 8 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 9 | it under the terms of the GNU General Public License as published by |
5259796b JG |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | |
bd5635a1 | 12 | |
5259796b | 13 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
5259796b | 19 | along with this program; if not, write to the Free Software |
0e2c2c1e | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 RP |
21 | |
22 | #include "defs.h" | |
bd5635a1 | 23 | #include "symtab.h" |
23a8e291 JK |
24 | #include "bfd.h" |
25 | #include "symfile.h" | |
26 | #include "objfiles.h" | |
bd5635a1 RP |
27 | #include "frame.h" |
28 | #include "gdbcore.h" | |
29 | #include "value.h" /* for read_register */ | |
30 | #include "target.h" /* for target_has_stack */ | |
23a8e291 | 31 | #include "inferior.h" /* for read_pc */ |
16726dd1 | 32 | #include "annotate.h" |
bd5635a1 | 33 | |
23a8e291 | 34 | /* Is ADDR inside the startup file? Note that if your machine |
bd5635a1 RP |
35 | has a way to detect the bottom of the stack, there is no need |
36 | to call this function from FRAME_CHAIN_VALID; the reason for | |
37 | doing so is that some machines have no way of detecting bottom | |
23a8e291 JK |
38 | of stack. |
39 | ||
40 | A PC of zero is always considered to be the bottom of the stack. */ | |
41 | ||
bd5635a1 | 42 | int |
23a8e291 | 43 | inside_entry_file (addr) |
bd5635a1 RP |
44 | CORE_ADDR addr; |
45 | { | |
23a8e291 JK |
46 | if (addr == 0) |
47 | return 1; | |
48 | if (symfile_objfile == 0) | |
49 | return 0; | |
cef4c2e7 PS |
50 | #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT |
51 | /* Do not stop backtracing if the pc is in the call dummy | |
52 | at the entry point. */ | |
dc1b349d MS |
53 | /* FIXME: Won't always work with zeros for the last two arguments */ |
54 | if (PC_IN_CALL_DUMMY (addr, 0, 0)) | |
cef4c2e7 PS |
55 | return 0; |
56 | #endif | |
23a8e291 JK |
57 | return (addr >= symfile_objfile -> ei.entry_file_lowpc && |
58 | addr < symfile_objfile -> ei.entry_file_highpc); | |
bd5635a1 RP |
59 | } |
60 | ||
e140f1da JG |
61 | /* Test a specified PC value to see if it is in the range of addresses |
62 | that correspond to the main() function. See comments above for why | |
63 | we might want to do this. | |
64 | ||
23a8e291 JK |
65 | Typically called from FRAME_CHAIN_VALID. |
66 | ||
67 | A PC of zero is always considered to be the bottom of the stack. */ | |
e140f1da JG |
68 | |
69 | int | |
23a8e291 | 70 | inside_main_func (pc) |
e140f1da JG |
71 | CORE_ADDR pc; |
72 | { | |
23a8e291 JK |
73 | if (pc == 0) |
74 | return 1; | |
75 | if (symfile_objfile == 0) | |
76 | return 0; | |
0e2c2c1e | 77 | |
dc1b349d MS |
78 | /* If the addr range is not set up at symbol reading time, set it up now. |
79 | This is for FRAME_CHAIN_VALID_ALTERNATE. I do this for coff, because | |
80 | it is unable to set it up and symbol reading time. */ | |
81 | ||
82 | if (symfile_objfile -> ei.main_func_lowpc == INVALID_ENTRY_LOWPC && | |
83 | symfile_objfile -> ei.main_func_highpc == INVALID_ENTRY_HIGHPC) | |
0e2c2c1e | 84 | { |
dc1b349d MS |
85 | struct symbol *mainsym; |
86 | ||
0e2c2c1e KH |
87 | mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL); |
88 | if (mainsym && SYMBOL_CLASS(mainsym) == LOC_BLOCK) | |
89 | { | |
90 | symfile_objfile->ei.main_func_lowpc = BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym)); | |
91 | symfile_objfile->ei.main_func_highpc = BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym)); | |
92 | } | |
0e2c2c1e | 93 | } |
23a8e291 JK |
94 | return (symfile_objfile -> ei.main_func_lowpc <= pc && |
95 | symfile_objfile -> ei.main_func_highpc > pc); | |
e140f1da JG |
96 | } |
97 | ||
98 | /* Test a specified PC value to see if it is in the range of addresses | |
23a8e291 JK |
99 | that correspond to the process entry point function. See comments |
100 | in objfiles.h for why we might want to do this. | |
101 | ||
102 | Typically called from FRAME_CHAIN_VALID. | |
e140f1da | 103 | |
23a8e291 | 104 | A PC of zero is always considered to be the bottom of the stack. */ |
e140f1da JG |
105 | |
106 | int | |
23a8e291 | 107 | inside_entry_func (pc) |
e140f1da JG |
108 | CORE_ADDR pc; |
109 | { | |
23a8e291 JK |
110 | if (pc == 0) |
111 | return 1; | |
112 | if (symfile_objfile == 0) | |
113 | return 0; | |
cef4c2e7 PS |
114 | #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT |
115 | /* Do not stop backtracing if the pc is in the call dummy | |
116 | at the entry point. */ | |
dc1b349d | 117 | /* FIXME: Won't always work with zeros for the last two arguments */ |
cef4c2e7 PS |
118 | if (PC_IN_CALL_DUMMY (pc, 0, 0)) |
119 | return 0; | |
120 | #endif | |
23a8e291 JK |
121 | return (symfile_objfile -> ei.entry_func_lowpc <= pc && |
122 | symfile_objfile -> ei.entry_func_highpc > pc); | |
e140f1da JG |
123 | } |
124 | ||
0e2c2c1e KH |
125 | /* Info about the innermost stack frame (contents of FP register) */ |
126 | ||
127 | static struct frame_info *current_frame; | |
bd5635a1 | 128 | |
0e2c2c1e KH |
129 | /* Cache for frame addresses already read by gdb. Valid only while |
130 | inferior is stopped. Control variables for the frame cache should | |
131 | be local to this module. */ | |
bd5635a1 | 132 | |
bd5635a1 RP |
133 | struct obstack frame_cache_obstack; |
134 | ||
135 | /* Return the innermost (currently executing) stack frame. */ | |
136 | ||
0e2c2c1e | 137 | struct frame_info * |
bd5635a1 RP |
138 | get_current_frame () |
139 | { | |
16726dd1 JK |
140 | if (current_frame == NULL) |
141 | { | |
142 | if (target_has_stack) | |
143 | current_frame = create_new_frame (read_fp (), read_pc ()); | |
144 | else | |
145 | error ("No stack."); | |
146 | } | |
bd5635a1 RP |
147 | return current_frame; |
148 | } | |
149 | ||
150 | void | |
151 | set_current_frame (frame) | |
0e2c2c1e | 152 | struct frame_info *frame; |
bd5635a1 RP |
153 | { |
154 | current_frame = frame; | |
155 | } | |
156 | ||
16726dd1 JK |
157 | /* Create an arbitrary (i.e. address specified by user) or innermost frame. |
158 | Always returns a non-NULL value. */ | |
159 | ||
0e2c2c1e | 160 | struct frame_info * |
bd5635a1 | 161 | create_new_frame (addr, pc) |
0e2c2c1e | 162 | CORE_ADDR addr; |
bd5635a1 RP |
163 | CORE_ADDR pc; |
164 | { | |
0e2c2c1e | 165 | struct frame_info *fi; |
d541211d | 166 | char *name; |
bd5635a1 | 167 | |
0e2c2c1e | 168 | fi = (struct frame_info *) |
bd5635a1 RP |
169 | obstack_alloc (&frame_cache_obstack, |
170 | sizeof (struct frame_info)); | |
171 | ||
172 | /* Arbitrary frame */ | |
0e2c2c1e KH |
173 | fi->next = NULL; |
174 | fi->prev = NULL; | |
175 | fi->frame = addr; | |
176 | fi->pc = pc; | |
d541211d | 177 | find_pc_partial_function (pc, &name, (CORE_ADDR *)NULL,(CORE_ADDR *)NULL); |
0e2c2c1e | 178 | fi->signal_handler_caller = IN_SIGTRAMP (fi->pc, name); |
bd5635a1 RP |
179 | |
180 | #ifdef INIT_EXTRA_FRAME_INFO | |
0e2c2c1e | 181 | INIT_EXTRA_FRAME_INFO (0, fi); |
bd5635a1 RP |
182 | #endif |
183 | ||
0e2c2c1e | 184 | return fi; |
bd5635a1 RP |
185 | } |
186 | ||
0e2c2c1e KH |
187 | /* Return the frame that called FI. |
188 | If FI is the original frame (it has no caller), return 0. */ | |
bd5635a1 | 189 | |
0e2c2c1e | 190 | struct frame_info * |
bd5635a1 | 191 | get_prev_frame (frame) |
0e2c2c1e | 192 | struct frame_info *frame; |
bd5635a1 | 193 | { |
bd5635a1 RP |
194 | return get_prev_frame_info (frame); |
195 | } | |
196 | ||
0e2c2c1e | 197 | /* Return the frame that FRAME calls (NULL if FRAME is the innermost |
bd5635a1 RP |
198 | frame). */ |
199 | ||
0e2c2c1e | 200 | struct frame_info * |
bd5635a1 | 201 | get_next_frame (frame) |
0e2c2c1e | 202 | struct frame_info *frame; |
bd5635a1 | 203 | { |
bd5635a1 RP |
204 | return frame->next; |
205 | } | |
206 | ||
0e2c2c1e KH |
207 | /* Flush the entire frame cache. */ |
208 | ||
bd5635a1 RP |
209 | void |
210 | flush_cached_frames () | |
211 | { | |
212 | /* Since we can't really be sure what the first object allocated was */ | |
213 | obstack_free (&frame_cache_obstack, 0); | |
214 | obstack_init (&frame_cache_obstack); | |
215 | ||
0e2c2c1e KH |
216 | current_frame = NULL; /* Invalidate cache */ |
217 | select_frame (NULL, -1); | |
16726dd1 | 218 | annotate_frames_invalid (); |
bd5635a1 RP |
219 | } |
220 | ||
2403f49b | 221 | /* Flush the frame cache, and start a new one if necessary. */ |
16726dd1 | 222 | |
2403f49b JK |
223 | void |
224 | reinit_frame_cache () | |
225 | { | |
2403f49b | 226 | flush_cached_frames (); |
0e2c2c1e KH |
227 | |
228 | /* FIXME: The inferior_pid test is wrong if there is a corefile. */ | |
16726dd1 | 229 | if (inferior_pid != 0) |
2289e1c3 | 230 | { |
2289e1c3 JK |
231 | select_frame (get_current_frame (), 0); |
232 | } | |
bd5635a1 RP |
233 | } |
234 | ||
235 | /* If a machine allows frameless functions, it should define a macro | |
236 | FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h. FI is the struct | |
237 | frame_info for the frame, and FRAMELESS should be set to nonzero | |
238 | if it represents a frameless function invocation. */ | |
239 | ||
23a8e291 | 240 | /* Return nonzero if the function for this frame lacks a prologue. Many |
bd5635a1 RP |
241 | machines can define FRAMELESS_FUNCTION_INVOCATION to just call this |
242 | function. */ | |
243 | ||
244 | int | |
245 | frameless_look_for_prologue (frame) | |
0e2c2c1e | 246 | struct frame_info *frame; |
bd5635a1 RP |
247 | { |
248 | CORE_ADDR func_start, after_prologue; | |
dc1b349d | 249 | func_start = get_pc_function_start (frame->pc); |
bd5635a1 RP |
250 | if (func_start) |
251 | { | |
dc1b349d | 252 | func_start += FUNCTION_START_OFFSET; |
bd5635a1 | 253 | after_prologue = func_start; |
5259796b JG |
254 | #ifdef SKIP_PROLOGUE_FRAMELESS_P |
255 | /* This is faster, since only care whether there *is* a prologue, | |
256 | not how long it is. */ | |
257 | SKIP_PROLOGUE_FRAMELESS_P (after_prologue); | |
258 | #else | |
bd5635a1 | 259 | SKIP_PROLOGUE (after_prologue); |
5259796b | 260 | #endif |
bd5635a1 RP |
261 | return after_prologue == func_start; |
262 | } | |
15cb042b PS |
263 | else if (frame->pc == 0) |
264 | /* A frame with a zero PC is usually created by dereferencing a NULL | |
265 | function pointer, normally causing an immediate core dump of the | |
266 | inferior. Mark function as frameless, as the inferior has no chance | |
267 | of setting up a stack frame. */ | |
268 | return 1; | |
bd5635a1 RP |
269 | else |
270 | /* If we can't find the start of the function, we don't really | |
271 | know whether the function is frameless, but we should be able | |
272 | to get a reasonable (i.e. best we can do under the | |
273 | circumstances) backtrace by saying that it isn't. */ | |
274 | return 0; | |
275 | } | |
276 | ||
e140f1da JG |
277 | /* Default a few macros that people seldom redefine. */ |
278 | ||
bd5635a1 RP |
279 | #if !defined (INIT_FRAME_PC) |
280 | #define INIT_FRAME_PC(fromleaf, prev) \ | |
281 | prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \ | |
282 | prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ()); | |
283 | #endif | |
284 | ||
e140f1da JG |
285 | #ifndef FRAME_CHAIN_COMBINE |
286 | #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain) | |
287 | #endif | |
288 | ||
bd5635a1 RP |
289 | /* Return a structure containing various interesting information |
290 | about the frame that called NEXT_FRAME. Returns NULL | |
291 | if there is no such frame. */ | |
292 | ||
293 | struct frame_info * | |
294 | get_prev_frame_info (next_frame) | |
0e2c2c1e | 295 | struct frame_info *next_frame; |
bd5635a1 | 296 | { |
0e2c2c1e | 297 | CORE_ADDR address = 0; |
bd5635a1 RP |
298 | struct frame_info *prev; |
299 | int fromleaf = 0; | |
d541211d | 300 | char *name; |
bd5635a1 RP |
301 | |
302 | /* If the requested entry is in the cache, return it. | |
303 | Otherwise, figure out what the address should be for the entry | |
304 | we're about to add to the cache. */ | |
305 | ||
306 | if (!next_frame) | |
307 | { | |
9e837b37 PS |
308 | #if 0 |
309 | /* This screws value_of_variable, which just wants a nice clean | |
310 | NULL return from block_innermost_frame if there are no frames. | |
311 | I don't think I've ever seen this message happen otherwise. | |
312 | And returning NULL here is a perfectly legitimate thing to do. */ | |
bd5635a1 RP |
313 | if (!current_frame) |
314 | { | |
315 | error ("You haven't set up a process's stack to examine."); | |
316 | } | |
9e837b37 | 317 | #endif |
bd5635a1 RP |
318 | |
319 | return current_frame; | |
320 | } | |
321 | ||
322 | /* If we have the prev one, return it */ | |
323 | if (next_frame->prev) | |
324 | return next_frame->prev; | |
325 | ||
326 | /* On some machines it is possible to call a function without | |
327 | setting up a stack frame for it. On these machines, we | |
328 | define this macro to take two args; a frameinfo pointer | |
329 | identifying a frame and a variable to set or clear if it is | |
330 | or isn't leafless. */ | |
331 | #ifdef FRAMELESS_FUNCTION_INVOCATION | |
332 | /* Still don't want to worry about this except on the innermost | |
333 | frame. This macro will set FROMLEAF if NEXT_FRAME is a | |
334 | frameless function invocation. */ | |
335 | if (!(next_frame->next)) | |
336 | { | |
337 | FRAMELESS_FUNCTION_INVOCATION (next_frame, fromleaf); | |
338 | if (fromleaf) | |
0e2c2c1e | 339 | address = FRAME_FP (next_frame); |
bd5635a1 RP |
340 | } |
341 | #endif | |
342 | ||
343 | if (!fromleaf) | |
344 | { | |
345 | /* Two macros defined in tm.h specify the machine-dependent | |
346 | actions to be performed here. | |
347 | First, get the frame's chain-pointer. | |
348 | If that is zero, the frame is the outermost frame or a leaf | |
349 | called by the outermost frame. This means that if start | |
350 | calls main without a frame, we'll return 0 (which is fine | |
351 | anyway). | |
352 | ||
353 | Nope; there's a problem. This also returns when the current | |
354 | routine is a leaf of main. This is unacceptable. We move | |
355 | this to after the ffi test; I'd rather have backtraces from | |
356 | start go curfluy than have an abort called from main not show | |
357 | main. */ | |
358 | address = FRAME_CHAIN (next_frame); | |
359 | if (!FRAME_CHAIN_VALID (address, next_frame)) | |
360 | return 0; | |
361 | address = FRAME_CHAIN_COMBINE (address, next_frame); | |
362 | } | |
e140f1da JG |
363 | if (address == 0) |
364 | return 0; | |
bd5635a1 RP |
365 | |
366 | prev = (struct frame_info *) | |
367 | obstack_alloc (&frame_cache_obstack, | |
368 | sizeof (struct frame_info)); | |
369 | ||
370 | if (next_frame) | |
371 | next_frame->prev = prev; | |
372 | prev->next = next_frame; | |
373 | prev->prev = (struct frame_info *) 0; | |
374 | prev->frame = address; | |
23a8e291 JK |
375 | prev->signal_handler_caller = 0; |
376 | ||
377 | /* This change should not be needed, FIXME! We should | |
378 | determine whether any targets *need* INIT_FRAME_PC to happen | |
379 | after INIT_EXTRA_FRAME_INFO and come up with a simple way to | |
380 | express what goes on here. | |
381 | ||
382 | INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame | |
383 | (where the PC is already set up) and here (where it isn't). | |
384 | INIT_FRAME_PC is only called from here, always after | |
385 | INIT_EXTRA_FRAME_INFO. | |
386 | ||
387 | The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC | |
388 | value (which hasn't been set yet). Some other machines appear to | |
389 | require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC. Phoo. | |
390 | ||
391 | We shouldn't need INIT_FRAME_PC_FIRST to add more complication to | |
392 | an already overcomplicated part of GDB. [email protected], 15Sep92. | |
393 | ||
0e2c2c1e KH |
394 | Assuming that some machines need INIT_FRAME_PC after |
395 | INIT_EXTRA_FRAME_INFO, one possible scheme: | |
23a8e291 JK |
396 | |
397 | SETUP_INNERMOST_FRAME() | |
398 | Default version is just create_new_frame (read_fp ()), | |
399 | read_pc ()). Machines with extra frame info would do that (or the | |
400 | local equivalent) and then set the extra fields. | |
401 | SETUP_ARBITRARY_FRAME(argc, argv) | |
402 | Only change here is that create_new_frame would no longer init extra | |
403 | frame info; SETUP_ARBITRARY_FRAME would have to do that. | |
404 | INIT_PREV_FRAME(fromleaf, prev) | |
9e837b37 PS |
405 | Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC. This should |
406 | also return a flag saying whether to keep the new frame, or | |
407 | whether to discard it, because on some machines (e.g. mips) it | |
408 | is really awkward to have FRAME_CHAIN_VALID called *before* | |
409 | INIT_EXTRA_FRAME_INFO (there is no good way to get information | |
410 | deduced in FRAME_CHAIN_VALID into the extra fields of the new frame). | |
23a8e291 JK |
411 | std_frame_pc(fromleaf, prev) |
412 | This is the default setting for INIT_PREV_FRAME. It just does what | |
413 | the default INIT_FRAME_PC does. Some machines will call it from | |
414 | INIT_PREV_FRAME (either at the beginning, the end, or in the middle). | |
415 | Some machines won't use it. | |
0e2c2c1e | 416 | [email protected], 13Apr93, 31Jan94, 14Dec94. */ |
23a8e291 JK |
417 | |
418 | #ifdef INIT_FRAME_PC_FIRST | |
419 | INIT_FRAME_PC_FIRST (fromleaf, prev); | |
420 | #endif | |
bd5635a1 RP |
421 | |
422 | #ifdef INIT_EXTRA_FRAME_INFO | |
e140f1da | 423 | INIT_EXTRA_FRAME_INFO(fromleaf, prev); |
bd5635a1 RP |
424 | #endif |
425 | ||
426 | /* This entry is in the frame queue now, which is good since | |
9e837b37 | 427 | FRAME_SAVED_PC may use that queue to figure out its value |
e140f1da | 428 | (see tm-sparc.h). We want the pc saved in the inferior frame. */ |
bd5635a1 RP |
429 | INIT_FRAME_PC(fromleaf, prev); |
430 | ||
9e837b37 PS |
431 | /* If ->frame and ->pc are unchanged, we are in the process of getting |
432 | ourselves into an infinite backtrace. Some architectures check this | |
433 | in FRAME_CHAIN or thereabouts, but it seems like there is no reason | |
434 | this can't be an architecture-independent check. */ | |
435 | if (next_frame != NULL) | |
436 | { | |
437 | if (prev->frame == next_frame->frame | |
438 | && prev->pc == next_frame->pc) | |
439 | { | |
440 | next_frame->prev = NULL; | |
441 | obstack_free (&frame_cache_obstack, prev); | |
442 | return NULL; | |
443 | } | |
444 | } | |
445 | ||
d541211d PS |
446 | find_pc_partial_function (prev->pc, &name, |
447 | (CORE_ADDR *)NULL,(CORE_ADDR *)NULL); | |
448 | if (IN_SIGTRAMP (prev->pc, name)) | |
23a8e291 JK |
449 | prev->signal_handler_caller = 1; |
450 | ||
bd5635a1 RP |
451 | return prev; |
452 | } | |
453 | ||
454 | CORE_ADDR | |
455 | get_frame_pc (frame) | |
0e2c2c1e | 456 | struct frame_info *frame; |
bd5635a1 | 457 | { |
0e2c2c1e | 458 | return frame->pc; |
bd5635a1 RP |
459 | } |
460 | ||
461 | #if defined (FRAME_FIND_SAVED_REGS) | |
462 | /* Find the addresses in which registers are saved in FRAME. */ | |
463 | ||
464 | void | |
0e2c2c1e KH |
465 | get_frame_saved_regs (frame, saved_regs_addr) |
466 | struct frame_info *frame; | |
bd5635a1 RP |
467 | struct frame_saved_regs *saved_regs_addr; |
468 | { | |
0e2c2c1e | 469 | FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr); |
bd5635a1 RP |
470 | } |
471 | #endif | |
472 | ||
473 | /* Return the innermost lexical block in execution | |
474 | in a specified stack frame. The frame address is assumed valid. */ | |
475 | ||
476 | struct block * | |
477 | get_frame_block (frame) | |
0e2c2c1e | 478 | struct frame_info *frame; |
bd5635a1 | 479 | { |
bd5635a1 RP |
480 | CORE_ADDR pc; |
481 | ||
0e2c2c1e KH |
482 | pc = frame->pc; |
483 | if (frame->next != 0 && frame->next->signal_handler_caller == 0) | |
747a6329 PS |
484 | /* We are not in the innermost frame and we were not interrupted |
485 | by a signal. We need to subtract one to get the correct block, | |
486 | in case the call instruction was the last instruction of the block. | |
487 | If there are any machines on which the saved pc does not point to | |
0e2c2c1e | 488 | after the call insn, we probably want to make frame->pc point after |
747a6329 | 489 | the call insn anyway. */ |
bd5635a1 RP |
490 | --pc; |
491 | return block_for_pc (pc); | |
492 | } | |
493 | ||
494 | struct block * | |
495 | get_current_block () | |
496 | { | |
497 | return block_for_pc (read_pc ()); | |
498 | } | |
499 | ||
500 | CORE_ADDR | |
501 | get_pc_function_start (pc) | |
502 | CORE_ADDR pc; | |
503 | { | |
23a8e291 | 504 | register struct block *bl; |
bd5635a1 | 505 | register struct symbol *symbol; |
23a8e291 JK |
506 | register struct minimal_symbol *msymbol; |
507 | CORE_ADDR fstart; | |
508 | ||
509 | if ((bl = block_for_pc (pc)) != NULL && | |
510 | (symbol = block_function (bl)) != NULL) | |
bd5635a1 | 511 | { |
23a8e291 JK |
512 | bl = SYMBOL_BLOCK_VALUE (symbol); |
513 | fstart = BLOCK_START (bl); | |
bd5635a1 | 514 | } |
23a8e291 JK |
515 | else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL) |
516 | { | |
517 | fstart = SYMBOL_VALUE_ADDRESS (msymbol); | |
518 | } | |
519 | else | |
520 | { | |
521 | fstart = 0; | |
522 | } | |
523 | return (fstart); | |
bd5635a1 RP |
524 | } |
525 | ||
526 | /* Return the symbol for the function executing in frame FRAME. */ | |
527 | ||
528 | struct symbol * | |
529 | get_frame_function (frame) | |
0e2c2c1e | 530 | struct frame_info *frame; |
bd5635a1 RP |
531 | { |
532 | register struct block *bl = get_frame_block (frame); | |
533 | if (bl == 0) | |
534 | return 0; | |
535 | return block_function (bl); | |
536 | } | |
537 | \f | |
538 | /* Return the blockvector immediately containing the innermost lexical block | |
539 | containing the specified pc value, or 0 if there is none. | |
540 | PINDEX is a pointer to the index value of the block. If PINDEX | |
541 | is NULL, we don't pass this information back to the caller. */ | |
542 | ||
543 | struct blockvector * | |
544 | blockvector_for_pc (pc, pindex) | |
545 | register CORE_ADDR pc; | |
546 | int *pindex; | |
547 | { | |
548 | register struct block *b; | |
549 | register int bot, top, half; | |
550 | register struct symtab *s; | |
551 | struct blockvector *bl; | |
552 | ||
553 | /* First search all symtabs for one whose file contains our pc */ | |
554 | s = find_pc_symtab (pc); | |
555 | if (s == 0) | |
556 | return 0; | |
557 | ||
558 | bl = BLOCKVECTOR (s); | |
559 | b = BLOCKVECTOR_BLOCK (bl, 0); | |
560 | ||
561 | /* Then search that symtab for the smallest block that wins. */ | |
562 | /* Use binary search to find the last block that starts before PC. */ | |
563 | ||
564 | bot = 0; | |
565 | top = BLOCKVECTOR_NBLOCKS (bl); | |
566 | ||
567 | while (top - bot > 1) | |
568 | { | |
569 | half = (top - bot + 1) >> 1; | |
570 | b = BLOCKVECTOR_BLOCK (bl, bot + half); | |
571 | if (BLOCK_START (b) <= pc) | |
572 | bot += half; | |
573 | else | |
574 | top = bot + half; | |
575 | } | |
576 | ||
577 | /* Now search backward for a block that ends after PC. */ | |
578 | ||
579 | while (bot >= 0) | |
580 | { | |
581 | b = BLOCKVECTOR_BLOCK (bl, bot); | |
582 | if (BLOCK_END (b) > pc) | |
583 | { | |
584 | if (pindex) | |
585 | *pindex = bot; | |
586 | return bl; | |
587 | } | |
588 | bot--; | |
589 | } | |
590 | ||
591 | return 0; | |
592 | } | |
593 | ||
594 | /* Return the innermost lexical block containing the specified pc value, | |
595 | or 0 if there is none. */ | |
596 | ||
597 | struct block * | |
598 | block_for_pc (pc) | |
599 | register CORE_ADDR pc; | |
600 | { | |
601 | register struct blockvector *bl; | |
602 | int index; | |
603 | ||
604 | bl = blockvector_for_pc (pc, &index); | |
605 | if (bl) | |
606 | return BLOCKVECTOR_BLOCK (bl, index); | |
607 | return 0; | |
608 | } | |
609 | ||
610 | /* Return the function containing pc value PC. | |
611 | Returns 0 if function is not known. */ | |
612 | ||
613 | struct symbol * | |
614 | find_pc_function (pc) | |
615 | CORE_ADDR pc; | |
616 | { | |
617 | register struct block *b = block_for_pc (pc); | |
618 | if (b == 0) | |
619 | return 0; | |
620 | return block_function (b); | |
621 | } | |
622 | ||
623 | /* These variables are used to cache the most recent result | |
624 | * of find_pc_partial_function. */ | |
625 | ||
626 | static CORE_ADDR cache_pc_function_low = 0; | |
627 | static CORE_ADDR cache_pc_function_high = 0; | |
628 | static char *cache_pc_function_name = 0; | |
629 | ||
630 | /* Clear cache, e.g. when symbol table is discarded. */ | |
631 | ||
632 | void | |
633 | clear_pc_function_cache() | |
634 | { | |
635 | cache_pc_function_low = 0; | |
636 | cache_pc_function_high = 0; | |
637 | cache_pc_function_name = (char *)0; | |
638 | } | |
639 | ||
d541211d PS |
640 | /* Finds the "function" (text symbol) that is smaller than PC but |
641 | greatest of all of the potential text symbols. Sets *NAME and/or | |
642 | *ADDRESS conditionally if that pointer is non-null. If ENDADDR is | |
643 | non-null, then set *ENDADDR to be the end of the function | |
644 | (exclusive), but passing ENDADDR as non-null means that the | |
645 | function might cause symbols to be read. This function either | |
646 | succeeds or fails (not halfway succeeds). If it succeeds, it sets | |
647 | *NAME, *ADDRESS, and *ENDADDR to real information and returns 1. | |
648 | If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero | |
649 | and returns 0. */ | |
bd5635a1 RP |
650 | |
651 | int | |
d541211d | 652 | find_pc_partial_function (pc, name, address, endaddr) |
bd5635a1 RP |
653 | CORE_ADDR pc; |
654 | char **name; | |
655 | CORE_ADDR *address; | |
d541211d | 656 | CORE_ADDR *endaddr; |
bd5635a1 RP |
657 | { |
658 | struct partial_symtab *pst; | |
659 | struct symbol *f; | |
23a8e291 | 660 | struct minimal_symbol *msymbol; |
bd5635a1 | 661 | struct partial_symbol *psb; |
981a3309 | 662 | struct obj_section *sec; |
bd5635a1 RP |
663 | |
664 | if (pc >= cache_pc_function_low && pc < cache_pc_function_high) | |
d541211d PS |
665 | goto return_cached_value; |
666 | ||
667 | /* If sigtramp is in the u area, it counts as a function (especially | |
668 | important for step_1). */ | |
669 | #if defined SIGTRAMP_START | |
670 | if (IN_SIGTRAMP (pc, (char *)NULL)) | |
bd5635a1 | 671 | { |
dc1b349d MS |
672 | cache_pc_function_low = SIGTRAMP_START (pc); |
673 | cache_pc_function_high = SIGTRAMP_END (pc); | |
d541211d PS |
674 | cache_pc_function_name = "<sigtramp>"; |
675 | ||
676 | goto return_cached_value; | |
bd5635a1 | 677 | } |
d541211d | 678 | #endif |
bd5635a1 | 679 | |
d541211d | 680 | msymbol = lookup_minimal_symbol_by_pc (pc); |
bd5635a1 RP |
681 | pst = find_pc_psymtab (pc); |
682 | if (pst) | |
683 | { | |
d541211d PS |
684 | /* Need to read the symbols to get a good value for the end address. */ |
685 | if (endaddr != NULL && !pst->readin) | |
2f1c7c3f JK |
686 | { |
687 | /* Need to get the terminal in case symbol-reading produces | |
688 | output. */ | |
689 | target_terminal_ours_for_output (); | |
690 | PSYMTAB_TO_SYMTAB (pst); | |
691 | } | |
d541211d | 692 | |
bd5635a1 RP |
693 | if (pst->readin) |
694 | { | |
d541211d PS |
695 | /* Checking whether the msymbol has a larger value is for the |
696 | "pathological" case mentioned in print_frame_info. */ | |
bd5635a1 | 697 | f = find_pc_function (pc); |
d541211d PS |
698 | if (f != NULL |
699 | && (msymbol == NULL | |
700 | || (BLOCK_START (SYMBOL_BLOCK_VALUE (f)) | |
701 | >= SYMBOL_VALUE_ADDRESS (msymbol)))) | |
bd5635a1 | 702 | { |
d541211d PS |
703 | cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f)); |
704 | cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f)); | |
705 | cache_pc_function_name = SYMBOL_NAME (f); | |
706 | goto return_cached_value; | |
bd5635a1 | 707 | } |
bd5635a1 | 708 | } |
cef4c2e7 | 709 | else |
bd5635a1 | 710 | { |
cef4c2e7 PS |
711 | /* Now that static symbols go in the minimal symbol table, perhaps |
712 | we could just ignore the partial symbols. But at least for now | |
713 | we use the partial or minimal symbol, whichever is larger. */ | |
714 | psb = find_pc_psymbol (pst, pc); | |
715 | ||
716 | if (psb | |
717 | && (msymbol == NULL || | |
718 | (SYMBOL_VALUE_ADDRESS (psb) | |
719 | >= SYMBOL_VALUE_ADDRESS (msymbol)))) | |
720 | { | |
721 | /* This case isn't being cached currently. */ | |
722 | if (address) | |
723 | *address = SYMBOL_VALUE_ADDRESS (psb); | |
724 | if (name) | |
725 | *name = SYMBOL_NAME (psb); | |
726 | /* endaddr non-NULL can't happen here. */ | |
727 | return 1; | |
728 | } | |
bd5635a1 RP |
729 | } |
730 | } | |
d541211d | 731 | |
981a3309 SG |
732 | /* Not in the normal symbol tables, see if the pc is in a known section. |
733 | If it's not, then give up. This ensures that anything beyond the end | |
734 | of the text seg doesn't appear to be part of the last function in the | |
735 | text segment. */ | |
736 | ||
737 | sec = find_pc_section (pc); | |
738 | ||
739 | if (!sec) | |
740 | msymbol = NULL; | |
741 | ||
d541211d PS |
742 | /* Must be in the minimal symbol table. */ |
743 | if (msymbol == NULL) | |
bd5635a1 | 744 | { |
d541211d PS |
745 | /* No available symbol. */ |
746 | if (name != NULL) | |
747 | *name = 0; | |
748 | if (address != NULL) | |
749 | *address = 0; | |
750 | if (endaddr != NULL) | |
751 | *endaddr = 0; | |
752 | return 0; | |
bd5635a1 RP |
753 | } |
754 | ||
dc1b349d | 755 | cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol); |
23a8e291 | 756 | cache_pc_function_name = SYMBOL_NAME (msymbol); |
d541211d | 757 | |
981a3309 SG |
758 | /* Use the lesser of the next minimal symbol, or the end of the section, as |
759 | the end of the function. */ | |
760 | ||
761 | if (SYMBOL_NAME (msymbol + 1) != NULL | |
762 | && SYMBOL_VALUE_ADDRESS (msymbol + 1) < sec->endaddr) | |
23a8e291 | 763 | cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + 1); |
bd5635a1 | 764 | else |
981a3309 SG |
765 | /* We got the start address from the last msymbol in the objfile. |
766 | So the end address is the end of the section. */ | |
767 | cache_pc_function_high = sec->endaddr; | |
d541211d PS |
768 | |
769 | return_cached_value: | |
bd5635a1 RP |
770 | if (address) |
771 | *address = cache_pc_function_low; | |
772 | if (name) | |
773 | *name = cache_pc_function_name; | |
d541211d PS |
774 | if (endaddr) |
775 | *endaddr = cache_pc_function_high; | |
bd5635a1 RP |
776 | return 1; |
777 | } | |
778 | ||
479fdd26 | 779 | /* Return the innermost stack frame executing inside of BLOCK, |
2289e1c3 | 780 | or NULL if there is no such frame. If BLOCK is NULL, just return NULL. */ |
23a8e291 | 781 | |
0e2c2c1e | 782 | struct frame_info * |
bd5635a1 RP |
783 | block_innermost_frame (block) |
784 | struct block *block; | |
785 | { | |
0e2c2c1e | 786 | struct frame_info *frame; |
2289e1c3 JK |
787 | register CORE_ADDR start; |
788 | register CORE_ADDR end; | |
bd5635a1 | 789 | |
479fdd26 JK |
790 | if (block == NULL) |
791 | return NULL; | |
792 | ||
2289e1c3 JK |
793 | start = BLOCK_START (block); |
794 | end = BLOCK_END (block); | |
795 | ||
0e2c2c1e | 796 | frame = NULL; |
bd5635a1 RP |
797 | while (1) |
798 | { | |
799 | frame = get_prev_frame (frame); | |
0e2c2c1e KH |
800 | if (frame == NULL) |
801 | return NULL; | |
802 | if (frame->pc >= start && frame->pc < end) | |
bd5635a1 RP |
803 | return frame; |
804 | } | |
805 | } | |
806 | ||
0e2c2c1e KH |
807 | /* Return the full FRAME which corresponds to the given CORE_ADDR |
808 | or NULL if no FRAME on the chain corresponds to CORE_ADDR. */ | |
999dd04b | 809 | |
0e2c2c1e | 810 | struct frame_info * |
999dd04b | 811 | find_frame_addr_in_frame_chain (frame_addr) |
0e2c2c1e | 812 | CORE_ADDR frame_addr; |
999dd04b | 813 | { |
0e2c2c1e | 814 | struct frame_info *frame = NULL; |
999dd04b | 815 | |
16726dd1 | 816 | if (frame_addr == (CORE_ADDR)0) |
999dd04b JL |
817 | return NULL; |
818 | ||
819 | while (1) | |
820 | { | |
821 | frame = get_prev_frame (frame); | |
822 | if (frame == NULL) | |
823 | return NULL; | |
999dd04b JL |
824 | if (FRAME_FP (frame) == frame_addr) |
825 | return frame; | |
826 | } | |
827 | } | |
828 | ||
d541211d PS |
829 | #ifdef SIGCONTEXT_PC_OFFSET |
830 | /* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp. */ | |
831 | ||
832 | CORE_ADDR | |
833 | sigtramp_saved_pc (frame) | |
0e2c2c1e | 834 | struct frame_info *frame; |
d541211d PS |
835 | { |
836 | CORE_ADDR sigcontext_addr; | |
837 | char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT]; | |
838 | int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT; | |
839 | int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT; | |
840 | ||
841 | /* Get sigcontext address, it is the third parameter on the stack. */ | |
842 | if (frame->next) | |
843 | sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next) | |
0e2c2c1e KH |
844 | + FRAME_ARGS_SKIP |
845 | + sigcontext_offs, | |
d541211d PS |
846 | ptrbytes); |
847 | else | |
848 | sigcontext_addr = read_memory_integer (read_register (SP_REGNUM) | |
849 | + sigcontext_offs, | |
850 | ptrbytes); | |
851 | ||
852 | /* Don't cause a memory_error when accessing sigcontext in case the stack | |
853 | layout has changed or the stack is corrupt. */ | |
854 | target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes); | |
855 | return extract_unsigned_integer (buf, ptrbytes); | |
856 | } | |
857 | #endif /* SIGCONTEXT_PC_OFFSET */ | |
858 | ||
15cb042b PS |
859 | #ifdef USE_GENERIC_DUMMY_FRAMES |
860 | ||
dc1b349d | 861 | /* |
15cb042b | 862 | * GENERIC DUMMY FRAMES |
dc1b349d MS |
863 | * |
864 | * The following code serves to maintain the dummy stack frames for | |
865 | * inferior function calls (ie. when gdb calls into the inferior via | |
866 | * call_function_by_hand). This code saves the machine state before | |
15cb042b | 867 | * the call in host memory, so we must maintain an independant stack |
dc1b349d MS |
868 | * and keep it consistant etc. I am attempting to make this code |
869 | * generic enough to be used by many targets. | |
870 | * | |
871 | * The cheapest and most generic way to do CALL_DUMMY on a new target | |
872 | * is probably to define CALL_DUMMY to be empty, CALL_DUMMY_LENGTH to zero, | |
873 | * and CALL_DUMMY_LOCATION to AT_ENTRY. Then you must remember to define | |
15cb042b PS |
874 | * PUSH_RETURN_ADDRESS, because no call instruction will be being |
875 | * executed by the target. | |
dc1b349d MS |
876 | */ |
877 | ||
878 | static struct dummy_frame *dummy_frame_stack = NULL; | |
879 | ||
880 | /* Function: find_dummy_frame(pc, fp, sp) | |
881 | Search the stack of dummy frames for one matching the given PC, FP and SP. | |
882 | This is the work-horse for pc_in_call_dummy and read_register_dummy */ | |
883 | ||
884 | char * | |
885 | generic_find_dummy_frame (pc, fp) | |
886 | CORE_ADDR pc; | |
887 | CORE_ADDR fp; | |
888 | { | |
889 | struct dummy_frame * dummyframe; | |
dc1b349d | 890 | |
dc1b349d MS |
891 | if (pc != entry_point_address ()) |
892 | return 0; | |
dc1b349d MS |
893 | |
894 | for (dummyframe = dummy_frame_stack; dummyframe != NULL; | |
895 | dummyframe = dummyframe->next) | |
896 | if (fp == dummyframe->fp || fp == dummyframe->sp) | |
15cb042b PS |
897 | /* The frame in question lies between the saved fp and sp, inclusive */ |
898 | return dummyframe->regs; | |
899 | ||
dc1b349d MS |
900 | return 0; |
901 | } | |
902 | ||
903 | /* Function: pc_in_call_dummy (pc, fp) | |
904 | Return true if this is a dummy frame created by gdb for an inferior call */ | |
905 | ||
906 | int | |
907 | generic_pc_in_call_dummy (pc, fp) | |
908 | CORE_ADDR pc; | |
909 | CORE_ADDR fp; | |
910 | { | |
911 | /* if find_dummy_frame succeeds, then PC is in a call dummy */ | |
912 | return (generic_find_dummy_frame (pc, fp) != 0); | |
913 | } | |
914 | ||
915 | /* Function: read_register_dummy | |
916 | Find a saved register from before GDB calls a function in the inferior */ | |
917 | ||
918 | CORE_ADDR | |
919 | generic_read_register_dummy (pc, fp, regno) | |
920 | CORE_ADDR pc; | |
921 | CORE_ADDR fp; | |
922 | int regno; | |
923 | { | |
924 | char *dummy_regs = generic_find_dummy_frame (pc, fp); | |
925 | ||
926 | if (dummy_regs) | |
927 | return extract_address (&dummy_regs[REGISTER_BYTE (regno)], | |
928 | REGISTER_RAW_SIZE(regno)); | |
929 | else | |
930 | return 0; | |
931 | } | |
932 | ||
933 | /* Save all the registers on the dummy frame stack. Most ports save the | |
934 | registers on the target stack. This results in lots of unnecessary memory | |
935 | references, which are slow when debugging via a serial line. Instead, we | |
936 | save all the registers internally, and never write them to the stack. The | |
937 | registers get restored when the called function returns to the entry point, | |
938 | where a breakpoint is laying in wait. */ | |
939 | ||
940 | void | |
941 | generic_push_dummy_frame () | |
942 | { | |
943 | struct dummy_frame *dummy_frame; | |
944 | CORE_ADDR fp = (get_current_frame ())->frame; | |
945 | ||
946 | /* check to see if there are stale dummy frames, | |
947 | perhaps left over from when a longjump took us out of a | |
948 | function that was called by the debugger */ | |
949 | ||
950 | dummy_frame = dummy_frame_stack; | |
951 | while (dummy_frame) | |
952 | if (dummy_frame->fp INNER_THAN fp) /* stale -- destroy! */ | |
953 | { | |
954 | dummy_frame_stack = dummy_frame->next; | |
955 | free (dummy_frame); | |
956 | dummy_frame = dummy_frame_stack; | |
957 | } | |
958 | else | |
959 | dummy_frame = dummy_frame->next; | |
960 | ||
961 | dummy_frame = xmalloc (sizeof (struct dummy_frame)); | |
962 | dummy_frame->pc = read_register (PC_REGNUM); | |
963 | dummy_frame->sp = read_register (SP_REGNUM); | |
964 | dummy_frame->fp = fp; | |
965 | read_register_bytes (0, dummy_frame->regs, REGISTER_BYTES); | |
966 | dummy_frame->next = dummy_frame_stack; | |
967 | dummy_frame_stack = dummy_frame; | |
968 | } | |
969 | ||
970 | /* Function: pop_dummy_frame | |
971 | Restore the machine state from a saved dummy stack frame. */ | |
972 | ||
973 | void | |
974 | generic_pop_dummy_frame () | |
975 | { | |
976 | struct dummy_frame *dummy_frame = dummy_frame_stack; | |
977 | ||
978 | /* FIXME: what if the first frame isn't the right one, eg.. | |
979 | because one call-by-hand function has done a longjmp into another one? */ | |
980 | ||
981 | if (!dummy_frame) | |
982 | error ("Can't pop dummy frame!"); | |
983 | dummy_frame_stack = dummy_frame->next; | |
984 | write_register_bytes (0, dummy_frame->regs, REGISTER_BYTES); | |
985 | free (dummy_frame); | |
986 | } | |
987 | ||
988 | /* Function: frame_chain_valid | |
989 | Returns true for a user frame or a call_function_by_hand dummy frame, | |
990 | and false for the CRT0 start-up frame. Purpose is to terminate backtrace */ | |
991 | ||
992 | int | |
993 | generic_frame_chain_valid (fp, fi) | |
994 | CORE_ADDR fp; | |
995 | struct frame_info *fi; | |
996 | { | |
dc1b349d MS |
997 | if (PC_IN_CALL_DUMMY(FRAME_SAVED_PC(fi), fp, fp)) |
998 | return 1; /* don't prune CALL_DUMMY frames */ | |
999 | else /* fall back to default algorithm (see frame.h) */ | |
c301abbd JL |
1000 | return (fp != 0 |
1001 | && fi->frame INNER_THAN fp | |
1002 | && !inside_entry_file (FRAME_SAVED_PC(fi))); | |
dc1b349d MS |
1003 | } |
1004 | ||
1005 | /* Function: get_saved_register | |
1006 | Find register number REGNUM relative to FRAME and put its (raw, | |
1007 | target format) contents in *RAW_BUFFER. | |
1008 | ||
1009 | Set *OPTIMIZED if the variable was optimized out (and thus can't be | |
1010 | fetched). Note that this is never set to anything other than zero | |
1011 | in this implementation. | |
1012 | ||
1013 | Set *LVAL to lval_memory, lval_register, or not_lval, depending on | |
1014 | whether the value was fetched from memory, from a register, or in a | |
1015 | strange and non-modifiable way (e.g. a frame pointer which was | |
1016 | calculated rather than fetched). We will use not_lval for values | |
1017 | fetched from generic dummy frames. | |
1018 | ||
1019 | Set *ADDRP to the address, either in memory on as a REGISTER_BYTE | |
1020 | offset into the registers array. If the value is stored in a dummy | |
1021 | frame, set *ADDRP to zero. | |
1022 | ||
1023 | To use this implementation, define a function called | |
1024 | "get_saved_register" in your target code, which simply passes all | |
1025 | of its arguments to this function. | |
1026 | ||
1027 | The argument RAW_BUFFER must point to aligned memory. */ | |
1028 | ||
1029 | void | |
1030 | generic_get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval) | |
1031 | char *raw_buffer; | |
1032 | int *optimized; | |
1033 | CORE_ADDR *addrp; | |
1034 | struct frame_info *frame; | |
1035 | int regnum; | |
1036 | enum lval_type *lval; | |
1037 | { | |
1038 | CORE_ADDR addr; | |
1039 | struct frame_saved_regs fsr; | |
1040 | ||
1041 | if (!target_has_registers) | |
1042 | error ("No registers."); | |
1043 | ||
1044 | /* Normal systems don't optimize out things with register numbers. */ | |
1045 | if (optimized != NULL) | |
1046 | *optimized = 0; | |
1047 | ||
1048 | if (addrp) /* default assumption: not found in memory */ | |
1049 | *addrp = 0; | |
1050 | ||
1051 | /* Note: since the current frame's registers could only have been | |
1052 | saved by frames INTERIOR TO the current frame, we skip examining | |
1053 | the current frame itself: otherwise, we would be getting the | |
1054 | previous frame's registers which were saved by the current frame. */ | |
1055 | ||
b444216f | 1056 | while (frame && ((frame = frame->next) != NULL)) |
dc1b349d MS |
1057 | { |
1058 | if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame)) | |
1059 | { | |
1060 | if (lval) /* found it in a CALL_DUMMY frame */ | |
1061 | *lval = not_lval; | |
1062 | if (raw_buffer) | |
1063 | memcpy (raw_buffer, | |
1064 | generic_find_dummy_frame (frame->pc, frame->frame) + | |
1065 | REGISTER_BYTE (regnum), | |
1066 | REGISTER_RAW_SIZE (regnum)); | |
1067 | return; | |
1068 | } | |
1069 | ||
1070 | FRAME_FIND_SAVED_REGS(frame, fsr); | |
1071 | if (fsr.regs[regnum] != 0) | |
1072 | { | |
1073 | if (lval) /* found it saved on the stack */ | |
1074 | *lval = lval_memory; | |
1075 | if (regnum == SP_REGNUM) | |
1076 | { | |
1077 | if (raw_buffer) /* SP register treated specially */ | |
1078 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), | |
1079 | fsr.regs[regnum]); | |
1080 | } | |
1081 | else | |
1082 | { | |
1083 | if (addrp) /* any other register */ | |
1084 | *addrp = fsr.regs[regnum]; | |
1085 | if (raw_buffer) | |
1086 | read_memory (fsr.regs[regnum], raw_buffer, | |
1087 | REGISTER_RAW_SIZE (regnum)); | |
1088 | } | |
1089 | return; | |
1090 | } | |
1091 | } | |
1092 | ||
1093 | /* If we get thru the loop to this point, it means the register was | |
1094 | not saved in any frame. Return the actual live-register value. */ | |
1095 | ||
1096 | if (lval) /* found it in a live register */ | |
1097 | *lval = lval_register; | |
1098 | if (addrp) | |
1099 | *addrp = REGISTER_BYTE (regnum); | |
1100 | if (raw_buffer) | |
1101 | read_register_gen (regnum, raw_buffer); | |
1102 | } | |
15cb042b | 1103 | #endif /* USE_GENERIC_DUMMY_FRAMES */ |
dc1b349d | 1104 | |
bd5635a1 RP |
1105 | void |
1106 | _initialize_blockframe () | |
1107 | { | |
1108 | obstack_init (&frame_cache_obstack); | |
1109 | } |