]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/trad-frame.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / trad-frame.c
1 /* Traditional frame unwind support, for GDB the GNU Debugger.
2
3 Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "trad-frame.h"
25 #include "regcache.h"
26
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
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
51 struct trad_frame_saved_reg *
52 trad_frame_alloc_saved_regs (struct frame_info *next_frame)
53 {
54 int regnum;
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++)
60 {
61 this_saved_regs[regnum].realreg = regnum;
62 this_saved_regs[regnum].addr = -1;
63 }
64 return this_saved_regs;
65 }
66
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
90 void
91 trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
92 int regnum, LONGEST val)
93 {
94 /* Make the REALREG invalid, indicating that the ADDR contains the
95 register's value. */
96 this_saved_regs[regnum].realreg = REG_VALUE;
97 this_saved_regs[regnum].addr = val;
98 }
99
100 void
101 trad_frame_set_reg_value (struct trad_frame_cache *this_trad_cache,
102 int regnum, LONGEST val)
103 {
104 /* External interface for users of trad_frame_cache
105 (who cannot access the prev_regs object directly). */
106 trad_frame_set_value (this_trad_cache->prev_regs, regnum, val);
107 }
108
109 void
110 trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache,
111 int regnum, int realreg)
112 {
113 this_trad_cache->prev_regs[regnum].realreg = realreg;
114 this_trad_cache->prev_regs[regnum].addr = -1;
115 }
116
117 void
118 trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
119 int regnum, CORE_ADDR addr)
120 {
121 this_trad_cache->prev_regs[regnum].addr = addr;
122 }
123
124 void
125 trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[],
126 int regnum)
127 {
128 /* Make the REALREG invalid, indicating that the value is not known. */
129 this_saved_regs[regnum].realreg = REG_UNKNOWN;
130 this_saved_regs[regnum].addr = -1;
131 }
132
133 void
134 trad_frame_get_prev_register (struct frame_info *next_frame,
135 struct trad_frame_saved_reg this_saved_regs[],
136 int regnum, int *optimizedp,
137 enum lval_type *lvalp, CORE_ADDR *addrp,
138 int *realregp, gdb_byte *bufferp)
139 {
140 struct gdbarch *gdbarch = get_frame_arch (next_frame);
141 if (trad_frame_addr_p (this_saved_regs, regnum))
142 {
143 /* The register was saved in memory. */
144 *optimizedp = 0;
145 *lvalp = lval_memory;
146 *addrp = this_saved_regs[regnum].addr;
147 *realregp = -1;
148 if (bufferp != NULL)
149 {
150 /* Read the value in from memory. */
151 get_frame_memory (next_frame, this_saved_regs[regnum].addr, bufferp,
152 register_size (gdbarch, regnum));
153 }
154 }
155 else if (trad_frame_realreg_p (this_saved_regs, regnum))
156 {
157 *optimizedp = 0;
158 *lvalp = lval_register;
159 *addrp = 0;
160 *realregp = this_saved_regs[regnum].realreg;
161 /* Ask the next frame to return the value of the register. */
162 if (bufferp)
163 frame_unwind_register (next_frame, (*realregp), bufferp);
164 }
165 else if (trad_frame_value_p (this_saved_regs, regnum))
166 {
167 /* The register's value is available. */
168 *optimizedp = 0;
169 *lvalp = not_lval;
170 *addrp = 0;
171 *realregp = -1;
172 if (bufferp != NULL)
173 store_unsigned_integer (bufferp, register_size (gdbarch, regnum),
174 this_saved_regs[regnum].addr);
175 }
176 else
177 {
178 error (_("Register %s not available"),
179 gdbarch_register_name (gdbarch, regnum));
180 }
181 }
182
183 void
184 trad_frame_get_register (struct trad_frame_cache *this_trad_cache,
185 struct frame_info *next_frame,
186 int regnum, int *optimizedp,
187 enum lval_type *lvalp, CORE_ADDR *addrp,
188 int *realregp, gdb_byte *bufferp)
189 {
190 trad_frame_get_prev_register (next_frame, this_trad_cache->prev_regs,
191 regnum, optimizedp, lvalp, addrp, realregp,
192 bufferp);
193 }
194
195 void
196 trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
197 struct frame_id this_id)
198 {
199 this_trad_cache->this_id = this_id;
200 }
201
202 void
203 trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
204 struct frame_id *this_id)
205 {
206 (*this_id) = this_trad_cache->this_id;
207 }
208
209 void
210 trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache,
211 CORE_ADDR this_base)
212 {
213 this_trad_cache->this_base = this_base;
214 }
215
216 CORE_ADDR
217 trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache)
218 {
219 return this_trad_cache->this_base;
220 }