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