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