1 /* Traditional frame unwind support, for GDB the GNU Debugger.
3 Copyright 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "trad-frame.h"
27 struct trad_frame_cache
29 struct frame_info
*next_frame
;
31 struct trad_frame_saved_reg
*prev_regs
;
32 struct frame_id this_id
;
35 struct trad_frame_cache
*
36 trad_frame_cache_zalloc (struct frame_info
*next_frame
)
38 struct trad_frame_cache
*this_trad_cache
;
40 this_trad_cache
= FRAME_OBSTACK_ZALLOC (struct trad_frame_cache
);
41 this_trad_cache
->prev_regs
= trad_frame_alloc_saved_regs (next_frame
);
42 this_trad_cache
->next_frame
= next_frame
;
43 return this_trad_cache
;
46 /* A traditional frame is unwound by analysing the function prologue
47 and using the information gathered to track registers. For
48 non-optimized frames, the technique is reliable (just need to check
49 for all potential instruction sequences). */
51 struct trad_frame_saved_reg
*
52 trad_frame_alloc_saved_regs (struct frame_info
*next_frame
)
55 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
56 int numregs
= NUM_REGS
+ NUM_PSEUDO_REGS
;
57 struct trad_frame_saved_reg
*this_saved_regs
58 = FRAME_OBSTACK_CALLOC (numregs
, struct trad_frame_saved_reg
);
59 for (regnum
= 0; regnum
< numregs
; regnum
++)
61 this_saved_regs
[regnum
].realreg
= regnum
;
62 this_saved_regs
[regnum
].addr
= -1;
64 return this_saved_regs
;
67 enum { REG_VALUE
= -1, REG_UNKNOWN
= -2 };
70 trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs
[], int regnum
)
72 return (this_saved_regs
[regnum
].realreg
== REG_VALUE
);
76 trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs
[], int regnum
)
78 return (this_saved_regs
[regnum
].realreg
>= 0
79 && this_saved_regs
[regnum
].addr
!= -1);
83 trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs
[],
86 return (this_saved_regs
[regnum
].realreg
>= 0
87 && this_saved_regs
[regnum
].addr
== -1);
91 trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs
[],
92 int regnum
, LONGEST val
)
94 /* Make the REALREG invalid, indicating that the ADDR contains the
96 this_saved_regs
[regnum
].realreg
= REG_VALUE
;
97 this_saved_regs
[regnum
].addr
= val
;
101 trad_frame_set_reg_addr (struct trad_frame_cache
*this_trad_cache
,
102 int regnum
, CORE_ADDR addr
)
104 this_trad_cache
->prev_regs
[regnum
].addr
= addr
;
108 trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs
[],
111 /* Make the REALREG invalid, indicating that the value is not known. */
112 this_saved_regs
[regnum
].realreg
= REG_UNKNOWN
;
113 this_saved_regs
[regnum
].addr
= -1;
117 trad_frame_prev_register (struct frame_info
*next_frame
,
118 struct trad_frame_saved_reg this_saved_regs
[],
119 int regnum
, int *optimizedp
,
120 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
121 int *realregp
, void *bufferp
)
123 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
124 if (trad_frame_addr_p (this_saved_regs
, regnum
))
126 /* The register was saved in memory. */
128 *lvalp
= lval_memory
;
129 *addrp
= this_saved_regs
[regnum
].addr
;
133 /* Read the value in from memory. */
134 get_frame_memory (next_frame
, this_saved_regs
[regnum
].addr
, bufferp
,
135 register_size (gdbarch
, regnum
));
138 else if (trad_frame_realreg_p (this_saved_regs
, regnum
))
140 /* Ask the next frame to return the value of the register. */
141 frame_register_unwind (next_frame
, this_saved_regs
[regnum
].realreg
,
142 optimizedp
, lvalp
, addrp
, realregp
, bufferp
);
144 else if (trad_frame_value_p (this_saved_regs
, regnum
))
146 /* The register's value is available. */
152 store_unsigned_integer (bufferp
, register_size (gdbarch
, regnum
),
153 this_saved_regs
[regnum
].addr
);
157 error ("Register %s not available",
158 gdbarch_register_name (gdbarch
, regnum
));
163 trad_frame_get_register (struct trad_frame_cache
*this_trad_cache
,
164 struct frame_info
*next_frame
,
165 int regnum
, int *optimizedp
,
166 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
167 int *realregp
, void *bufferp
)
169 trad_frame_prev_register (next_frame
, this_trad_cache
->prev_regs
,
170 regnum
, optimizedp
, lvalp
, addrp
, realregp
,
175 trad_frame_set_id (struct trad_frame_cache
*this_trad_cache
,
176 struct frame_id this_id
)
178 this_trad_cache
->this_id
= this_id
;
182 trad_frame_get_id (struct trad_frame_cache
*this_trad_cache
,
183 struct frame_id
*this_id
)
185 (*this_id
) = this_trad_cache
->this_id
;