1 /* Get info from stack frames;
2 convert between frames, blocks, functions and pc values.
3 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
5 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
6 WARRANTY. No author or distributor accepts responsibility to anyone
7 for the consequences of using it or for whether it serves any
8 particular purpose or works at all, unless he says so in writing.
9 Refer to the GDB General Public License for full details.
11 Everyone is granted permission to copy, modify and redistribute GDB,
12 but only under the conditions described in the GDB General Public
13 License. A copy of this license is supposed to have been given to you
14 along with GDB so you can know your rights and responsibilities. It
15 should be in a file named COPYING. Among other things, the copyright
16 notice and this notice must be preserved on all copies.
18 In other words, go ahead and share GDB, but don't try to stop
19 anyone else from sharing it farther. Help stamp out software hoarding!
23 #include "initialize.h"
28 /* Address of end of first object file.
29 This file is assumed to be a startup file
30 and frames with pc's inside it
31 are treated as nonexistent. */
33 CORE_ADDR first_object_file_end
;
35 /* Address of innermost stack frame (contents of FP register) */
37 static FRAME current_frame
;
39 struct block
*block_for_pc ();
40 CORE_ADDR
get_pc_function_start ();
44 /* Return the innermost (currently executing) stack frame. */
49 /* We assume its address is kept in a general register;
50 param.h says which register. */
56 set_current_frame (frame
)
59 current_frame
= frame
;
62 /* Return the frame that called FRAME.
63 If FRAME is the original frame (it has no caller), return 0. */
66 get_prev_frame (frame
)
70 /* The caller of "no frame" is the innermost frame. */
72 return get_current_frame ();
74 /* Two macros defined in param.h specify the machine-dependent
75 actions to be performed here. */
76 /* First, get the frame's chain-pointer.
77 If that is zero, the frame is the outermost frame. */
78 pointer
= FRAME_CHAIN (frame
);
79 if (!FRAME_CHAIN_VALID (pointer
, frame
))
81 /* If frame has a caller, combine the chain pointer and the frame's own
82 address to get the address of the caller. */
83 return FRAME_CHAIN_COMBINE (pointer
, frame
);
86 /* Return a structure containing various interesting information
87 about a specified stack frame. */
90 get_frame_info (frame
)
93 struct frame_info val
;
94 FRAME current
= get_current_frame ();
95 register FRAME frame1
, frame2
;
103 val
.next_next_frame
= 0;
107 for (frame1
= current
, frame2
= 0;
109 frame2
= frame1
, frame1
= get_prev_frame (frame1
))
115 val
.pc
= FRAME_SAVED_PC (frame1
, frame2
);
116 val
.next_frame
= frame1
;
117 val
.next_next_frame
= frame2
;
124 /* Return a structure containing various interesting information
125 about the frame that called FRAME.
127 This is much faster than get_frame_info (get_prev_frame (FRAME))
128 because it does not need to search the entire stack
129 to find the frame called by the one being described -- that is FRAME. */
132 get_prev_frame_info (next_frame
, next_next_frame
)
133 FRAME next_frame
, next_next_frame
;
135 struct frame_info val
;
136 register FRAME frame
= get_prev_frame (next_frame
);
139 val
.next_frame
= next_frame
;
140 val
.next_next_frame
= next_next_frame
;
148 val
.pc
= FRAME_SAVED_PC (next_frame
, next_next_frame
);
158 struct frame_info fi
;
159 fi
= get_frame_info (frame
);
163 /* Find the addresses in which registers are saved in FRAME. */
166 get_frame_saved_regs (frame_info_addr
, saved_regs_addr
)
167 struct frame_info
*frame_info_addr
;
168 struct frame_saved_regs
*saved_regs_addr
;
170 FRAME_FIND_SAVED_REGS (*frame_info_addr
, *saved_regs_addr
);
173 /* Return the innermost lexical block in execution
174 in a specified stack frame. The frame address is assumed valid. */
177 get_frame_block (frame
)
180 struct frame_info fi
;
182 fi
= get_frame_info (frame
);
183 return block_for_pc (fi
.pc
);
189 return block_for_pc (read_pc ());
193 get_pc_function_start (pc
)
196 register struct block
*bl
= block_for_pc (pc
);
197 register struct symbol
*symbol
;
200 register int misc_index
= find_pc_misc_function (pc
);
202 return misc_function_vector
[misc_index
].address
;
205 symbol
= block_function (bl
);
206 bl
= SYMBOL_BLOCK_VALUE (symbol
);
207 return BLOCK_START (bl
);
210 /* Return the symbol for the function executing in frame FRAME. */
213 get_frame_function (frame
)
216 register struct block
*bl
= get_frame_block (frame
);
219 return block_function (bl
);
222 /* Return the innermost lexical block containing the specified pc value,
223 or 0 if there is none. */
227 register CORE_ADDR pc
;
229 register struct block
*b
;
230 register int bot
, top
, half
;
231 register struct symtab
*s
;
232 struct blockvector
*bl
;
234 /* First search all symtabs for one whose file contains our pc */
236 for (s
= symtab_list
; s
; s
= s
->next
)
238 bl
= BLOCKVECTOR (s
);
239 b
= BLOCKVECTOR_BLOCK (bl
, 0);
240 if (BLOCK_START (b
) <= pc
241 && BLOCK_END (b
) > pc
)
248 /* Then search that symtab for the smallest block that wins. */
249 /* Use binary search to find the last block that starts before PC. */
252 top
= BLOCKVECTOR_NBLOCKS (bl
);
254 while (top
- bot
> 1)
256 half
= (top
- bot
+ 1) >> 1;
257 b
= BLOCKVECTOR_BLOCK (bl
, bot
+ half
);
258 if (BLOCK_START (b
) <= pc
)
264 /* Now search backward for a block that ends after PC. */
268 b
= BLOCKVECTOR_BLOCK (bl
, bot
);
269 if (BLOCK_END (b
) > pc
)
277 /* Return the function containing pc value PC.
278 Returns 0 if function is not known. */
281 find_pc_function (pc
)
284 register struct block
*b
= block_for_pc (pc
);
287 return block_function (b
);
290 /* Find the misc function whose address is the largest
291 while being less than PC. Return its index in misc_function_vector.
292 Returns -1 if PC is not in suitable range. */
295 find_pc_misc_function (pc
)
296 register CORE_ADDR pc
;
299 register int hi
= misc_function_count
-1;
301 register int distance
;
303 /* Note that the last thing in the vector is always _etext. */
305 /* Above statement is not *always* true - fix for case where there are */
306 /* no misc functions at all (ie no symbol table has been read). */
307 if (hi
< 0) return -1; /* no misc functions recorded */
309 /* trivial reject range test */
310 if (pc
< misc_function_vector
[0].address
||
311 pc
> misc_function_vector
[hi
].address
)
315 new = (lo
+ hi
) >> 1;
316 distance
= misc_function_vector
[new].address
- pc
;
318 return new; /* an exact match */
319 else if (distance
> 0)
323 } while (hi
-lo
!= 1);
325 /* if here, we had no exact match, so return the lower choice */
329 /* Return the innermost stack frame executing inside of the specified block,
330 or zero if there is no such frame. */
333 block_innermost_frame (block
)
336 struct frame_info fi
;
337 register FRAME frame
;
338 register CORE_ADDR start
= BLOCK_START (block
);
339 register CORE_ADDR end
= BLOCK_END (block
);
344 fi
= get_prev_frame_info (frame
);
348 if (fi
.pc
>= start
&& fi
.pc
< end
)