annotate libgcc/unwind-dw2.c @ 136:4627f235cf2a

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