Commit | Line | Data |
---|---|---|
a0f267c7 AC |
1 | /* Traditional frame unwind support, for GDB the GNU Debugger. |
2 | ||
6aba47ca | 3 | Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc. |
a0f267c7 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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 | |
197e01b6 EZ |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
a0f267c7 AC |
21 | |
22 | #include "defs.h" | |
23 | #include "frame.h" | |
24 | #include "trad-frame.h" | |
25 | #include "regcache.h" | |
26 | ||
0db9b4b7 AC |
27 | struct trad_frame_cache |
28 | { | |
29 | struct frame_info *next_frame; | |
30 | CORE_ADDR this_base; | |
31 | struct trad_frame_saved_reg *prev_regs; | |
32 | struct frame_id this_id; | |
33 | }; | |
34 | ||
35 | struct trad_frame_cache * | |
36 | trad_frame_cache_zalloc (struct frame_info *next_frame) | |
37 | { | |
38 | struct trad_frame_cache *this_trad_cache; | |
39 | ||
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; | |
44 | } | |
45 | ||
a0f267c7 AC |
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). */ | |
50 | ||
8983bd83 | 51 | struct trad_frame_saved_reg * |
a0f267c7 AC |
52 | trad_frame_alloc_saved_regs (struct frame_info *next_frame) |
53 | { | |
8983bd83 | 54 | int regnum; |
a0f267c7 | 55 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
f57d151a UW |
56 | int numregs = gdbarch_num_regs (current_gdbarch) |
57 | + gdbarch_num_pseudo_regs (current_gdbarch); | |
8983bd83 AC |
58 | struct trad_frame_saved_reg *this_saved_regs |
59 | = FRAME_OBSTACK_CALLOC (numregs, struct trad_frame_saved_reg); | |
60 | for (regnum = 0; regnum < numregs; regnum++) | |
3b3850e8 AC |
61 | { |
62 | this_saved_regs[regnum].realreg = regnum; | |
63 | this_saved_regs[regnum].addr = -1; | |
64 | } | |
a0f267c7 AC |
65 | return this_saved_regs; |
66 | } | |
67 | ||
3b3850e8 AC |
68 | enum { REG_VALUE = -1, REG_UNKNOWN = -2 }; |
69 | ||
70 | int | |
71 | trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[], int regnum) | |
72 | { | |
73 | return (this_saved_regs[regnum].realreg == REG_VALUE); | |
74 | } | |
75 | ||
76 | int | |
77 | trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[], int regnum) | |
78 | { | |
79 | return (this_saved_regs[regnum].realreg >= 0 | |
80 | && this_saved_regs[regnum].addr != -1); | |
81 | } | |
82 | ||
83 | int | |
84 | trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[], | |
85 | int regnum) | |
86 | { | |
87 | return (this_saved_regs[regnum].realreg >= 0 | |
88 | && this_saved_regs[regnum].addr == -1); | |
89 | } | |
90 | ||
a0f267c7 | 91 | void |
3b3850e8 AC |
92 | trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[], |
93 | int regnum, LONGEST val) | |
a0f267c7 | 94 | { |
3b3850e8 | 95 | /* Make the REALREG invalid, indicating that the ADDR contains the |
a0f267c7 | 96 | register's value. */ |
3b3850e8 | 97 | this_saved_regs[regnum].realreg = REG_VALUE; |
a0f267c7 AC |
98 | this_saved_regs[regnum].addr = val; |
99 | } | |
100 | ||
61e784e7 MS |
101 | void |
102 | trad_frame_set_reg_value (struct trad_frame_cache *this_trad_cache, | |
103 | int regnum, LONGEST val) | |
104 | { | |
105 | /* External interface for users of trad_frame_cache | |
106 | (who cannot access the prev_regs object directly). */ | |
107 | trad_frame_set_value (this_trad_cache->prev_regs, regnum, val); | |
108 | } | |
109 | ||
e66299b3 AC |
110 | void |
111 | trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache, | |
112 | int regnum, int realreg) | |
113 | { | |
114 | this_trad_cache->prev_regs[regnum].realreg = realreg; | |
115 | this_trad_cache->prev_regs[regnum].addr = -1; | |
116 | } | |
117 | ||
0db9b4b7 AC |
118 | void |
119 | trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache, | |
120 | int regnum, CORE_ADDR addr) | |
121 | { | |
122 | this_trad_cache->prev_regs[regnum].addr = addr; | |
123 | } | |
124 | ||
3b3850e8 AC |
125 | void |
126 | trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[], | |
127 | int regnum) | |
128 | { | |
129 | /* Make the REALREG invalid, indicating that the value is not known. */ | |
130 | this_saved_regs[regnum].realreg = REG_UNKNOWN; | |
131 | this_saved_regs[regnum].addr = -1; | |
132 | } | |
133 | ||
a0f267c7 | 134 | void |
1f67027d AC |
135 | trad_frame_get_prev_register (struct frame_info *next_frame, |
136 | struct trad_frame_saved_reg this_saved_regs[], | |
137 | int regnum, int *optimizedp, | |
138 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
10c42a71 | 139 | int *realregp, gdb_byte *bufferp) |
a0f267c7 AC |
140 | { |
141 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
3b3850e8 | 142 | if (trad_frame_addr_p (this_saved_regs, regnum)) |
a0f267c7 | 143 | { |
8983bd83 | 144 | /* The register was saved in memory. */ |
a0f267c7 AC |
145 | *optimizedp = 0; |
146 | *lvalp = lval_memory; | |
147 | *addrp = this_saved_regs[regnum].addr; | |
3b3850e8 | 148 | *realregp = -1; |
a0f267c7 AC |
149 | if (bufferp != NULL) |
150 | { | |
151 | /* Read the value in from memory. */ | |
152 | get_frame_memory (next_frame, this_saved_regs[regnum].addr, bufferp, | |
153 | register_size (gdbarch, regnum)); | |
154 | } | |
155 | } | |
3b3850e8 | 156 | else if (trad_frame_realreg_p (this_saved_regs, regnum)) |
a0f267c7 | 157 | { |
00b25ff3 AC |
158 | *optimizedp = 0; |
159 | *lvalp = lval_register; | |
160 | *addrp = 0; | |
161 | *realregp = this_saved_regs[regnum].realreg; | |
260a4188 | 162 | /* Ask the next frame to return the value of the register. */ |
00b25ff3 AC |
163 | if (bufferp) |
164 | frame_unwind_register (next_frame, (*realregp), bufferp); | |
a0f267c7 | 165 | } |
3b3850e8 | 166 | else if (trad_frame_value_p (this_saved_regs, regnum)) |
a0f267c7 AC |
167 | { |
168 | /* The register's value is available. */ | |
169 | *optimizedp = 0; | |
170 | *lvalp = not_lval; | |
171 | *addrp = 0; | |
3b3850e8 | 172 | *realregp = -1; |
a0f267c7 AC |
173 | if (bufferp != NULL) |
174 | store_unsigned_integer (bufferp, register_size (gdbarch, regnum), | |
175 | this_saved_regs[regnum].addr); | |
176 | } | |
3b3850e8 AC |
177 | else |
178 | { | |
8a3fe4f8 | 179 | error (_("Register %s not available"), |
3b3850e8 AC |
180 | gdbarch_register_name (gdbarch, regnum)); |
181 | } | |
a0f267c7 | 182 | } |
0db9b4b7 AC |
183 | |
184 | void | |
185 | trad_frame_get_register (struct trad_frame_cache *this_trad_cache, | |
186 | struct frame_info *next_frame, | |
187 | int regnum, int *optimizedp, | |
188 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
10c42a71 | 189 | int *realregp, gdb_byte *bufferp) |
0db9b4b7 | 190 | { |
1f67027d AC |
191 | trad_frame_get_prev_register (next_frame, this_trad_cache->prev_regs, |
192 | regnum, optimizedp, lvalp, addrp, realregp, | |
193 | bufferp); | |
0db9b4b7 AC |
194 | } |
195 | ||
196 | void | |
197 | trad_frame_set_id (struct trad_frame_cache *this_trad_cache, | |
198 | struct frame_id this_id) | |
199 | { | |
200 | this_trad_cache->this_id = this_id; | |
201 | } | |
202 | ||
203 | void | |
204 | trad_frame_get_id (struct trad_frame_cache *this_trad_cache, | |
205 | struct frame_id *this_id) | |
206 | { | |
207 | (*this_id) = this_trad_cache->this_id; | |
208 | } | |
e66299b3 AC |
209 | |
210 | void | |
211 | trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache, | |
212 | CORE_ADDR this_base) | |
213 | { | |
214 | this_trad_cache->this_base = this_base; | |
215 | } | |
216 | ||
217 | CORE_ADDR | |
218 | trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache) | |
219 | { | |
220 | return this_trad_cache->this_base; | |
221 | } |