Commit | Line | Data |
---|---|---|
4f460812 | 1 | /* Cache and manage frames for GDB, the GNU debugger. |
96cb11df AC |
2 | |
3 | Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, | |
51603483 | 4 | 2001, 2002, 2003 Free Software Foundation, Inc. |
d65fe839 AC |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
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 | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
23 | #include "defs.h" | |
24 | #include "frame.h" | |
25 | #include "target.h" | |
26 | #include "value.h" | |
39f77062 | 27 | #include "inferior.h" /* for inferior_ptid */ |
4e052eda | 28 | #include "regcache.h" |
4f460812 | 29 | #include "gdb_assert.h" |
e36180d7 AC |
30 | #include "gdb_string.h" |
31 | #include "builtin-regs.h" | |
4c1e7e9d AC |
32 | #include "gdb_obstack.h" |
33 | #include "dummy-frame.h" | |
a94dd1fd | 34 | #include "sentinel-frame.h" |
4c1e7e9d AC |
35 | #include "gdbcore.h" |
36 | #include "annotate.h" | |
6e7f8b9c | 37 | #include "language.h" |
494cca16 | 38 | #include "frame-unwind.h" |
eb4f72c5 AC |
39 | #include "command.h" |
40 | #include "gdbcmd.h" | |
41 | ||
ac2bd0a9 AC |
42 | /* Flag to control debugging. */ |
43 | ||
44 | static int frame_debug; | |
45 | ||
eb4f72c5 AC |
46 | /* Flag to indicate whether backtraces should stop at main. */ |
47 | ||
48 | static int backtrace_below_main; | |
d65fe839 | 49 | |
7a424e99 | 50 | /* Return a frame uniq ID that can be used to, later, re-find the |
101dcfbe AC |
51 | frame. */ |
52 | ||
7a424e99 AC |
53 | struct frame_id |
54 | get_frame_id (struct frame_info *fi) | |
101dcfbe AC |
55 | { |
56 | if (fi == NULL) | |
57 | { | |
7a424e99 | 58 | return null_frame_id; |
101dcfbe AC |
59 | } |
60 | else | |
61 | { | |
7a424e99 AC |
62 | struct frame_id id; |
63 | id.base = fi->frame; | |
64 | id.pc = fi->pc; | |
65 | return id; | |
101dcfbe AC |
66 | } |
67 | } | |
68 | ||
7a424e99 AC |
69 | const struct frame_id null_frame_id; /* All zeros. */ |
70 | ||
71 | struct frame_id | |
72 | frame_id_build (CORE_ADDR base, CORE_ADDR func_or_pc) | |
73 | { | |
74 | struct frame_id id; | |
75 | id.base = base; | |
76 | id.pc = func_or_pc; | |
77 | return id; | |
78 | } | |
79 | ||
80 | int | |
81 | frame_id_p (struct frame_id l) | |
82 | { | |
83 | /* The .func can be NULL but the .base cannot. */ | |
84 | return (l.base != 0); | |
85 | } | |
86 | ||
87 | int | |
88 | frame_id_eq (struct frame_id l, struct frame_id r) | |
89 | { | |
90 | /* If .base is different, the frames are different. */ | |
91 | if (l.base != r.base) | |
92 | return 0; | |
93 | /* Add a test to check that the frame ID's are for the same function | |
94 | here. */ | |
95 | return 1; | |
96 | } | |
97 | ||
98 | int | |
99 | frame_id_inner (struct frame_id l, struct frame_id r) | |
100 | { | |
101 | /* Only return non-zero when strictly inner than. Note that, per | |
102 | comment in "frame.h", there is some fuzz here. Frameless | |
103 | functions are not strictly inner than (same .base but different | |
104 | .func). */ | |
105 | return INNER_THAN (l.base, r.base); | |
106 | } | |
107 | ||
101dcfbe AC |
108 | struct frame_info * |
109 | frame_find_by_id (struct frame_id id) | |
110 | { | |
111 | struct frame_info *frame; | |
112 | ||
113 | /* ZERO denotes the null frame, let the caller decide what to do | |
114 | about it. Should it instead return get_current_frame()? */ | |
7a424e99 | 115 | if (!frame_id_p (id)) |
101dcfbe AC |
116 | return NULL; |
117 | ||
118 | for (frame = get_current_frame (); | |
119 | frame != NULL; | |
120 | frame = get_prev_frame (frame)) | |
121 | { | |
7a424e99 AC |
122 | struct frame_id this = get_frame_id (frame); |
123 | if (frame_id_eq (id, this)) | |
124 | /* An exact match. */ | |
125 | return frame; | |
126 | if (frame_id_inner (id, this)) | |
127 | /* Gone to far. */ | |
101dcfbe | 128 | return NULL; |
7a424e99 AC |
129 | /* Either, we're not yet gone far enough out along the frame |
130 | chain (inner(this,id), or we're comparing frameless functions | |
131 | (same .base, different .func, no test available). Struggle | |
132 | on until we've definitly gone to far. */ | |
101dcfbe AC |
133 | } |
134 | return NULL; | |
135 | } | |
136 | ||
f18c5a73 AC |
137 | CORE_ADDR |
138 | frame_pc_unwind (struct frame_info *frame) | |
139 | { | |
140 | if (!frame->pc_unwind_cache_p) | |
141 | { | |
494cca16 | 142 | frame->pc_unwind_cache = frame->unwind->pc (frame, &frame->unwind_cache); |
f18c5a73 AC |
143 | frame->pc_unwind_cache_p = 1; |
144 | } | |
145 | return frame->pc_unwind_cache; | |
146 | } | |
147 | ||
c689142b AC |
148 | struct frame_id |
149 | frame_id_unwind (struct frame_info *frame) | |
150 | { | |
151 | if (!frame->id_unwind_cache_p) | |
152 | { | |
494cca16 | 153 | frame->unwind->id (frame, &frame->unwind_cache, &frame->id_unwind_cache); |
c689142b AC |
154 | frame->id_unwind_cache_p = 1; |
155 | } | |
156 | return frame->id_unwind_cache; | |
157 | } | |
158 | ||
dbe9fe58 AC |
159 | void |
160 | frame_pop (struct frame_info *frame) | |
161 | { | |
162 | /* FIXME: cagney/2003-01-18: There is probably a chicken-egg problem | |
163 | with passing in current_regcache. The pop function needs to be | |
164 | written carefully so as to not overwrite registers whose [old] | |
165 | values are needed to restore other registers. Instead, this code | |
166 | should pass in a scratch cache and, as a second step, restore the | |
167 | registers using that. */ | |
168 | frame->unwind->pop (frame, &frame->unwind_cache, current_regcache); | |
169 | flush_cached_frames (); | |
170 | } | |
c689142b | 171 | |
4f460812 AC |
172 | void |
173 | frame_register_unwind (struct frame_info *frame, int regnum, | |
174 | int *optimizedp, enum lval_type *lvalp, | |
175 | CORE_ADDR *addrp, int *realnump, void *bufferp) | |
176 | { | |
177 | struct frame_unwind_cache *cache; | |
178 | ||
179 | /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates | |
180 | that the value proper does not need to be fetched. */ | |
181 | gdb_assert (optimizedp != NULL); | |
182 | gdb_assert (lvalp != NULL); | |
183 | gdb_assert (addrp != NULL); | |
184 | gdb_assert (realnump != NULL); | |
185 | /* gdb_assert (bufferp != NULL); */ | |
186 | ||
a94dd1fd AC |
187 | /* NOTE: cagney/2002-11-27: A program trying to unwind a NULL frame |
188 | is broken. There is always a frame. If there, for some reason, | |
189 | isn't, there is some pretty busted code as it should have | |
190 | detected the problem before calling here. */ | |
191 | gdb_assert (frame != NULL); | |
4f460812 AC |
192 | |
193 | /* Ask this frame to unwind its register. */ | |
494cca16 AC |
194 | frame->unwind->reg (frame, &frame->unwind_cache, regnum, |
195 | optimizedp, lvalp, addrp, realnump, bufferp); | |
4f460812 AC |
196 | } |
197 | ||
a216a322 AC |
198 | void |
199 | frame_register (struct frame_info *frame, int regnum, | |
200 | int *optimizedp, enum lval_type *lvalp, | |
201 | CORE_ADDR *addrp, int *realnump, void *bufferp) | |
202 | { | |
203 | /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates | |
204 | that the value proper does not need to be fetched. */ | |
205 | gdb_assert (optimizedp != NULL); | |
206 | gdb_assert (lvalp != NULL); | |
207 | gdb_assert (addrp != NULL); | |
208 | gdb_assert (realnump != NULL); | |
209 | /* gdb_assert (bufferp != NULL); */ | |
210 | ||
211 | /* Ulgh! Old code that, for lval_register, sets ADDRP to the offset | |
212 | of the register in the register cache. It should instead return | |
213 | the REGNUM corresponding to that register. Translate the . */ | |
214 | if (GET_SAVED_REGISTER_P ()) | |
215 | { | |
216 | GET_SAVED_REGISTER (bufferp, optimizedp, addrp, frame, regnum, lvalp); | |
217 | /* Compute the REALNUM if the caller wants it. */ | |
218 | if (*lvalp == lval_register) | |
219 | { | |
220 | int regnum; | |
221 | for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) | |
222 | { | |
223 | if (*addrp == register_offset_hack (current_gdbarch, regnum)) | |
224 | { | |
225 | *realnump = regnum; | |
226 | return; | |
227 | } | |
228 | } | |
229 | internal_error (__FILE__, __LINE__, | |
230 | "Failed to compute the register number corresponding" | |
231 | " to 0x%s", paddr_d (*addrp)); | |
232 | } | |
233 | *realnump = -1; | |
234 | return; | |
235 | } | |
236 | ||
a94dd1fd AC |
237 | /* Obtain the register value by unwinding the register from the next |
238 | (more inner frame). */ | |
239 | gdb_assert (frame != NULL && frame->next != NULL); | |
240 | frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp, | |
241 | realnump, bufferp); | |
a216a322 AC |
242 | } |
243 | ||
135c175f | 244 | void |
5b181d62 | 245 | frame_unwind_register (struct frame_info *frame, int regnum, void *buf) |
135c175f AC |
246 | { |
247 | int optimized; | |
248 | CORE_ADDR addr; | |
249 | int realnum; | |
250 | enum lval_type lval; | |
135c175f AC |
251 | frame_register_unwind (frame, regnum, &optimized, &lval, &addr, |
252 | &realnum, buf); | |
5b181d62 AC |
253 | } |
254 | ||
255 | void | |
256 | frame_unwind_signed_register (struct frame_info *frame, int regnum, | |
257 | LONGEST *val) | |
258 | { | |
259 | void *buf = alloca (MAX_REGISTER_RAW_SIZE); | |
260 | frame_unwind_register (frame, regnum, buf); | |
135c175f AC |
261 | (*val) = extract_signed_integer (buf, REGISTER_VIRTUAL_SIZE (regnum)); |
262 | } | |
263 | ||
264 | void | |
265 | frame_unwind_unsigned_register (struct frame_info *frame, int regnum, | |
266 | ULONGEST *val) | |
267 | { | |
135c175f | 268 | void *buf = alloca (MAX_REGISTER_RAW_SIZE); |
5b181d62 | 269 | frame_unwind_register (frame, regnum, buf); |
135c175f AC |
270 | (*val) = extract_unsigned_integer (buf, REGISTER_VIRTUAL_SIZE (regnum)); |
271 | } | |
4f460812 | 272 | |
5b181d62 AC |
273 | void |
274 | frame_read_register (struct frame_info *frame, int regnum, void *buf) | |
275 | { | |
276 | gdb_assert (frame != NULL && frame->next != NULL); | |
277 | frame_unwind_register (frame->next, regnum, buf); | |
278 | } | |
279 | ||
f908a0eb AC |
280 | void |
281 | frame_read_unsigned_register (struct frame_info *frame, int regnum, | |
282 | ULONGEST *val) | |
283 | { | |
284 | /* NOTE: cagney/2002-10-31: There is a bit of dogma here - there is | |
285 | always a frame. Both this, and the equivalent | |
286 | frame_read_signed_register() function, can only be called with a | |
287 | valid frame. If, for some reason, this function is called | |
288 | without a frame then the problem isn't here, but rather in the | |
289 | caller. It should of first created a frame and then passed that | |
290 | in. */ | |
291 | /* NOTE: cagney/2002-10-31: As a side bar, keep in mind that the | |
292 | ``current_frame'' should not be treated as a special case. While | |
293 | ``get_next_frame (current_frame) == NULL'' currently holds, it | |
294 | should, as far as possible, not be relied upon. In the future, | |
295 | ``get_next_frame (current_frame)'' may instead simply return a | |
296 | normal frame object that simply always gets register values from | |
297 | the register cache. Consequently, frame code should try to avoid | |
298 | tests like ``if get_next_frame() == NULL'' and instead just rely | |
299 | on recursive frame calls (like the below code) when manipulating | |
300 | a frame chain. */ | |
a94dd1fd AC |
301 | gdb_assert (frame != NULL && frame->next != NULL); |
302 | frame_unwind_unsigned_register (frame->next, regnum, val); | |
f908a0eb AC |
303 | } |
304 | ||
305 | void | |
306 | frame_read_signed_register (struct frame_info *frame, int regnum, | |
307 | LONGEST *val) | |
308 | { | |
a94dd1fd AC |
309 | /* See note above in frame_read_unsigned_register(). */ |
310 | gdb_assert (frame != NULL && frame->next != NULL); | |
311 | frame_unwind_signed_register (frame->next, regnum, val); | |
f908a0eb AC |
312 | } |
313 | ||
f796e4be | 314 | void |
4f460812 AC |
315 | generic_unwind_get_saved_register (char *raw_buffer, |
316 | int *optimizedp, | |
317 | CORE_ADDR *addrp, | |
318 | struct frame_info *frame, | |
319 | int regnum, | |
320 | enum lval_type *lvalp) | |
321 | { | |
322 | int optimizedx; | |
323 | CORE_ADDR addrx; | |
324 | int realnumx; | |
325 | enum lval_type lvalx; | |
326 | ||
327 | if (!target_has_registers) | |
328 | error ("No registers."); | |
329 | ||
330 | /* Keep things simple, ensure that all the pointers (except valuep) | |
331 | are non NULL. */ | |
332 | if (optimizedp == NULL) | |
333 | optimizedp = &optimizedx; | |
334 | if (lvalp == NULL) | |
335 | lvalp = &lvalx; | |
336 | if (addrp == NULL) | |
337 | addrp = &addrx; | |
338 | ||
a94dd1fd AC |
339 | gdb_assert (frame != NULL && frame->next != NULL); |
340 | frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp, | |
341 | &realnumx, raw_buffer); | |
4f460812 AC |
342 | } |
343 | ||
d65fe839 AC |
344 | void |
345 | get_saved_register (char *raw_buffer, | |
346 | int *optimized, | |
347 | CORE_ADDR *addrp, | |
348 | struct frame_info *frame, | |
349 | int regnum, | |
350 | enum lval_type *lval) | |
351 | { | |
a216a322 AC |
352 | if (GET_SAVED_REGISTER_P ()) |
353 | { | |
354 | GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval); | |
355 | return; | |
356 | } | |
357 | generic_unwind_get_saved_register (raw_buffer, optimized, addrp, frame, | |
358 | regnum, lval); | |
d65fe839 AC |
359 | } |
360 | ||
cda5a58a | 361 | /* frame_register_read () |
d65fe839 | 362 | |
cda5a58a | 363 | Find and return the value of REGNUM for the specified stack frame. |
d65fe839 AC |
364 | The number of bytes copied is REGISTER_RAW_SIZE (REGNUM). |
365 | ||
cda5a58a | 366 | Returns 0 if the register value could not be found. */ |
d65fe839 | 367 | |
cda5a58a AC |
368 | int |
369 | frame_register_read (struct frame_info *frame, int regnum, void *myaddr) | |
d65fe839 | 370 | { |
a216a322 AC |
371 | int optimized; |
372 | enum lval_type lval; | |
373 | CORE_ADDR addr; | |
374 | int realnum; | |
375 | frame_register (frame, regnum, &optimized, &lval, &addr, &realnum, myaddr); | |
d65fe839 | 376 | |
c97dcfc7 AC |
377 | /* FIXME: cagney/2002-05-15: This test, is just bogus. |
378 | ||
379 | It indicates that the target failed to supply a value for a | |
380 | register because it was "not available" at this time. Problem | |
381 | is, the target still has the register and so get saved_register() | |
382 | may be returning a value saved on the stack. */ | |
383 | ||
d65fe839 | 384 | if (register_cached (regnum) < 0) |
cda5a58a | 385 | return 0; /* register value not available */ |
d65fe839 | 386 | |
a216a322 | 387 | return !optimized; |
d65fe839 | 388 | } |
e36180d7 AC |
389 | |
390 | ||
391 | /* Map between a frame register number and its name. A frame register | |
392 | space is a superset of the cooked register space --- it also | |
393 | includes builtin registers. */ | |
394 | ||
395 | int | |
396 | frame_map_name_to_regnum (const char *name, int len) | |
397 | { | |
398 | int i; | |
399 | ||
5f601589 AC |
400 | if (len < 0) |
401 | len = strlen (name); | |
402 | ||
e36180d7 AC |
403 | /* Search register name space. */ |
404 | for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++) | |
405 | if (REGISTER_NAME (i) && len == strlen (REGISTER_NAME (i)) | |
406 | && strncmp (name, REGISTER_NAME (i), len) == 0) | |
407 | { | |
408 | return i; | |
409 | } | |
410 | ||
411 | /* Try builtin registers. */ | |
412 | i = builtin_reg_map_name_to_regnum (name, len); | |
413 | if (i >= 0) | |
414 | { | |
415 | /* A builtin register doesn't fall into the architecture's | |
416 | register range. */ | |
417 | gdb_assert (i >= NUM_REGS + NUM_PSEUDO_REGS); | |
418 | return i; | |
419 | } | |
420 | ||
421 | return -1; | |
422 | } | |
423 | ||
424 | const char * | |
425 | frame_map_regnum_to_name (int regnum) | |
426 | { | |
427 | if (regnum < 0) | |
428 | return NULL; | |
429 | if (regnum < NUM_REGS + NUM_PSEUDO_REGS) | |
430 | return REGISTER_NAME (regnum); | |
431 | return builtin_reg_map_regnum_to_name (regnum); | |
432 | } | |
4c1e7e9d | 433 | |
a94dd1fd AC |
434 | /* Create a sentinel frame. */ |
435 | ||
436 | struct frame_info * | |
437 | create_sentinel_frame (struct regcache *regcache) | |
438 | { | |
439 | struct frame_info *frame = FRAME_OBSTACK_ZALLOC (struct frame_info); | |
440 | frame->type = NORMAL_FRAME; | |
441 | frame->level = -1; | |
442 | /* Explicitly initialize the sentinel frame's cache. Provide it | |
443 | with the underlying regcache. In the future additional | |
444 | information, such as the frame's thread will be added. */ | |
445 | frame->unwind_cache = sentinel_frame_cache (regcache); | |
446 | /* For the moment there is only one sentinel frame implementation. */ | |
447 | frame->unwind = sentinel_frame_unwind; | |
448 | /* Link this frame back to itself. The frame is self referential | |
449 | (the unwound PC is the same as the pc), so make it so. */ | |
450 | frame->next = frame; | |
451 | /* Always unwind the PC as part of creating this frame. This | |
452 | ensures that the frame's PC points at something valid. */ | |
453 | /* FIXME: cagney/2003-01-10: Problem here. Unwinding a sentinel | |
454 | frame's PC may require information such as the frame's thread's | |
455 | stop reason. Is it possible to get to that? */ | |
456 | frame->pc = frame_pc_unwind (frame); | |
457 | return frame; | |
458 | } | |
459 | ||
4c1e7e9d AC |
460 | /* Info about the innermost stack frame (contents of FP register) */ |
461 | ||
462 | static struct frame_info *current_frame; | |
463 | ||
464 | /* Cache for frame addresses already read by gdb. Valid only while | |
465 | inferior is stopped. Control variables for the frame cache should | |
466 | be local to this module. */ | |
467 | ||
468 | static struct obstack frame_cache_obstack; | |
469 | ||
470 | void * | |
479ab5a0 | 471 | frame_obstack_zalloc (unsigned long size) |
4c1e7e9d | 472 | { |
479ab5a0 AC |
473 | void *data = obstack_alloc (&frame_cache_obstack, size); |
474 | memset (data, 0, size); | |
475 | return data; | |
4c1e7e9d AC |
476 | } |
477 | ||
6baff1d2 | 478 | CORE_ADDR * |
4c1e7e9d AC |
479 | frame_saved_regs_zalloc (struct frame_info *fi) |
480 | { | |
481 | fi->saved_regs = (CORE_ADDR *) | |
479ab5a0 | 482 | frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS); |
6baff1d2 | 483 | return fi->saved_regs; |
4c1e7e9d AC |
484 | } |
485 | ||
6baff1d2 AC |
486 | CORE_ADDR * |
487 | get_frame_saved_regs (struct frame_info *fi) | |
488 | { | |
489 | return fi->saved_regs; | |
490 | } | |
4c1e7e9d | 491 | |
a94dd1fd AC |
492 | /* Return the innermost (currently executing) stack frame. This is |
493 | split into two functions. The function unwind_to_current_frame() | |
494 | is wrapped in catch exceptions so that, even when the unwind of the | |
495 | sentinel frame fails, the function still returns a stack frame. */ | |
496 | ||
497 | static int | |
498 | unwind_to_current_frame (struct ui_out *ui_out, void *args) | |
499 | { | |
500 | struct frame_info *frame = get_prev_frame (args); | |
501 | /* A sentinel frame can fail to unwind, eg, because it's PC value | |
502 | lands in somewhere like start. */ | |
503 | if (frame == NULL) | |
504 | return 1; | |
505 | current_frame = frame; | |
506 | return 0; | |
507 | } | |
4c1e7e9d AC |
508 | |
509 | struct frame_info * | |
510 | get_current_frame (void) | |
511 | { | |
a94dd1fd AC |
512 | if (!target_has_stack) |
513 | error ("No stack."); | |
514 | if (!target_has_registers) | |
515 | error ("No registers."); | |
516 | if (!target_has_memory) | |
517 | error ("No memory."); | |
4c1e7e9d AC |
518 | if (current_frame == NULL) |
519 | { | |
a94dd1fd AC |
520 | struct frame_info *sentinel_frame = |
521 | create_sentinel_frame (current_regcache); | |
522 | if (catch_exceptions (uiout, unwind_to_current_frame, sentinel_frame, | |
523 | NULL, RETURN_MASK_ERROR) != 0) | |
524 | { | |
525 | /* Oops! Fake a current frame? Is this useful? It has a PC | |
526 | of zero, for instance. */ | |
527 | current_frame = sentinel_frame; | |
528 | } | |
4c1e7e9d AC |
529 | } |
530 | return current_frame; | |
531 | } | |
532 | ||
6e7f8b9c AC |
533 | /* The "selected" stack frame is used by default for local and arg |
534 | access. May be zero, for no selected frame. */ | |
535 | ||
536 | struct frame_info *deprecated_selected_frame; | |
537 | ||
538 | /* Return the selected frame. Always non-null (unless there isn't an | |
539 | inferior sufficient for creating a frame) in which case an error is | |
540 | thrown. */ | |
541 | ||
542 | struct frame_info * | |
543 | get_selected_frame (void) | |
544 | { | |
545 | if (deprecated_selected_frame == NULL) | |
546 | /* Hey! Don't trust this. It should really be re-finding the | |
547 | last selected frame of the currently selected thread. This, | |
548 | though, is better than nothing. */ | |
549 | select_frame (get_current_frame ()); | |
550 | /* There is always a frame. */ | |
551 | gdb_assert (deprecated_selected_frame != NULL); | |
552 | return deprecated_selected_frame; | |
553 | } | |
554 | ||
555 | /* Select frame FI (or NULL - to invalidate the current frame). */ | |
556 | ||
557 | void | |
558 | select_frame (struct frame_info *fi) | |
559 | { | |
560 | register struct symtab *s; | |
561 | ||
562 | deprecated_selected_frame = fi; | |
563 | /* NOTE: cagney/2002-05-04: FI can be NULL. This occures when the | |
564 | frame is being invalidated. */ | |
565 | if (selected_frame_level_changed_hook) | |
566 | selected_frame_level_changed_hook (frame_relative_level (fi)); | |
567 | ||
568 | /* FIXME: kseitz/2002-08-28: It would be nice to call | |
569 | selected_frame_level_changed_event right here, but due to limitations | |
570 | in the current interfaces, we would end up flooding UIs with events | |
571 | because select_frame is used extensively internally. | |
572 | ||
573 | Once we have frame-parameterized frame (and frame-related) commands, | |
574 | the event notification can be moved here, since this function will only | |
575 | be called when the users selected frame is being changed. */ | |
576 | ||
577 | /* Ensure that symbols for this frame are read in. Also, determine the | |
578 | source language of this frame, and switch to it if desired. */ | |
579 | if (fi) | |
580 | { | |
581 | s = find_pc_symtab (fi->pc); | |
582 | if (s | |
583 | && s->language != current_language->la_language | |
584 | && s->language != language_unknown | |
585 | && language_mode == language_mode_auto) | |
586 | { | |
587 | set_language (s->language); | |
588 | } | |
589 | } | |
590 | } | |
591 | ||
4c1e7e9d AC |
592 | /* Return the register saved in the simplistic ``saved_regs'' cache. |
593 | If the value isn't here AND a value is needed, try the next inner | |
594 | most frame. */ | |
595 | ||
596 | static void | |
597 | frame_saved_regs_register_unwind (struct frame_info *frame, void **cache, | |
598 | int regnum, int *optimizedp, | |
599 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
600 | int *realnump, void *bufferp) | |
601 | { | |
602 | /* There is always a frame at this point. And THIS is the frame | |
603 | we're interested in. */ | |
604 | gdb_assert (frame != NULL); | |
605 | /* If we're using generic dummy frames, we'd better not be in a call | |
606 | dummy. (generic_call_dummy_register_unwind ought to have been called | |
607 | instead.) */ | |
07555a72 | 608 | gdb_assert (!(DEPRECATED_USE_GENERIC_DUMMY_FRAMES |
5e0f933e | 609 | && (get_frame_type (frame) == DUMMY_FRAME))); |
4c1e7e9d | 610 | |
8f871025 AC |
611 | /* Only (older) architectures that implement the |
612 | FRAME_INIT_SAVED_REGS method should be using this function. */ | |
613 | gdb_assert (FRAME_INIT_SAVED_REGS_P ()); | |
614 | ||
4c1e7e9d | 615 | /* Load the saved_regs register cache. */ |
a94dd1fd | 616 | if (get_frame_saved_regs (frame) == NULL) |
4c1e7e9d AC |
617 | FRAME_INIT_SAVED_REGS (frame); |
618 | ||
a94dd1fd AC |
619 | if (get_frame_saved_regs (frame) != NULL |
620 | && get_frame_saved_regs (frame)[regnum] != 0) | |
4c1e7e9d AC |
621 | { |
622 | if (regnum == SP_REGNUM) | |
623 | { | |
624 | /* SP register treated specially. */ | |
625 | *optimizedp = 0; | |
626 | *lvalp = not_lval; | |
627 | *addrp = 0; | |
628 | *realnump = -1; | |
629 | if (bufferp != NULL) | |
630 | store_address (bufferp, REGISTER_RAW_SIZE (regnum), | |
a94dd1fd | 631 | get_frame_saved_regs (frame)[regnum]); |
4c1e7e9d AC |
632 | } |
633 | else | |
634 | { | |
635 | /* Any other register is saved in memory, fetch it but cache | |
636 | a local copy of its value. */ | |
637 | *optimizedp = 0; | |
638 | *lvalp = lval_memory; | |
a94dd1fd | 639 | *addrp = get_frame_saved_regs (frame)[regnum]; |
4c1e7e9d AC |
640 | *realnump = -1; |
641 | if (bufferp != NULL) | |
642 | { | |
643 | #if 1 | |
644 | /* Save each register value, as it is read in, in a | |
645 | frame based cache. */ | |
646 | void **regs = (*cache); | |
647 | if (regs == NULL) | |
648 | { | |
649 | int sizeof_cache = ((NUM_REGS + NUM_PSEUDO_REGS) | |
650 | * sizeof (void *)); | |
479ab5a0 | 651 | regs = frame_obstack_zalloc (sizeof_cache); |
4c1e7e9d AC |
652 | (*cache) = regs; |
653 | } | |
654 | if (regs[regnum] == NULL) | |
655 | { | |
656 | regs[regnum] | |
479ab5a0 | 657 | = frame_obstack_zalloc (REGISTER_RAW_SIZE (regnum)); |
a94dd1fd | 658 | read_memory (get_frame_saved_regs (frame)[regnum], regs[regnum], |
4c1e7e9d AC |
659 | REGISTER_RAW_SIZE (regnum)); |
660 | } | |
661 | memcpy (bufferp, regs[regnum], REGISTER_RAW_SIZE (regnum)); | |
662 | #else | |
663 | /* Read the value in from memory. */ | |
a94dd1fd | 664 | read_memory (get_frame_saved_regs (frame)[regnum], bufferp, |
4c1e7e9d AC |
665 | REGISTER_RAW_SIZE (regnum)); |
666 | #endif | |
667 | } | |
668 | } | |
669 | return; | |
670 | } | |
671 | ||
672 | /* No luck, assume this and the next frame have the same register | |
a94dd1fd AC |
673 | value. Pass the request down the frame chain to the next frame. |
674 | Hopefully that will find the register's location, either in a | |
675 | register or in memory. */ | |
676 | frame_register (frame, regnum, optimizedp, lvalp, addrp, realnump, | |
677 | bufferp); | |
4c1e7e9d AC |
678 | } |
679 | ||
f18c5a73 AC |
680 | static CORE_ADDR |
681 | frame_saved_regs_pc_unwind (struct frame_info *frame, void **cache) | |
682 | { | |
d62d1979 | 683 | gdb_assert (FRAME_SAVED_PC_P ()); |
f18c5a73 AC |
684 | return FRAME_SAVED_PC (frame); |
685 | } | |
686 | ||
c170fb60 AC |
687 | static void |
688 | frame_saved_regs_id_unwind (struct frame_info *next_frame, void **cache, | |
689 | struct frame_id *id) | |
c689142b AC |
690 | { |
691 | int fromleaf; | |
c170fb60 AC |
692 | CORE_ADDR base; |
693 | CORE_ADDR pc; | |
694 | ||
695 | /* Start out by assuming it's NULL. */ | |
696 | (*id) = null_frame_id; | |
c689142b | 697 | |
a94dd1fd | 698 | if (frame_relative_level (next_frame) <= 0) |
c689142b AC |
699 | /* FIXME: 2002-11-09: Frameless functions can occure anywhere in |
700 | the frame chain, not just the inner most frame! The generic, | |
701 | per-architecture, frame code should handle this and the below | |
702 | should simply be removed. */ | |
703 | fromleaf = FRAMELESS_FUNCTION_INVOCATION (next_frame); | |
704 | else | |
705 | fromleaf = 0; | |
706 | ||
707 | if (fromleaf) | |
708 | /* A frameless inner-most frame. The `FP' (which isn't an | |
709 | architecture frame-pointer register!) of the caller is the same | |
710 | as the callee. */ | |
711 | /* FIXME: 2002-11-09: There isn't any reason to special case this | |
712 | edge condition. Instead the per-architecture code should hande | |
713 | it locally. */ | |
c170fb60 | 714 | base = get_frame_base (next_frame); |
c689142b AC |
715 | else |
716 | { | |
717 | /* Two macros defined in tm.h specify the machine-dependent | |
718 | actions to be performed here. | |
719 | ||
720 | First, get the frame's chain-pointer. | |
721 | ||
722 | If that is zero, the frame is the outermost frame or a leaf | |
723 | called by the outermost frame. This means that if start | |
724 | calls main without a frame, we'll return 0 (which is fine | |
725 | anyway). | |
726 | ||
727 | Nope; there's a problem. This also returns when the current | |
728 | routine is a leaf of main. This is unacceptable. We move | |
729 | this to after the ffi test; I'd rather have backtraces from | |
730 | start go curfluy than have an abort called from main not show | |
731 | main. */ | |
d62d1979 | 732 | gdb_assert (FRAME_CHAIN_P ()); |
c170fb60 | 733 | base = FRAME_CHAIN (next_frame); |
c689142b | 734 | |
c170fb60 AC |
735 | if (!frame_chain_valid (base, next_frame)) |
736 | return; | |
c689142b | 737 | } |
c170fb60 AC |
738 | if (base == 0) |
739 | return; | |
c689142b AC |
740 | |
741 | /* FIXME: cagney/2002-06-08: This should probably return the frame's | |
742 | function and not the PC (a.k.a. resume address). */ | |
c170fb60 AC |
743 | pc = frame_pc_unwind (next_frame); |
744 | id->pc = pc; | |
745 | id->base = base; | |
c689142b AC |
746 | } |
747 | ||
dbe9fe58 AC |
748 | static void |
749 | frame_saved_regs_pop (struct frame_info *fi, void **cache, | |
750 | struct regcache *regcache) | |
751 | { | |
dedc2a2b | 752 | gdb_assert (POP_FRAME_P ()); |
dbe9fe58 AC |
753 | POP_FRAME; |
754 | } | |
755 | ||
494cca16 | 756 | const struct frame_unwind trad_frame_unwinder = { |
dbe9fe58 | 757 | frame_saved_regs_pop, |
494cca16 AC |
758 | frame_saved_regs_pc_unwind, |
759 | frame_saved_regs_id_unwind, | |
760 | frame_saved_regs_register_unwind | |
761 | }; | |
762 | const struct frame_unwind *trad_frame_unwind = &trad_frame_unwinder; | |
763 | ||
764 | ||
4c1e7e9d AC |
765 | /* Function: get_saved_register |
766 | Find register number REGNUM relative to FRAME and put its (raw, | |
767 | target format) contents in *RAW_BUFFER. | |
768 | ||
769 | Set *OPTIMIZED if the variable was optimized out (and thus can't be | |
770 | fetched). Note that this is never set to anything other than zero | |
771 | in this implementation. | |
772 | ||
773 | Set *LVAL to lval_memory, lval_register, or not_lval, depending on | |
774 | whether the value was fetched from memory, from a register, or in a | |
775 | strange and non-modifiable way (e.g. a frame pointer which was | |
776 | calculated rather than fetched). We will use not_lval for values | |
777 | fetched from generic dummy frames. | |
778 | ||
779 | Set *ADDRP to the address, either in memory or as a REGISTER_BYTE | |
780 | offset into the registers array. If the value is stored in a dummy | |
781 | frame, set *ADDRP to zero. | |
782 | ||
783 | To use this implementation, define a function called | |
784 | "get_saved_register" in your target code, which simply passes all | |
785 | of its arguments to this function. | |
786 | ||
787 | The argument RAW_BUFFER must point to aligned memory. */ | |
788 | ||
789 | void | |
790 | deprecated_generic_get_saved_register (char *raw_buffer, int *optimized, | |
791 | CORE_ADDR *addrp, | |
792 | struct frame_info *frame, int regnum, | |
793 | enum lval_type *lval) | |
794 | { | |
795 | if (!target_has_registers) | |
796 | error ("No registers."); | |
797 | ||
8f871025 AC |
798 | gdb_assert (FRAME_INIT_SAVED_REGS_P ()); |
799 | ||
4c1e7e9d AC |
800 | /* Normal systems don't optimize out things with register numbers. */ |
801 | if (optimized != NULL) | |
802 | *optimized = 0; | |
803 | ||
804 | if (addrp) /* default assumption: not found in memory */ | |
805 | *addrp = 0; | |
806 | ||
807 | /* Note: since the current frame's registers could only have been | |
808 | saved by frames INTERIOR TO the current frame, we skip examining | |
809 | the current frame itself: otherwise, we would be getting the | |
810 | previous frame's registers which were saved by the current frame. */ | |
811 | ||
a94dd1fd | 812 | if (frame != NULL) |
4c1e7e9d | 813 | { |
a94dd1fd AC |
814 | for (frame = get_next_frame (frame); |
815 | frame_relative_level (frame) >= 0; | |
816 | frame = get_next_frame (frame)) | |
4c1e7e9d | 817 | { |
a94dd1fd | 818 | if (get_frame_type (frame) == DUMMY_FRAME) |
4c1e7e9d | 819 | { |
a94dd1fd AC |
820 | if (lval) /* found it in a CALL_DUMMY frame */ |
821 | *lval = not_lval; | |
822 | if (raw_buffer) | |
823 | /* FIXME: cagney/2002-06-26: This should be via the | |
824 | gdbarch_register_read() method so that it, on the | |
825 | fly, constructs either a raw or pseudo register | |
826 | from the raw register cache. */ | |
827 | regcache_raw_read | |
828 | (generic_find_dummy_frame (get_frame_pc (frame), | |
829 | get_frame_base (frame)), | |
830 | regnum, raw_buffer); | |
831 | return; | |
4c1e7e9d | 832 | } |
a94dd1fd AC |
833 | |
834 | FRAME_INIT_SAVED_REGS (frame); | |
835 | if (get_frame_saved_regs (frame) != NULL | |
836 | && get_frame_saved_regs (frame)[regnum] != 0) | |
4c1e7e9d | 837 | { |
a94dd1fd AC |
838 | if (lval) /* found it saved on the stack */ |
839 | *lval = lval_memory; | |
840 | if (regnum == SP_REGNUM) | |
841 | { | |
842 | if (raw_buffer) /* SP register treated specially */ | |
843 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), | |
844 | get_frame_saved_regs (frame)[regnum]); | |
845 | } | |
846 | else | |
847 | { | |
848 | if (addrp) /* any other register */ | |
849 | *addrp = get_frame_saved_regs (frame)[regnum]; | |
850 | if (raw_buffer) | |
851 | read_memory (get_frame_saved_regs (frame)[regnum], raw_buffer, | |
852 | REGISTER_RAW_SIZE (regnum)); | |
853 | } | |
854 | return; | |
4c1e7e9d | 855 | } |
4c1e7e9d AC |
856 | } |
857 | } | |
858 | ||
859 | /* If we get thru the loop to this point, it means the register was | |
860 | not saved in any frame. Return the actual live-register value. */ | |
861 | ||
862 | if (lval) /* found it in a live register */ | |
863 | *lval = lval_register; | |
864 | if (addrp) | |
865 | *addrp = REGISTER_BYTE (regnum); | |
866 | if (raw_buffer) | |
867 | deprecated_read_register_gen (regnum, raw_buffer); | |
868 | } | |
869 | ||
eb4f72c5 AC |
870 | /* Determine the frame's type based on its PC. */ |
871 | ||
872 | static enum frame_type | |
873 | frame_type_from_pc (CORE_ADDR pc) | |
874 | { | |
875 | /* FIXME: cagney/2002-11-24: Can't yet directly call | |
876 | pc_in_dummy_frame() as some architectures don't set | |
877 | PC_IN_CALL_DUMMY() to generic_pc_in_call_dummy() (remember the | |
878 | latter is implemented by simply calling pc_in_dummy_frame). */ | |
879 | if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES | |
880 | && DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0)) | |
881 | return DUMMY_FRAME; | |
882 | else | |
883 | { | |
884 | char *name; | |
885 | find_pc_partial_function (pc, &name, NULL, NULL); | |
886 | if (PC_IN_SIGTRAMP (pc, name)) | |
887 | return SIGTRAMP_FRAME; | |
888 | else | |
889 | return NORMAL_FRAME; | |
890 | } | |
891 | } | |
892 | ||
4c1e7e9d AC |
893 | /* Create an arbitrary (i.e. address specified by user) or innermost frame. |
894 | Always returns a non-NULL value. */ | |
895 | ||
896 | struct frame_info * | |
897 | create_new_frame (CORE_ADDR addr, CORE_ADDR pc) | |
898 | { | |
899 | struct frame_info *fi; | |
4c1e7e9d | 900 | |
479ab5a0 | 901 | fi = frame_obstack_zalloc (sizeof (struct frame_info)); |
4c1e7e9d AC |
902 | |
903 | fi->frame = addr; | |
904 | fi->pc = pc; | |
a94dd1fd | 905 | fi->next = create_sentinel_frame (current_regcache); |
eb4f72c5 | 906 | fi->type = frame_type_from_pc (pc); |
4c1e7e9d | 907 | |
e9582e71 AC |
908 | if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ()) |
909 | DEPRECATED_INIT_EXTRA_FRAME_INFO (0, fi); | |
4c1e7e9d AC |
910 | |
911 | /* Select/initialize an unwind function. */ | |
494cca16 | 912 | fi->unwind = frame_unwind_find_by_pc (current_gdbarch, fi->pc); |
4c1e7e9d AC |
913 | |
914 | return fi; | |
915 | } | |
916 | ||
917 | /* Return the frame that FRAME calls (NULL if FRAME is the innermost | |
a94dd1fd AC |
918 | frame). Be careful to not fall off the bottom of the frame chain |
919 | and onto the sentinel frame. */ | |
4c1e7e9d AC |
920 | |
921 | struct frame_info * | |
922 | get_next_frame (struct frame_info *frame) | |
923 | { | |
a94dd1fd AC |
924 | if (frame->level > 0) |
925 | return frame->next; | |
926 | else | |
927 | return NULL; | |
4c1e7e9d AC |
928 | } |
929 | ||
930 | /* Flush the entire frame cache. */ | |
931 | ||
932 | void | |
933 | flush_cached_frames (void) | |
934 | { | |
935 | /* Since we can't really be sure what the first object allocated was */ | |
936 | obstack_free (&frame_cache_obstack, 0); | |
937 | obstack_init (&frame_cache_obstack); | |
938 | ||
939 | current_frame = NULL; /* Invalidate cache */ | |
940 | select_frame (NULL); | |
941 | annotate_frames_invalid (); | |
942 | } | |
943 | ||
944 | /* Flush the frame cache, and start a new one if necessary. */ | |
945 | ||
946 | void | |
947 | reinit_frame_cache (void) | |
948 | { | |
949 | flush_cached_frames (); | |
950 | ||
951 | /* FIXME: The inferior_ptid test is wrong if there is a corefile. */ | |
952 | if (PIDGET (inferior_ptid) != 0) | |
953 | { | |
954 | select_frame (get_current_frame ()); | |
955 | } | |
956 | } | |
957 | ||
eb4f72c5 AC |
958 | /* Create the previous frame using the deprecated methods |
959 | INIT_EXTRA_INFO, INIT_FRAME_PC and INIT_FRAME_PC_FIRST. */ | |
4c1e7e9d | 960 | |
eb4f72c5 AC |
961 | static struct frame_info * |
962 | legacy_get_prev_frame (struct frame_info *next_frame) | |
4c1e7e9d AC |
963 | { |
964 | CORE_ADDR address = 0; | |
965 | struct frame_info *prev; | |
95adb866 | 966 | int fromleaf; |
4c1e7e9d | 967 | |
eb4f72c5 AC |
968 | /* This code only works on normal frames. A sentinel frame, where |
969 | the level is -1, should never reach this code. */ | |
970 | gdb_assert (next_frame->level >= 0); | |
4c1e7e9d AC |
971 | |
972 | /* On some machines it is possible to call a function without | |
973 | setting up a stack frame for it. On these machines, we | |
974 | define this macro to take two args; a frameinfo pointer | |
975 | identifying a frame and a variable to set or clear if it is | |
976 | or isn't leafless. */ | |
977 | ||
978 | /* Still don't want to worry about this except on the innermost | |
95adb866 AC |
979 | frame. This macro will set FROMLEAF if NEXT_FRAME is a frameless |
980 | function invocation. */ | |
eb4f72c5 | 981 | if (next_frame->level == 0) |
95adb866 AC |
982 | /* FIXME: 2002-11-09: Frameless functions can occure anywhere in |
983 | the frame chain, not just the inner most frame! The generic, | |
984 | per-architecture, frame code should handle this and the below | |
985 | should simply be removed. */ | |
986 | fromleaf = FRAMELESS_FUNCTION_INVOCATION (next_frame); | |
987 | else | |
988 | fromleaf = 0; | |
989 | ||
990 | if (fromleaf) | |
991 | /* A frameless inner-most frame. The `FP' (which isn't an | |
992 | architecture frame-pointer register!) of the caller is the same | |
993 | as the callee. */ | |
994 | /* FIXME: 2002-11-09: There isn't any reason to special case this | |
995 | edge condition. Instead the per-architecture code should hande | |
996 | it locally. */ | |
c193f6ac | 997 | address = get_frame_base (next_frame); |
95adb866 | 998 | else |
4c1e7e9d AC |
999 | { |
1000 | /* Two macros defined in tm.h specify the machine-dependent | |
1001 | actions to be performed here. | |
95adb866 | 1002 | |
4c1e7e9d | 1003 | First, get the frame's chain-pointer. |
95adb866 | 1004 | |
4c1e7e9d AC |
1005 | If that is zero, the frame is the outermost frame or a leaf |
1006 | called by the outermost frame. This means that if start | |
1007 | calls main without a frame, we'll return 0 (which is fine | |
1008 | anyway). | |
1009 | ||
1010 | Nope; there's a problem. This also returns when the current | |
1011 | routine is a leaf of main. This is unacceptable. We move | |
1012 | this to after the ffi test; I'd rather have backtraces from | |
1013 | start go curfluy than have an abort called from main not show | |
1014 | main. */ | |
d62d1979 | 1015 | gdb_assert (FRAME_CHAIN_P ()); |
4c1e7e9d AC |
1016 | address = FRAME_CHAIN (next_frame); |
1017 | ||
51603483 | 1018 | if (!frame_chain_valid (address, next_frame)) |
4c1e7e9d AC |
1019 | return 0; |
1020 | } | |
1021 | if (address == 0) | |
1022 | return 0; | |
1023 | ||
95adb866 | 1024 | /* Create an initially zero previous frame. */ |
479ab5a0 | 1025 | prev = frame_obstack_zalloc (sizeof (struct frame_info)); |
4c1e7e9d | 1026 | |
95adb866 AC |
1027 | /* Link it in. */ |
1028 | next_frame->prev = prev; | |
4c1e7e9d AC |
1029 | prev->next = next_frame; |
1030 | prev->frame = address; | |
1031 | prev->level = next_frame->level + 1; | |
5a203e44 AC |
1032 | /* FIXME: cagney/2002-11-18: Should be setting the frame's type |
1033 | here, before anything else, and not last. Various INIT functions | |
1034 | are full of work-arounds for the frames type not being set | |
1035 | correctly from the word go. Ulgh! */ | |
1036 | prev->type = NORMAL_FRAME; | |
4c1e7e9d | 1037 | |
95adb866 | 1038 | /* This change should not be needed, FIXME! We should determine |
a5afb99f | 1039 | whether any targets *need* DEPRECATED_INIT_FRAME_PC to happen |
e9582e71 AC |
1040 | after DEPRECATED_INIT_EXTRA_FRAME_INFO and come up with a simple |
1041 | way to express what goes on here. | |
95adb866 | 1042 | |
e9582e71 AC |
1043 | DEPRECATED_INIT_EXTRA_FRAME_INFO is called from two places: |
1044 | create_new_frame (where the PC is already set up) and here (where | |
1045 | it isn't). DEPRECATED_INIT_FRAME_PC is only called from here, | |
1046 | always after DEPRECATED_INIT_EXTRA_FRAME_INFO. | |
95adb866 | 1047 | |
e9582e71 AC |
1048 | The catch is the MIPS, where DEPRECATED_INIT_EXTRA_FRAME_INFO |
1049 | requires the PC value (which hasn't been set yet). Some other | |
1050 | machines appear to require DEPRECATED_INIT_EXTRA_FRAME_INFO | |
1051 | before they can do DEPRECATED_INIT_FRAME_PC. Phoo. | |
95adb866 | 1052 | |
2ca6c561 AC |
1053 | We shouldn't need DEPRECATED_INIT_FRAME_PC_FIRST to add more |
1054 | complication to an already overcomplicated part of GDB. | |
1055 | gnu@cygnus.com, 15Sep92. | |
95adb866 | 1056 | |
a5afb99f | 1057 | Assuming that some machines need DEPRECATED_INIT_FRAME_PC after |
e9582e71 | 1058 | DEPRECATED_INIT_EXTRA_FRAME_INFO, one possible scheme: |
95adb866 AC |
1059 | |
1060 | SETUP_INNERMOST_FRAME(): Default version is just create_new_frame | |
1061 | (read_fp ()), read_pc ()). Machines with extra frame info would | |
1062 | do that (or the local equivalent) and then set the extra fields. | |
1063 | ||
1064 | SETUP_ARBITRARY_FRAME(argc, argv): Only change here is that | |
1065 | create_new_frame would no longer init extra frame info; | |
1066 | SETUP_ARBITRARY_FRAME would have to do that. | |
1067 | ||
e9582e71 AC |
1068 | INIT_PREV_FRAME(fromleaf, prev) Replace |
1069 | DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC. | |
1070 | This should also return a flag saying whether to keep the new | |
1071 | frame, or whether to discard it, because on some machines (e.g. | |
1072 | mips) it is really awkward to have FRAME_CHAIN_VALID called | |
1073 | BEFORE DEPRECATED_INIT_EXTRA_FRAME_INFO (there is no good way to | |
1074 | get information deduced in FRAME_CHAIN_VALID into the extra | |
1075 | fields of the new frame). std_frame_pc(fromleaf, prev) | |
95adb866 AC |
1076 | |
1077 | This is the default setting for INIT_PREV_FRAME. It just does | |
a5afb99f AC |
1078 | what the default DEPRECATED_INIT_FRAME_PC does. Some machines |
1079 | will call it from INIT_PREV_FRAME (either at the beginning, the | |
1080 | end, or in the middle). Some machines won't use it. | |
95adb866 AC |
1081 | |
1082 | kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */ | |
1083 | ||
1084 | /* NOTE: cagney/2002-11-09: Just ignore the above! There is no | |
1085 | reason for things to be this complicated. | |
1086 | ||
1087 | The trick is to assume that there is always a frame. Instead of | |
1088 | special casing the inner-most frame, create fake frame | |
1089 | (containing the hardware registers) that is inner to the | |
1090 | user-visible inner-most frame (...) and then unwind from that. | |
1091 | That way architecture code can use use the standard | |
1092 | frame_XX_unwind() functions and not differentiate between the | |
1093 | inner most and any other case. | |
1094 | ||
1095 | Since there is always a frame to unwind from, there is always | |
1096 | somewhere (NEXT_FRAME) to store all the info needed to construct | |
1097 | a new (previous) frame without having to first create it. This | |
1098 | means that the convolution below - needing to carefully order a | |
1099 | frame's initialization - isn't needed. | |
1100 | ||
1101 | The irony here though, is that FRAME_CHAIN(), at least for a more | |
1102 | up-to-date architecture, always calls FRAME_SAVED_PC(), and | |
1103 | FRAME_SAVED_PC() computes the PC but without first needing the | |
1104 | frame! Instead of the convolution below, we could have simply | |
1105 | called FRAME_SAVED_PC() and been done with it! Note that | |
1106 | FRAME_SAVED_PC() is being superseed by frame_pc_unwind() and that | |
1107 | function does have somewhere to cache that PC value. */ | |
4c1e7e9d | 1108 | |
2ca6c561 | 1109 | if (DEPRECATED_INIT_FRAME_PC_FIRST_P ()) |
97f46953 | 1110 | prev->pc = (DEPRECATED_INIT_FRAME_PC_FIRST (fromleaf, prev)); |
4c1e7e9d | 1111 | |
e9582e71 AC |
1112 | if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ()) |
1113 | DEPRECATED_INIT_EXTRA_FRAME_INFO (fromleaf, prev); | |
4c1e7e9d AC |
1114 | |
1115 | /* This entry is in the frame queue now, which is good since | |
95adb866 AC |
1116 | FRAME_SAVED_PC may use that queue to figure out its value (see |
1117 | tm-sparc.h). We want the pc saved in the inferior frame. */ | |
a5afb99f AC |
1118 | if (DEPRECATED_INIT_FRAME_PC_P ()) |
1119 | prev->pc = DEPRECATED_INIT_FRAME_PC (fromleaf, prev); | |
4c1e7e9d | 1120 | |
95adb866 AC |
1121 | /* If ->frame and ->pc are unchanged, we are in the process of |
1122 | getting ourselves into an infinite backtrace. Some architectures | |
1123 | check this in FRAME_CHAIN or thereabouts, but it seems like there | |
1124 | is no reason this can't be an architecture-independent check. */ | |
1125 | if (prev->frame == next_frame->frame | |
1126 | && prev->pc == next_frame->pc) | |
4c1e7e9d | 1127 | { |
95adb866 AC |
1128 | next_frame->prev = NULL; |
1129 | obstack_free (&frame_cache_obstack, prev); | |
1130 | return NULL; | |
4c1e7e9d AC |
1131 | } |
1132 | ||
1133 | /* Initialize the code used to unwind the frame PREV based on the PC | |
1134 | (and probably other architectural information). The PC lets you | |
1135 | check things like the debug info at that point (dwarf2cfi?) and | |
1136 | use that to decide how the frame should be unwound. */ | |
494cca16 | 1137 | prev->unwind = frame_unwind_find_by_pc (current_gdbarch, prev->pc); |
4c1e7e9d | 1138 | |
5a203e44 AC |
1139 | /* NOTE: cagney/2002-11-18: The code segments, found in |
1140 | create_new_frame and get_prev_frame(), that initializes the | |
1141 | frames type is subtly different. The latter only updates ->type | |
1142 | when it encounters a SIGTRAMP_FRAME or DUMMY_FRAME. This stops | |
1143 | get_prev_frame() overriding the frame's type when the INIT code | |
1144 | has previously set it. This is really somewhat bogus. The | |
1145 | initialization, as seen in create_new_frame(), should occur | |
1146 | before the INIT function has been called. */ | |
07555a72 | 1147 | if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES |
ae45cd16 AC |
1148 | && (DEPRECATED_PC_IN_CALL_DUMMY_P () |
1149 | ? DEPRECATED_PC_IN_CALL_DUMMY (prev->pc, 0, 0) | |
1150 | : pc_in_dummy_frame (prev->pc))) | |
5a203e44 AC |
1151 | prev->type = DUMMY_FRAME; |
1152 | else | |
1153 | { | |
1154 | /* FIXME: cagney/2002-11-10: This should be moved to before the | |
1155 | INIT code above so that the INIT code knows what the frame's | |
1156 | type is (in fact, for a [generic] dummy-frame, the type can | |
1157 | be set and then the entire initialization can be skipped. | |
1158 | Unforunatly, its the INIT code that sets the PC (Hmm, catch | |
1159 | 22). */ | |
1160 | char *name; | |
1161 | find_pc_partial_function (prev->pc, &name, NULL, NULL); | |
1162 | if (PC_IN_SIGTRAMP (prev->pc, name)) | |
1163 | prev->type = SIGTRAMP_FRAME; | |
1164 | /* FIXME: cagney/2002-11-11: Leave prev->type alone. Some | |
1165 | architectures are forcing the frame's type in INIT so we | |
1166 | don't want to override it here. Remember, NORMAL_FRAME == 0, | |
1167 | so it all works (just :-/). Once this initialization is | |
1168 | moved to the start of this function, all this nastness will | |
1169 | go away. */ | |
1170 | } | |
4c1e7e9d AC |
1171 | |
1172 | return prev; | |
1173 | } | |
1174 | ||
eb4f72c5 AC |
1175 | /* Return a structure containing various interesting information |
1176 | about the frame that called NEXT_FRAME. Returns NULL | |
1177 | if there is no such frame. */ | |
1178 | ||
1179 | struct frame_info * | |
1180 | get_prev_frame (struct frame_info *next_frame) | |
1181 | { | |
1182 | struct frame_info *prev_frame; | |
1183 | ||
1184 | /* Return the inner-most frame, when the caller passes in NULL. */ | |
1185 | /* NOTE: cagney/2002-11-09: Not sure how this would happen. The | |
1186 | caller should have previously obtained a valid frame using | |
1187 | get_selected_frame() and then called this code - only possibility | |
1188 | I can think of is code behaving badly. | |
1189 | ||
1190 | NOTE: cagney/2003-01-10: Talk about code behaving badly. Check | |
1191 | block_innermost_frame(). It does the sequence: frame = NULL; | |
1192 | while (1) { frame = get_prev_frame (frame); .... }. Ulgh! Why | |
1193 | it couldn't be written better, I don't know. | |
1194 | ||
1195 | NOTE: cagney/2003-01-11: I suspect what is happening is | |
1196 | block_innermost_frame() is, when the target has no state | |
1197 | (registers, memory, ...), still calling this function. The | |
1198 | assumption being that this function will return NULL indicating | |
1199 | that a frame isn't possible, rather than checking that the target | |
1200 | has state and then calling get_current_frame() and | |
1201 | get_prev_frame(). This is a guess mind. */ | |
1202 | if (next_frame == NULL) | |
1203 | { | |
1204 | /* NOTE: cagney/2002-11-09: There was a code segment here that | |
1205 | would error out when CURRENT_FRAME was NULL. The comment | |
1206 | that went with it made the claim ... | |
1207 | ||
1208 | ``This screws value_of_variable, which just wants a nice | |
1209 | clean NULL return from block_innermost_frame if there are no | |
1210 | frames. I don't think I've ever seen this message happen | |
1211 | otherwise. And returning NULL here is a perfectly legitimate | |
1212 | thing to do.'' | |
1213 | ||
1214 | Per the above, this code shouldn't even be called with a NULL | |
1215 | NEXT_FRAME. */ | |
1216 | return current_frame; | |
1217 | } | |
1218 | ||
1219 | /* There is always a frame. If this assertion fails, suspect that | |
1220 | something should be calling get_selected_frame() or | |
1221 | get_current_frame(). */ | |
1222 | gdb_assert (next_frame != NULL); | |
1223 | ||
1224 | if (next_frame->level >= 0 | |
1225 | && !backtrace_below_main | |
1226 | && inside_main_func (get_frame_pc (next_frame))) | |
1227 | /* Don't unwind past main(), bug always unwind the sentinel frame. | |
1228 | Note, this is done _before_ the frame has been marked as | |
1229 | previously unwound. That way if the user later decides to | |
1230 | allow unwinds past main(), that just happens. */ | |
ac2bd0a9 AC |
1231 | { |
1232 | if (frame_debug) | |
1233 | fprintf_unfiltered (gdb_stdlog, | |
1234 | "Outermost frame - inside main func.\n"); | |
1235 | return NULL; | |
1236 | } | |
eb4f72c5 AC |
1237 | |
1238 | /* Only try to do the unwind once. */ | |
1239 | if (next_frame->prev_p) | |
1240 | return next_frame->prev; | |
1241 | next_frame->prev_p = 1; | |
1242 | ||
b14185ce AC |
1243 | /* If we're inside the entry file, it isn't valid. Don't apply this |
1244 | test to a dummy frame - dummy frame PC's typically land in the | |
1245 | entry file. Don't apply this test to the sentinel frame. | |
1246 | Sentinel frames should always be allowed to unwind. */ | |
eb4f72c5 AC |
1247 | /* NOTE: drow/2002-12-25: should there be a way to disable this |
1248 | check? It assumes a single small entry file, and the way some | |
1249 | debug readers (e.g. dbxread) figure out which object is the | |
1250 | entry file is somewhat hokey. */ | |
1251 | /* NOTE: cagney/2003-01-10: If there is a way of disabling this test | |
1252 | then it should probably be moved to before the ->prev_p test, | |
1253 | above. */ | |
b14185ce AC |
1254 | if (next_frame->type != DUMMY_FRAME && next_frame->level >= 0 |
1255 | && inside_entry_file (get_frame_pc (next_frame))) | |
ac2bd0a9 AC |
1256 | { |
1257 | if (frame_debug) | |
1258 | fprintf_unfiltered (gdb_stdlog, | |
1259 | "Outermost frame - inside entry file\n"); | |
eb4f72c5 | 1260 | return NULL; |
ac2bd0a9 | 1261 | } |
eb4f72c5 | 1262 | |
b14185ce AC |
1263 | /* If we're already inside the entry function for the main objfile, |
1264 | then it isn't valid. Don't apply this test to a dummy frame - | |
1265 | dummy frame PC's typically land in the entry func. Don't apply | |
1266 | this test to the sentinel frame. Sentinel frames should always | |
1267 | be allowed to unwind. */ | |
1268 | /* NOTE: cagney/2003-02-25: Don't enable until someone has found | |
1269 | hard evidence that this is needed. */ | |
1270 | if (0 | |
1271 | && next_frame->type != DUMMY_FRAME && next_frame->level >= 0 | |
1272 | && inside_entry_func (get_frame_pc (next_frame))) | |
1273 | { | |
1274 | if (frame_debug) | |
1275 | fprintf_unfiltered (gdb_stdlog, | |
1276 | "Outermost frame - inside entry func\n"); | |
1277 | return NULL; | |
1278 | } | |
1279 | ||
eb4f72c5 AC |
1280 | /* If any of the old frame initialization methods are around, use |
1281 | the legacy get_prev_frame method. Just don't try to unwind a | |
1282 | sentinel frame using that method - it doesn't work. All sentinal | |
1283 | frames use the new unwind code. */ | |
1284 | if ((DEPRECATED_INIT_FRAME_PC_P () | |
1285 | || DEPRECATED_INIT_FRAME_PC_FIRST_P () | |
e9582e71 | 1286 | || DEPRECATED_INIT_EXTRA_FRAME_INFO_P () |
d62d1979 | 1287 | || FRAME_CHAIN_P ()) |
eb4f72c5 | 1288 | && next_frame->level >= 0) |
ac2bd0a9 AC |
1289 | { |
1290 | prev_frame = legacy_get_prev_frame (next_frame); | |
1291 | if (frame_debug && prev_frame == NULL) | |
1292 | fprintf_unfiltered (gdb_stdlog, | |
1293 | "Outermost frame - legacy_get_prev_frame NULL.\n"); | |
1294 | return prev_frame; | |
1295 | } | |
eb4f72c5 AC |
1296 | |
1297 | /* Allocate the new frame but do not wire it in to the frame chain. | |
1298 | Some (bad) code in INIT_FRAME_EXTRA_INFO tries to look along | |
1299 | frame->next to pull some fancy tricks (of course such code is, by | |
1300 | definition, recursive). Try to prevent it. | |
1301 | ||
1302 | There is no reason to worry about memory leaks, should the | |
1303 | remainder of the function fail. The allocated memory will be | |
1304 | quickly reclaimed when the frame cache is flushed, and the `we've | |
1305 | been here before' check above will stop repeated memory | |
1306 | allocation calls. */ | |
1307 | prev_frame = FRAME_OBSTACK_ZALLOC (struct frame_info); | |
1308 | prev_frame->level = next_frame->level + 1; | |
1309 | ||
1310 | /* Try to unwind the PC. If that doesn't work, assume we've reached | |
1311 | the oldest frame and simply return. Is there a better sentinal | |
1312 | value? The unwound PC value is then used to initialize the new | |
1313 | previous frame's type. | |
1314 | ||
1315 | Note that the pc-unwind is intentionally performed before the | |
1316 | frame chain. This is ok since, for old targets, both | |
1317 | frame_pc_unwind (nee, FRAME_SAVED_PC) and FRAME_CHAIN()) assume | |
1318 | NEXT_FRAME's data structures have already been initialized (using | |
e9582e71 AC |
1319 | DEPRECATED_INIT_EXTRA_FRAME_INFO) and hence the call order |
1320 | doesn't matter. | |
eb4f72c5 AC |
1321 | |
1322 | By unwinding the PC first, it becomes possible to, in the case of | |
1323 | a dummy frame, avoid also unwinding the frame ID. This is | |
1324 | because (well ignoring the PPC) a dummy frame can be located | |
1325 | using NEXT_FRAME's frame ID. */ | |
1326 | ||
1327 | prev_frame->pc = frame_pc_unwind (next_frame); | |
1328 | if (prev_frame->pc == 0) | |
ac2bd0a9 AC |
1329 | { |
1330 | /* The allocated PREV_FRAME will be reclaimed when the frame | |
1331 | obstack is next purged. */ | |
1332 | if (frame_debug) | |
1333 | fprintf_unfiltered (gdb_stdlog, | |
1334 | "Outermost frame - unwound PC zero\n"); | |
1335 | return NULL; | |
1336 | } | |
eb4f72c5 AC |
1337 | prev_frame->type = frame_type_from_pc (prev_frame->pc); |
1338 | ||
1339 | /* Set the unwind functions based on that identified PC. */ | |
1340 | prev_frame->unwind = frame_unwind_find_by_pc (current_gdbarch, | |
1341 | prev_frame->pc); | |
1342 | ||
1343 | /* FIXME: cagney/2003-01-13: A dummy frame doesn't need to unwind | |
1344 | the frame ID because the frame ID comes from the previous frame. | |
1345 | The other frames do though. True? */ | |
1346 | { | |
1347 | /* FIXME: cagney/2002-12-18: Instead of this hack, should just | |
1348 | save the frame ID directly. */ | |
1349 | struct frame_id id = frame_id_unwind (next_frame); | |
b14185ce AC |
1350 | /* Check that the unwound ID is valid. As of 2003-02-24 the |
1351 | x86-64 was returning an invalid frame ID when trying to do an | |
1352 | unwind a sentinel frame that belonged to a frame dummy. */ | |
eb4f72c5 | 1353 | if (!frame_id_p (id)) |
ac2bd0a9 AC |
1354 | { |
1355 | if (frame_debug) | |
1356 | fprintf_unfiltered (gdb_stdlog, | |
1357 | "Outermost frame - unwound frame ID invalid\n"); | |
1358 | return NULL; | |
1359 | } | |
b14185ce AC |
1360 | /* Check that the new frame isn't inner to (younger, below, next) |
1361 | the old frame. If that happens the frame unwind is going | |
1362 | backwards. */ | |
1363 | /* FIXME: cagney/2003-02-25: Ignore the sentinel frame since that | |
1364 | doesn't have a valid frame ID. Should instead set the sentinel | |
1365 | frame's frame ID to a `sentinel'. Leave it until after the | |
1366 | switch to storing the frame ID, instead of the frame base, in | |
1367 | the frame object. */ | |
1368 | if (next_frame->level >= 0 | |
1369 | && frame_id_inner (id, get_frame_id (next_frame))) | |
1370 | error ("Unwound frame inner-to selected frame (corrupt stack?)"); | |
1371 | /* Note that, due to frameless functions, the stronger test of the | |
1372 | new frame being outer to the old frame can't be used - | |
1373 | frameless functions differ by only their PC value. */ | |
eb4f72c5 AC |
1374 | prev_frame->frame = id.base; |
1375 | } | |
1376 | ||
1377 | /* Link it in. */ | |
1378 | next_frame->prev = prev_frame; | |
1379 | prev_frame->next = next_frame; | |
1380 | ||
1381 | /* FIXME: cagney/2002-01-19: This call will go away. Instead of | |
1382 | initializing extra info, all frames will use the frame_cache | |
1383 | (passed to the unwind functions) to store additional frame info. | |
1384 | Unfortunatly legacy targets can't use legacy_get_prev_frame() to | |
1385 | unwind the sentinel frame and, consequently, are forced to take | |
e9582e71 AC |
1386 | this code path and rely on the below call to |
1387 | DEPRECATED_INIT_EXTRA_FRAME_INFO to initialize the inner-most | |
1388 | frame. */ | |
1389 | if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ()) | |
eb4f72c5 AC |
1390 | { |
1391 | gdb_assert (prev_frame->level == 0); | |
e9582e71 | 1392 | DEPRECATED_INIT_EXTRA_FRAME_INFO (0, prev_frame); |
eb4f72c5 AC |
1393 | } |
1394 | ||
1395 | return prev_frame; | |
1396 | } | |
1397 | ||
4c1e7e9d AC |
1398 | CORE_ADDR |
1399 | get_frame_pc (struct frame_info *frame) | |
1400 | { | |
1401 | return frame->pc; | |
1402 | } | |
1403 | ||
1058bca7 AC |
1404 | static int |
1405 | pc_notcurrent (struct frame_info *frame) | |
1406 | { | |
1407 | /* If FRAME is not the innermost frame, that normally means that | |
1408 | FRAME->pc points at the return instruction (which is *after* the | |
1409 | call instruction), and we want to get the line containing the | |
1410 | call (because the call is where the user thinks the program is). | |
1411 | However, if the next frame is either a SIGTRAMP_FRAME or a | |
1412 | DUMMY_FRAME, then the next frame will contain a saved interrupt | |
1413 | PC and such a PC indicates the current (rather than next) | |
1414 | instruction/line, consequently, for such cases, want to get the | |
1415 | line containing fi->pc. */ | |
1416 | struct frame_info *next = get_next_frame (frame); | |
1417 | int notcurrent = (next != NULL && get_frame_type (next) == NORMAL_FRAME); | |
1418 | return notcurrent; | |
1419 | } | |
1420 | ||
1421 | void | |
1422 | find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal) | |
1423 | { | |
1424 | (*sal) = find_pc_line (frame->pc, pc_notcurrent (frame)); | |
1425 | } | |
1426 | ||
c193f6ac AC |
1427 | /* Per "frame.h", return the ``address'' of the frame. Code should |
1428 | really be using get_frame_id(). */ | |
1429 | CORE_ADDR | |
1430 | get_frame_base (struct frame_info *fi) | |
1431 | { | |
1432 | return fi->frame; | |
1433 | } | |
1434 | ||
85cf597a AC |
1435 | /* Level of the selected frame: 0 for innermost, 1 for its caller, ... |
1436 | or -1 for a NULL frame. */ | |
1437 | ||
1438 | int | |
1439 | frame_relative_level (struct frame_info *fi) | |
1440 | { | |
1441 | if (fi == NULL) | |
1442 | return -1; | |
1443 | else | |
1444 | return fi->level; | |
1445 | } | |
1446 | ||
5a203e44 AC |
1447 | enum frame_type |
1448 | get_frame_type (struct frame_info *frame) | |
1449 | { | |
1450 | /* Some targets still don't use [generic] dummy frames. Catch them | |
1451 | here. */ | |
07555a72 | 1452 | if (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES |
5a203e44 AC |
1453 | && deprecated_frame_in_dummy (frame)) |
1454 | return DUMMY_FRAME; | |
1455 | return frame->type; | |
1456 | } | |
1457 | ||
1458 | void | |
1459 | deprecated_set_frame_type (struct frame_info *frame, enum frame_type type) | |
1460 | { | |
1461 | /* Arrrg! See comment in "frame.h". */ | |
1462 | frame->type = type; | |
1463 | } | |
1464 | ||
4c1e7e9d AC |
1465 | #ifdef FRAME_FIND_SAVED_REGS |
1466 | /* XXX - deprecated. This is a compatibility function for targets | |
1467 | that do not yet implement FRAME_INIT_SAVED_REGS. */ | |
1468 | /* Find the addresses in which registers are saved in FRAME. */ | |
1469 | ||
1470 | void | |
95486978 AC |
1471 | deprecated_get_frame_saved_regs (struct frame_info *frame, |
1472 | struct frame_saved_regs *saved_regs_addr) | |
4c1e7e9d AC |
1473 | { |
1474 | if (frame->saved_regs == NULL) | |
1475 | { | |
1476 | frame->saved_regs = (CORE_ADDR *) | |
479ab5a0 | 1477 | frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS); |
4c1e7e9d AC |
1478 | } |
1479 | if (saved_regs_addr == NULL) | |
1480 | { | |
1481 | struct frame_saved_regs saved_regs; | |
1482 | FRAME_FIND_SAVED_REGS (frame, saved_regs); | |
1483 | memcpy (frame->saved_regs, &saved_regs, SIZEOF_FRAME_SAVED_REGS); | |
1484 | } | |
1485 | else | |
1486 | { | |
1487 | FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr); | |
1488 | memcpy (frame->saved_regs, saved_regs_addr, SIZEOF_FRAME_SAVED_REGS); | |
1489 | } | |
1490 | } | |
1491 | #endif | |
1492 | ||
0394eb2a AC |
1493 | struct frame_extra_info * |
1494 | get_frame_extra_info (struct frame_info *fi) | |
1495 | { | |
1496 | return fi->extra_info; | |
1497 | } | |
1498 | ||
2c517d0e AC |
1499 | struct frame_extra_info * |
1500 | frame_extra_info_zalloc (struct frame_info *fi, long size) | |
1501 | { | |
479ab5a0 | 1502 | fi->extra_info = frame_obstack_zalloc (size); |
2c517d0e AC |
1503 | return fi->extra_info; |
1504 | } | |
1505 | ||
b87efeee | 1506 | void |
2f107107 | 1507 | deprecated_update_frame_pc_hack (struct frame_info *frame, CORE_ADDR pc) |
b87efeee | 1508 | { |
2f107107 | 1509 | /* See comment in "frame.h". */ |
a94dd1fd | 1510 | gdb_assert (frame->next != NULL); |
2f107107 AC |
1511 | frame->pc = pc; |
1512 | } | |
1513 | ||
1514 | void | |
1515 | deprecated_update_frame_base_hack (struct frame_info *frame, CORE_ADDR base) | |
1516 | { | |
1517 | /* See comment in "frame.h". */ | |
1518 | frame->frame = base; | |
b87efeee AC |
1519 | } |
1520 | ||
c8b8a898 AC |
1521 | void |
1522 | deprecated_set_frame_saved_regs_hack (struct frame_info *frame, | |
1523 | CORE_ADDR *saved_regs) | |
1524 | { | |
1525 | frame->saved_regs = saved_regs; | |
1526 | } | |
1527 | ||
1528 | void | |
1529 | deprecated_set_frame_extra_info_hack (struct frame_info *frame, | |
1530 | struct frame_extra_info *extra_info) | |
1531 | { | |
1532 | frame->extra_info = extra_info; | |
1533 | } | |
1534 | ||
483d36b2 AC |
1535 | void |
1536 | deprecated_set_frame_next_hack (struct frame_info *fi, | |
1537 | struct frame_info *next) | |
1538 | { | |
1539 | fi->next = next; | |
1540 | } | |
1541 | ||
1542 | void | |
1543 | deprecated_set_frame_prev_hack (struct frame_info *fi, | |
1544 | struct frame_info *prev) | |
1545 | { | |
1546 | fi->prev = prev; | |
1547 | } | |
1548 | ||
2d75187b AC |
1549 | struct context * |
1550 | deprecated_get_frame_context (struct frame_info *fi) | |
1551 | { | |
1552 | return fi->context; | |
1553 | } | |
1554 | ||
1555 | void | |
1556 | deprecated_set_frame_context (struct frame_info *fi, | |
1557 | struct context *context) | |
1558 | { | |
1559 | fi->context = context; | |
1560 | } | |
1561 | ||
c8b8a898 AC |
1562 | struct frame_info * |
1563 | deprecated_frame_xmalloc (void) | |
1564 | { | |
1565 | struct frame_info *frame = XMALLOC (struct frame_info); | |
1566 | memset (frame, 0, sizeof (struct frame_info)); | |
1567 | return frame; | |
1568 | } | |
1569 | ||
f6c609c4 AC |
1570 | struct frame_info * |
1571 | deprecated_frame_xmalloc_with_cleanup (long sizeof_saved_regs, | |
1572 | long sizeof_extra_info) | |
1573 | { | |
1574 | struct frame_info *frame = deprecated_frame_xmalloc (); | |
1575 | make_cleanup (xfree, frame); | |
1576 | if (sizeof_saved_regs > 0) | |
1577 | { | |
1578 | frame->saved_regs = xcalloc (1, sizeof_saved_regs); | |
1579 | make_cleanup (xfree, frame->saved_regs); | |
1580 | } | |
1581 | if (sizeof_extra_info > 0) | |
1582 | { | |
1583 | frame->extra_info = xcalloc (1, sizeof_extra_info); | |
1584 | make_cleanup (xfree, frame->extra_info); | |
1585 | } | |
1586 | return frame; | |
1587 | } | |
c8b8a898 | 1588 | |
4c1e7e9d AC |
1589 | void |
1590 | _initialize_frame (void) | |
1591 | { | |
1592 | obstack_init (&frame_cache_obstack); | |
eb4f72c5 AC |
1593 | |
1594 | /* FIXME: cagney/2003-01-19: This command needs a rename. Suggest | |
1595 | `set backtrace {past,beyond,...}-main'. Also suggest adding `set | |
1596 | backtrace ...-start' to control backtraces past start. The | |
1597 | problem with `below' is that it stops the `up' command. */ | |
1598 | ||
1599 | add_setshow_boolean_cmd ("backtrace-below-main", class_obscure, | |
1600 | &backtrace_below_main, "\ | |
1601 | Set whether backtraces should continue past \"main\".\n\ | |
1602 | Normally the caller of \"main\" is not of interest, so GDB will terminate\n\ | |
1603 | the backtrace at \"main\". Set this variable if you need to see the rest\n\ | |
1604 | of the stack trace.", "\ | |
1605 | Show whether backtraces should continue past \"main\".\n\ | |
1606 | Normally the caller of \"main\" is not of interest, so GDB will terminate\n\ | |
1607 | the backtrace at \"main\". Set this variable if you need to see the rest\n\ | |
1608 | of the stack trace.", | |
1609 | NULL, NULL, &setlist, &showlist); | |
ac2bd0a9 AC |
1610 | |
1611 | ||
1612 | /* Debug this files internals. */ | |
1613 | add_show_from_set (add_set_cmd ("frame", class_maintenance, var_zinteger, | |
1614 | &frame_debug, "Set frame debugging.\n\ | |
1615 | When non-zero, frame specific internal debugging is enabled.", &setdebuglist), | |
1616 | &showdebuglist); | |
4c1e7e9d | 1617 | } |