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