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