annotate libgcc/unwind-dw2.c @ 120:f93fa5091070

fix conv1.c
author mir3636
date Thu, 08 Mar 2018 14:53:42 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* DWARF2 exception handling and frame unwind runtime interface routines.
kono
parents:
diff changeset
2 Copyright (C) 1997-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
kono
parents:
diff changeset
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
kono
parents:
diff changeset
14 License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "tconfig.h"
kono
parents:
diff changeset
26 #include "tsystem.h"
kono
parents:
diff changeset
27 #include "coretypes.h"
kono
parents:
diff changeset
28 #include "tm.h"
kono
parents:
diff changeset
29 #include "libgcc_tm.h"
kono
parents:
diff changeset
30 #include "dwarf2.h"
kono
parents:
diff changeset
31 #include "unwind.h"
kono
parents:
diff changeset
32 #ifdef __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
33 # define NO_SIZE_OF_ENCODED_VALUE
kono
parents:
diff changeset
34 #endif
kono
parents:
diff changeset
35 #include "unwind-pe.h"
kono
parents:
diff changeset
36 #include "unwind-dw2-fde.h"
kono
parents:
diff changeset
37 #include "gthr.h"
kono
parents:
diff changeset
38 #include "unwind-dw2.h"
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #ifdef HAVE_SYS_SDT_H
kono
parents:
diff changeset
41 #include <sys/sdt.h>
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 #ifndef __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 #ifndef __LIBGCC_STACK_GROWS_DOWNWARD__
kono
parents:
diff changeset
47 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 0
kono
parents:
diff changeset
48 #else
kono
parents:
diff changeset
49 #undef __LIBGCC_STACK_GROWS_DOWNWARD__
kono
parents:
diff changeset
50 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 1
kono
parents:
diff changeset
51 #endif
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 /* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */
kono
parents:
diff changeset
54 #ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
kono
parents:
diff changeset
55 #define PRE_GCC3_DWARF_FRAME_REGISTERS __LIBGCC_DWARF_FRAME_REGISTERS__
kono
parents:
diff changeset
56 #endif
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 /* ??? For the public function interfaces, we tend to gcc_assert that the
kono
parents:
diff changeset
59 column numbers are in range. For the dwarf2 unwind info this does happen,
kono
parents:
diff changeset
60 although so far in a case that doesn't actually matter.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores
kono
parents:
diff changeset
63 the call-saved xmm registers and annotates them. We havn't bothered
kono
parents:
diff changeset
64 providing support for the xmm registers for the x86_64 port primarily
kono
parents:
diff changeset
65 because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or
kono
parents:
diff changeset
66 SEH instead. Adding the support for unix targets would generally be a
kono
parents:
diff changeset
67 waste. However, some runtime libraries supplied with ICC do contain such
kono
parents:
diff changeset
68 an unorthodox transition, as well as the unwind info to match. This loss
kono
parents:
diff changeset
69 of register restoration doesn't matter in practice, because the exception
kono
parents:
diff changeset
70 is caught in the native unix abi, where all of the xmm registers are
kono
parents:
diff changeset
71 call clobbered.
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 Ideally, we'd record some bit to notice when we're failing to restore some
kono
parents:
diff changeset
74 register recorded in the unwind info, but to do that we need annotation on
kono
parents:
diff changeset
75 the unix->ms abi edge, so that we know when the register data may be
kono
parents:
diff changeset
76 discarded. And since this edge is also within the ICC library, we're
kono
parents:
diff changeset
77 unlikely to be able to get the new annotation.
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 Barring a magic solution to restore the ms abi defined 128-bit xmm registers
kono
parents:
diff changeset
80 (as distictly opposed to the full runtime width) without causing extra
kono
parents:
diff changeset
81 overhead for normal unix abis, the best solution seems to be to simply
kono
parents:
diff changeset
82 ignore unwind data for unknown columns. */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 #define UNWIND_COLUMN_IN_RANGE(x) \
kono
parents:
diff changeset
85 __builtin_expect((x) <= __LIBGCC_DWARF_FRAME_REGISTERS__, 1)
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 #ifdef REG_VALUE_IN_UNWIND_CONTEXT
kono
parents:
diff changeset
88 typedef _Unwind_Word _Unwind_Context_Reg_Val;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
kono
parents:
diff changeset
91 #define ASSUME_EXTENDED_UNWIND_CONTEXT 1
kono
parents:
diff changeset
92 #endif
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 static inline _Unwind_Word
kono
parents:
diff changeset
95 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
kono
parents:
diff changeset
96 {
kono
parents:
diff changeset
97 return val;
kono
parents:
diff changeset
98 }
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 static inline _Unwind_Context_Reg_Val
kono
parents:
diff changeset
101 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
kono
parents:
diff changeset
102 {
kono
parents:
diff changeset
103 return val;
kono
parents:
diff changeset
104 }
kono
parents:
diff changeset
105 #else
kono
parents:
diff changeset
106 typedef void *_Unwind_Context_Reg_Val;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 static inline _Unwind_Word
kono
parents:
diff changeset
109 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
kono
parents:
diff changeset
110 {
kono
parents:
diff changeset
111 return (_Unwind_Word) (_Unwind_Internal_Ptr) val;
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 static inline _Unwind_Context_Reg_Val
kono
parents:
diff changeset
115 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
kono
parents:
diff changeset
116 {
kono
parents:
diff changeset
117 return (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) val;
kono
parents:
diff changeset
118 }
kono
parents:
diff changeset
119 #endif
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
kono
parents:
diff changeset
122 #define ASSUME_EXTENDED_UNWIND_CONTEXT 0
kono
parents:
diff changeset
123 #endif
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 /* This is the register and unwind state for a particular frame. This
kono
parents:
diff changeset
126 provides the information necessary to unwind up past a frame and return
kono
parents:
diff changeset
127 to its caller. */
kono
parents:
diff changeset
128 struct _Unwind_Context
kono
parents:
diff changeset
129 {
kono
parents:
diff changeset
130 _Unwind_Context_Reg_Val reg[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
kono
parents:
diff changeset
131 void *cfa;
kono
parents:
diff changeset
132 void *ra;
kono
parents:
diff changeset
133 void *lsda;
kono
parents:
diff changeset
134 struct dwarf_eh_bases bases;
kono
parents:
diff changeset
135 /* Signal frame context. */
kono
parents:
diff changeset
136 #define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
kono
parents:
diff changeset
137 /* Context which has version/args_size/by_value fields. */
kono
parents:
diff changeset
138 #define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
kono
parents:
diff changeset
139 /* Bit reserved on AArch64, return address has been signed with A key. */
kono
parents:
diff changeset
140 #define RA_A_SIGNED_BIT ((~(_Unwind_Word) 0 >> 3) + 1)
kono
parents:
diff changeset
141 _Unwind_Word flags;
kono
parents:
diff changeset
142 /* 0 for now, can be increased when further fields are added to
kono
parents:
diff changeset
143 struct _Unwind_Context. */
kono
parents:
diff changeset
144 _Unwind_Word version;
kono
parents:
diff changeset
145 _Unwind_Word args_size;
kono
parents:
diff changeset
146 char by_value[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
kono
parents:
diff changeset
147 };
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /* Byte size of every register managed by these routines. */
kono
parents:
diff changeset
150 static unsigned char dwarf_reg_size_table[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 /* Read unaligned data from the instruction buffer. */
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 union unaligned
kono
parents:
diff changeset
156 {
kono
parents:
diff changeset
157 void *p;
kono
parents:
diff changeset
158 unsigned u2 __attribute__ ((mode (HI)));
kono
parents:
diff changeset
159 unsigned u4 __attribute__ ((mode (SI)));
kono
parents:
diff changeset
160 unsigned u8 __attribute__ ((mode (DI)));
kono
parents:
diff changeset
161 signed s2 __attribute__ ((mode (HI)));
kono
parents:
diff changeset
162 signed s4 __attribute__ ((mode (SI)));
kono
parents:
diff changeset
163 signed s8 __attribute__ ((mode (DI)));
kono
parents:
diff changeset
164 } __attribute__ ((packed));
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 static void uw_update_context (struct _Unwind_Context *, _Unwind_FrameState *);
kono
parents:
diff changeset
167 static _Unwind_Reason_Code uw_frame_state_for (struct _Unwind_Context *,
kono
parents:
diff changeset
168 _Unwind_FrameState *);
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 static inline void *
kono
parents:
diff changeset
171 read_pointer (const void *p) { const union unaligned *up = p; return up->p; }
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 static inline int
kono
parents:
diff changeset
174 read_1u (const void *p) { return *(const unsigned char *) p; }
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 static inline int
kono
parents:
diff changeset
177 read_1s (const void *p) { return *(const signed char *) p; }
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 static inline int
kono
parents:
diff changeset
180 read_2u (const void *p) { const union unaligned *up = p; return up->u2; }
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 static inline int
kono
parents:
diff changeset
183 read_2s (const void *p) { const union unaligned *up = p; return up->s2; }
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 static inline unsigned int
kono
parents:
diff changeset
186 read_4u (const void *p) { const union unaligned *up = p; return up->u4; }
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 static inline int
kono
parents:
diff changeset
189 read_4s (const void *p) { const union unaligned *up = p; return up->s4; }
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 static inline unsigned long
kono
parents:
diff changeset
192 read_8u (const void *p) { const union unaligned *up = p; return up->u8; }
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 static inline unsigned long
kono
parents:
diff changeset
195 read_8s (const void *p) { const union unaligned *up = p; return up->s8; }
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 static inline _Unwind_Word
kono
parents:
diff changeset
198 _Unwind_IsSignalFrame (struct _Unwind_Context *context)
kono
parents:
diff changeset
199 {
kono
parents:
diff changeset
200 return (context->flags & SIGNAL_FRAME_BIT) ? 1 : 0;
kono
parents:
diff changeset
201 }
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 static inline void
kono
parents:
diff changeset
204 _Unwind_SetSignalFrame (struct _Unwind_Context *context, int val)
kono
parents:
diff changeset
205 {
kono
parents:
diff changeset
206 if (val)
kono
parents:
diff changeset
207 context->flags |= SIGNAL_FRAME_BIT;
kono
parents:
diff changeset
208 else
kono
parents:
diff changeset
209 context->flags &= ~SIGNAL_FRAME_BIT;
kono
parents:
diff changeset
210 }
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 static inline _Unwind_Word
kono
parents:
diff changeset
213 _Unwind_IsExtendedContext (struct _Unwind_Context *context)
kono
parents:
diff changeset
214 {
kono
parents:
diff changeset
215 return (ASSUME_EXTENDED_UNWIND_CONTEXT
kono
parents:
diff changeset
216 || (context->flags & EXTENDED_CONTEXT_BIT));
kono
parents:
diff changeset
217 }
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 /* Get the value of register INDEX as saved in CONTEXT. */
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 inline _Unwind_Word
kono
parents:
diff changeset
222 _Unwind_GetGR (struct _Unwind_Context *context, int index)
kono
parents:
diff changeset
223 {
kono
parents:
diff changeset
224 int size;
kono
parents:
diff changeset
225 _Unwind_Context_Reg_Val val;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 #ifdef DWARF_ZERO_REG
kono
parents:
diff changeset
228 if (index == DWARF_ZERO_REG)
kono
parents:
diff changeset
229 return 0;
kono
parents:
diff changeset
230 #endif
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 index = DWARF_REG_TO_UNWIND_COLUMN (index);
kono
parents:
diff changeset
233 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
kono
parents:
diff changeset
234 size = dwarf_reg_size_table[index];
kono
parents:
diff changeset
235 val = context->reg[index];
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
kono
parents:
diff changeset
238 return _Unwind_Get_Unwind_Word (val);
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 /* This will segfault if the register hasn't been saved. */
kono
parents:
diff changeset
241 if (size == sizeof(_Unwind_Ptr))
kono
parents:
diff changeset
242 return * (_Unwind_Ptr *) (_Unwind_Internal_Ptr) val;
kono
parents:
diff changeset
243 else
kono
parents:
diff changeset
244 {
kono
parents:
diff changeset
245 gcc_assert (size == sizeof(_Unwind_Word));
kono
parents:
diff changeset
246 return * (_Unwind_Word *) (_Unwind_Internal_Ptr) val;
kono
parents:
diff changeset
247 }
kono
parents:
diff changeset
248 }
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 static inline void *
kono
parents:
diff changeset
251 _Unwind_GetPtr (struct _Unwind_Context *context, int index)
kono
parents:
diff changeset
252 {
kono
parents:
diff changeset
253 return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index);
kono
parents:
diff changeset
254 }
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 /* Get the value of the CFA as saved in CONTEXT. */
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 _Unwind_Word
kono
parents:
diff changeset
259 _Unwind_GetCFA (struct _Unwind_Context *context)
kono
parents:
diff changeset
260 {
kono
parents:
diff changeset
261 return (_Unwind_Ptr) context->cfa;
kono
parents:
diff changeset
262 }
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 inline void
kono
parents:
diff changeset
267 _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
kono
parents:
diff changeset
268 {
kono
parents:
diff changeset
269 int size;
kono
parents:
diff changeset
270 void *ptr;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 index = DWARF_REG_TO_UNWIND_COLUMN (index);
kono
parents:
diff changeset
273 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
kono
parents:
diff changeset
274 size = dwarf_reg_size_table[index];
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
kono
parents:
diff changeset
277 {
kono
parents:
diff changeset
278 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
kono
parents:
diff changeset
279 return;
kono
parents:
diff changeset
280 }
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 ptr = (void *) (_Unwind_Internal_Ptr) context->reg[index];
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 if (size == sizeof(_Unwind_Ptr))
kono
parents:
diff changeset
285 * (_Unwind_Ptr *) ptr = val;
kono
parents:
diff changeset
286 else
kono
parents:
diff changeset
287 {
kono
parents:
diff changeset
288 gcc_assert (size == sizeof(_Unwind_Word));
kono
parents:
diff changeset
289 * (_Unwind_Word *) ptr = val;
kono
parents:
diff changeset
290 }
kono
parents:
diff changeset
291 }
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 /* Get the pointer to a register INDEX as saved in CONTEXT. */
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 static inline void *
kono
parents:
diff changeset
296 _Unwind_GetGRPtr (struct _Unwind_Context *context, int index)
kono
parents:
diff changeset
297 {
kono
parents:
diff changeset
298 index = DWARF_REG_TO_UNWIND_COLUMN (index);
kono
parents:
diff changeset
299 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
kono
parents:
diff changeset
300 return &context->reg[index];
kono
parents:
diff changeset
301 return (void *) (_Unwind_Internal_Ptr) context->reg[index];
kono
parents:
diff changeset
302 }
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 /* Set the pointer to a register INDEX as saved in CONTEXT. */
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 static inline void
kono
parents:
diff changeset
307 _Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p)
kono
parents:
diff changeset
308 {
kono
parents:
diff changeset
309 index = DWARF_REG_TO_UNWIND_COLUMN (index);
kono
parents:
diff changeset
310 if (_Unwind_IsExtendedContext (context))
kono
parents:
diff changeset
311 context->by_value[index] = 0;
kono
parents:
diff changeset
312 context->reg[index] = (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) p;
kono
parents:
diff changeset
313 }
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 static inline void
kono
parents:
diff changeset
318 _Unwind_SetGRValue (struct _Unwind_Context *context, int index,
kono
parents:
diff changeset
319 _Unwind_Word val)
kono
parents:
diff changeset
320 {
kono
parents:
diff changeset
321 index = DWARF_REG_TO_UNWIND_COLUMN (index);
kono
parents:
diff changeset
322 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
kono
parents:
diff changeset
323 /* Return column size may be smaller than _Unwind_Context_Reg_Val. */
kono
parents:
diff changeset
324 gcc_assert (dwarf_reg_size_table[index] <= sizeof (_Unwind_Context_Reg_Val));
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 context->by_value[index] = 1;
kono
parents:
diff changeset
327 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
kono
parents:
diff changeset
328 }
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 /* Return nonzero if register INDEX is stored by value rather than
kono
parents:
diff changeset
331 by reference. */
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 static inline int
kono
parents:
diff changeset
334 _Unwind_GRByValue (struct _Unwind_Context *context, int index)
kono
parents:
diff changeset
335 {
kono
parents:
diff changeset
336 index = DWARF_REG_TO_UNWIND_COLUMN (index);
kono
parents:
diff changeset
337 return context->by_value[index];
kono
parents:
diff changeset
338 }
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 /* Retrieve the return address for CONTEXT. */
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 inline _Unwind_Ptr
kono
parents:
diff changeset
343 _Unwind_GetIP (struct _Unwind_Context *context)
kono
parents:
diff changeset
344 {
kono
parents:
diff changeset
345 return (_Unwind_Ptr) context->ra;
kono
parents:
diff changeset
346 }
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 /* Retrieve the return address and flag whether that IP is before
kono
parents:
diff changeset
349 or after first not yet fully executed instruction. */
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 inline _Unwind_Ptr
kono
parents:
diff changeset
352 _Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
kono
parents:
diff changeset
353 {
kono
parents:
diff changeset
354 *ip_before_insn = _Unwind_IsSignalFrame (context);
kono
parents:
diff changeset
355 return (_Unwind_Ptr) context->ra;
kono
parents:
diff changeset
356 }
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 /* Overwrite the return address for CONTEXT with VAL. */
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 inline void
kono
parents:
diff changeset
361 _Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
kono
parents:
diff changeset
362 {
kono
parents:
diff changeset
363 context->ra = (void *) val;
kono
parents:
diff changeset
364 }
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 void *
kono
parents:
diff changeset
367 _Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
kono
parents:
diff changeset
368 {
kono
parents:
diff changeset
369 return context->lsda;
kono
parents:
diff changeset
370 }
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 _Unwind_Ptr
kono
parents:
diff changeset
373 _Unwind_GetRegionStart (struct _Unwind_Context *context)
kono
parents:
diff changeset
374 {
kono
parents:
diff changeset
375 return (_Unwind_Ptr) context->bases.func;
kono
parents:
diff changeset
376 }
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 void *
kono
parents:
diff changeset
379 _Unwind_FindEnclosingFunction (void *pc)
kono
parents:
diff changeset
380 {
kono
parents:
diff changeset
381 struct dwarf_eh_bases bases;
kono
parents:
diff changeset
382 const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
kono
parents:
diff changeset
383 if (fde)
kono
parents:
diff changeset
384 return bases.func;
kono
parents:
diff changeset
385 else
kono
parents:
diff changeset
386 return NULL;
kono
parents:
diff changeset
387 }
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 #ifndef __ia64__
kono
parents:
diff changeset
390 _Unwind_Ptr
kono
parents:
diff changeset
391 _Unwind_GetDataRelBase (struct _Unwind_Context *context)
kono
parents:
diff changeset
392 {
kono
parents:
diff changeset
393 return (_Unwind_Ptr) context->bases.dbase;
kono
parents:
diff changeset
394 }
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 _Unwind_Ptr
kono
parents:
diff changeset
397 _Unwind_GetTextRelBase (struct _Unwind_Context *context)
kono
parents:
diff changeset
398 {
kono
parents:
diff changeset
399 return (_Unwind_Ptr) context->bases.tbase;
kono
parents:
diff changeset
400 }
kono
parents:
diff changeset
401 #endif
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 #include "md-unwind-support.h"
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 /* Extract any interesting information from the CIE for the translation
kono
parents:
diff changeset
406 unit F belongs to. Return a pointer to the byte after the augmentation,
kono
parents:
diff changeset
407 or NULL if we encountered an undecipherable augmentation. */
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 static const unsigned char *
kono
parents:
diff changeset
410 extract_cie_info (const struct dwarf_cie *cie, struct _Unwind_Context *context,
kono
parents:
diff changeset
411 _Unwind_FrameState *fs)
kono
parents:
diff changeset
412 {
kono
parents:
diff changeset
413 const unsigned char *aug = cie->augmentation;
kono
parents:
diff changeset
414 const unsigned char *p = aug + strlen ((const char *)aug) + 1;
kono
parents:
diff changeset
415 const unsigned char *ret = NULL;
kono
parents:
diff changeset
416 _uleb128_t utmp;
kono
parents:
diff changeset
417 _sleb128_t stmp;
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 /* g++ v2 "eh" has pointer immediately following augmentation string,
kono
parents:
diff changeset
420 so it must be handled first. */
kono
parents:
diff changeset
421 if (aug[0] == 'e' && aug[1] == 'h')
kono
parents:
diff changeset
422 {
kono
parents:
diff changeset
423 fs->eh_ptr = read_pointer (p);
kono
parents:
diff changeset
424 p += sizeof (void *);
kono
parents:
diff changeset
425 aug += 2;
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 /* After the augmentation resp. pointer for "eh" augmentation
kono
parents:
diff changeset
429 follows for CIE version >= 4 address size byte and
kono
parents:
diff changeset
430 segment size byte. */
kono
parents:
diff changeset
431 if (__builtin_expect (cie->version >= 4, 0))
kono
parents:
diff changeset
432 {
kono
parents:
diff changeset
433 if (p[0] != sizeof (void *) || p[1] != 0)
kono
parents:
diff changeset
434 return NULL;
kono
parents:
diff changeset
435 p += 2;
kono
parents:
diff changeset
436 }
kono
parents:
diff changeset
437 /* Immediately following this are the code and
kono
parents:
diff changeset
438 data alignment and return address column. */
kono
parents:
diff changeset
439 p = read_uleb128 (p, &utmp);
kono
parents:
diff changeset
440 fs->code_align = (_Unwind_Word)utmp;
kono
parents:
diff changeset
441 p = read_sleb128 (p, &stmp);
kono
parents:
diff changeset
442 fs->data_align = (_Unwind_Sword)stmp;
kono
parents:
diff changeset
443 if (cie->version == 1)
kono
parents:
diff changeset
444 fs->retaddr_column = *p++;
kono
parents:
diff changeset
445 else
kono
parents:
diff changeset
446 {
kono
parents:
diff changeset
447 p = read_uleb128 (p, &utmp);
kono
parents:
diff changeset
448 fs->retaddr_column = (_Unwind_Word)utmp;
kono
parents:
diff changeset
449 }
kono
parents:
diff changeset
450 fs->lsda_encoding = DW_EH_PE_omit;
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 /* If the augmentation starts with 'z', then a uleb128 immediately
kono
parents:
diff changeset
453 follows containing the length of the augmentation field following
kono
parents:
diff changeset
454 the size. */
kono
parents:
diff changeset
455 if (*aug == 'z')
kono
parents:
diff changeset
456 {
kono
parents:
diff changeset
457 p = read_uleb128 (p, &utmp);
kono
parents:
diff changeset
458 ret = p + utmp;
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 fs->saw_z = 1;
kono
parents:
diff changeset
461 ++aug;
kono
parents:
diff changeset
462 }
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 /* Iterate over recognized augmentation subsequences. */
kono
parents:
diff changeset
465 while (*aug != '\0')
kono
parents:
diff changeset
466 {
kono
parents:
diff changeset
467 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
kono
parents:
diff changeset
468 if (aug[0] == 'L')
kono
parents:
diff changeset
469 {
kono
parents:
diff changeset
470 fs->lsda_encoding = *p++;
kono
parents:
diff changeset
471 aug += 1;
kono
parents:
diff changeset
472 }
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 /* "R" indicates a byte indicating how FDE addresses are encoded. */
kono
parents:
diff changeset
475 else if (aug[0] == 'R')
kono
parents:
diff changeset
476 {
kono
parents:
diff changeset
477 fs->fde_encoding = *p++;
kono
parents:
diff changeset
478 aug += 1;
kono
parents:
diff changeset
479 }
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 /* "P" indicates a personality routine in the CIE augmentation. */
kono
parents:
diff changeset
482 else if (aug[0] == 'P')
kono
parents:
diff changeset
483 {
kono
parents:
diff changeset
484 _Unwind_Ptr personality;
kono
parents:
diff changeset
485
kono
parents:
diff changeset
486 p = read_encoded_value (context, *p, p + 1, &personality);
kono
parents:
diff changeset
487 fs->personality = (_Unwind_Personality_Fn) personality;
kono
parents:
diff changeset
488 aug += 1;
kono
parents:
diff changeset
489 }
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 /* "S" indicates a signal frame. */
kono
parents:
diff changeset
492 else if (aug[0] == 'S')
kono
parents:
diff changeset
493 {
kono
parents:
diff changeset
494 fs->signal_frame = 1;
kono
parents:
diff changeset
495 aug += 1;
kono
parents:
diff changeset
496 }
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 /* Otherwise we have an unknown augmentation string.
kono
parents:
diff changeset
499 Bail unless we saw a 'z' prefix. */
kono
parents:
diff changeset
500 else
kono
parents:
diff changeset
501 return ret;
kono
parents:
diff changeset
502 }
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 return ret ? ret : p;
kono
parents:
diff changeset
505 }
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
kono
parents:
diff changeset
509 onto the stack to start. */
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 static _Unwind_Word
kono
parents:
diff changeset
512 execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
kono
parents:
diff changeset
513 struct _Unwind_Context *context, _Unwind_Word initial)
kono
parents:
diff changeset
514 {
kono
parents:
diff changeset
515 _Unwind_Word stack[64]; /* ??? Assume this is enough. */
kono
parents:
diff changeset
516 int stack_elt;
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 stack[0] = initial;
kono
parents:
diff changeset
519 stack_elt = 1;
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 while (op_ptr < op_end)
kono
parents:
diff changeset
522 {
kono
parents:
diff changeset
523 enum dwarf_location_atom op = *op_ptr++;
kono
parents:
diff changeset
524 _Unwind_Word result;
kono
parents:
diff changeset
525 _uleb128_t reg, utmp;
kono
parents:
diff changeset
526 _sleb128_t offset, stmp;
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 switch (op)
kono
parents:
diff changeset
529 {
kono
parents:
diff changeset
530 case DW_OP_lit0:
kono
parents:
diff changeset
531 case DW_OP_lit1:
kono
parents:
diff changeset
532 case DW_OP_lit2:
kono
parents:
diff changeset
533 case DW_OP_lit3:
kono
parents:
diff changeset
534 case DW_OP_lit4:
kono
parents:
diff changeset
535 case DW_OP_lit5:
kono
parents:
diff changeset
536 case DW_OP_lit6:
kono
parents:
diff changeset
537 case DW_OP_lit7:
kono
parents:
diff changeset
538 case DW_OP_lit8:
kono
parents:
diff changeset
539 case DW_OP_lit9:
kono
parents:
diff changeset
540 case DW_OP_lit10:
kono
parents:
diff changeset
541 case DW_OP_lit11:
kono
parents:
diff changeset
542 case DW_OP_lit12:
kono
parents:
diff changeset
543 case DW_OP_lit13:
kono
parents:
diff changeset
544 case DW_OP_lit14:
kono
parents:
diff changeset
545 case DW_OP_lit15:
kono
parents:
diff changeset
546 case DW_OP_lit16:
kono
parents:
diff changeset
547 case DW_OP_lit17:
kono
parents:
diff changeset
548 case DW_OP_lit18:
kono
parents:
diff changeset
549 case DW_OP_lit19:
kono
parents:
diff changeset
550 case DW_OP_lit20:
kono
parents:
diff changeset
551 case DW_OP_lit21:
kono
parents:
diff changeset
552 case DW_OP_lit22:
kono
parents:
diff changeset
553 case DW_OP_lit23:
kono
parents:
diff changeset
554 case DW_OP_lit24:
kono
parents:
diff changeset
555 case DW_OP_lit25:
kono
parents:
diff changeset
556 case DW_OP_lit26:
kono
parents:
diff changeset
557 case DW_OP_lit27:
kono
parents:
diff changeset
558 case DW_OP_lit28:
kono
parents:
diff changeset
559 case DW_OP_lit29:
kono
parents:
diff changeset
560 case DW_OP_lit30:
kono
parents:
diff changeset
561 case DW_OP_lit31:
kono
parents:
diff changeset
562 result = op - DW_OP_lit0;
kono
parents:
diff changeset
563 break;
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 case DW_OP_addr:
kono
parents:
diff changeset
566 result = (_Unwind_Word) (_Unwind_Ptr) read_pointer (op_ptr);
kono
parents:
diff changeset
567 op_ptr += sizeof (void *);
kono
parents:
diff changeset
568 break;
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 case DW_OP_GNU_encoded_addr:
kono
parents:
diff changeset
571 {
kono
parents:
diff changeset
572 _Unwind_Ptr presult;
kono
parents:
diff changeset
573 op_ptr = read_encoded_value (context, *op_ptr, op_ptr+1, &presult);
kono
parents:
diff changeset
574 result = presult;
kono
parents:
diff changeset
575 }
kono
parents:
diff changeset
576 break;
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 case DW_OP_const1u:
kono
parents:
diff changeset
579 result = read_1u (op_ptr);
kono
parents:
diff changeset
580 op_ptr += 1;
kono
parents:
diff changeset
581 break;
kono
parents:
diff changeset
582 case DW_OP_const1s:
kono
parents:
diff changeset
583 result = read_1s (op_ptr);
kono
parents:
diff changeset
584 op_ptr += 1;
kono
parents:
diff changeset
585 break;
kono
parents:
diff changeset
586 case DW_OP_const2u:
kono
parents:
diff changeset
587 result = read_2u (op_ptr);
kono
parents:
diff changeset
588 op_ptr += 2;
kono
parents:
diff changeset
589 break;
kono
parents:
diff changeset
590 case DW_OP_const2s:
kono
parents:
diff changeset
591 result = read_2s (op_ptr);
kono
parents:
diff changeset
592 op_ptr += 2;
kono
parents:
diff changeset
593 break;
kono
parents:
diff changeset
594 case DW_OP_const4u:
kono
parents:
diff changeset
595 result = read_4u (op_ptr);
kono
parents:
diff changeset
596 op_ptr += 4;
kono
parents:
diff changeset
597 break;
kono
parents:
diff changeset
598 case DW_OP_const4s:
kono
parents:
diff changeset
599 result = read_4s (op_ptr);
kono
parents:
diff changeset
600 op_ptr += 4;
kono
parents:
diff changeset
601 break;
kono
parents:
diff changeset
602 case DW_OP_const8u:
kono
parents:
diff changeset
603 result = read_8u (op_ptr);
kono
parents:
diff changeset
604 op_ptr += 8;
kono
parents:
diff changeset
605 break;
kono
parents:
diff changeset
606 case DW_OP_const8s:
kono
parents:
diff changeset
607 result = read_8s (op_ptr);
kono
parents:
diff changeset
608 op_ptr += 8;
kono
parents:
diff changeset
609 break;
kono
parents:
diff changeset
610 case DW_OP_constu:
kono
parents:
diff changeset
611 op_ptr = read_uleb128 (op_ptr, &utmp);
kono
parents:
diff changeset
612 result = (_Unwind_Word)utmp;
kono
parents:
diff changeset
613 break;
kono
parents:
diff changeset
614 case DW_OP_consts:
kono
parents:
diff changeset
615 op_ptr = read_sleb128 (op_ptr, &stmp);
kono
parents:
diff changeset
616 result = (_Unwind_Sword)stmp;
kono
parents:
diff changeset
617 break;
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 case DW_OP_reg0:
kono
parents:
diff changeset
620 case DW_OP_reg1:
kono
parents:
diff changeset
621 case DW_OP_reg2:
kono
parents:
diff changeset
622 case DW_OP_reg3:
kono
parents:
diff changeset
623 case DW_OP_reg4:
kono
parents:
diff changeset
624 case DW_OP_reg5:
kono
parents:
diff changeset
625 case DW_OP_reg6:
kono
parents:
diff changeset
626 case DW_OP_reg7:
kono
parents:
diff changeset
627 case DW_OP_reg8:
kono
parents:
diff changeset
628 case DW_OP_reg9:
kono
parents:
diff changeset
629 case DW_OP_reg10:
kono
parents:
diff changeset
630 case DW_OP_reg11:
kono
parents:
diff changeset
631 case DW_OP_reg12:
kono
parents:
diff changeset
632 case DW_OP_reg13:
kono
parents:
diff changeset
633 case DW_OP_reg14:
kono
parents:
diff changeset
634 case DW_OP_reg15:
kono
parents:
diff changeset
635 case DW_OP_reg16:
kono
parents:
diff changeset
636 case DW_OP_reg17:
kono
parents:
diff changeset
637 case DW_OP_reg18:
kono
parents:
diff changeset
638 case DW_OP_reg19:
kono
parents:
diff changeset
639 case DW_OP_reg20:
kono
parents:
diff changeset
640 case DW_OP_reg21:
kono
parents:
diff changeset
641 case DW_OP_reg22:
kono
parents:
diff changeset
642 case DW_OP_reg23:
kono
parents:
diff changeset
643 case DW_OP_reg24:
kono
parents:
diff changeset
644 case DW_OP_reg25:
kono
parents:
diff changeset
645 case DW_OP_reg26:
kono
parents:
diff changeset
646 case DW_OP_reg27:
kono
parents:
diff changeset
647 case DW_OP_reg28:
kono
parents:
diff changeset
648 case DW_OP_reg29:
kono
parents:
diff changeset
649 case DW_OP_reg30:
kono
parents:
diff changeset
650 case DW_OP_reg31:
kono
parents:
diff changeset
651 result = _Unwind_GetGR (context, op - DW_OP_reg0);
kono
parents:
diff changeset
652 break;
kono
parents:
diff changeset
653 case DW_OP_regx:
kono
parents:
diff changeset
654 op_ptr = read_uleb128 (op_ptr, &reg);
kono
parents:
diff changeset
655 result = _Unwind_GetGR (context, reg);
kono
parents:
diff changeset
656 break;
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 case DW_OP_breg0:
kono
parents:
diff changeset
659 case DW_OP_breg1:
kono
parents:
diff changeset
660 case DW_OP_breg2:
kono
parents:
diff changeset
661 case DW_OP_breg3:
kono
parents:
diff changeset
662 case DW_OP_breg4:
kono
parents:
diff changeset
663 case DW_OP_breg5:
kono
parents:
diff changeset
664 case DW_OP_breg6:
kono
parents:
diff changeset
665 case DW_OP_breg7:
kono
parents:
diff changeset
666 case DW_OP_breg8:
kono
parents:
diff changeset
667 case DW_OP_breg9:
kono
parents:
diff changeset
668 case DW_OP_breg10:
kono
parents:
diff changeset
669 case DW_OP_breg11:
kono
parents:
diff changeset
670 case DW_OP_breg12:
kono
parents:
diff changeset
671 case DW_OP_breg13:
kono
parents:
diff changeset
672 case DW_OP_breg14:
kono
parents:
diff changeset
673 case DW_OP_breg15:
kono
parents:
diff changeset
674 case DW_OP_breg16:
kono
parents:
diff changeset
675 case DW_OP_breg17:
kono
parents:
diff changeset
676 case DW_OP_breg18:
kono
parents:
diff changeset
677 case DW_OP_breg19:
kono
parents:
diff changeset
678 case DW_OP_breg20:
kono
parents:
diff changeset
679 case DW_OP_breg21:
kono
parents:
diff changeset
680 case DW_OP_breg22:
kono
parents:
diff changeset
681 case DW_OP_breg23:
kono
parents:
diff changeset
682 case DW_OP_breg24:
kono
parents:
diff changeset
683 case DW_OP_breg25:
kono
parents:
diff changeset
684 case DW_OP_breg26:
kono
parents:
diff changeset
685 case DW_OP_breg27:
kono
parents:
diff changeset
686 case DW_OP_breg28:
kono
parents:
diff changeset
687 case DW_OP_breg29:
kono
parents:
diff changeset
688 case DW_OP_breg30:
kono
parents:
diff changeset
689 case DW_OP_breg31:
kono
parents:
diff changeset
690 op_ptr = read_sleb128 (op_ptr, &offset);
kono
parents:
diff changeset
691 result = _Unwind_GetGR (context, op - DW_OP_breg0) + offset;
kono
parents:
diff changeset
692 break;
kono
parents:
diff changeset
693 case DW_OP_bregx:
kono
parents:
diff changeset
694 op_ptr = read_uleb128 (op_ptr, &reg);
kono
parents:
diff changeset
695 op_ptr = read_sleb128 (op_ptr, &offset);
kono
parents:
diff changeset
696 result = _Unwind_GetGR (context, reg) + (_Unwind_Word)offset;
kono
parents:
diff changeset
697 break;
kono
parents:
diff changeset
698
kono
parents:
diff changeset
699 case DW_OP_dup:
kono
parents:
diff changeset
700 gcc_assert (stack_elt);
kono
parents:
diff changeset
701 result = stack[stack_elt - 1];
kono
parents:
diff changeset
702 break;
kono
parents:
diff changeset
703
kono
parents:
diff changeset
704 case DW_OP_drop:
kono
parents:
diff changeset
705 gcc_assert (stack_elt);
kono
parents:
diff changeset
706 stack_elt -= 1;
kono
parents:
diff changeset
707 goto no_push;
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 case DW_OP_pick:
kono
parents:
diff changeset
710 offset = *op_ptr++;
kono
parents:
diff changeset
711 gcc_assert (offset < stack_elt - 1);
kono
parents:
diff changeset
712 result = stack[stack_elt - 1 - offset];
kono
parents:
diff changeset
713 break;
kono
parents:
diff changeset
714
kono
parents:
diff changeset
715 case DW_OP_over:
kono
parents:
diff changeset
716 gcc_assert (stack_elt >= 2);
kono
parents:
diff changeset
717 result = stack[stack_elt - 2];
kono
parents:
diff changeset
718 break;
kono
parents:
diff changeset
719
kono
parents:
diff changeset
720 case DW_OP_swap:
kono
parents:
diff changeset
721 {
kono
parents:
diff changeset
722 _Unwind_Word t;
kono
parents:
diff changeset
723 gcc_assert (stack_elt >= 2);
kono
parents:
diff changeset
724 t = stack[stack_elt - 1];
kono
parents:
diff changeset
725 stack[stack_elt - 1] = stack[stack_elt - 2];
kono
parents:
diff changeset
726 stack[stack_elt - 2] = t;
kono
parents:
diff changeset
727 goto no_push;
kono
parents:
diff changeset
728 }
kono
parents:
diff changeset
729
kono
parents:
diff changeset
730 case DW_OP_rot:
kono
parents:
diff changeset
731 {
kono
parents:
diff changeset
732 _Unwind_Word t1, t2, t3;
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 gcc_assert (stack_elt >= 3);
kono
parents:
diff changeset
735 t1 = stack[stack_elt - 1];
kono
parents:
diff changeset
736 t2 = stack[stack_elt - 2];
kono
parents:
diff changeset
737 t3 = stack[stack_elt - 3];
kono
parents:
diff changeset
738 stack[stack_elt - 1] = t2;
kono
parents:
diff changeset
739 stack[stack_elt - 2] = t3;
kono
parents:
diff changeset
740 stack[stack_elt - 3] = t1;
kono
parents:
diff changeset
741 goto no_push;
kono
parents:
diff changeset
742 }
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 case DW_OP_deref:
kono
parents:
diff changeset
745 case DW_OP_deref_size:
kono
parents:
diff changeset
746 case DW_OP_abs:
kono
parents:
diff changeset
747 case DW_OP_neg:
kono
parents:
diff changeset
748 case DW_OP_not:
kono
parents:
diff changeset
749 case DW_OP_plus_uconst:
kono
parents:
diff changeset
750 /* Unary operations. */
kono
parents:
diff changeset
751 gcc_assert (stack_elt);
kono
parents:
diff changeset
752 stack_elt -= 1;
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 result = stack[stack_elt];
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 switch (op)
kono
parents:
diff changeset
757 {
kono
parents:
diff changeset
758 case DW_OP_deref:
kono
parents:
diff changeset
759 {
kono
parents:
diff changeset
760 void *ptr = (void *) (_Unwind_Ptr) result;
kono
parents:
diff changeset
761 result = (_Unwind_Ptr) read_pointer (ptr);
kono
parents:
diff changeset
762 }
kono
parents:
diff changeset
763 break;
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 case DW_OP_deref_size:
kono
parents:
diff changeset
766 {
kono
parents:
diff changeset
767 void *ptr = (void *) (_Unwind_Ptr) result;
kono
parents:
diff changeset
768 switch (*op_ptr++)
kono
parents:
diff changeset
769 {
kono
parents:
diff changeset
770 case 1:
kono
parents:
diff changeset
771 result = read_1u (ptr);
kono
parents:
diff changeset
772 break;
kono
parents:
diff changeset
773 case 2:
kono
parents:
diff changeset
774 result = read_2u (ptr);
kono
parents:
diff changeset
775 break;
kono
parents:
diff changeset
776 case 4:
kono
parents:
diff changeset
777 result = read_4u (ptr);
kono
parents:
diff changeset
778 break;
kono
parents:
diff changeset
779 case 8:
kono
parents:
diff changeset
780 result = read_8u (ptr);
kono
parents:
diff changeset
781 break;
kono
parents:
diff changeset
782 default:
kono
parents:
diff changeset
783 gcc_unreachable ();
kono
parents:
diff changeset
784 }
kono
parents:
diff changeset
785 }
kono
parents:
diff changeset
786 break;
kono
parents:
diff changeset
787
kono
parents:
diff changeset
788 case DW_OP_abs:
kono
parents:
diff changeset
789 if ((_Unwind_Sword) result < 0)
kono
parents:
diff changeset
790 result = -result;
kono
parents:
diff changeset
791 break;
kono
parents:
diff changeset
792 case DW_OP_neg:
kono
parents:
diff changeset
793 result = -result;
kono
parents:
diff changeset
794 break;
kono
parents:
diff changeset
795 case DW_OP_not:
kono
parents:
diff changeset
796 result = ~result;
kono
parents:
diff changeset
797 break;
kono
parents:
diff changeset
798 case DW_OP_plus_uconst:
kono
parents:
diff changeset
799 op_ptr = read_uleb128 (op_ptr, &utmp);
kono
parents:
diff changeset
800 result += (_Unwind_Word)utmp;
kono
parents:
diff changeset
801 break;
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 default:
kono
parents:
diff changeset
804 gcc_unreachable ();
kono
parents:
diff changeset
805 }
kono
parents:
diff changeset
806 break;
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 case DW_OP_and:
kono
parents:
diff changeset
809 case DW_OP_div:
kono
parents:
diff changeset
810 case DW_OP_minus:
kono
parents:
diff changeset
811 case DW_OP_mod:
kono
parents:
diff changeset
812 case DW_OP_mul:
kono
parents:
diff changeset
813 case DW_OP_or:
kono
parents:
diff changeset
814 case DW_OP_plus:
kono
parents:
diff changeset
815 case DW_OP_shl:
kono
parents:
diff changeset
816 case DW_OP_shr:
kono
parents:
diff changeset
817 case DW_OP_shra:
kono
parents:
diff changeset
818 case DW_OP_xor:
kono
parents:
diff changeset
819 case DW_OP_le:
kono
parents:
diff changeset
820 case DW_OP_ge:
kono
parents:
diff changeset
821 case DW_OP_eq:
kono
parents:
diff changeset
822 case DW_OP_lt:
kono
parents:
diff changeset
823 case DW_OP_gt:
kono
parents:
diff changeset
824 case DW_OP_ne:
kono
parents:
diff changeset
825 {
kono
parents:
diff changeset
826 /* Binary operations. */
kono
parents:
diff changeset
827 _Unwind_Word first, second;
kono
parents:
diff changeset
828 gcc_assert (stack_elt >= 2);
kono
parents:
diff changeset
829 stack_elt -= 2;
kono
parents:
diff changeset
830
kono
parents:
diff changeset
831 second = stack[stack_elt];
kono
parents:
diff changeset
832 first = stack[stack_elt + 1];
kono
parents:
diff changeset
833
kono
parents:
diff changeset
834 switch (op)
kono
parents:
diff changeset
835 {
kono
parents:
diff changeset
836 case DW_OP_and:
kono
parents:
diff changeset
837 result = second & first;
kono
parents:
diff changeset
838 break;
kono
parents:
diff changeset
839 case DW_OP_div:
kono
parents:
diff changeset
840 result = (_Unwind_Sword) second / (_Unwind_Sword) first;
kono
parents:
diff changeset
841 break;
kono
parents:
diff changeset
842 case DW_OP_minus:
kono
parents:
diff changeset
843 result = second - first;
kono
parents:
diff changeset
844 break;
kono
parents:
diff changeset
845 case DW_OP_mod:
kono
parents:
diff changeset
846 result = second % first;
kono
parents:
diff changeset
847 break;
kono
parents:
diff changeset
848 case DW_OP_mul:
kono
parents:
diff changeset
849 result = second * first;
kono
parents:
diff changeset
850 break;
kono
parents:
diff changeset
851 case DW_OP_or:
kono
parents:
diff changeset
852 result = second | first;
kono
parents:
diff changeset
853 break;
kono
parents:
diff changeset
854 case DW_OP_plus:
kono
parents:
diff changeset
855 result = second + first;
kono
parents:
diff changeset
856 break;
kono
parents:
diff changeset
857 case DW_OP_shl:
kono
parents:
diff changeset
858 result = second << first;
kono
parents:
diff changeset
859 break;
kono
parents:
diff changeset
860 case DW_OP_shr:
kono
parents:
diff changeset
861 result = second >> first;
kono
parents:
diff changeset
862 break;
kono
parents:
diff changeset
863 case DW_OP_shra:
kono
parents:
diff changeset
864 result = (_Unwind_Sword) second >> first;
kono
parents:
diff changeset
865 break;
kono
parents:
diff changeset
866 case DW_OP_xor:
kono
parents:
diff changeset
867 result = second ^ first;
kono
parents:
diff changeset
868 break;
kono
parents:
diff changeset
869 case DW_OP_le:
kono
parents:
diff changeset
870 result = (_Unwind_Sword) second <= (_Unwind_Sword) first;
kono
parents:
diff changeset
871 break;
kono
parents:
diff changeset
872 case DW_OP_ge:
kono
parents:
diff changeset
873 result = (_Unwind_Sword) second >= (_Unwind_Sword) first;
kono
parents:
diff changeset
874 break;
kono
parents:
diff changeset
875 case DW_OP_eq:
kono
parents:
diff changeset
876 result = (_Unwind_Sword) second == (_Unwind_Sword) first;
kono
parents:
diff changeset
877 break;
kono
parents:
diff changeset
878 case DW_OP_lt:
kono
parents:
diff changeset
879 result = (_Unwind_Sword) second < (_Unwind_Sword) first;
kono
parents:
diff changeset
880 break;
kono
parents:
diff changeset
881 case DW_OP_gt:
kono
parents:
diff changeset
882 result = (_Unwind_Sword) second > (_Unwind_Sword) first;
kono
parents:
diff changeset
883 break;
kono
parents:
diff changeset
884 case DW_OP_ne:
kono
parents:
diff changeset
885 result = (_Unwind_Sword) second != (_Unwind_Sword) first;
kono
parents:
diff changeset
886 break;
kono
parents:
diff changeset
887
kono
parents:
diff changeset
888 default:
kono
parents:
diff changeset
889 gcc_unreachable ();
kono
parents:
diff changeset
890 }
kono
parents:
diff changeset
891 }
kono
parents:
diff changeset
892 break;
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 case DW_OP_skip:
kono
parents:
diff changeset
895 offset = read_2s (op_ptr);
kono
parents:
diff changeset
896 op_ptr += 2;
kono
parents:
diff changeset
897 op_ptr += offset;
kono
parents:
diff changeset
898 goto no_push;
kono
parents:
diff changeset
899
kono
parents:
diff changeset
900 case DW_OP_bra:
kono
parents:
diff changeset
901 gcc_assert (stack_elt);
kono
parents:
diff changeset
902 stack_elt -= 1;
kono
parents:
diff changeset
903
kono
parents:
diff changeset
904 offset = read_2s (op_ptr);
kono
parents:
diff changeset
905 op_ptr += 2;
kono
parents:
diff changeset
906 if (stack[stack_elt] != 0)
kono
parents:
diff changeset
907 op_ptr += offset;
kono
parents:
diff changeset
908 goto no_push;
kono
parents:
diff changeset
909
kono
parents:
diff changeset
910 case DW_OP_nop:
kono
parents:
diff changeset
911 goto no_push;
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 default:
kono
parents:
diff changeset
914 gcc_unreachable ();
kono
parents:
diff changeset
915 }
kono
parents:
diff changeset
916
kono
parents:
diff changeset
917 /* Most things push a result value. */
kono
parents:
diff changeset
918 gcc_assert ((size_t) stack_elt < sizeof(stack)/sizeof(*stack));
kono
parents:
diff changeset
919 stack[stack_elt++] = result;
kono
parents:
diff changeset
920 no_push:;
kono
parents:
diff changeset
921 }
kono
parents:
diff changeset
922
kono
parents:
diff changeset
923 /* We were executing this program to get a value. It should be
kono
parents:
diff changeset
924 at top of stack. */
kono
parents:
diff changeset
925 gcc_assert (stack_elt);
kono
parents:
diff changeset
926 stack_elt -= 1;
kono
parents:
diff changeset
927 return stack[stack_elt];
kono
parents:
diff changeset
928 }
kono
parents:
diff changeset
929
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 /* Decode DWARF 2 call frame information. Takes pointers the
kono
parents:
diff changeset
932 instruction sequence to decode, current register information and
kono
parents:
diff changeset
933 CIE info, and the PC range to evaluate. */
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 static void
kono
parents:
diff changeset
936 execute_cfa_program (const unsigned char *insn_ptr,
kono
parents:
diff changeset
937 const unsigned char *insn_end,
kono
parents:
diff changeset
938 struct _Unwind_Context *context,
kono
parents:
diff changeset
939 _Unwind_FrameState *fs)
kono
parents:
diff changeset
940 {
kono
parents:
diff changeset
941 struct frame_state_reg_info *unused_rs = NULL;
kono
parents:
diff changeset
942
kono
parents:
diff changeset
943 /* Don't allow remember/restore between CIE and FDE programs. */
kono
parents:
diff changeset
944 fs->regs.prev = NULL;
kono
parents:
diff changeset
945
kono
parents:
diff changeset
946 /* The comparison with the return address uses < rather than <= because
kono
parents:
diff changeset
947 we are only interested in the effects of code before the call; for a
kono
parents:
diff changeset
948 noreturn function, the return address may point to unrelated code with
kono
parents:
diff changeset
949 a different stack configuration that we are not interested in. We
kono
parents:
diff changeset
950 assume that the call itself is unwind info-neutral; if not, or if
kono
parents:
diff changeset
951 there are delay instructions that adjust the stack, these must be
kono
parents:
diff changeset
952 reflected at the point immediately before the call insn.
kono
parents:
diff changeset
953 In signal frames, return address is after last completed instruction,
kono
parents:
diff changeset
954 so we add 1 to return address to make the comparison <=. */
kono
parents:
diff changeset
955 while (insn_ptr < insn_end
kono
parents:
diff changeset
956 && fs->pc < context->ra + _Unwind_IsSignalFrame (context))
kono
parents:
diff changeset
957 {
kono
parents:
diff changeset
958 unsigned char insn = *insn_ptr++;
kono
parents:
diff changeset
959 _uleb128_t reg, utmp;
kono
parents:
diff changeset
960 _sleb128_t offset, stmp;
kono
parents:
diff changeset
961
kono
parents:
diff changeset
962 if ((insn & 0xc0) == DW_CFA_advance_loc)
kono
parents:
diff changeset
963 fs->pc += (insn & 0x3f) * fs->code_align;
kono
parents:
diff changeset
964 else if ((insn & 0xc0) == DW_CFA_offset)
kono
parents:
diff changeset
965 {
kono
parents:
diff changeset
966 reg = insn & 0x3f;
kono
parents:
diff changeset
967 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
968 offset = (_Unwind_Sword) utmp * fs->data_align;
kono
parents:
diff changeset
969 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
970 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
971 {
kono
parents:
diff changeset
972 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
kono
parents:
diff changeset
973 fs->regs.reg[reg].loc.offset = offset;
kono
parents:
diff changeset
974 }
kono
parents:
diff changeset
975 }
kono
parents:
diff changeset
976 else if ((insn & 0xc0) == DW_CFA_restore)
kono
parents:
diff changeset
977 {
kono
parents:
diff changeset
978 reg = insn & 0x3f;
kono
parents:
diff changeset
979 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
980 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
981 fs->regs.reg[reg].how = REG_UNSAVED;
kono
parents:
diff changeset
982 }
kono
parents:
diff changeset
983 else switch (insn)
kono
parents:
diff changeset
984 {
kono
parents:
diff changeset
985 case DW_CFA_set_loc:
kono
parents:
diff changeset
986 {
kono
parents:
diff changeset
987 _Unwind_Ptr pc;
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 insn_ptr = read_encoded_value (context, fs->fde_encoding,
kono
parents:
diff changeset
990 insn_ptr, &pc);
kono
parents:
diff changeset
991 fs->pc = (void *) pc;
kono
parents:
diff changeset
992 }
kono
parents:
diff changeset
993 break;
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 case DW_CFA_advance_loc1:
kono
parents:
diff changeset
996 fs->pc += read_1u (insn_ptr) * fs->code_align;
kono
parents:
diff changeset
997 insn_ptr += 1;
kono
parents:
diff changeset
998 break;
kono
parents:
diff changeset
999 case DW_CFA_advance_loc2:
kono
parents:
diff changeset
1000 fs->pc += read_2u (insn_ptr) * fs->code_align;
kono
parents:
diff changeset
1001 insn_ptr += 2;
kono
parents:
diff changeset
1002 break;
kono
parents:
diff changeset
1003 case DW_CFA_advance_loc4:
kono
parents:
diff changeset
1004 fs->pc += read_4u (insn_ptr) * fs->code_align;
kono
parents:
diff changeset
1005 insn_ptr += 4;
kono
parents:
diff changeset
1006 break;
kono
parents:
diff changeset
1007
kono
parents:
diff changeset
1008 case DW_CFA_offset_extended:
kono
parents:
diff changeset
1009 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1010 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1011 offset = (_Unwind_Sword) utmp * fs->data_align;
kono
parents:
diff changeset
1012 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1013 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1014 {
kono
parents:
diff changeset
1015 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
kono
parents:
diff changeset
1016 fs->regs.reg[reg].loc.offset = offset;
kono
parents:
diff changeset
1017 }
kono
parents:
diff changeset
1018 break;
kono
parents:
diff changeset
1019
kono
parents:
diff changeset
1020 case DW_CFA_restore_extended:
kono
parents:
diff changeset
1021 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1022 /* FIXME, this is wrong; the CIE might have said that the
kono
parents:
diff changeset
1023 register was saved somewhere. */
kono
parents:
diff changeset
1024 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1025 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1026 fs->regs.reg[reg].how = REG_UNSAVED;
kono
parents:
diff changeset
1027 break;
kono
parents:
diff changeset
1028
kono
parents:
diff changeset
1029 case DW_CFA_same_value:
kono
parents:
diff changeset
1030 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1031 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1032 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1033 fs->regs.reg[reg].how = REG_UNSAVED;
kono
parents:
diff changeset
1034 break;
kono
parents:
diff changeset
1035
kono
parents:
diff changeset
1036 case DW_CFA_undefined:
kono
parents:
diff changeset
1037 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1038 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1039 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1040 fs->regs.reg[reg].how = REG_UNDEFINED;
kono
parents:
diff changeset
1041 break;
kono
parents:
diff changeset
1042
kono
parents:
diff changeset
1043 case DW_CFA_nop:
kono
parents:
diff changeset
1044 break;
kono
parents:
diff changeset
1045
kono
parents:
diff changeset
1046 case DW_CFA_register:
kono
parents:
diff changeset
1047 {
kono
parents:
diff changeset
1048 _uleb128_t reg2;
kono
parents:
diff changeset
1049 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1050 insn_ptr = read_uleb128 (insn_ptr, &reg2);
kono
parents:
diff changeset
1051 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1052 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1053 {
kono
parents:
diff changeset
1054 fs->regs.reg[reg].how = REG_SAVED_REG;
kono
parents:
diff changeset
1055 fs->regs.reg[reg].loc.reg = (_Unwind_Word)reg2;
kono
parents:
diff changeset
1056 }
kono
parents:
diff changeset
1057 }
kono
parents:
diff changeset
1058 break;
kono
parents:
diff changeset
1059
kono
parents:
diff changeset
1060 case DW_CFA_remember_state:
kono
parents:
diff changeset
1061 {
kono
parents:
diff changeset
1062 struct frame_state_reg_info *new_rs;
kono
parents:
diff changeset
1063 if (unused_rs)
kono
parents:
diff changeset
1064 {
kono
parents:
diff changeset
1065 new_rs = unused_rs;
kono
parents:
diff changeset
1066 unused_rs = unused_rs->prev;
kono
parents:
diff changeset
1067 }
kono
parents:
diff changeset
1068 else
kono
parents:
diff changeset
1069 new_rs = alloca (sizeof (struct frame_state_reg_info));
kono
parents:
diff changeset
1070
kono
parents:
diff changeset
1071 *new_rs = fs->regs;
kono
parents:
diff changeset
1072 fs->regs.prev = new_rs;
kono
parents:
diff changeset
1073 }
kono
parents:
diff changeset
1074 break;
kono
parents:
diff changeset
1075
kono
parents:
diff changeset
1076 case DW_CFA_restore_state:
kono
parents:
diff changeset
1077 {
kono
parents:
diff changeset
1078 struct frame_state_reg_info *old_rs = fs->regs.prev;
kono
parents:
diff changeset
1079 fs->regs = *old_rs;
kono
parents:
diff changeset
1080 old_rs->prev = unused_rs;
kono
parents:
diff changeset
1081 unused_rs = old_rs;
kono
parents:
diff changeset
1082 }
kono
parents:
diff changeset
1083 break;
kono
parents:
diff changeset
1084
kono
parents:
diff changeset
1085 case DW_CFA_def_cfa:
kono
parents:
diff changeset
1086 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1087 fs->regs.cfa_reg = (_Unwind_Word)utmp;
kono
parents:
diff changeset
1088 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1089 fs->regs.cfa_offset = (_Unwind_Word)utmp;
kono
parents:
diff changeset
1090 fs->regs.cfa_how = CFA_REG_OFFSET;
kono
parents:
diff changeset
1091 break;
kono
parents:
diff changeset
1092
kono
parents:
diff changeset
1093 case DW_CFA_def_cfa_register:
kono
parents:
diff changeset
1094 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1095 fs->regs.cfa_reg = (_Unwind_Word)utmp;
kono
parents:
diff changeset
1096 fs->regs.cfa_how = CFA_REG_OFFSET;
kono
parents:
diff changeset
1097 break;
kono
parents:
diff changeset
1098
kono
parents:
diff changeset
1099 case DW_CFA_def_cfa_offset:
kono
parents:
diff changeset
1100 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1101 fs->regs.cfa_offset = utmp;
kono
parents:
diff changeset
1102 /* cfa_how deliberately not set. */
kono
parents:
diff changeset
1103 break;
kono
parents:
diff changeset
1104
kono
parents:
diff changeset
1105 case DW_CFA_def_cfa_expression:
kono
parents:
diff changeset
1106 fs->regs.cfa_exp = insn_ptr;
kono
parents:
diff changeset
1107 fs->regs.cfa_how = CFA_EXP;
kono
parents:
diff changeset
1108 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1109 insn_ptr += utmp;
kono
parents:
diff changeset
1110 break;
kono
parents:
diff changeset
1111
kono
parents:
diff changeset
1112 case DW_CFA_expression:
kono
parents:
diff changeset
1113 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1114 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1115 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1116 {
kono
parents:
diff changeset
1117 fs->regs.reg[reg].how = REG_SAVED_EXP;
kono
parents:
diff changeset
1118 fs->regs.reg[reg].loc.exp = insn_ptr;
kono
parents:
diff changeset
1119 }
kono
parents:
diff changeset
1120 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1121 insn_ptr += utmp;
kono
parents:
diff changeset
1122 break;
kono
parents:
diff changeset
1123
kono
parents:
diff changeset
1124 /* Dwarf3. */
kono
parents:
diff changeset
1125 case DW_CFA_offset_extended_sf:
kono
parents:
diff changeset
1126 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1127 insn_ptr = read_sleb128 (insn_ptr, &stmp);
kono
parents:
diff changeset
1128 offset = stmp * fs->data_align;
kono
parents:
diff changeset
1129 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1130 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1131 {
kono
parents:
diff changeset
1132 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
kono
parents:
diff changeset
1133 fs->regs.reg[reg].loc.offset = offset;
kono
parents:
diff changeset
1134 }
kono
parents:
diff changeset
1135 break;
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 case DW_CFA_def_cfa_sf:
kono
parents:
diff changeset
1138 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1139 fs->regs.cfa_reg = (_Unwind_Word)utmp;
kono
parents:
diff changeset
1140 insn_ptr = read_sleb128 (insn_ptr, &stmp);
kono
parents:
diff changeset
1141 fs->regs.cfa_offset = (_Unwind_Sword)stmp;
kono
parents:
diff changeset
1142 fs->regs.cfa_how = CFA_REG_OFFSET;
kono
parents:
diff changeset
1143 fs->regs.cfa_offset *= fs->data_align;
kono
parents:
diff changeset
1144 break;
kono
parents:
diff changeset
1145
kono
parents:
diff changeset
1146 case DW_CFA_def_cfa_offset_sf:
kono
parents:
diff changeset
1147 insn_ptr = read_sleb128 (insn_ptr, &stmp);
kono
parents:
diff changeset
1148 fs->regs.cfa_offset = (_Unwind_Sword)stmp;
kono
parents:
diff changeset
1149 fs->regs.cfa_offset *= fs->data_align;
kono
parents:
diff changeset
1150 /* cfa_how deliberately not set. */
kono
parents:
diff changeset
1151 break;
kono
parents:
diff changeset
1152
kono
parents:
diff changeset
1153 case DW_CFA_val_offset:
kono
parents:
diff changeset
1154 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1155 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1156 offset = (_Unwind_Sword) utmp * fs->data_align;
kono
parents:
diff changeset
1157 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1158 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1159 {
kono
parents:
diff changeset
1160 fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
kono
parents:
diff changeset
1161 fs->regs.reg[reg].loc.offset = offset;
kono
parents:
diff changeset
1162 }
kono
parents:
diff changeset
1163 break;
kono
parents:
diff changeset
1164
kono
parents:
diff changeset
1165 case DW_CFA_val_offset_sf:
kono
parents:
diff changeset
1166 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1167 insn_ptr = read_sleb128 (insn_ptr, &stmp);
kono
parents:
diff changeset
1168 offset = stmp * fs->data_align;
kono
parents:
diff changeset
1169 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1170 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1171 {
kono
parents:
diff changeset
1172 fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
kono
parents:
diff changeset
1173 fs->regs.reg[reg].loc.offset = offset;
kono
parents:
diff changeset
1174 }
kono
parents:
diff changeset
1175 break;
kono
parents:
diff changeset
1176
kono
parents:
diff changeset
1177 case DW_CFA_val_expression:
kono
parents:
diff changeset
1178 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1179 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1180 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1181 {
kono
parents:
diff changeset
1182 fs->regs.reg[reg].how = REG_SAVED_VAL_EXP;
kono
parents:
diff changeset
1183 fs->regs.reg[reg].loc.exp = insn_ptr;
kono
parents:
diff changeset
1184 }
kono
parents:
diff changeset
1185 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1186 insn_ptr += utmp;
kono
parents:
diff changeset
1187 break;
kono
parents:
diff changeset
1188
kono
parents:
diff changeset
1189 case DW_CFA_GNU_window_save:
kono
parents:
diff changeset
1190 #if defined (__aarch64__) && !defined (__ILP32__)
kono
parents:
diff changeset
1191 /* This CFA is multiplexed with Sparc. On AArch64 it's used to toggle
kono
parents:
diff changeset
1192 return address signing status. */
kono
parents:
diff changeset
1193 fs->regs.reg[DWARF_REGNUM_AARCH64_RA_STATE].loc.offset ^= 1;
kono
parents:
diff changeset
1194 #else
kono
parents:
diff changeset
1195 /* ??? Hardcoded for SPARC register window configuration. */
kono
parents:
diff changeset
1196 if (__LIBGCC_DWARF_FRAME_REGISTERS__ >= 32)
kono
parents:
diff changeset
1197 for (reg = 16; reg < 32; ++reg)
kono
parents:
diff changeset
1198 {
kono
parents:
diff changeset
1199 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
kono
parents:
diff changeset
1200 fs->regs.reg[reg].loc.offset = (reg - 16) * sizeof (void *);
kono
parents:
diff changeset
1201 }
kono
parents:
diff changeset
1202 #endif
kono
parents:
diff changeset
1203 break;
kono
parents:
diff changeset
1204
kono
parents:
diff changeset
1205 case DW_CFA_GNU_args_size:
kono
parents:
diff changeset
1206 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1207 context->args_size = (_Unwind_Word)utmp;
kono
parents:
diff changeset
1208 break;
kono
parents:
diff changeset
1209
kono
parents:
diff changeset
1210 case DW_CFA_GNU_negative_offset_extended:
kono
parents:
diff changeset
1211 /* Obsoleted by DW_CFA_offset_extended_sf, but used by
kono
parents:
diff changeset
1212 older PowerPC code. */
kono
parents:
diff changeset
1213 insn_ptr = read_uleb128 (insn_ptr, &reg);
kono
parents:
diff changeset
1214 insn_ptr = read_uleb128 (insn_ptr, &utmp);
kono
parents:
diff changeset
1215 offset = (_Unwind_Word) utmp * fs->data_align;
kono
parents:
diff changeset
1216 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
kono
parents:
diff changeset
1217 if (UNWIND_COLUMN_IN_RANGE (reg))
kono
parents:
diff changeset
1218 {
kono
parents:
diff changeset
1219 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
kono
parents:
diff changeset
1220 fs->regs.reg[reg].loc.offset = -offset;
kono
parents:
diff changeset
1221 }
kono
parents:
diff changeset
1222 break;
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 default:
kono
parents:
diff changeset
1225 gcc_unreachable ();
kono
parents:
diff changeset
1226 }
kono
parents:
diff changeset
1227 }
kono
parents:
diff changeset
1228 }
kono
parents:
diff changeset
1229
kono
parents:
diff changeset
1230 /* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
kono
parents:
diff changeset
1231 its caller and decode it into FS. This function also sets the
kono
parents:
diff changeset
1232 args_size and lsda members of CONTEXT, as they are really information
kono
parents:
diff changeset
1233 about the caller's frame. */
kono
parents:
diff changeset
1234
kono
parents:
diff changeset
1235 static _Unwind_Reason_Code
kono
parents:
diff changeset
1236 uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
kono
parents:
diff changeset
1237 {
kono
parents:
diff changeset
1238 const struct dwarf_fde *fde;
kono
parents:
diff changeset
1239 const struct dwarf_cie *cie;
kono
parents:
diff changeset
1240 const unsigned char *aug, *insn, *end;
kono
parents:
diff changeset
1241
kono
parents:
diff changeset
1242 memset (fs, 0, sizeof (*fs));
kono
parents:
diff changeset
1243 context->args_size = 0;
kono
parents:
diff changeset
1244 context->lsda = 0;
kono
parents:
diff changeset
1245
kono
parents:
diff changeset
1246 if (context->ra == 0)
kono
parents:
diff changeset
1247 return _URC_END_OF_STACK;
kono
parents:
diff changeset
1248
kono
parents:
diff changeset
1249 fde = _Unwind_Find_FDE (context->ra + _Unwind_IsSignalFrame (context) - 1,
kono
parents:
diff changeset
1250 &context->bases);
kono
parents:
diff changeset
1251 if (fde == NULL)
kono
parents:
diff changeset
1252 {
kono
parents:
diff changeset
1253 #ifdef MD_FALLBACK_FRAME_STATE_FOR
kono
parents:
diff changeset
1254 /* Couldn't find frame unwind info for this function. Try a
kono
parents:
diff changeset
1255 target-specific fallback mechanism. This will necessarily
kono
parents:
diff changeset
1256 not provide a personality routine or LSDA. */
kono
parents:
diff changeset
1257 return MD_FALLBACK_FRAME_STATE_FOR (context, fs);
kono
parents:
diff changeset
1258 #else
kono
parents:
diff changeset
1259 return _URC_END_OF_STACK;
kono
parents:
diff changeset
1260 #endif
kono
parents:
diff changeset
1261 }
kono
parents:
diff changeset
1262
kono
parents:
diff changeset
1263 fs->pc = context->bases.func;
kono
parents:
diff changeset
1264
kono
parents:
diff changeset
1265 cie = get_cie (fde);
kono
parents:
diff changeset
1266 insn = extract_cie_info (cie, context, fs);
kono
parents:
diff changeset
1267 if (insn == NULL)
kono
parents:
diff changeset
1268 /* CIE contained unknown augmentation. */
kono
parents:
diff changeset
1269 return _URC_FATAL_PHASE1_ERROR;
kono
parents:
diff changeset
1270
kono
parents:
diff changeset
1271 /* First decode all the insns in the CIE. */
kono
parents:
diff changeset
1272 end = (const unsigned char *) next_fde ((const struct dwarf_fde *) cie);
kono
parents:
diff changeset
1273 execute_cfa_program (insn, end, context, fs);
kono
parents:
diff changeset
1274
kono
parents:
diff changeset
1275 /* Locate augmentation for the fde. */
kono
parents:
diff changeset
1276 aug = (const unsigned char *) fde + sizeof (*fde);
kono
parents:
diff changeset
1277 aug += 2 * size_of_encoded_value (fs->fde_encoding);
kono
parents:
diff changeset
1278 insn = NULL;
kono
parents:
diff changeset
1279 if (fs->saw_z)
kono
parents:
diff changeset
1280 {
kono
parents:
diff changeset
1281 _uleb128_t i;
kono
parents:
diff changeset
1282 aug = read_uleb128 (aug, &i);
kono
parents:
diff changeset
1283 insn = aug + i;
kono
parents:
diff changeset
1284 }
kono
parents:
diff changeset
1285 if (fs->lsda_encoding != DW_EH_PE_omit)
kono
parents:
diff changeset
1286 {
kono
parents:
diff changeset
1287 _Unwind_Ptr lsda;
kono
parents:
diff changeset
1288
kono
parents:
diff changeset
1289 aug = read_encoded_value (context, fs->lsda_encoding, aug, &lsda);
kono
parents:
diff changeset
1290 context->lsda = (void *) lsda;
kono
parents:
diff changeset
1291 }
kono
parents:
diff changeset
1292
kono
parents:
diff changeset
1293 /* Then the insns in the FDE up to our target PC. */
kono
parents:
diff changeset
1294 if (insn == NULL)
kono
parents:
diff changeset
1295 insn = aug;
kono
parents:
diff changeset
1296 end = (const unsigned char *) next_fde (fde);
kono
parents:
diff changeset
1297 execute_cfa_program (insn, end, context, fs);
kono
parents:
diff changeset
1298
kono
parents:
diff changeset
1299 return _URC_NO_REASON;
kono
parents:
diff changeset
1300 }
kono
parents:
diff changeset
1301
kono
parents:
diff changeset
1302 typedef struct frame_state
kono
parents:
diff changeset
1303 {
kono
parents:
diff changeset
1304 void *cfa;
kono
parents:
diff changeset
1305 void *eh_ptr;
kono
parents:
diff changeset
1306 long cfa_offset;
kono
parents:
diff changeset
1307 long args_size;
kono
parents:
diff changeset
1308 long reg_or_offset[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
kono
parents:
diff changeset
1309 unsigned short cfa_reg;
kono
parents:
diff changeset
1310 unsigned short retaddr_column;
kono
parents:
diff changeset
1311 char saved[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
kono
parents:
diff changeset
1312 } frame_state;
kono
parents:
diff changeset
1313
kono
parents:
diff changeset
1314 struct frame_state * __frame_state_for (void *, struct frame_state *);
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 /* Called from pre-G++ 3.0 __throw to find the registers to restore for
kono
parents:
diff changeset
1317 a given PC_TARGET. The caller should allocate a local variable of
kono
parents:
diff changeset
1318 `struct frame_state' and pass its address to STATE_IN. */
kono
parents:
diff changeset
1319
kono
parents:
diff changeset
1320 struct frame_state *
kono
parents:
diff changeset
1321 __frame_state_for (void *pc_target, struct frame_state *state_in)
kono
parents:
diff changeset
1322 {
kono
parents:
diff changeset
1323 struct _Unwind_Context context;
kono
parents:
diff changeset
1324 _Unwind_FrameState fs;
kono
parents:
diff changeset
1325 int reg;
kono
parents:
diff changeset
1326
kono
parents:
diff changeset
1327 memset (&context, 0, sizeof (struct _Unwind_Context));
kono
parents:
diff changeset
1328 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
kono
parents:
diff changeset
1329 context.flags = EXTENDED_CONTEXT_BIT;
kono
parents:
diff changeset
1330 context.ra = pc_target + 1;
kono
parents:
diff changeset
1331
kono
parents:
diff changeset
1332 if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON)
kono
parents:
diff changeset
1333 return 0;
kono
parents:
diff changeset
1334
kono
parents:
diff changeset
1335 /* We have no way to pass a location expression for the CFA to our
kono
parents:
diff changeset
1336 caller. It wouldn't understand it anyway. */
kono
parents:
diff changeset
1337 if (fs.regs.cfa_how == CFA_EXP)
kono
parents:
diff changeset
1338 return 0;
kono
parents:
diff changeset
1339
kono
parents:
diff changeset
1340 for (reg = 0; reg < PRE_GCC3_DWARF_FRAME_REGISTERS + 1; reg++)
kono
parents:
diff changeset
1341 {
kono
parents:
diff changeset
1342 state_in->saved[reg] = fs.regs.reg[reg].how;
kono
parents:
diff changeset
1343 switch (state_in->saved[reg])
kono
parents:
diff changeset
1344 {
kono
parents:
diff changeset
1345 case REG_SAVED_REG:
kono
parents:
diff changeset
1346 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.reg;
kono
parents:
diff changeset
1347 break;
kono
parents:
diff changeset
1348 case REG_SAVED_OFFSET:
kono
parents:
diff changeset
1349 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.offset;
kono
parents:
diff changeset
1350 break;
kono
parents:
diff changeset
1351 default:
kono
parents:
diff changeset
1352 state_in->reg_or_offset[reg] = 0;
kono
parents:
diff changeset
1353 break;
kono
parents:
diff changeset
1354 }
kono
parents:
diff changeset
1355 }
kono
parents:
diff changeset
1356
kono
parents:
diff changeset
1357 state_in->cfa_offset = fs.regs.cfa_offset;
kono
parents:
diff changeset
1358 state_in->cfa_reg = fs.regs.cfa_reg;
kono
parents:
diff changeset
1359 state_in->retaddr_column = fs.retaddr_column;
kono
parents:
diff changeset
1360 state_in->args_size = context.args_size;
kono
parents:
diff changeset
1361 state_in->eh_ptr = fs.eh_ptr;
kono
parents:
diff changeset
1362
kono
parents:
diff changeset
1363 return state_in;
kono
parents:
diff changeset
1364 }
kono
parents:
diff changeset
1365
kono
parents:
diff changeset
1366 typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp;
kono
parents:
diff changeset
1367
kono
parents:
diff changeset
1368 static inline void
kono
parents:
diff changeset
1369 _Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa,
kono
parents:
diff changeset
1370 _Unwind_SpTmp *tmp_sp)
kono
parents:
diff changeset
1371 {
kono
parents:
diff changeset
1372 int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()];
kono
parents:
diff changeset
1373
kono
parents:
diff changeset
1374 if (size == sizeof(_Unwind_Ptr))
kono
parents:
diff changeset
1375 tmp_sp->ptr = (_Unwind_Ptr) cfa;
kono
parents:
diff changeset
1376 else
kono
parents:
diff changeset
1377 {
kono
parents:
diff changeset
1378 gcc_assert (size == sizeof(_Unwind_Word));
kono
parents:
diff changeset
1379 tmp_sp->word = (_Unwind_Ptr) cfa;
kono
parents:
diff changeset
1380 }
kono
parents:
diff changeset
1381 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp);
kono
parents:
diff changeset
1382 }
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 static void
kono
parents:
diff changeset
1385 uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
kono
parents:
diff changeset
1386 {
kono
parents:
diff changeset
1387 struct _Unwind_Context orig_context = *context;
kono
parents:
diff changeset
1388 void *cfa;
kono
parents:
diff changeset
1389 long i;
kono
parents:
diff changeset
1390
kono
parents:
diff changeset
1391 #ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__
kono
parents:
diff changeset
1392 /* Special handling here: Many machines do not use a frame pointer,
kono
parents:
diff changeset
1393 and track the CFA only through offsets from the stack pointer from
kono
parents:
diff changeset
1394 one frame to the next. In this case, the stack pointer is never
kono
parents:
diff changeset
1395 stored, so it has no saved address in the context. What we do
kono
parents:
diff changeset
1396 have is the CFA from the previous stack frame.
kono
parents:
diff changeset
1397
kono
parents:
diff changeset
1398 In very special situations (such as unwind info for signal return),
kono
parents:
diff changeset
1399 there may be location expressions that use the stack pointer as well.
kono
parents:
diff changeset
1400
kono
parents:
diff changeset
1401 Do this conditionally for one frame. This allows the unwind info
kono
parents:
diff changeset
1402 for one frame to save a copy of the stack pointer from the previous
kono
parents:
diff changeset
1403 frame, and be able to use much easier CFA mechanisms to do it.
kono
parents:
diff changeset
1404 Always zap the saved stack pointer value for the next frame; carrying
kono
parents:
diff changeset
1405 the value over from one frame to another doesn't make sense. */
kono
parents:
diff changeset
1406
kono
parents:
diff changeset
1407 _Unwind_SpTmp tmp_sp;
kono
parents:
diff changeset
1408
kono
parents:
diff changeset
1409 if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
kono
parents:
diff changeset
1410 _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp);
kono
parents:
diff changeset
1411 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
kono
parents:
diff changeset
1412 #endif
kono
parents:
diff changeset
1413
kono
parents:
diff changeset
1414 /* Compute this frame's CFA. */
kono
parents:
diff changeset
1415 switch (fs->regs.cfa_how)
kono
parents:
diff changeset
1416 {
kono
parents:
diff changeset
1417 case CFA_REG_OFFSET:
kono
parents:
diff changeset
1418 cfa = _Unwind_GetPtr (&orig_context, fs->regs.cfa_reg);
kono
parents:
diff changeset
1419 cfa += fs->regs.cfa_offset;
kono
parents:
diff changeset
1420 break;
kono
parents:
diff changeset
1421
kono
parents:
diff changeset
1422 case CFA_EXP:
kono
parents:
diff changeset
1423 {
kono
parents:
diff changeset
1424 const unsigned char *exp = fs->regs.cfa_exp;
kono
parents:
diff changeset
1425 _uleb128_t len;
kono
parents:
diff changeset
1426
kono
parents:
diff changeset
1427 exp = read_uleb128 (exp, &len);
kono
parents:
diff changeset
1428 cfa = (void *) (_Unwind_Ptr)
kono
parents:
diff changeset
1429 execute_stack_op (exp, exp + len, &orig_context, 0);
kono
parents:
diff changeset
1430 break;
kono
parents:
diff changeset
1431 }
kono
parents:
diff changeset
1432
kono
parents:
diff changeset
1433 default:
kono
parents:
diff changeset
1434 gcc_unreachable ();
kono
parents:
diff changeset
1435 }
kono
parents:
diff changeset
1436 context->cfa = cfa;
kono
parents:
diff changeset
1437
kono
parents:
diff changeset
1438 /* Compute the addresses of all registers saved in this frame. */
kono
parents:
diff changeset
1439 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__ + 1; ++i)
kono
parents:
diff changeset
1440 switch (fs->regs.reg[i].how)
kono
parents:
diff changeset
1441 {
kono
parents:
diff changeset
1442 case REG_UNSAVED:
kono
parents:
diff changeset
1443 case REG_UNDEFINED:
kono
parents:
diff changeset
1444 break;
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 case REG_SAVED_OFFSET:
kono
parents:
diff changeset
1447 _Unwind_SetGRPtr (context, i,
kono
parents:
diff changeset
1448 (void *) (cfa + fs->regs.reg[i].loc.offset));
kono
parents:
diff changeset
1449 break;
kono
parents:
diff changeset
1450
kono
parents:
diff changeset
1451 case REG_SAVED_REG:
kono
parents:
diff changeset
1452 if (_Unwind_GRByValue (&orig_context, fs->regs.reg[i].loc.reg))
kono
parents:
diff changeset
1453 _Unwind_SetGRValue (context, i,
kono
parents:
diff changeset
1454 _Unwind_GetGR (&orig_context,
kono
parents:
diff changeset
1455 fs->regs.reg[i].loc.reg));
kono
parents:
diff changeset
1456 else
kono
parents:
diff changeset
1457 _Unwind_SetGRPtr (context, i,
kono
parents:
diff changeset
1458 _Unwind_GetGRPtr (&orig_context,
kono
parents:
diff changeset
1459 fs->regs.reg[i].loc.reg));
kono
parents:
diff changeset
1460 break;
kono
parents:
diff changeset
1461
kono
parents:
diff changeset
1462 case REG_SAVED_EXP:
kono
parents:
diff changeset
1463 {
kono
parents:
diff changeset
1464 const unsigned char *exp = fs->regs.reg[i].loc.exp;
kono
parents:
diff changeset
1465 _uleb128_t len;
kono
parents:
diff changeset
1466 _Unwind_Ptr val;
kono
parents:
diff changeset
1467
kono
parents:
diff changeset
1468 exp = read_uleb128 (exp, &len);
kono
parents:
diff changeset
1469 val = execute_stack_op (exp, exp + len, &orig_context,
kono
parents:
diff changeset
1470 (_Unwind_Ptr) cfa);
kono
parents:
diff changeset
1471 _Unwind_SetGRPtr (context, i, (void *) val);
kono
parents:
diff changeset
1472 }
kono
parents:
diff changeset
1473 break;
kono
parents:
diff changeset
1474
kono
parents:
diff changeset
1475 case REG_SAVED_VAL_OFFSET:
kono
parents:
diff changeset
1476 _Unwind_SetGRValue (context, i,
kono
parents:
diff changeset
1477 (_Unwind_Internal_Ptr)
kono
parents:
diff changeset
1478 (cfa + fs->regs.reg[i].loc.offset));
kono
parents:
diff changeset
1479 break;
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 case REG_SAVED_VAL_EXP:
kono
parents:
diff changeset
1482 {
kono
parents:
diff changeset
1483 const unsigned char *exp = fs->regs.reg[i].loc.exp;
kono
parents:
diff changeset
1484 _uleb128_t len;
kono
parents:
diff changeset
1485 _Unwind_Ptr val;
kono
parents:
diff changeset
1486
kono
parents:
diff changeset
1487 exp = read_uleb128 (exp, &len);
kono
parents:
diff changeset
1488 val = execute_stack_op (exp, exp + len, &orig_context,
kono
parents:
diff changeset
1489 (_Unwind_Ptr) cfa);
kono
parents:
diff changeset
1490 _Unwind_SetGRValue (context, i, val);
kono
parents:
diff changeset
1491 }
kono
parents:
diff changeset
1492 break;
kono
parents:
diff changeset
1493 }
kono
parents:
diff changeset
1494
kono
parents:
diff changeset
1495 _Unwind_SetSignalFrame (context, fs->signal_frame);
kono
parents:
diff changeset
1496
kono
parents:
diff changeset
1497 #ifdef MD_FROB_UPDATE_CONTEXT
kono
parents:
diff changeset
1498 MD_FROB_UPDATE_CONTEXT (context, fs);
kono
parents:
diff changeset
1499 #endif
kono
parents:
diff changeset
1500 }
kono
parents:
diff changeset
1501
kono
parents:
diff changeset
1502 /* CONTEXT describes the unwind state for a frame, and FS describes the FDE
kono
parents:
diff changeset
1503 of its caller. Update CONTEXT to refer to the caller as well. Note
kono
parents:
diff changeset
1504 that the args_size and lsda members are not updated here, but later in
kono
parents:
diff changeset
1505 uw_frame_state_for. */
kono
parents:
diff changeset
1506
kono
parents:
diff changeset
1507 static void
kono
parents:
diff changeset
1508 uw_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
kono
parents:
diff changeset
1509 {
kono
parents:
diff changeset
1510 uw_update_context_1 (context, fs);
kono
parents:
diff changeset
1511
kono
parents:
diff changeset
1512 /* In general this unwinder doesn't make any distinction between
kono
parents:
diff changeset
1513 undefined and same_value rule. Call-saved registers are assumed
kono
parents:
diff changeset
1514 to have same_value rule by default and explicit undefined
kono
parents:
diff changeset
1515 rule is handled like same_value. The only exception is
kono
parents:
diff changeset
1516 DW_CFA_undefined on retaddr_column which is supposed to
kono
parents:
diff changeset
1517 mark outermost frame in DWARF 3. */
kono
parents:
diff changeset
1518 if (fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (fs->retaddr_column)].how
kono
parents:
diff changeset
1519 == REG_UNDEFINED)
kono
parents:
diff changeset
1520 /* uw_frame_state_for uses context->ra == 0 check to find outermost
kono
parents:
diff changeset
1521 stack frame. */
kono
parents:
diff changeset
1522 context->ra = 0;
kono
parents:
diff changeset
1523 else
kono
parents:
diff changeset
1524 {
kono
parents:
diff changeset
1525 /* Compute the return address now, since the return address column
kono
parents:
diff changeset
1526 can change from frame to frame. */
kono
parents:
diff changeset
1527 context->ra = __builtin_extract_return_addr
kono
parents:
diff changeset
1528 (_Unwind_GetPtr (context, fs->retaddr_column));
kono
parents:
diff changeset
1529 #ifdef MD_POST_EXTRACT_FRAME_ADDR
kono
parents:
diff changeset
1530 context->ra = MD_POST_EXTRACT_FRAME_ADDR (context, fs, context->ra);
kono
parents:
diff changeset
1531 #endif
kono
parents:
diff changeset
1532 }
kono
parents:
diff changeset
1533 }
kono
parents:
diff changeset
1534
kono
parents:
diff changeset
1535 static void
kono
parents:
diff changeset
1536 uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
kono
parents:
diff changeset
1537 {
kono
parents:
diff changeset
1538 uw_update_context (context, fs);
kono
parents:
diff changeset
1539 }
kono
parents:
diff changeset
1540
kono
parents:
diff changeset
1541 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
kono
parents:
diff changeset
1542 level will be the return address and the CFA. */
kono
parents:
diff changeset
1543
kono
parents:
diff changeset
1544 #define uw_init_context(CONTEXT) \
kono
parents:
diff changeset
1545 do \
kono
parents:
diff changeset
1546 { \
kono
parents:
diff changeset
1547 /* Do any necessary initialization to access arbitrary stack frames. \
kono
parents:
diff changeset
1548 On the SPARC, this means flushing the register windows. */ \
kono
parents:
diff changeset
1549 __builtin_unwind_init (); \
kono
parents:
diff changeset
1550 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
kono
parents:
diff changeset
1551 __builtin_return_address (0)); \
kono
parents:
diff changeset
1552 } \
kono
parents:
diff changeset
1553 while (0)
kono
parents:
diff changeset
1554
kono
parents:
diff changeset
1555 static inline void
kono
parents:
diff changeset
1556 init_dwarf_reg_size_table (void)
kono
parents:
diff changeset
1557 {
kono
parents:
diff changeset
1558 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
kono
parents:
diff changeset
1559 }
kono
parents:
diff changeset
1560
kono
parents:
diff changeset
1561 static void __attribute__((noinline))
kono
parents:
diff changeset
1562 uw_init_context_1 (struct _Unwind_Context *context,
kono
parents:
diff changeset
1563 void *outer_cfa, void *outer_ra)
kono
parents:
diff changeset
1564 {
kono
parents:
diff changeset
1565 void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
kono
parents:
diff changeset
1566 #ifdef MD_POST_EXTRACT_ROOT_ADDR
kono
parents:
diff changeset
1567 ra = MD_POST_EXTRACT_ROOT_ADDR (ra);
kono
parents:
diff changeset
1568 #endif
kono
parents:
diff changeset
1569 _Unwind_FrameState fs;
kono
parents:
diff changeset
1570 _Unwind_SpTmp sp_slot;
kono
parents:
diff changeset
1571 _Unwind_Reason_Code code;
kono
parents:
diff changeset
1572
kono
parents:
diff changeset
1573 memset (context, 0, sizeof (struct _Unwind_Context));
kono
parents:
diff changeset
1574 context->ra = ra;
kono
parents:
diff changeset
1575 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
kono
parents:
diff changeset
1576 context->flags = EXTENDED_CONTEXT_BIT;
kono
parents:
diff changeset
1577
kono
parents:
diff changeset
1578 code = uw_frame_state_for (context, &fs);
kono
parents:
diff changeset
1579 gcc_assert (code == _URC_NO_REASON);
kono
parents:
diff changeset
1580
kono
parents:
diff changeset
1581 #if __GTHREADS
kono
parents:
diff changeset
1582 {
kono
parents:
diff changeset
1583 static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
kono
parents:
diff changeset
1584 if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
kono
parents:
diff changeset
1585 && dwarf_reg_size_table[0] == 0)
kono
parents:
diff changeset
1586 init_dwarf_reg_size_table ();
kono
parents:
diff changeset
1587 }
kono
parents:
diff changeset
1588 #else
kono
parents:
diff changeset
1589 if (dwarf_reg_size_table[0] == 0)
kono
parents:
diff changeset
1590 init_dwarf_reg_size_table ();
kono
parents:
diff changeset
1591 #endif
kono
parents:
diff changeset
1592
kono
parents:
diff changeset
1593 /* Force the frame state to use the known cfa value. */
kono
parents:
diff changeset
1594 _Unwind_SetSpColumn (context, outer_cfa, &sp_slot);
kono
parents:
diff changeset
1595 fs.regs.cfa_how = CFA_REG_OFFSET;
kono
parents:
diff changeset
1596 fs.regs.cfa_reg = __builtin_dwarf_sp_column ();
kono
parents:
diff changeset
1597 fs.regs.cfa_offset = 0;
kono
parents:
diff changeset
1598
kono
parents:
diff changeset
1599 uw_update_context_1 (context, &fs);
kono
parents:
diff changeset
1600
kono
parents:
diff changeset
1601 /* If the return address column was saved in a register in the
kono
parents:
diff changeset
1602 initialization context, then we can't see it in the given
kono
parents:
diff changeset
1603 call frame data. So have the initialization context tell us. */
kono
parents:
diff changeset
1604 context->ra = __builtin_extract_return_addr (outer_ra);
kono
parents:
diff changeset
1605 #ifdef MD_POST_EXTRACT_ROOT_ADDR
kono
parents:
diff changeset
1606 context->ra = MD_POST_EXTRACT_ROOT_ADDR (context->ra);
kono
parents:
diff changeset
1607 #endif
kono
parents:
diff changeset
1608 }
kono
parents:
diff changeset
1609
kono
parents:
diff changeset
1610 static void _Unwind_DebugHook (void *, void *)
kono
parents:
diff changeset
1611 __attribute__ ((__noinline__, __used__, __noclone__));
kono
parents:
diff changeset
1612
kono
parents:
diff changeset
1613 /* This function is called during unwinding. It is intended as a hook
kono
parents:
diff changeset
1614 for a debugger to intercept exceptions. CFA is the CFA of the
kono
parents:
diff changeset
1615 target frame. HANDLER is the PC to which control will be
kono
parents:
diff changeset
1616 transferred. */
kono
parents:
diff changeset
1617 static void
kono
parents:
diff changeset
1618 _Unwind_DebugHook (void *cfa __attribute__ ((__unused__)),
kono
parents:
diff changeset
1619 void *handler __attribute__ ((__unused__)))
kono
parents:
diff changeset
1620 {
kono
parents:
diff changeset
1621 /* We only want to use stap probes starting with v3. Earlier
kono
parents:
diff changeset
1622 versions added too much startup cost. */
kono
parents:
diff changeset
1623 #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
kono
parents:
diff changeset
1624 STAP_PROBE2 (libgcc, unwind, cfa, handler);
kono
parents:
diff changeset
1625 #else
kono
parents:
diff changeset
1626 asm ("");
kono
parents:
diff changeset
1627 #endif
kono
parents:
diff changeset
1628 }
kono
parents:
diff changeset
1629
kono
parents:
diff changeset
1630 /* Frob exception handler's address kept in TARGET before installing into
kono
parents:
diff changeset
1631 CURRENT context. */
kono
parents:
diff changeset
1632
kono
parents:
diff changeset
1633 static inline void *
kono
parents:
diff changeset
1634 uw_frob_return_addr (struct _Unwind_Context *current
kono
parents:
diff changeset
1635 __attribute__ ((__unused__)),
kono
parents:
diff changeset
1636 struct _Unwind_Context *target)
kono
parents:
diff changeset
1637 {
kono
parents:
diff changeset
1638 void *ret_addr = __builtin_frob_return_addr (target->ra);
kono
parents:
diff changeset
1639 #ifdef MD_POST_FROB_EH_HANDLER_ADDR
kono
parents:
diff changeset
1640 ret_addr = MD_POST_FROB_EH_HANDLER_ADDR (current, target, ret_addr);
kono
parents:
diff changeset
1641 #endif
kono
parents:
diff changeset
1642 return ret_addr;
kono
parents:
diff changeset
1643 }
kono
parents:
diff changeset
1644
kono
parents:
diff changeset
1645 /* Install TARGET into CURRENT so that we can return to it. This is a
kono
parents:
diff changeset
1646 macro because __builtin_eh_return must be invoked in the context of
kono
parents:
diff changeset
1647 our caller. */
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 #define uw_install_context(CURRENT, TARGET) \
kono
parents:
diff changeset
1650 do \
kono
parents:
diff changeset
1651 { \
kono
parents:
diff changeset
1652 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
kono
parents:
diff changeset
1653 void *handler = uw_frob_return_addr ((CURRENT), (TARGET)); \
kono
parents:
diff changeset
1654 _Unwind_DebugHook ((TARGET)->cfa, handler); \
kono
parents:
diff changeset
1655 __builtin_eh_return (offset, handler); \
kono
parents:
diff changeset
1656 } \
kono
parents:
diff changeset
1657 while (0)
kono
parents:
diff changeset
1658
kono
parents:
diff changeset
1659 static long
kono
parents:
diff changeset
1660 uw_install_context_1 (struct _Unwind_Context *current,
kono
parents:
diff changeset
1661 struct _Unwind_Context *target)
kono
parents:
diff changeset
1662 {
kono
parents:
diff changeset
1663 long i;
kono
parents:
diff changeset
1664 _Unwind_SpTmp sp_slot;
kono
parents:
diff changeset
1665
kono
parents:
diff changeset
1666 /* If the target frame does not have a saved stack pointer,
kono
parents:
diff changeset
1667 then set up the target's CFA. */
kono
parents:
diff changeset
1668 if (!_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ()))
kono
parents:
diff changeset
1669 _Unwind_SetSpColumn (target, target->cfa, &sp_slot);
kono
parents:
diff changeset
1670
kono
parents:
diff changeset
1671 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__; ++i)
kono
parents:
diff changeset
1672 {
kono
parents:
diff changeset
1673 void *c = (void *) (_Unwind_Internal_Ptr) current->reg[i];
kono
parents:
diff changeset
1674 void *t = (void *) (_Unwind_Internal_Ptr)target->reg[i];
kono
parents:
diff changeset
1675
kono
parents:
diff changeset
1676 gcc_assert (current->by_value[i] == 0);
kono
parents:
diff changeset
1677 if (target->by_value[i] && c)
kono
parents:
diff changeset
1678 {
kono
parents:
diff changeset
1679 _Unwind_Word w;
kono
parents:
diff changeset
1680 _Unwind_Ptr p;
kono
parents:
diff changeset
1681 if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word))
kono
parents:
diff changeset
1682 {
kono
parents:
diff changeset
1683 w = (_Unwind_Internal_Ptr) t;
kono
parents:
diff changeset
1684 memcpy (c, &w, sizeof (_Unwind_Word));
kono
parents:
diff changeset
1685 }
kono
parents:
diff changeset
1686 else
kono
parents:
diff changeset
1687 {
kono
parents:
diff changeset
1688 gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr));
kono
parents:
diff changeset
1689 p = (_Unwind_Internal_Ptr) t;
kono
parents:
diff changeset
1690 memcpy (c, &p, sizeof (_Unwind_Ptr));
kono
parents:
diff changeset
1691 }
kono
parents:
diff changeset
1692 }
kono
parents:
diff changeset
1693 else if (t && c && t != c)
kono
parents:
diff changeset
1694 memcpy (c, t, dwarf_reg_size_table[i]);
kono
parents:
diff changeset
1695 }
kono
parents:
diff changeset
1696
kono
parents:
diff changeset
1697 /* If the current frame doesn't have a saved stack pointer, then we
kono
parents:
diff changeset
1698 need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
kono
parents:
diff changeset
1699 pointer value reloaded. */
kono
parents:
diff changeset
1700 if (!_Unwind_GetGRPtr (current, __builtin_dwarf_sp_column ()))
kono
parents:
diff changeset
1701 {
kono
parents:
diff changeset
1702 void *target_cfa;
kono
parents:
diff changeset
1703
kono
parents:
diff changeset
1704 target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ());
kono
parents:
diff changeset
1705
kono
parents:
diff changeset
1706 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
kono
parents:
diff changeset
1707 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
kono
parents:
diff changeset
1708 return target_cfa - current->cfa + target->args_size;
kono
parents:
diff changeset
1709 else
kono
parents:
diff changeset
1710 return current->cfa - target_cfa - target->args_size;
kono
parents:
diff changeset
1711 }
kono
parents:
diff changeset
1712 return 0;
kono
parents:
diff changeset
1713 }
kono
parents:
diff changeset
1714
kono
parents:
diff changeset
1715 static inline _Unwind_Ptr
kono
parents:
diff changeset
1716 uw_identify_context (struct _Unwind_Context *context)
kono
parents:
diff changeset
1717 {
kono
parents:
diff changeset
1718 /* The CFA is not sufficient to disambiguate the context of a function
kono
parents:
diff changeset
1719 interrupted by a signal before establishing its frame and the context
kono
parents:
diff changeset
1720 of the signal itself. */
kono
parents:
diff changeset
1721 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
kono
parents:
diff changeset
1722 return _Unwind_GetCFA (context) - _Unwind_IsSignalFrame (context);
kono
parents:
diff changeset
1723 else
kono
parents:
diff changeset
1724 return _Unwind_GetCFA (context) + _Unwind_IsSignalFrame (context);
kono
parents:
diff changeset
1725 }
kono
parents:
diff changeset
1726
kono
parents:
diff changeset
1727
kono
parents:
diff changeset
1728 #include "unwind.inc"
kono
parents:
diff changeset
1729
kono
parents:
diff changeset
1730 #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
kono
parents:
diff changeset
1731 alias (_Unwind_Backtrace);
kono
parents:
diff changeset
1732 alias (_Unwind_DeleteException);
kono
parents:
diff changeset
1733 alias (_Unwind_FindEnclosingFunction);
kono
parents:
diff changeset
1734 alias (_Unwind_ForcedUnwind);
kono
parents:
diff changeset
1735 alias (_Unwind_GetDataRelBase);
kono
parents:
diff changeset
1736 alias (_Unwind_GetTextRelBase);
kono
parents:
diff changeset
1737 alias (_Unwind_GetCFA);
kono
parents:
diff changeset
1738 alias (_Unwind_GetGR);
kono
parents:
diff changeset
1739 alias (_Unwind_GetIP);
kono
parents:
diff changeset
1740 alias (_Unwind_GetLanguageSpecificData);
kono
parents:
diff changeset
1741 alias (_Unwind_GetRegionStart);
kono
parents:
diff changeset
1742 alias (_Unwind_RaiseException);
kono
parents:
diff changeset
1743 alias (_Unwind_Resume);
kono
parents:
diff changeset
1744 alias (_Unwind_Resume_or_Rethrow);
kono
parents:
diff changeset
1745 alias (_Unwind_SetGR);
kono
parents:
diff changeset
1746 alias (_Unwind_SetIP);
kono
parents:
diff changeset
1747 #endif
kono
parents:
diff changeset
1748
kono
parents:
diff changeset
1749 #endif /* !USING_SJLJ_EXCEPTIONS */