]>
Commit | Line | Data |
---|---|---|
a0f267c7 AC |
1 | /* Traditional frame unwind support, for GDB the GNU Debugger. |
2 | ||
0db9b4b7 | 3 | Copyright 2003, 2004 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 | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
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 AC |
55 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
56 | int numregs = NUM_REGS + NUM_PSEUDO_REGS; | |
8983bd83 AC |
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++) | |
3b3850e8 AC |
60 | { |
61 | this_saved_regs[regnum].realreg = regnum; | |
62 | this_saved_regs[regnum].addr = -1; | |
63 | } | |
a0f267c7 AC |
64 | return this_saved_regs; |
65 | } | |
66 | ||
3b3850e8 AC |
67 | enum { REG_VALUE = -1, REG_UNKNOWN = -2 }; |
68 | ||
69 | int | |
70 | trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[], int regnum) | |
71 | { | |
72 | return (this_saved_regs[regnum].realreg == REG_VALUE); | |
73 | } | |
74 | ||
75 | int | |
76 | trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[], int regnum) | |
77 | { | |
78 | return (this_saved_regs[regnum].realreg >= 0 | |
79 | && this_saved_regs[regnum].addr != -1); | |
80 | } | |
81 | ||
82 | int | |
83 | trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[], | |
84 | int regnum) | |
85 | { | |
86 | return (this_saved_regs[regnum].realreg >= 0 | |
87 | && this_saved_regs[regnum].addr == -1); | |
88 | } | |
89 | ||
a0f267c7 | 90 | void |
3b3850e8 AC |
91 | trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[], |
92 | int regnum, LONGEST val) | |
a0f267c7 | 93 | { |
3b3850e8 | 94 | /* Make the REALREG invalid, indicating that the ADDR contains the |
a0f267c7 | 95 | register's value. */ |
3b3850e8 | 96 | this_saved_regs[regnum].realreg = REG_VALUE; |
a0f267c7 AC |
97 | this_saved_regs[regnum].addr = val; |
98 | } | |
99 | ||
e66299b3 AC |
100 | void |
101 | trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache, | |
102 | int regnum, int realreg) | |
103 | { | |
104 | this_trad_cache->prev_regs[regnum].realreg = realreg; | |
105 | this_trad_cache->prev_regs[regnum].addr = -1; | |
106 | } | |
107 | ||
0db9b4b7 AC |
108 | void |
109 | trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache, | |
110 | int regnum, CORE_ADDR addr) | |
111 | { | |
112 | this_trad_cache->prev_regs[regnum].addr = addr; | |
113 | } | |
114 | ||
3b3850e8 AC |
115 | void |
116 | trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[], | |
117 | int regnum) | |
118 | { | |
119 | /* Make the REALREG invalid, indicating that the value is not known. */ | |
120 | this_saved_regs[regnum].realreg = REG_UNKNOWN; | |
121 | this_saved_regs[regnum].addr = -1; | |
122 | } | |
123 | ||
a0f267c7 | 124 | void |
1f67027d AC |
125 | trad_frame_get_prev_register (struct frame_info *next_frame, |
126 | struct trad_frame_saved_reg this_saved_regs[], | |
127 | int regnum, int *optimizedp, | |
128 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
129 | int *realregp, void *bufferp) | |
a0f267c7 AC |
130 | { |
131 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
3b3850e8 | 132 | if (trad_frame_addr_p (this_saved_regs, regnum)) |
a0f267c7 | 133 | { |
8983bd83 | 134 | /* The register was saved in memory. */ |
a0f267c7 AC |
135 | *optimizedp = 0; |
136 | *lvalp = lval_memory; | |
137 | *addrp = this_saved_regs[regnum].addr; | |
3b3850e8 | 138 | *realregp = -1; |
a0f267c7 AC |
139 | if (bufferp != NULL) |
140 | { | |
141 | /* Read the value in from memory. */ | |
142 | get_frame_memory (next_frame, this_saved_regs[regnum].addr, bufferp, | |
143 | register_size (gdbarch, regnum)); | |
144 | } | |
145 | } | |
3b3850e8 | 146 | else if (trad_frame_realreg_p (this_saved_regs, regnum)) |
a0f267c7 | 147 | { |
00b25ff3 AC |
148 | *optimizedp = 0; |
149 | *lvalp = lval_register; | |
150 | *addrp = 0; | |
151 | *realregp = this_saved_regs[regnum].realreg; | |
260a4188 | 152 | /* Ask the next frame to return the value of the register. */ |
00b25ff3 AC |
153 | if (bufferp) |
154 | frame_unwind_register (next_frame, (*realregp), bufferp); | |
a0f267c7 | 155 | } |
3b3850e8 | 156 | else if (trad_frame_value_p (this_saved_regs, regnum)) |
a0f267c7 AC |
157 | { |
158 | /* The register's value is available. */ | |
159 | *optimizedp = 0; | |
160 | *lvalp = not_lval; | |
161 | *addrp = 0; | |
3b3850e8 | 162 | *realregp = -1; |
a0f267c7 AC |
163 | if (bufferp != NULL) |
164 | store_unsigned_integer (bufferp, register_size (gdbarch, regnum), | |
165 | this_saved_regs[regnum].addr); | |
166 | } | |
3b3850e8 AC |
167 | else |
168 | { | |
8a3fe4f8 | 169 | error (_("Register %s not available"), |
3b3850e8 AC |
170 | gdbarch_register_name (gdbarch, regnum)); |
171 | } | |
a0f267c7 | 172 | } |
0db9b4b7 AC |
173 | |
174 | void | |
175 | trad_frame_get_register (struct trad_frame_cache *this_trad_cache, | |
176 | struct frame_info *next_frame, | |
177 | int regnum, int *optimizedp, | |
178 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
179 | int *realregp, void *bufferp) | |
180 | { | |
1f67027d AC |
181 | trad_frame_get_prev_register (next_frame, this_trad_cache->prev_regs, |
182 | regnum, optimizedp, lvalp, addrp, realregp, | |
183 | bufferp); | |
0db9b4b7 AC |
184 | } |
185 | ||
186 | void | |
187 | trad_frame_set_id (struct trad_frame_cache *this_trad_cache, | |
188 | struct frame_id this_id) | |
189 | { | |
190 | this_trad_cache->this_id = this_id; | |
191 | } | |
192 | ||
193 | void | |
194 | trad_frame_get_id (struct trad_frame_cache *this_trad_cache, | |
195 | struct frame_id *this_id) | |
196 | { | |
197 | (*this_id) = this_trad_cache->this_id; | |
198 | } | |
e66299b3 AC |
199 | |
200 | void | |
201 | trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache, | |
202 | CORE_ADDR this_base) | |
203 | { | |
204 | this_trad_cache->this_base = this_base; | |
205 | } | |
206 | ||
207 | CORE_ADDR | |
208 | trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache) | |
209 | { | |
210 | return this_trad_cache->this_base; | |
211 | } |