1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "unwind-dw2-fde.h"
29 #if !USING_SJLJ_EXCEPTIONS
31 #ifndef STACK_GROWS_DOWNWARD
32 #define STACK_GROWS_DOWNWARD 0
34 #undef STACK_GROWS_DOWNWARD
35 #define STACK_GROWS_DOWNWARD 1
38 /* A target can override (perhaps for backward compatibility) how
39 many dwarf2 columns are unwound. */
40 #ifndef DWARF_FRAME_REGISTERS
41 #define DWARF_FRAME_REGISTERS FIRST_PSEUDO_REGISTER
44 /* This is the register and unwind state for a particular frame. */
45 struct _Unwind_Context
47 void *reg
[DWARF_FRAME_REGISTERS
+1];
51 struct dwarf_eh_bases bases
;
52 _Unwind_Word args_size
;
55 /* Byte size of every register managed by these routines. */
56 static unsigned char dwarf_reg_size_table
[DWARF_FRAME_REGISTERS
];
59 /* The result of interpreting the frame unwind info for a frame.
60 This is all symbolic at this point, as none of the values can
61 be resolved until the target pc is located. */
64 /* Each register save state can be described in terms of a CFA slot,
65 another register, or a location expression. */
66 struct frame_state_reg_info
80 } reg
[DWARF_FRAME_REGISTERS
+1];
82 /* Used to implement DW_CFA_remember_state. */
83 struct frame_state_reg_info
*prev
;
86 /* The CFA can be described in terms of a reg+offset or a
87 location expression. */
88 _Unwind_Sword cfa_offset
;
90 unsigned char *cfa_exp
;
97 /* The PC described by the current frame state. */
100 /* The information we care about from the CIE/FDE. */
101 _Unwind_Personality_Fn personality
;
102 signed int data_align
;
103 unsigned int code_align
;
104 unsigned char retaddr_column
;
105 unsigned char addr_encoding
;
107 unsigned char saw_lsda
;
108 } _Unwind_FrameState
;
110 /* Decode the unsigned LEB128 constant at BUF into the variable pointed to
111 by R, and return the new value of BUF. */
113 static unsigned char *
114 read_uleb128 (unsigned char *buf
, _Unwind_Word
*r
)
117 _Unwind_Word result
= 0;
121 unsigned char byte
= *buf
++;
122 result
|= (byte
& 0x7f) << shift
;
123 if ((byte
& 0x80) == 0)
131 /* Decode the signed LEB128 constant at BUF into the variable pointed to
132 by R, and return the new value of BUF. */
134 static unsigned char *
135 read_sleb128 (unsigned char *buf
, _Unwind_Sword
*r
)
138 _Unwind_Sword result
= 0;
144 result
|= (byte
& 0x7f) << shift
;
146 if ((byte
& 0x80) == 0)
149 if (shift
< (sizeof (*r
) * 8) && (byte
& 0x40) != 0)
150 result
|= - (1 << shift
);
156 /* Read unaligned data from the instruction buffer. */
161 unsigned u2
__attribute__ ((mode (HI
)));
162 unsigned u4
__attribute__ ((mode (SI
)));
163 unsigned u8
__attribute__ ((mode (DI
)));
164 signed s2
__attribute__ ((mode (HI
)));
165 signed s4
__attribute__ ((mode (SI
)));
166 signed s8
__attribute__ ((mode (DI
)));
167 } __attribute__ ((packed
));
170 read_pointer (void *p
) { union unaligned
*up
= p
; return up
->p
; }
173 read_1u (void *p
) { return *(unsigned char *)p
; }
176 read_1s (void *p
) { return *(signed char *)p
; }
179 read_2u (void *p
) { union unaligned
*up
= p
; return up
->u2
; }
182 read_2s (void *p
) { union unaligned
*up
= p
; return up
->s2
; }
184 static inline unsigned int
185 read_4u (void *p
) { union unaligned
*up
= p
; return up
->u4
; }
188 read_4s (void *p
) { union unaligned
*up
= p
; return up
->s4
; }
190 static inline unsigned long
191 read_8u (void *p
) { union unaligned
*up
= p
; return up
->u8
; }
193 static inline unsigned long
194 read_8s (void *p
) { union unaligned
*up
= p
; return up
->s8
; }
196 static unsigned char *
197 read_encoded_pointer (unsigned char *p
, unsigned char encoding
,
198 struct dwarf_eh_bases
*bases
, void **pptr
)
203 switch (encoding
& 0x0f)
205 case DW_EH_PE_absptr
:
206 val
= (_Unwind_Ptr
) read_pointer (p
);
207 ret
= p
+ sizeof (void *);
210 case DW_EH_PE_uleb128
:
211 ret
= read_uleb128 (p
, &val
);
213 case DW_EH_PE_sleb128
:
214 ret
= read_sleb128 (p
, &val
);
217 case DW_EH_PE_udata2
:
221 case DW_EH_PE_udata4
:
225 case DW_EH_PE_udata8
:
230 case DW_EH_PE_sdata2
:
234 case DW_EH_PE_sdata4
:
238 case DW_EH_PE_sdata8
:
248 switch (encoding
& 0xf0)
250 case DW_EH_PE_absptr
:
253 val
+= (_Unwind_Ptr
) p
;
255 case DW_EH_PE_textrel
:
256 val
+= (_Unwind_Ptr
) bases
->tbase
;
258 case DW_EH_PE_datarel
:
259 val
+= (_Unwind_Ptr
) bases
->dbase
;
261 case DW_EH_PE_funcrel
:
262 val
+= (_Unwind_Ptr
) bases
->func
;
268 *pptr
= (void *) (_Unwind_Ptr
) val
;
272 /* Get the value of register REG as saved in CONTEXT. */
275 _Unwind_GetGR (struct _Unwind_Context
*context
, int index
)
277 /* This will segfault if the register hasn't been saved. */
278 return * (_Unwind_Word
*) context
->reg
[index
];
281 /* Overwrite the saved value for register REG in CONTEXT with VAL. */
284 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
286 * (_Unwind_Word
*) context
->reg
[index
] = val
;
289 /* Retrieve the return address for CONTEXT. */
292 _Unwind_GetIP (struct _Unwind_Context
*context
)
294 return (_Unwind_Ptr
) context
->ra
;
297 /* Overwrite the return address for CONTEXT with VAL. */
300 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
302 context
->ra
= (void *) val
;
306 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
308 return context
->lsda
;
312 _Unwind_GetRegionStart (struct _Unwind_Context
*context
)
314 return (_Unwind_Ptr
) context
->bases
.func
;
319 _Unwind_GetDataRelBase (struct _Unwind_Context
*context
)
321 return (_Unwind_Ptr
) context
->bases
.dbase
;
325 _Unwind_GetTextRelBase (struct _Unwind_Context
*context
)
327 return (_Unwind_Ptr
) context
->bases
.tbase
;
331 /* Extract any interesting information from the CIE for the translation
332 unit F belongs to. Return a pointer to the byte after the augmentation,
333 or NULL if we encountered an undecipherable augmentation. */
335 static unsigned char *
336 extract_cie_info (struct dwarf_cie
*cie
, struct _Unwind_Context
*context
,
337 _Unwind_FrameState
*fs
)
339 unsigned char *aug
= cie
->augmentation
;
340 unsigned char *p
= aug
+ strlen (aug
) + 1;
341 unsigned char *ret
= NULL
;
342 _Unwind_Word code_align
;
343 _Unwind_Sword data_align
;
345 /* Immediately following the augmentation are the code and
346 data alignment and return address column. */
347 p
= read_uleb128 (p
, &code_align
);
348 p
= read_sleb128 (p
, &data_align
);
349 fs
->code_align
= code_align
;
350 fs
->data_align
= data_align
;
351 fs
->retaddr_column
= *p
++;
353 /* If the augmentation starts with 'z', then a uleb128 immediately
354 follows containing the length of the augmentation field following
359 p
= read_uleb128 (p
, &i
);
366 /* Iterate over recognized augmentation subsequences. */
369 /* "eh" was used by g++ v2; recognize and skip. */
370 if (aug
[0] == 'e' && aug
[1] == 'h')
372 p
+= sizeof (void *);
376 /* "R" indicates a byte indicating how addresses are encoded. */
377 else if (aug
[0] == 'R')
379 fs
->addr_encoding
= *p
++;
383 /* "P" indicates a personality routine in the CIE augmentation
384 and an lsda pointer in the FDE augmentation. */
385 else if (aug
[0] == 'P')
387 p
= read_encoded_pointer (p
, fs
->addr_encoding
, &context
->bases
,
388 (void **) &fs
->personality
);
393 /* Otherwise we have an unknown augmentation string.
394 Bail unless we saw a 'z' prefix. */
399 return ret
? ret
: p
;
403 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
404 onto the stack to start. */
407 execute_stack_op (unsigned char *op_ptr
, unsigned char *op_end
,
408 struct _Unwind_Context
*context
, _Unwind_Word initial
)
410 _Unwind_Word stack
[64]; /* ??? Assume this is enough. */
416 while (op_ptr
< op_end
)
418 enum dwarf_location_atom op
= *op_ptr
++;
419 _Unwind_Word result
, reg
;
420 _Unwind_Sword offset
;
456 result
= op
- DW_OP_lit0
;
460 result
= (_Unwind_Word
) (_Unwind_Ptr
) read_pointer (op_ptr
);
461 op_ptr
+= sizeof (void *);
465 result
= read_1u (op_ptr
);
469 result
= read_1s (op_ptr
);
473 result
= read_2u (op_ptr
);
477 result
= read_2s (op_ptr
);
481 result
= read_4u (op_ptr
);
485 result
= read_4s (op_ptr
);
489 result
= read_8u (op_ptr
);
493 result
= read_8s (op_ptr
);
497 op_ptr
= read_uleb128 (op_ptr
, &result
);
500 op_ptr
= read_sleb128 (op_ptr
, &offset
);
536 result
= _Unwind_GetGR (context
, op
- DW_OP_reg0
);
539 op_ptr
= read_uleb128 (op_ptr
, ®
);
540 result
= _Unwind_GetGR (context
, reg
);
575 op_ptr
= read_sleb128 (op_ptr
, &offset
);
576 result
= _Unwind_GetGR (context
, op
- DW_OP_breg0
) + offset
;
579 op_ptr
= read_uleb128 (op_ptr
, ®
);
580 op_ptr
= read_sleb128 (op_ptr
, &offset
);
581 result
= _Unwind_GetGR (context
, reg
) + offset
;
587 result
= stack
[stack_elt
- 1];
597 if (offset
>= stack_elt
- 1)
599 result
= stack
[stack_elt
- 1 - offset
];
605 result
= stack
[stack_elt
- 2];
610 _Unwind_Word t1
, t2
, t3
;
614 t1
= stack
[stack_elt
- 1];
615 t2
= stack
[stack_elt
- 2];
616 t3
= stack
[stack_elt
- 3];
617 stack
[stack_elt
- 1] = t2
;
618 stack
[stack_elt
- 2] = t3
;
619 stack
[stack_elt
- 3] = t1
;
624 case DW_OP_deref_size
:
628 case DW_OP_plus_uconst
:
629 /* Unary operations. */
632 result
= stack
[stack_elt
];
638 void *ptr
= (void *)(_Unwind_Ptr
) result
;
639 result
= (_Unwind_Ptr
) read_pointer (ptr
);
643 case DW_OP_deref_size
:
645 void *ptr
= (void *)(_Unwind_Ptr
) result
;
649 result
= read_1u (ptr
);
652 result
= read_2u (ptr
);
655 result
= read_4u (ptr
);
658 result
= read_8u (ptr
);
667 if ((_Unwind_Sword
) result
< 0)
676 case DW_OP_plus_uconst
:
677 op_ptr
= read_uleb128 (op_ptr
, ®
);
697 /* Binary operations. */
698 _Unwind_Word first
, second
;
699 if ((stack_elt
-= 2) < 0)
701 second
= stack
[stack_elt
];
702 first
= stack
[stack_elt
+ 1];
707 result
= second
& first
;
710 result
= (_Unwind_Sword
)second
/ (_Unwind_Sword
)first
;
713 result
= second
- first
;
716 result
= (_Unwind_Sword
)second
% (_Unwind_Sword
)first
;
719 result
= second
* first
;
722 result
= second
| first
;
725 result
= second
+ first
;
728 result
= second
<< first
;
731 result
= second
>> first
;
734 result
= (_Unwind_Sword
)second
>> first
;
737 result
= second
^ first
;
740 result
= (_Unwind_Sword
)first
<= (_Unwind_Sword
)second
;
743 result
= (_Unwind_Sword
)first
>= (_Unwind_Sword
)second
;
746 result
= (_Unwind_Sword
)first
== (_Unwind_Sword
)second
;
749 result
= (_Unwind_Sword
)first
< (_Unwind_Sword
)second
;
752 result
= (_Unwind_Sword
)first
> (_Unwind_Sword
)second
;
755 result
= (_Unwind_Sword
)first
!= (_Unwind_Sword
)second
;
762 offset
= read_2s (op_ptr
);
770 offset
= read_2s (op_ptr
);
772 if (stack
[stack_elt
] != 0)
783 /* Most things push a result value. */
784 if ((size_t) stack_elt
>= sizeof(stack
)/sizeof(*stack
))
786 stack
[++stack_elt
] = result
;
790 /* We were executing this program to get a value. It should be
794 return stack
[stack_elt
];
798 /* Decode DWARF 2 call frame information. Takes pointers the
799 instruction sequence to decode, current register information and
800 CIE info, and the PC range to evaluate. */
803 execute_cfa_program (unsigned char *insn_ptr
, unsigned char *insn_end
,
804 struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
806 struct frame_state_reg_info
*unused_rs
= NULL
;
808 /* Don't allow remember/restore between CIE and FDE programs. */
809 fs
->regs
.prev
= NULL
;
811 while (insn_ptr
< insn_end
&& fs
->pc
< context
->ra
)
813 unsigned char insn
= *insn_ptr
++;
814 _Unwind_Word reg
, uoffset
;
815 _Unwind_Sword offset
;
817 if (insn
& DW_CFA_advance_loc
)
818 fs
->pc
+= (insn
& 0x3f) * fs
->code_align
;
819 else if (insn
& DW_CFA_offset
)
822 insn_ptr
= read_uleb128 (insn_ptr
, &uoffset
);
823 offset
= (_Unwind_Sword
)uoffset
* fs
->data_align
;
824 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
825 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
827 else if (insn
& DW_CFA_restore
)
830 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
835 insn_ptr
= read_encoded_pointer (insn_ptr
, fs
->addr_encoding
,
836 &context
->bases
, &fs
->pc
);
839 case DW_CFA_advance_loc1
:
840 fs
->pc
+= read_1u (insn_ptr
);
843 case DW_CFA_advance_loc2
:
844 fs
->pc
+= read_2u (insn_ptr
);
847 case DW_CFA_advance_loc4
:
848 fs
->pc
+= read_4u (insn_ptr
);
852 case DW_CFA_offset_extended
:
853 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
854 insn_ptr
= read_uleb128 (insn_ptr
, &uoffset
);
855 offset
= (_Unwind_Sword
)uoffset
* fs
->data_align
;
856 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
857 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
860 case DW_CFA_restore_extended
:
861 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
862 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
865 case DW_CFA_undefined
:
866 case DW_CFA_same_value
:
870 case DW_CFA_register
:
873 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
874 insn_ptr
= read_uleb128 (insn_ptr
, ®2
);
875 fs
->regs
.reg
[reg
].how
= REG_SAVED_REG
;
876 fs
->regs
.reg
[reg
].loc
.reg
= reg2
;
880 case DW_CFA_remember_state
:
882 struct frame_state_reg_info
*new_rs
;
886 unused_rs
= unused_rs
->prev
;
889 new_rs
= alloca (sizeof (struct frame_state_reg_info
));
892 fs
->regs
.prev
= new_rs
;
896 case DW_CFA_restore_state
:
898 struct frame_state_reg_info
*old_rs
= fs
->regs
.prev
;
900 old_rs
->prev
= unused_rs
;
906 insn_ptr
= read_uleb128 (insn_ptr
, &fs
->cfa_reg
);
907 insn_ptr
= read_uleb128 (insn_ptr
, &uoffset
);
908 fs
->cfa_offset
= uoffset
;
909 fs
->cfa_how
= CFA_REG_OFFSET
;
912 case DW_CFA_def_cfa_register
:
913 insn_ptr
= read_uleb128 (insn_ptr
, &fs
->cfa_reg
);
914 fs
->cfa_how
= CFA_REG_OFFSET
;
917 case DW_CFA_def_cfa_offset
:
918 insn_ptr
= read_uleb128 (insn_ptr
, &uoffset
);
919 fs
->cfa_offset
= uoffset
;
920 /* cfa_how deliberately not set. */
923 case DW_CFA_def_cfa_expression
:
924 insn_ptr
= read_uleb128 (insn_ptr
, &uoffset
);
925 fs
->cfa_exp
= insn_ptr
;
926 fs
->cfa_how
= CFA_EXP
;
930 case DW_CFA_expression
:
931 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
932 insn_ptr
= read_uleb128 (insn_ptr
, &uoffset
);
933 fs
->regs
.reg
[reg
].how
= REG_SAVED_EXP
;
934 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
938 /* From the 2.1 draft. */
939 case DW_CFA_offset_extended_sf
:
940 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
941 insn_ptr
= read_sleb128 (insn_ptr
, &offset
);
942 offset
*= fs
->data_align
;
943 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
944 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
947 case DW_CFA_def_cfa_sf
:
948 insn_ptr
= read_uleb128 (insn_ptr
, &fs
->cfa_reg
);
949 insn_ptr
= read_sleb128 (insn_ptr
, &fs
->cfa_offset
);
950 fs
->cfa_how
= CFA_REG_OFFSET
;
953 case DW_CFA_def_cfa_offset_sf
:
954 insn_ptr
= read_uleb128 (insn_ptr
, &fs
->cfa_offset
);
955 /* cfa_how deliberately not set. */
958 case DW_CFA_GNU_window_save
:
959 /* ??? Hardcoded for SPARC register window configuration. */
960 for (reg
= 16; reg
< 32; ++reg
)
962 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
963 fs
->regs
.reg
[reg
].loc
.offset
= (reg
- 16) * sizeof (void *);
967 case DW_CFA_GNU_args_size
:
968 insn_ptr
= read_uleb128 (insn_ptr
, &context
->args_size
);
971 case DW_CFA_GNU_negative_offset_extended
:
972 /* Obsoleted by DW_CFA_offset_extended_sf, but used by
973 older PowerPC code. */
974 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
975 insn_ptr
= read_uleb128 (insn_ptr
, &uoffset
);
976 offset
= (_Unwind_Sword
)uoffset
* fs
->data_align
;
977 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
978 fs
->regs
.reg
[reg
].loc
.offset
= -offset
;
987 static _Unwind_Reason_Code
988 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
990 struct dwarf_fde
*fde
;
991 struct dwarf_cie
*cie
;
992 unsigned char *aug
, *insn
, *end
;
994 memset (fs
, 0, sizeof (*fs
));
995 context
->args_size
= 0;
998 fde
= _Unwind_Find_FDE (context
->ra
- 1, &context
->bases
);
1001 /* Couldn't find frame unwind info for this function. Try a
1002 target-specific fallback mechanism. This will necessarily
1003 not profide a personality routine or LSDA. */
1004 #ifdef MD_FALLBACK_FRAME_STATE_FOR
1005 MD_FALLBACK_FRAME_STATE_FOR (context
, fs
, success
);
1006 return _URC_END_OF_STACK
;
1008 return _URC_NO_REASON
;
1010 return _URC_END_OF_STACK
;
1014 context
->bases
.func
= fde
->pc_begin
;
1015 fs
->pc
= fde
->pc_begin
;
1017 cie
= get_cie (fde
);
1018 insn
= extract_cie_info (cie
, context
, fs
);
1020 /* CIE contained unknown augmentation. */
1021 return _URC_FATAL_PHASE1_ERROR
;
1023 /* First decode all the insns in the CIE. */
1024 end
= (unsigned char *) next_fde ((struct dwarf_fde
*) cie
);
1025 execute_cfa_program (insn
, end
, context
, fs
);
1027 /* Locate augmentation for the fde. */
1028 aug
= (unsigned char *)fde
+ sizeof (*fde
);
1033 aug
= read_uleb128 (aug
, &i
);
1037 aug
= read_encoded_pointer (aug
, fs
->addr_encoding
,
1038 &context
->bases
, &context
->lsda
);
1040 /* Then the insns in the FDE up to our target PC. */
1043 end
= (unsigned char *) next_fde (fde
);
1044 execute_cfa_program (insn
, end
, context
, fs
);
1046 return _URC_NO_REASON
;
1051 uw_update_context_1 (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1053 struct _Unwind_Context orig_context
= *context
;
1057 /* Compute this frame's CFA. */
1058 switch (fs
->cfa_how
)
1060 case CFA_REG_OFFSET
:
1061 /* Special handling here: Many machines do not use a frame pointer,
1062 and track the CFA only through offsets from the stack pointer from
1063 one frame to the next. In this case, the stack pointer is never
1064 stored, so it has no saved address in the context. What we do
1065 have is the CFA from the previous stack frame. */
1066 if (context
->reg
[fs
->cfa_reg
] == NULL
)
1069 cfa
= (void *) (_Unwind_Ptr
) _Unwind_GetGR (context
, fs
->cfa_reg
);
1070 cfa
+= fs
->cfa_offset
;
1074 /* ??? No way of knowing what register number is the stack pointer
1075 to do the same sort of handling as above. Assume that if the
1076 CFA calculation is so complicated as to require a stack program
1077 that this will not be a problem. */
1079 unsigned char *exp
= fs
->cfa_exp
;
1082 exp
= read_uleb128 (exp
, &len
);
1083 cfa
= (void *) (_Unwind_Ptr
)
1084 execute_stack_op (exp
, exp
+ len
, context
, 0);
1093 /* Compute the addresses of all registers saved in this frame. */
1094 for (i
= 0; i
< DWARF_FRAME_REGISTERS
+ 1; ++i
)
1095 switch (fs
->regs
.reg
[i
].how
)
1099 case REG_SAVED_OFFSET
:
1100 context
->reg
[i
] = cfa
+ fs
->regs
.reg
[i
].loc
.offset
;
1103 context
->reg
[i
] = orig_context
.reg
[fs
->regs
.reg
[i
].loc
.reg
];
1107 unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1111 exp
= read_uleb128 (exp
, &len
);
1112 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1114 context
->reg
[i
] = (void *) val
;
1121 uw_update_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1123 uw_update_context_1 (context
, fs
);
1125 /* Compute the return address now, since the return address column
1126 can change from frame to frame. */
1127 context
->ra
= __builtin_extract_return_addr
1128 ((void *) (_Unwind_Ptr
) _Unwind_GetGR (context
, fs
->retaddr_column
));
1131 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
1132 level will be the return address and the CFA. */
1134 #define uw_init_context(CONTEXT) \
1136 /* Do any necessary initialization to access arbitrary stack frames. \
1137 On the SPARC, this means flushing the register windows. */ \
1138 __builtin_unwind_init (); \
1139 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
1140 __builtin_return_address (0)); \
1144 uw_init_context_1 (struct _Unwind_Context
*context
,
1145 void *outer_cfa
, void *outer_ra
)
1147 void *ra
= __builtin_extract_return_addr (__builtin_return_address (0));
1148 _Unwind_FrameState fs
;
1150 memset (context
, 0, sizeof (struct _Unwind_Context
));
1153 if (uw_frame_state_for (context
, &fs
) != _URC_NO_REASON
)
1156 /* Force the frame state to use the known cfa value. */
1157 context
->cfa
= outer_cfa
;
1158 fs
.cfa_how
= CFA_REG_OFFSET
;
1162 uw_update_context_1 (context
, &fs
);
1164 /* If the return address column was saved in a register in the
1165 initialization context, then we can't see it in the given
1166 call frame data. So have the initialization context tell us. */
1167 context
->ra
= __builtin_extract_return_addr (outer_ra
);
1171 /* Install TARGET into CURRENT so that we can return to it. This is a
1172 macro because __builtin_eh_return must be invoked in the context of
1175 #define uw_install_context(CURRENT, TARGET) \
1177 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
1178 void *handler = __builtin_frob_return_addr ((TARGET)->ra); \
1179 __builtin_eh_return (offset, handler); \
1183 init_dwarf_reg_size_table (void)
1185 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table
);
1189 uw_install_context_1 (struct _Unwind_Context
*current
,
1190 struct _Unwind_Context
*target
)
1196 static __gthread_once_t once_regsizes
= __GTHREAD_ONCE_INIT
;
1197 if (__gthread_once (&once_regsizes
, init_dwarf_reg_size_table
) != 0
1198 || dwarf_reg_size_table
[0] == 0)
1199 init_dwarf_reg_size_table ();
1202 if (dwarf_reg_size_table
[0] == 0)
1203 init_dwarf_reg_size_table ();
1206 for (i
= 0; i
< DWARF_FRAME_REGISTERS
; ++i
)
1208 void *c
= current
->reg
[i
];
1209 void *t
= target
->reg
[i
];
1210 if (t
&& c
&& t
!= c
)
1211 memcpy (c
, t
, dwarf_reg_size_table
[i
]);
1214 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
1215 if (STACK_GROWS_DOWNWARD
)
1216 return target
->cfa
- current
->cfa
+ target
->args_size
;
1218 return current
->cfa
- target
->cfa
- target
->args_size
;
1221 static inline _Unwind_Ptr
1222 uw_identify_context (struct _Unwind_Context
*context
)
1224 return _Unwind_GetIP (context
);
1228 #include "unwind.inc"
1230 #endif /* !USING_SJLJ_EXCEPTIONS */