]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/frame.c
2003-01-07 Andrew Cagney <cagney@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / frame.c
CommitLineData
b0c6b05c 1#define FRAME_C
4f460812 2/* Cache and manage frames for GDB, the GNU debugger.
96cb11df
AC
3
4 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
51603483 5 2001, 2002, 2003 Free Software Foundation, Inc.
d65fe839
AC
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24#include "defs.h"
25#include "frame.h"
26#include "target.h"
27#include "value.h"
39f77062 28#include "inferior.h" /* for inferior_ptid */
4e052eda 29#include "regcache.h"
4f460812 30#include "gdb_assert.h"
e36180d7
AC
31#include "gdb_string.h"
32#include "builtin-regs.h"
4c1e7e9d
AC
33#include "gdb_obstack.h"
34#include "dummy-frame.h"
35#include "gdbcore.h"
36#include "annotate.h"
6e7f8b9c 37#include "language.h"
d65fe839 38
7a424e99 39/* Return a frame uniq ID that can be used to, later, re-find the
101dcfbe
AC
40 frame. */
41
7a424e99
AC
42struct frame_id
43get_frame_id (struct frame_info *fi)
101dcfbe
AC
44{
45 if (fi == NULL)
46 {
7a424e99 47 return null_frame_id;
101dcfbe
AC
48 }
49 else
50 {
7a424e99
AC
51 struct frame_id id;
52 id.base = fi->frame;
53 id.pc = fi->pc;
54 return id;
101dcfbe
AC
55 }
56}
57
7a424e99
AC
58const struct frame_id null_frame_id; /* All zeros. */
59
60struct frame_id
61frame_id_build (CORE_ADDR base, CORE_ADDR func_or_pc)
62{
63 struct frame_id id;
64 id.base = base;
65 id.pc = func_or_pc;
66 return id;
67}
68
69int
70frame_id_p (struct frame_id l)
71{
72 /* The .func can be NULL but the .base cannot. */
73 return (l.base != 0);
74}
75
76int
77frame_id_eq (struct frame_id l, struct frame_id r)
78{
79 /* If .base is different, the frames are different. */
80 if (l.base != r.base)
81 return 0;
82 /* Add a test to check that the frame ID's are for the same function
83 here. */
84 return 1;
85}
86
87int
88frame_id_inner (struct frame_id l, struct frame_id r)
89{
90 /* Only return non-zero when strictly inner than. Note that, per
91 comment in "frame.h", there is some fuzz here. Frameless
92 functions are not strictly inner than (same .base but different
93 .func). */
94 return INNER_THAN (l.base, r.base);
95}
96
101dcfbe
AC
97struct frame_info *
98frame_find_by_id (struct frame_id id)
99{
100 struct frame_info *frame;
101
102 /* ZERO denotes the null frame, let the caller decide what to do
103 about it. Should it instead return get_current_frame()? */
7a424e99 104 if (!frame_id_p (id))
101dcfbe
AC
105 return NULL;
106
107 for (frame = get_current_frame ();
108 frame != NULL;
109 frame = get_prev_frame (frame))
110 {
7a424e99
AC
111 struct frame_id this = get_frame_id (frame);
112 if (frame_id_eq (id, this))
113 /* An exact match. */
114 return frame;
115 if (frame_id_inner (id, this))
116 /* Gone to far. */
101dcfbe 117 return NULL;
7a424e99
AC
118 /* Either, we're not yet gone far enough out along the frame
119 chain (inner(this,id), or we're comparing frameless functions
120 (same .base, different .func, no test available). Struggle
121 on until we've definitly gone to far. */
101dcfbe
AC
122 }
123 return NULL;
124}
125
f18c5a73
AC
126CORE_ADDR
127frame_pc_unwind (struct frame_info *frame)
128{
129 if (!frame->pc_unwind_cache_p)
130 {
131 frame->pc_unwind_cache = frame->pc_unwind (frame, &frame->unwind_cache);
132 frame->pc_unwind_cache_p = 1;
133 }
134 return frame->pc_unwind_cache;
135}
136
c689142b
AC
137struct frame_id
138frame_id_unwind (struct frame_info *frame)
139{
140 if (!frame->id_unwind_cache_p)
141 {
142 frame->id_unwind_cache =
143 frame->id_unwind (frame, &frame->unwind_cache);
144 frame->id_unwind_cache_p = 1;
145 }
146 return frame->id_unwind_cache;
147}
148
149
4f460812
AC
150void
151frame_register_unwind (struct frame_info *frame, int regnum,
152 int *optimizedp, enum lval_type *lvalp,
153 CORE_ADDR *addrp, int *realnump, void *bufferp)
154{
155 struct frame_unwind_cache *cache;
156
157 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
158 that the value proper does not need to be fetched. */
159 gdb_assert (optimizedp != NULL);
160 gdb_assert (lvalp != NULL);
161 gdb_assert (addrp != NULL);
162 gdb_assert (realnump != NULL);
163 /* gdb_assert (bufferp != NULL); */
164
165 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
166 special case, there was always an inner frame dedicated to the
167 hardware registers. Unfortunatly, there is too much unwind code
168 around that looks up/down the frame chain while making the
169 assumption that each frame level is using the same unwind code. */
170
171 if (frame == NULL)
172 {
173 /* We're in the inner-most frame, get the value direct from the
174 register cache. */
175 *optimizedp = 0;
176 *lvalp = lval_register;
fa5f27c7
AC
177 /* ULGH! Code uses the offset into the raw register byte array
178 as a way of identifying a register. */
179 *addrp = REGISTER_BYTE (regnum);
4f460812
AC
180 /* Should this code test ``register_cached (regnum) < 0'' and do
181 something like set realnum to -1 when the register isn't
182 available? */
183 *realnump = regnum;
184 if (bufferp)
4caf0990 185 deprecated_read_register_gen (regnum, bufferp);
4f460812
AC
186 return;
187 }
188
189 /* Ask this frame to unwind its register. */
f18c5a73 190 frame->register_unwind (frame, &frame->unwind_cache, regnum,
4f460812
AC
191 optimizedp, lvalp, addrp, realnump, bufferp);
192}
193
a216a322
AC
194void
195frame_register (struct frame_info *frame, int regnum,
196 int *optimizedp, enum lval_type *lvalp,
197 CORE_ADDR *addrp, int *realnump, void *bufferp)
198{
199 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
200 that the value proper does not need to be fetched. */
201 gdb_assert (optimizedp != NULL);
202 gdb_assert (lvalp != NULL);
203 gdb_assert (addrp != NULL);
204 gdb_assert (realnump != NULL);
205 /* gdb_assert (bufferp != NULL); */
206
207 /* Ulgh! Old code that, for lval_register, sets ADDRP to the offset
208 of the register in the register cache. It should instead return
209 the REGNUM corresponding to that register. Translate the . */
210 if (GET_SAVED_REGISTER_P ())
211 {
212 GET_SAVED_REGISTER (bufferp, optimizedp, addrp, frame, regnum, lvalp);
213 /* Compute the REALNUM if the caller wants it. */
214 if (*lvalp == lval_register)
215 {
216 int regnum;
217 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
218 {
219 if (*addrp == register_offset_hack (current_gdbarch, regnum))
220 {
221 *realnump = regnum;
222 return;
223 }
224 }
225 internal_error (__FILE__, __LINE__,
226 "Failed to compute the register number corresponding"
227 " to 0x%s", paddr_d (*addrp));
228 }
229 *realnump = -1;
230 return;
231 }
232
233 /* Reached the the bottom (youngest, inner most) of the frame chain
234 (youngest, inner most) frame, go direct to the hardware register
235 cache (do not pass go, do not try to cache the value, ...). The
236 unwound value would have been cached in frame->next but that
237 doesn't exist. This doesn't matter as the hardware register
238 cache is stopping any unnecessary accesses to the target. */
239
240 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
241 special case, there was always an inner frame dedicated to the
242 hardware registers. Unfortunatly, there is too much unwind code
243 around that looks up/down the frame chain while making the
244 assumption that each frame level is using the same unwind code. */
245
246 if (frame == NULL)
247 frame_register_unwind (NULL, regnum, optimizedp, lvalp, addrp, realnump,
248 bufferp);
249 else
250 frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
251 realnump, bufferp);
252}
253
135c175f
AC
254void
255frame_unwind_signed_register (struct frame_info *frame, int regnum,
256 LONGEST *val)
257{
258 int optimized;
259 CORE_ADDR addr;
260 int realnum;
261 enum lval_type lval;
262 void *buf = alloca (MAX_REGISTER_RAW_SIZE);
263 frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
264 &realnum, buf);
265 (*val) = extract_signed_integer (buf, REGISTER_VIRTUAL_SIZE (regnum));
266}
267
268void
269frame_unwind_unsigned_register (struct frame_info *frame, int regnum,
270 ULONGEST *val)
271{
272 int optimized;
273 CORE_ADDR addr;
274 int realnum;
275 enum lval_type lval;
276 void *buf = alloca (MAX_REGISTER_RAW_SIZE);
277 frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
278 &realnum, buf);
279 (*val) = extract_unsigned_integer (buf, REGISTER_VIRTUAL_SIZE (regnum));
280}
4f460812 281
f908a0eb
AC
282void
283frame_read_unsigned_register (struct frame_info *frame, int regnum,
284 ULONGEST *val)
285{
286 /* NOTE: cagney/2002-10-31: There is a bit of dogma here - there is
287 always a frame. Both this, and the equivalent
288 frame_read_signed_register() function, can only be called with a
289 valid frame. If, for some reason, this function is called
290 without a frame then the problem isn't here, but rather in the
291 caller. It should of first created a frame and then passed that
292 in. */
293 /* NOTE: cagney/2002-10-31: As a side bar, keep in mind that the
294 ``current_frame'' should not be treated as a special case. While
295 ``get_next_frame (current_frame) == NULL'' currently holds, it
296 should, as far as possible, not be relied upon. In the future,
297 ``get_next_frame (current_frame)'' may instead simply return a
298 normal frame object that simply always gets register values from
299 the register cache. Consequently, frame code should try to avoid
300 tests like ``if get_next_frame() == NULL'' and instead just rely
301 on recursive frame calls (like the below code) when manipulating
302 a frame chain. */
303 gdb_assert (frame != NULL);
304 frame_unwind_unsigned_register (get_next_frame (frame), regnum, val);
305}
306
307void
308frame_read_signed_register (struct frame_info *frame, int regnum,
309 LONGEST *val)
310{
311 /* See note in frame_read_unsigned_register(). */
312 gdb_assert (frame != NULL);
313 frame_unwind_signed_register (get_next_frame (frame), regnum, val);
314}
315
18cde8d5 316static void
4f460812
AC
317generic_unwind_get_saved_register (char *raw_buffer,
318 int *optimizedp,
319 CORE_ADDR *addrp,
320 struct frame_info *frame,
321 int regnum,
322 enum lval_type *lvalp)
323{
324 int optimizedx;
325 CORE_ADDR addrx;
326 int realnumx;
327 enum lval_type lvalx;
328
329 if (!target_has_registers)
330 error ("No registers.");
331
332 /* Keep things simple, ensure that all the pointers (except valuep)
333 are non NULL. */
334 if (optimizedp == NULL)
335 optimizedp = &optimizedx;
336 if (lvalp == NULL)
337 lvalp = &lvalx;
338 if (addrp == NULL)
339 addrp = &addrx;
340
341 /* Reached the the bottom (youngest, inner most) of the frame chain
342 (youngest, inner most) frame, go direct to the hardware register
343 cache (do not pass go, do not try to cache the value, ...). The
344 unwound value would have been cached in frame->next but that
345 doesn't exist. This doesn't matter as the hardware register
346 cache is stopping any unnecessary accesses to the target. */
347
348 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
349 special case, there was always an inner frame dedicated to the
350 hardware registers. Unfortunatly, there is too much unwind code
351 around that looks up/down the frame chain while making the
352 assumption that each frame level is using the same unwind code. */
353
354 if (frame == NULL)
355 frame_register_unwind (NULL, regnum, optimizedp, lvalp, addrp, &realnumx,
356 raw_buffer);
357 else
358 frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
359 &realnumx, raw_buffer);
360}
361
d65fe839
AC
362void
363get_saved_register (char *raw_buffer,
364 int *optimized,
365 CORE_ADDR *addrp,
366 struct frame_info *frame,
367 int regnum,
368 enum lval_type *lval)
369{
a216a322
AC
370 if (GET_SAVED_REGISTER_P ())
371 {
372 GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval);
373 return;
374 }
375 generic_unwind_get_saved_register (raw_buffer, optimized, addrp, frame,
376 regnum, lval);
d65fe839
AC
377}
378
cda5a58a 379/* frame_register_read ()
d65fe839 380
cda5a58a 381 Find and return the value of REGNUM for the specified stack frame.
d65fe839
AC
382 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
383
cda5a58a 384 Returns 0 if the register value could not be found. */
d65fe839 385
cda5a58a
AC
386int
387frame_register_read (struct frame_info *frame, int regnum, void *myaddr)
d65fe839 388{
a216a322
AC
389 int optimized;
390 enum lval_type lval;
391 CORE_ADDR addr;
392 int realnum;
393 frame_register (frame, regnum, &optimized, &lval, &addr, &realnum, myaddr);
d65fe839 394
c97dcfc7
AC
395 /* FIXME: cagney/2002-05-15: This test, is just bogus.
396
397 It indicates that the target failed to supply a value for a
398 register because it was "not available" at this time. Problem
399 is, the target still has the register and so get saved_register()
400 may be returning a value saved on the stack. */
401
d65fe839 402 if (register_cached (regnum) < 0)
cda5a58a 403 return 0; /* register value not available */
d65fe839 404
a216a322 405 return !optimized;
d65fe839 406}
e36180d7
AC
407
408
409/* Map between a frame register number and its name. A frame register
410 space is a superset of the cooked register space --- it also
411 includes builtin registers. */
412
413int
414frame_map_name_to_regnum (const char *name, int len)
415{
416 int i;
417
418 /* Search register name space. */
419 for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
420 if (REGISTER_NAME (i) && len == strlen (REGISTER_NAME (i))
421 && strncmp (name, REGISTER_NAME (i), len) == 0)
422 {
423 return i;
424 }
425
426 /* Try builtin registers. */
427 i = builtin_reg_map_name_to_regnum (name, len);
428 if (i >= 0)
429 {
430 /* A builtin register doesn't fall into the architecture's
431 register range. */
432 gdb_assert (i >= NUM_REGS + NUM_PSEUDO_REGS);
433 return i;
434 }
435
436 return -1;
437}
438
439const char *
440frame_map_regnum_to_name (int regnum)
441{
442 if (regnum < 0)
443 return NULL;
444 if (regnum < NUM_REGS + NUM_PSEUDO_REGS)
445 return REGISTER_NAME (regnum);
446 return builtin_reg_map_regnum_to_name (regnum);
447}
4c1e7e9d
AC
448
449/* Info about the innermost stack frame (contents of FP register) */
450
451static struct frame_info *current_frame;
452
453/* Cache for frame addresses already read by gdb. Valid only while
454 inferior is stopped. Control variables for the frame cache should
455 be local to this module. */
456
457static struct obstack frame_cache_obstack;
458
459void *
460frame_obstack_alloc (unsigned long size)
461{
462 return obstack_alloc (&frame_cache_obstack, size);
463}
464
6baff1d2 465CORE_ADDR *
4c1e7e9d
AC
466frame_saved_regs_zalloc (struct frame_info *fi)
467{
468 fi->saved_regs = (CORE_ADDR *)
469 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
470 memset (fi->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
6baff1d2 471 return fi->saved_regs;
4c1e7e9d
AC
472}
473
6baff1d2
AC
474CORE_ADDR *
475get_frame_saved_regs (struct frame_info *fi)
476{
477 return fi->saved_regs;
478}
4c1e7e9d
AC
479
480/* Return the innermost (currently executing) stack frame. */
481
482struct frame_info *
483get_current_frame (void)
484{
485 if (current_frame == NULL)
486 {
487 if (target_has_stack)
488 current_frame = create_new_frame (read_fp (), read_pc ());
489 else
490 error ("No stack.");
491 }
492 return current_frame;
493}
494
6e7f8b9c
AC
495/* The "selected" stack frame is used by default for local and arg
496 access. May be zero, for no selected frame. */
497
498struct frame_info *deprecated_selected_frame;
499
500/* Return the selected frame. Always non-null (unless there isn't an
501 inferior sufficient for creating a frame) in which case an error is
502 thrown. */
503
504struct frame_info *
505get_selected_frame (void)
506{
507 if (deprecated_selected_frame == NULL)
508 /* Hey! Don't trust this. It should really be re-finding the
509 last selected frame of the currently selected thread. This,
510 though, is better than nothing. */
511 select_frame (get_current_frame ());
512 /* There is always a frame. */
513 gdb_assert (deprecated_selected_frame != NULL);
514 return deprecated_selected_frame;
515}
516
517/* Select frame FI (or NULL - to invalidate the current frame). */
518
519void
520select_frame (struct frame_info *fi)
521{
522 register struct symtab *s;
523
524 deprecated_selected_frame = fi;
525 /* NOTE: cagney/2002-05-04: FI can be NULL. This occures when the
526 frame is being invalidated. */
527 if (selected_frame_level_changed_hook)
528 selected_frame_level_changed_hook (frame_relative_level (fi));
529
530 /* FIXME: kseitz/2002-08-28: It would be nice to call
531 selected_frame_level_changed_event right here, but due to limitations
532 in the current interfaces, we would end up flooding UIs with events
533 because select_frame is used extensively internally.
534
535 Once we have frame-parameterized frame (and frame-related) commands,
536 the event notification can be moved here, since this function will only
537 be called when the users selected frame is being changed. */
538
539 /* Ensure that symbols for this frame are read in. Also, determine the
540 source language of this frame, and switch to it if desired. */
541 if (fi)
542 {
543 s = find_pc_symtab (fi->pc);
544 if (s
545 && s->language != current_language->la_language
546 && s->language != language_unknown
547 && language_mode == language_mode_auto)
548 {
549 set_language (s->language);
550 }
551 }
552}
553
4c1e7e9d
AC
554/* Return the register saved in the simplistic ``saved_regs'' cache.
555 If the value isn't here AND a value is needed, try the next inner
556 most frame. */
557
558static void
559frame_saved_regs_register_unwind (struct frame_info *frame, void **cache,
560 int regnum, int *optimizedp,
561 enum lval_type *lvalp, CORE_ADDR *addrp,
562 int *realnump, void *bufferp)
563{
564 /* There is always a frame at this point. And THIS is the frame
565 we're interested in. */
566 gdb_assert (frame != NULL);
567 /* If we're using generic dummy frames, we'd better not be in a call
568 dummy. (generic_call_dummy_register_unwind ought to have been called
569 instead.) */
07555a72 570 gdb_assert (!(DEPRECATED_USE_GENERIC_DUMMY_FRAMES
5e0f933e 571 && (get_frame_type (frame) == DUMMY_FRAME)));
4c1e7e9d
AC
572
573 /* Load the saved_regs register cache. */
574 if (frame->saved_regs == NULL)
575 FRAME_INIT_SAVED_REGS (frame);
576
577 if (frame->saved_regs != NULL
578 && frame->saved_regs[regnum] != 0)
579 {
580 if (regnum == SP_REGNUM)
581 {
582 /* SP register treated specially. */
583 *optimizedp = 0;
584 *lvalp = not_lval;
585 *addrp = 0;
586 *realnump = -1;
587 if (bufferp != NULL)
588 store_address (bufferp, REGISTER_RAW_SIZE (regnum),
589 frame->saved_regs[regnum]);
590 }
591 else
592 {
593 /* Any other register is saved in memory, fetch it but cache
594 a local copy of its value. */
595 *optimizedp = 0;
596 *lvalp = lval_memory;
597 *addrp = frame->saved_regs[regnum];
598 *realnump = -1;
599 if (bufferp != NULL)
600 {
601#if 1
602 /* Save each register value, as it is read in, in a
603 frame based cache. */
604 void **regs = (*cache);
605 if (regs == NULL)
606 {
607 int sizeof_cache = ((NUM_REGS + NUM_PSEUDO_REGS)
608 * sizeof (void *));
609 regs = frame_obstack_alloc (sizeof_cache);
610 memset (regs, 0, sizeof_cache);
611 (*cache) = regs;
612 }
613 if (regs[regnum] == NULL)
614 {
615 regs[regnum]
616 = frame_obstack_alloc (REGISTER_RAW_SIZE (regnum));
617 read_memory (frame->saved_regs[regnum], regs[regnum],
618 REGISTER_RAW_SIZE (regnum));
619 }
620 memcpy (bufferp, regs[regnum], REGISTER_RAW_SIZE (regnum));
621#else
622 /* Read the value in from memory. */
623 read_memory (frame->saved_regs[regnum], bufferp,
624 REGISTER_RAW_SIZE (regnum));
625#endif
626 }
627 }
628 return;
629 }
630
631 /* No luck, assume this and the next frame have the same register
632 value. If a value is needed, pass the request on down the chain;
633 otherwise just return an indication that the value is in the same
634 register as the next frame. */
635 if (bufferp == NULL)
636 {
637 *optimizedp = 0;
638 *lvalp = lval_register;
639 *addrp = 0;
640 *realnump = regnum;
641 }
642 else
643 {
644 frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
645 realnump, bufferp);
646 }
647}
648
f18c5a73
AC
649static CORE_ADDR
650frame_saved_regs_pc_unwind (struct frame_info *frame, void **cache)
651{
652 return FRAME_SAVED_PC (frame);
653}
654
c689142b
AC
655static struct frame_id
656frame_saved_regs_id_unwind (struct frame_info *next_frame, void **cache)
657{
658 int fromleaf;
659 struct frame_id id;
660
661 if (next_frame->next == NULL)
662 /* FIXME: 2002-11-09: Frameless functions can occure anywhere in
663 the frame chain, not just the inner most frame! The generic,
664 per-architecture, frame code should handle this and the below
665 should simply be removed. */
666 fromleaf = FRAMELESS_FUNCTION_INVOCATION (next_frame);
667 else
668 fromleaf = 0;
669
670 if (fromleaf)
671 /* A frameless inner-most frame. The `FP' (which isn't an
672 architecture frame-pointer register!) of the caller is the same
673 as the callee. */
674 /* FIXME: 2002-11-09: There isn't any reason to special case this
675 edge condition. Instead the per-architecture code should hande
676 it locally. */
677 id.base = get_frame_base (next_frame);
678 else
679 {
680 /* Two macros defined in tm.h specify the machine-dependent
681 actions to be performed here.
682
683 First, get the frame's chain-pointer.
684
685 If that is zero, the frame is the outermost frame or a leaf
686 called by the outermost frame. This means that if start
687 calls main without a frame, we'll return 0 (which is fine
688 anyway).
689
690 Nope; there's a problem. This also returns when the current
691 routine is a leaf of main. This is unacceptable. We move
692 this to after the ffi test; I'd rather have backtraces from
693 start go curfluy than have an abort called from main not show
694 main. */
695 id.base = FRAME_CHAIN (next_frame);
696
51603483 697 if (!frame_chain_valid (id.base, next_frame))
c689142b
AC
698 return null_frame_id;
699 }
700 if (id.base == 0)
701 return null_frame_id;
702
703 /* FIXME: cagney/2002-06-08: This should probably return the frame's
704 function and not the PC (a.k.a. resume address). */
705 id.pc = frame_pc_unwind (next_frame);
706 return id;
707}
708
4c1e7e9d
AC
709/* Function: get_saved_register
710 Find register number REGNUM relative to FRAME and put its (raw,
711 target format) contents in *RAW_BUFFER.
712
713 Set *OPTIMIZED if the variable was optimized out (and thus can't be
714 fetched). Note that this is never set to anything other than zero
715 in this implementation.
716
717 Set *LVAL to lval_memory, lval_register, or not_lval, depending on
718 whether the value was fetched from memory, from a register, or in a
719 strange and non-modifiable way (e.g. a frame pointer which was
720 calculated rather than fetched). We will use not_lval for values
721 fetched from generic dummy frames.
722
723 Set *ADDRP to the address, either in memory or as a REGISTER_BYTE
724 offset into the registers array. If the value is stored in a dummy
725 frame, set *ADDRP to zero.
726
727 To use this implementation, define a function called
728 "get_saved_register" in your target code, which simply passes all
729 of its arguments to this function.
730
731 The argument RAW_BUFFER must point to aligned memory. */
732
733void
734deprecated_generic_get_saved_register (char *raw_buffer, int *optimized,
735 CORE_ADDR *addrp,
736 struct frame_info *frame, int regnum,
737 enum lval_type *lval)
738{
739 if (!target_has_registers)
740 error ("No registers.");
741
742 /* Normal systems don't optimize out things with register numbers. */
743 if (optimized != NULL)
744 *optimized = 0;
745
746 if (addrp) /* default assumption: not found in memory */
747 *addrp = 0;
748
749 /* Note: since the current frame's registers could only have been
750 saved by frames INTERIOR TO the current frame, we skip examining
751 the current frame itself: otherwise, we would be getting the
752 previous frame's registers which were saved by the current frame. */
753
754 while (frame && ((frame = frame->next) != NULL))
755 {
5e0f933e 756 if (get_frame_type (frame) == DUMMY_FRAME)
4c1e7e9d
AC
757 {
758 if (lval) /* found it in a CALL_DUMMY frame */
759 *lval = not_lval;
760 if (raw_buffer)
761 /* FIXME: cagney/2002-06-26: This should be via the
762 gdbarch_register_read() method so that it, on the fly,
763 constructs either a raw or pseudo register from the raw
764 register cache. */
765 regcache_raw_read (generic_find_dummy_frame (frame->pc,
766 frame->frame),
767 regnum, raw_buffer);
768 return;
769 }
770
771 FRAME_INIT_SAVED_REGS (frame);
772 if (frame->saved_regs != NULL
773 && frame->saved_regs[regnum] != 0)
774 {
775 if (lval) /* found it saved on the stack */
776 *lval = lval_memory;
777 if (regnum == SP_REGNUM)
778 {
779 if (raw_buffer) /* SP register treated specially */
780 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
781 frame->saved_regs[regnum]);
782 }
783 else
784 {
785 if (addrp) /* any other register */
786 *addrp = frame->saved_regs[regnum];
787 if (raw_buffer)
788 read_memory (frame->saved_regs[regnum], raw_buffer,
789 REGISTER_RAW_SIZE (regnum));
790 }
791 return;
792 }
793 }
794
795 /* If we get thru the loop to this point, it means the register was
796 not saved in any frame. Return the actual live-register value. */
797
798 if (lval) /* found it in a live register */
799 *lval = lval_register;
800 if (addrp)
801 *addrp = REGISTER_BYTE (regnum);
802 if (raw_buffer)
803 deprecated_read_register_gen (regnum, raw_buffer);
804}
805
806/* Using the PC, select a mechanism for unwinding a frame returning
807 the previous frame. The register unwind function should, on
808 demand, initialize the ->context object. */
809
810static void
811set_unwind_by_pc (CORE_ADDR pc, CORE_ADDR fp,
f18c5a73 812 frame_register_unwind_ftype **unwind_register,
c689142b
AC
813 frame_pc_unwind_ftype **unwind_pc,
814 frame_id_unwind_ftype **unwind_id)
4c1e7e9d 815{
07555a72 816 if (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES)
f18c5a73
AC
817 {
818 /* Still need to set this to something. The ``info frame'' code
819 calls this function to find out where the saved registers are.
820 Hopefully this is robust enough to stop any core dumps and
821 return vaguely correct values.. */
822 *unwind_register = frame_saved_regs_register_unwind;
823 *unwind_pc = frame_saved_regs_pc_unwind;
c689142b 824 *unwind_id = frame_saved_regs_id_unwind;
f18c5a73 825 }
ae45cd16
AC
826 else if (DEPRECATED_PC_IN_CALL_DUMMY_P ()
827 ? DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0)
828 : pc_in_dummy_frame (pc))
f18c5a73
AC
829 {
830 *unwind_register = dummy_frame_register_unwind;
831 *unwind_pc = dummy_frame_pc_unwind;
c689142b 832 *unwind_id = dummy_frame_id_unwind;
f18c5a73 833 }
4c1e7e9d 834 else
f18c5a73
AC
835 {
836 *unwind_register = frame_saved_regs_register_unwind;
837 *unwind_pc = frame_saved_regs_pc_unwind;
c689142b 838 *unwind_id = frame_saved_regs_id_unwind;
f18c5a73 839 }
4c1e7e9d
AC
840}
841
842/* Create an arbitrary (i.e. address specified by user) or innermost frame.
843 Always returns a non-NULL value. */
844
845struct frame_info *
846create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
847{
848 struct frame_info *fi;
5a203e44 849 enum frame_type type;
4c1e7e9d
AC
850
851 fi = (struct frame_info *)
852 obstack_alloc (&frame_cache_obstack,
853 sizeof (struct frame_info));
854
855 /* Zero all fields by default. */
856 memset (fi, 0, sizeof (struct frame_info));
857
858 fi->frame = addr;
859 fi->pc = pc;
5a203e44
AC
860 /* NOTE: cagney/2002-11-18: The code segments, found in
861 create_new_frame and get_prev_frame(), that initializes the
862 frames type is subtly different. The latter only updates ->type
863 when it encounters a SIGTRAMP_FRAME or DUMMY_FRAME. This stops
864 get_prev_frame() overriding the frame's type when the INIT code
865 has previously set it. This is really somewhat bogus. The
866 initialization, as seen in create_new_frame(), should occur
867 before the INIT function has been called. */
ae45cd16
AC
868 if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES
869 && (DEPRECATED_PC_IN_CALL_DUMMY_P ()
870 ? DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0)
871 : pc_in_dummy_frame (pc)))
5a203e44
AC
872 /* NOTE: cagney/2002-11-11: Does this even occure? */
873 type = DUMMY_FRAME;
874 else
875 {
876 char *name;
877 find_pc_partial_function (pc, &name, NULL, NULL);
878 if (PC_IN_SIGTRAMP (fi->pc, name))
879 type = SIGTRAMP_FRAME;
880 else
881 type = NORMAL_FRAME;
882 }
883 fi->type = type;
4c1e7e9d
AC
884
885 if (INIT_EXTRA_FRAME_INFO_P ())
886 INIT_EXTRA_FRAME_INFO (0, fi);
887
888 /* Select/initialize an unwind function. */
f18c5a73 889 set_unwind_by_pc (fi->pc, fi->frame, &fi->register_unwind,
c689142b 890 &fi->pc_unwind, &fi->id_unwind);
4c1e7e9d
AC
891
892 return fi;
893}
894
895/* Return the frame that FRAME calls (NULL if FRAME is the innermost
896 frame). */
897
898struct frame_info *
899get_next_frame (struct frame_info *frame)
900{
901 return frame->next;
902}
903
904/* Flush the entire frame cache. */
905
906void
907flush_cached_frames (void)
908{
909 /* Since we can't really be sure what the first object allocated was */
910 obstack_free (&frame_cache_obstack, 0);
911 obstack_init (&frame_cache_obstack);
912
913 current_frame = NULL; /* Invalidate cache */
914 select_frame (NULL);
915 annotate_frames_invalid ();
916}
917
918/* Flush the frame cache, and start a new one if necessary. */
919
920void
921reinit_frame_cache (void)
922{
923 flush_cached_frames ();
924
925 /* FIXME: The inferior_ptid test is wrong if there is a corefile. */
926 if (PIDGET (inferior_ptid) != 0)
927 {
928 select_frame (get_current_frame ());
929 }
930}
931
932/* Return a structure containing various interesting information
933 about the frame that called NEXT_FRAME. Returns NULL
934 if there is no such frame. */
935
936struct frame_info *
937get_prev_frame (struct frame_info *next_frame)
938{
939 CORE_ADDR address = 0;
940 struct frame_info *prev;
95adb866 941 int fromleaf;
4c1e7e9d 942
95adb866
AC
943 /* Return the inner-most frame, when the caller passes in NULL. */
944 /* NOTE: cagney/2002-11-09: Not sure how this would happen. The
945 caller should have previously obtained a valid frame using
946 get_selected_frame() and then called this code - only possibility
947 I can think of is code behaving badly. */
948 if (next_frame == NULL)
4c1e7e9d 949 {
95adb866
AC
950 /* NOTE: cagney/2002-11-09: There was a code segment here that
951 would error out when CURRENT_FRAME was NULL. The comment
952 that went with it made the claim ...
953
954 ``This screws value_of_variable, which just wants a nice
955 clean NULL return from block_innermost_frame if there are no
956 frames. I don't think I've ever seen this message happen
957 otherwise. And returning NULL here is a perfectly legitimate
958 thing to do.''
959
960 Per the above, this code shouldn't even be called with a NULL
961 NEXT_FRAME. */
4c1e7e9d
AC
962 return current_frame;
963 }
964
15220c65
AC
965 /* Only try to do the unwind once. */
966 if (next_frame->prev_p)
4c1e7e9d 967 return next_frame->prev;
15220c65 968 next_frame->prev_p = 1;
4c1e7e9d
AC
969
970 /* On some machines it is possible to call a function without
971 setting up a stack frame for it. On these machines, we
972 define this macro to take two args; a frameinfo pointer
973 identifying a frame and a variable to set or clear if it is
974 or isn't leafless. */
975
976 /* Still don't want to worry about this except on the innermost
95adb866
AC
977 frame. This macro will set FROMLEAF if NEXT_FRAME is a frameless
978 function invocation. */
979 if (next_frame->next == NULL)
980 /* FIXME: 2002-11-09: Frameless functions can occure anywhere in
981 the frame chain, not just the inner most frame! The generic,
982 per-architecture, frame code should handle this and the below
983 should simply be removed. */
984 fromleaf = FRAMELESS_FUNCTION_INVOCATION (next_frame);
985 else
986 fromleaf = 0;
987
988 if (fromleaf)
989 /* A frameless inner-most frame. The `FP' (which isn't an
990 architecture frame-pointer register!) of the caller is the same
991 as the callee. */
992 /* FIXME: 2002-11-09: There isn't any reason to special case this
993 edge condition. Instead the per-architecture code should hande
994 it locally. */
c193f6ac 995 address = get_frame_base (next_frame);
95adb866 996 else
4c1e7e9d
AC
997 {
998 /* Two macros defined in tm.h specify the machine-dependent
999 actions to be performed here.
95adb866 1000
4c1e7e9d 1001 First, get the frame's chain-pointer.
95adb866 1002
4c1e7e9d
AC
1003 If that is zero, the frame is the outermost frame or a leaf
1004 called by the outermost frame. This means that if start
1005 calls main without a frame, we'll return 0 (which is fine
1006 anyway).
1007
1008 Nope; there's a problem. This also returns when the current
1009 routine is a leaf of main. This is unacceptable. We move
1010 this to after the ffi test; I'd rather have backtraces from
1011 start go curfluy than have an abort called from main not show
1012 main. */
1013 address = FRAME_CHAIN (next_frame);
1014
51603483 1015 if (!frame_chain_valid (address, next_frame))
4c1e7e9d
AC
1016 return 0;
1017 }
1018 if (address == 0)
1019 return 0;
1020
95adb866 1021 /* Create an initially zero previous frame. */
4c1e7e9d
AC
1022 prev = (struct frame_info *)
1023 obstack_alloc (&frame_cache_obstack,
1024 sizeof (struct frame_info));
4c1e7e9d
AC
1025 memset (prev, 0, sizeof (struct frame_info));
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
AC
1039 whether any targets *need* DEPRECATED_INIT_FRAME_PC to happen
1040 after INIT_EXTRA_FRAME_INFO and come up with a simple way to
1041 express what goes on here.
95adb866
AC
1042
1043 INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
1044 (where the PC is already set up) and here (where it isn't).
a5afb99f 1045 DEPRECATED_INIT_FRAME_PC is only called from here, always after
95adb866
AC
1046 INIT_EXTRA_FRAME_INFO.
1047
1048 The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the
1049 PC value (which hasn't been set yet). Some other machines appear
1050 to require INIT_EXTRA_FRAME_INFO before they can do
a5afb99f 1051 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
95adb866
AC
1058 INIT_EXTRA_FRAME_INFO, one possible scheme:
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
1068 INIT_PREV_FRAME(fromleaf, prev) Replace INIT_EXTRA_FRAME_INFO and
a5afb99f
AC
1069 DEPRECATED_INIT_FRAME_PC. This should also return a flag saying
1070 whether to keep the new frame, or whether to discard it, because
1071 on some machines (e.g. mips) it is really awkward to have
95adb866
AC
1072 FRAME_CHAIN_VALID called *before* INIT_EXTRA_FRAME_INFO (there is
1073 no good way to get information deduced in FRAME_CHAIN_VALID into
1074 the extra fields of the new frame). std_frame_pc(fromleaf, prev)
1075
1076 This is the default setting for INIT_PREV_FRAME. It just does
a5afb99f
AC
1077 what the default DEPRECATED_INIT_FRAME_PC does. Some machines
1078 will call it from INIT_PREV_FRAME (either at the beginning, the
1079 end, or in the middle). Some machines won't use it.
95adb866
AC
1080
1081 kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */
1082
1083 /* NOTE: cagney/2002-11-09: Just ignore the above! There is no
1084 reason for things to be this complicated.
1085
1086 The trick is to assume that there is always a frame. Instead of
1087 special casing the inner-most frame, create fake frame
1088 (containing the hardware registers) that is inner to the
1089 user-visible inner-most frame (...) and then unwind from that.
1090 That way architecture code can use use the standard
1091 frame_XX_unwind() functions and not differentiate between the
1092 inner most and any other case.
1093
1094 Since there is always a frame to unwind from, there is always
1095 somewhere (NEXT_FRAME) to store all the info needed to construct
1096 a new (previous) frame without having to first create it. This
1097 means that the convolution below - needing to carefully order a
1098 frame's initialization - isn't needed.
1099
1100 The irony here though, is that FRAME_CHAIN(), at least for a more
1101 up-to-date architecture, always calls FRAME_SAVED_PC(), and
1102 FRAME_SAVED_PC() computes the PC but without first needing the
1103 frame! Instead of the convolution below, we could have simply
1104 called FRAME_SAVED_PC() and been done with it! Note that
1105 FRAME_SAVED_PC() is being superseed by frame_pc_unwind() and that
1106 function does have somewhere to cache that PC value. */
4c1e7e9d 1107
2ca6c561 1108 if (DEPRECATED_INIT_FRAME_PC_FIRST_P ())
97f46953 1109 prev->pc = (DEPRECATED_INIT_FRAME_PC_FIRST (fromleaf, prev));
4c1e7e9d
AC
1110
1111 if (INIT_EXTRA_FRAME_INFO_P ())
1112 INIT_EXTRA_FRAME_INFO (fromleaf, prev);
1113
1114 /* This entry is in the frame queue now, which is good since
95adb866
AC
1115 FRAME_SAVED_PC may use that queue to figure out its value (see
1116 tm-sparc.h). We want the pc saved in the inferior frame. */
a5afb99f
AC
1117 if (DEPRECATED_INIT_FRAME_PC_P ())
1118 prev->pc = DEPRECATED_INIT_FRAME_PC (fromleaf, prev);
4c1e7e9d 1119
95adb866
AC
1120 /* If ->frame and ->pc are unchanged, we are in the process of
1121 getting ourselves into an infinite backtrace. Some architectures
1122 check this in FRAME_CHAIN or thereabouts, but it seems like there
1123 is no reason this can't be an architecture-independent check. */
1124 if (prev->frame == next_frame->frame
1125 && prev->pc == next_frame->pc)
4c1e7e9d 1126 {
95adb866
AC
1127 next_frame->prev = NULL;
1128 obstack_free (&frame_cache_obstack, prev);
1129 return NULL;
4c1e7e9d
AC
1130 }
1131
1132 /* Initialize the code used to unwind the frame PREV based on the PC
1133 (and probably other architectural information). The PC lets you
1134 check things like the debug info at that point (dwarf2cfi?) and
1135 use that to decide how the frame should be unwound. */
f18c5a73 1136 set_unwind_by_pc (prev->pc, prev->frame, &prev->register_unwind,
c689142b 1137 &prev->pc_unwind, &prev->id_unwind);
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
1175CORE_ADDR
1176get_frame_pc (struct frame_info *frame)
1177{
1178 return frame->pc;
1179}
1180
1058bca7
AC
1181static int
1182pc_notcurrent (struct frame_info *frame)
1183{
1184 /* If FRAME is not the innermost frame, that normally means that
1185 FRAME->pc points at the return instruction (which is *after* the
1186 call instruction), and we want to get the line containing the
1187 call (because the call is where the user thinks the program is).
1188 However, if the next frame is either a SIGTRAMP_FRAME or a
1189 DUMMY_FRAME, then the next frame will contain a saved interrupt
1190 PC and such a PC indicates the current (rather than next)
1191 instruction/line, consequently, for such cases, want to get the
1192 line containing fi->pc. */
1193 struct frame_info *next = get_next_frame (frame);
1194 int notcurrent = (next != NULL && get_frame_type (next) == NORMAL_FRAME);
1195 return notcurrent;
1196}
1197
1198void
1199find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal)
1200{
1201 (*sal) = find_pc_line (frame->pc, pc_notcurrent (frame));
1202}
1203
c193f6ac
AC
1204/* Per "frame.h", return the ``address'' of the frame. Code should
1205 really be using get_frame_id(). */
1206CORE_ADDR
1207get_frame_base (struct frame_info *fi)
1208{
1209 return fi->frame;
1210}
1211
85cf597a
AC
1212/* Level of the selected frame: 0 for innermost, 1 for its caller, ...
1213 or -1 for a NULL frame. */
1214
1215int
1216frame_relative_level (struct frame_info *fi)
1217{
1218 if (fi == NULL)
1219 return -1;
1220 else
1221 return fi->level;
1222}
1223
5a203e44
AC
1224enum frame_type
1225get_frame_type (struct frame_info *frame)
1226{
1227 /* Some targets still don't use [generic] dummy frames. Catch them
1228 here. */
07555a72 1229 if (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES
5a203e44
AC
1230 && deprecated_frame_in_dummy (frame))
1231 return DUMMY_FRAME;
1232 return frame->type;
1233}
1234
1235void
1236deprecated_set_frame_type (struct frame_info *frame, enum frame_type type)
1237{
1238 /* Arrrg! See comment in "frame.h". */
1239 frame->type = type;
1240}
1241
4c1e7e9d
AC
1242#ifdef FRAME_FIND_SAVED_REGS
1243/* XXX - deprecated. This is a compatibility function for targets
1244 that do not yet implement FRAME_INIT_SAVED_REGS. */
1245/* Find the addresses in which registers are saved in FRAME. */
1246
1247void
95486978
AC
1248deprecated_get_frame_saved_regs (struct frame_info *frame,
1249 struct frame_saved_regs *saved_regs_addr)
4c1e7e9d
AC
1250{
1251 if (frame->saved_regs == NULL)
1252 {
1253 frame->saved_regs = (CORE_ADDR *)
1254 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
1255 }
1256 if (saved_regs_addr == NULL)
1257 {
1258 struct frame_saved_regs saved_regs;
1259 FRAME_FIND_SAVED_REGS (frame, saved_regs);
1260 memcpy (frame->saved_regs, &saved_regs, SIZEOF_FRAME_SAVED_REGS);
1261 }
1262 else
1263 {
1264 FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr);
1265 memcpy (frame->saved_regs, saved_regs_addr, SIZEOF_FRAME_SAVED_REGS);
1266 }
1267}
1268#endif
1269
0394eb2a
AC
1270struct frame_extra_info *
1271get_frame_extra_info (struct frame_info *fi)
1272{
1273 return fi->extra_info;
1274}
1275
2c517d0e
AC
1276struct frame_extra_info *
1277frame_extra_info_zalloc (struct frame_info *fi, long size)
1278{
1279 fi->extra_info = frame_obstack_alloc (size);
1280 memset (fi->extra_info, 0, size);
1281 return fi->extra_info;
1282}
1283
b87efeee 1284void
2f107107 1285deprecated_update_frame_pc_hack (struct frame_info *frame, CORE_ADDR pc)
b87efeee 1286{
2f107107
AC
1287 /* See comment in "frame.h". */
1288 frame->pc = pc;
1289}
1290
1291void
1292deprecated_update_frame_base_hack (struct frame_info *frame, CORE_ADDR base)
1293{
1294 /* See comment in "frame.h". */
1295 frame->frame = base;
b87efeee
AC
1296}
1297
c8b8a898
AC
1298void
1299deprecated_set_frame_saved_regs_hack (struct frame_info *frame,
1300 CORE_ADDR *saved_regs)
1301{
1302 frame->saved_regs = saved_regs;
1303}
1304
1305void
1306deprecated_set_frame_extra_info_hack (struct frame_info *frame,
1307 struct frame_extra_info *extra_info)
1308{
1309 frame->extra_info = extra_info;
1310}
1311
1312struct frame_info *
1313deprecated_frame_xmalloc (void)
1314{
1315 struct frame_info *frame = XMALLOC (struct frame_info);
1316 memset (frame, 0, sizeof (struct frame_info));
1317 return frame;
1318}
1319
f6c609c4
AC
1320struct frame_info *
1321deprecated_frame_xmalloc_with_cleanup (long sizeof_saved_regs,
1322 long sizeof_extra_info)
1323{
1324 struct frame_info *frame = deprecated_frame_xmalloc ();
1325 make_cleanup (xfree, frame);
1326 if (sizeof_saved_regs > 0)
1327 {
1328 frame->saved_regs = xcalloc (1, sizeof_saved_regs);
1329 make_cleanup (xfree, frame->saved_regs);
1330 }
1331 if (sizeof_extra_info > 0)
1332 {
1333 frame->extra_info = xcalloc (1, sizeof_extra_info);
1334 make_cleanup (xfree, frame->extra_info);
1335 }
1336 return frame;
1337}
c8b8a898 1338
4c1e7e9d
AC
1339void
1340_initialize_frame (void)
1341{
1342 obstack_init (&frame_cache_obstack);
1343}