1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "unwind-pe.h"
27 #include "unwind-dw2-fde.h"
31 #ifndef __USING_SJLJ_EXCEPTIONS__
33 #ifndef STACK_GROWS_DOWNWARD
34 #define STACK_GROWS_DOWNWARD 0
36 #undef STACK_GROWS_DOWNWARD
37 #define STACK_GROWS_DOWNWARD 1
40 /* A target can override (perhaps for backward compatibility) how
41 many dwarf2 columns are unwound. */
42 #ifndef DWARF_FRAME_REGISTERS
43 #define DWARF_FRAME_REGISTERS FIRST_PSEUDO_REGISTER
46 /* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */
47 #ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
48 #define PRE_GCC3_DWARF_FRAME_REGISTERS DWARF_FRAME_REGISTERS
51 /* This is the register and unwind state for a particular frame. */
52 struct _Unwind_Context
54 void *reg
[DWARF_FRAME_REGISTERS
+1];
58 struct dwarf_eh_bases bases
;
59 _Unwind_Word args_size
;
62 /* Byte size of every register managed by these routines. */
63 static unsigned char dwarf_reg_size_table
[DWARF_FRAME_REGISTERS
];
66 /* The result of interpreting the frame unwind info for a frame.
67 This is all symbolic at this point, as none of the values can
68 be resolved until the target pc is located. */
71 /* Each register save state can be described in terms of a CFA slot,
72 another register, or a location expression. */
73 struct frame_state_reg_info
79 const unsigned char *exp
;
87 } reg
[DWARF_FRAME_REGISTERS
+1];
89 /* Used to implement DW_CFA_remember_state. */
90 struct frame_state_reg_info
*prev
;
93 /* The CFA can be described in terms of a reg+offset or a
94 location expression. */
95 _Unwind_Sword cfa_offset
;
97 const unsigned char *cfa_exp
;
104 /* The PC described by the current frame state. */
107 /* The information we care about from the CIE/FDE. */
108 _Unwind_Personality_Fn personality
;
109 _Unwind_Sword data_align
;
110 _Unwind_Word code_align
;
111 unsigned char retaddr_column
;
112 unsigned char fde_encoding
;
113 unsigned char lsda_encoding
;
116 } _Unwind_FrameState
;
118 /* Read unaligned data from the instruction buffer. */
123 unsigned u2
__attribute__ ((mode (HI
)));
124 unsigned u4
__attribute__ ((mode (SI
)));
125 unsigned u8
__attribute__ ((mode (DI
)));
126 signed s2
__attribute__ ((mode (HI
)));
127 signed s4
__attribute__ ((mode (SI
)));
128 signed s8
__attribute__ ((mode (DI
)));
129 } __attribute__ ((packed
));
132 read_pointer (const void *p
) { const union unaligned
*up
= p
; return up
->p
; }
135 read_1u (const void *p
) { return *(const unsigned char *) p
; }
138 read_1s (const void *p
) { return *(const signed char *) p
; }
141 read_2u (const void *p
) { const union unaligned
*up
= p
; return up
->u2
; }
144 read_2s (const void *p
) { const union unaligned
*up
= p
; return up
->s2
; }
146 static inline unsigned int
147 read_4u (const void *p
) { const union unaligned
*up
= p
; return up
->u4
; }
150 read_4s (const void *p
) { const union unaligned
*up
= p
; return up
->s4
; }
152 static inline unsigned long
153 read_8u (const void *p
) { const union unaligned
*up
= p
; return up
->u8
; }
155 static inline unsigned long
156 read_8s (const void *p
) { const union unaligned
*up
= p
; return up
->s8
; }
158 /* Get the value of register REG as saved in CONTEXT. */
161 _Unwind_GetGR (struct _Unwind_Context
*context
, int index
)
163 /* This will segfault if the register hasn't been saved. */
164 return * (_Unwind_Word
*) context
->reg
[index
];
167 /* Overwrite the saved value for register REG in CONTEXT with VAL. */
170 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
172 * (_Unwind_Word
*) context
->reg
[index
] = val
;
175 /* Retrieve the return address for CONTEXT. */
178 _Unwind_GetIP (struct _Unwind_Context
*context
)
180 return (_Unwind_Ptr
) context
->ra
;
183 /* Overwrite the return address for CONTEXT with VAL. */
186 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
188 context
->ra
= (void *) val
;
192 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
194 return context
->lsda
;
198 _Unwind_GetRegionStart (struct _Unwind_Context
*context
)
200 return (_Unwind_Ptr
) context
->bases
.func
;
205 _Unwind_GetDataRelBase (struct _Unwind_Context
*context
)
207 return (_Unwind_Ptr
) context
->bases
.dbase
;
211 _Unwind_GetTextRelBase (struct _Unwind_Context
*context
)
213 return (_Unwind_Ptr
) context
->bases
.tbase
;
217 /* Extract any interesting information from the CIE for the translation
218 unit F belongs to. Return a pointer to the byte after the augmentation,
219 or NULL if we encountered an undecipherable augmentation. */
221 static const unsigned char *
222 extract_cie_info (struct dwarf_cie
*cie
, struct _Unwind_Context
*context
,
223 _Unwind_FrameState
*fs
)
225 const unsigned char *aug
= cie
->augmentation
;
226 const unsigned char *p
= aug
+ strlen (aug
) + 1;
227 const unsigned char *ret
= NULL
;
230 /* g++ v2 "eh" has pointer immediately following augmentation string,
231 so it must be handled first. */
232 if (aug
[0] == 'e' && aug
[1] == 'h')
234 fs
->eh_ptr
= read_pointer (p
);
235 p
+= sizeof (void *);
239 /* Immediately following the augmentation are the code and
240 data alignment and return address column. */
241 p
= read_uleb128 (p
, &fs
->code_align
);
242 p
= read_sleb128 (p
, &fs
->data_align
);
243 fs
->retaddr_column
= *p
++;
244 fs
->lsda_encoding
= DW_EH_PE_omit
;
246 /* If the augmentation starts with 'z', then a uleb128 immediately
247 follows containing the length of the augmentation field following
251 p
= read_uleb128 (p
, &utmp
);
258 /* Iterate over recognized augmentation subsequences. */
261 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
264 fs
->lsda_encoding
= *p
++;
268 /* "R" indicates a byte indicating how FDE addresses are encoded. */
269 else if (aug
[0] == 'R')
271 fs
->fde_encoding
= *p
++;
275 /* "P" indicates a personality routine in the CIE augmentation. */
276 else if (aug
[0] == 'P')
278 p
= read_encoded_value (context
, *p
, p
+ 1,
279 (_Unwind_Ptr
*) &fs
->personality
);
283 /* Otherwise we have an unknown augmentation string.
284 Bail unless we saw a 'z' prefix. */
289 return ret
? ret
: p
;
293 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
294 onto the stack to start. */
297 execute_stack_op (const unsigned char *op_ptr
, const unsigned char *op_end
,
298 struct _Unwind_Context
*context
, _Unwind_Word initial
)
300 _Unwind_Word stack
[64]; /* ??? Assume this is enough. */
306 while (op_ptr
< op_end
)
308 enum dwarf_location_atom op
= *op_ptr
++;
309 _Unwind_Word result
, reg
, utmp
;
310 _Unwind_Sword offset
, stmp
;
346 result
= op
- DW_OP_lit0
;
350 result
= (_Unwind_Word
) (_Unwind_Ptr
) read_pointer (op_ptr
);
351 op_ptr
+= sizeof (void *);
355 result
= read_1u (op_ptr
);
359 result
= read_1s (op_ptr
);
363 result
= read_2u (op_ptr
);
367 result
= read_2s (op_ptr
);
371 result
= read_4u (op_ptr
);
375 result
= read_4s (op_ptr
);
379 result
= read_8u (op_ptr
);
383 result
= read_8s (op_ptr
);
387 op_ptr
= read_uleb128 (op_ptr
, &result
);
390 op_ptr
= read_sleb128 (op_ptr
, &stmp
);
426 result
= _Unwind_GetGR (context
, op
- DW_OP_reg0
);
429 op_ptr
= read_uleb128 (op_ptr
, ®
);
430 result
= _Unwind_GetGR (context
, reg
);
465 op_ptr
= read_sleb128 (op_ptr
, &offset
);
466 result
= _Unwind_GetGR (context
, op
- DW_OP_breg0
) + offset
;
469 op_ptr
= read_uleb128 (op_ptr
, ®
);
470 op_ptr
= read_sleb128 (op_ptr
, &offset
);
471 result
= _Unwind_GetGR (context
, reg
) + offset
;
477 result
= stack
[stack_elt
- 1];
487 if (offset
>= stack_elt
- 1)
489 result
= stack
[stack_elt
- 1 - offset
];
495 result
= stack
[stack_elt
- 2];
500 _Unwind_Word t1
, t2
, t3
;
504 t1
= stack
[stack_elt
- 1];
505 t2
= stack
[stack_elt
- 2];
506 t3
= stack
[stack_elt
- 3];
507 stack
[stack_elt
- 1] = t2
;
508 stack
[stack_elt
- 2] = t3
;
509 stack
[stack_elt
- 3] = t1
;
514 case DW_OP_deref_size
:
518 case DW_OP_plus_uconst
:
519 /* Unary operations. */
522 result
= stack
[stack_elt
];
528 void *ptr
= (void *) (_Unwind_Ptr
) result
;
529 result
= (_Unwind_Ptr
) read_pointer (ptr
);
533 case DW_OP_deref_size
:
535 void *ptr
= (void *) (_Unwind_Ptr
) result
;
539 result
= read_1u (ptr
);
542 result
= read_2u (ptr
);
545 result
= read_4u (ptr
);
548 result
= read_8u (ptr
);
557 if ((_Unwind_Sword
) result
< 0)
566 case DW_OP_plus_uconst
:
567 op_ptr
= read_uleb128 (op_ptr
, &utmp
);
590 /* Binary operations. */
591 _Unwind_Word first
, second
;
592 if ((stack_elt
-= 2) < 0)
594 second
= stack
[stack_elt
];
595 first
= stack
[stack_elt
+ 1];
600 result
= second
& first
;
603 result
= (_Unwind_Sword
) second
/ (_Unwind_Sword
) first
;
606 result
= second
- first
;
609 result
= (_Unwind_Sword
) second
% (_Unwind_Sword
) first
;
612 result
= second
* first
;
615 result
= second
| first
;
618 result
= second
+ first
;
621 result
= second
<< first
;
624 result
= second
>> first
;
627 result
= (_Unwind_Sword
) second
>> first
;
630 result
= second
^ first
;
633 result
= (_Unwind_Sword
) first
<= (_Unwind_Sword
) second
;
636 result
= (_Unwind_Sword
) first
>= (_Unwind_Sword
) second
;
639 result
= (_Unwind_Sword
) first
== (_Unwind_Sword
) second
;
642 result
= (_Unwind_Sword
) first
< (_Unwind_Sword
) second
;
645 result
= (_Unwind_Sword
) first
> (_Unwind_Sword
) second
;
648 result
= (_Unwind_Sword
) first
!= (_Unwind_Sword
) second
;
658 offset
= read_2s (op_ptr
);
666 offset
= read_2s (op_ptr
);
668 if (stack
[stack_elt
] != 0)
679 /* Most things push a result value. */
680 if ((size_t) stack_elt
>= sizeof(stack
)/sizeof(*stack
))
682 stack
[++stack_elt
] = result
;
686 /* We were executing this program to get a value. It should be
690 return stack
[stack_elt
];
694 /* Decode DWARF 2 call frame information. Takes pointers the
695 instruction sequence to decode, current register information and
696 CIE info, and the PC range to evaluate. */
699 execute_cfa_program (const unsigned char *insn_ptr
,
700 const unsigned char *insn_end
,
701 struct _Unwind_Context
*context
,
702 _Unwind_FrameState
*fs
)
704 struct frame_state_reg_info
*unused_rs
= NULL
;
706 /* Don't allow remember/restore between CIE and FDE programs. */
707 fs
->regs
.prev
= NULL
;
709 /* The comparison with the return address uses < rather than <= because
710 we are only interested in the effects of code before the call; for a
711 noreturn function, the return address may point to unrelated code with
712 a different stack configuration that we are not interested in. We
713 assume that the call itself is unwind info-neutral; if not, or if
714 there are delay instructions that adjust the stack, these must be
715 reflected at the point immediately before the call insn. */
716 while (insn_ptr
< insn_end
&& fs
->pc
< context
->ra
)
718 unsigned char insn
= *insn_ptr
++;
719 _Unwind_Word reg
, utmp
;
720 _Unwind_Sword offset
, stmp
;
722 if ((insn
& 0xc0) == DW_CFA_advance_loc
)
723 fs
->pc
+= (insn
& 0x3f) * fs
->code_align
;
724 else if ((insn
& 0xc0) == DW_CFA_offset
)
727 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
728 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
729 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
730 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
732 else if ((insn
& 0xc0) == DW_CFA_restore
)
735 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
740 insn_ptr
= read_encoded_value (context
, fs
->fde_encoding
,
741 insn_ptr
, (_Unwind_Ptr
*) &fs
->pc
);
744 case DW_CFA_advance_loc1
:
745 fs
->pc
+= read_1u (insn_ptr
) * fs
->code_align
;
748 case DW_CFA_advance_loc2
:
749 fs
->pc
+= read_2u (insn_ptr
) * fs
->code_align
;
752 case DW_CFA_advance_loc4
:
753 fs
->pc
+= read_4u (insn_ptr
) * fs
->code_align
;
757 case DW_CFA_offset_extended
:
758 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
759 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
760 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
761 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
762 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
765 case DW_CFA_restore_extended
:
766 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
767 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
770 case DW_CFA_undefined
:
771 case DW_CFA_same_value
:
775 case DW_CFA_register
:
778 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
779 insn_ptr
= read_uleb128 (insn_ptr
, ®2
);
780 fs
->regs
.reg
[reg
].how
= REG_SAVED_REG
;
781 fs
->regs
.reg
[reg
].loc
.reg
= reg2
;
785 case DW_CFA_remember_state
:
787 struct frame_state_reg_info
*new_rs
;
791 unused_rs
= unused_rs
->prev
;
794 new_rs
= __builtin_alloca (sizeof (struct frame_state_reg_info
));
797 fs
->regs
.prev
= new_rs
;
801 case DW_CFA_restore_state
:
803 struct frame_state_reg_info
*old_rs
= fs
->regs
.prev
;
805 old_rs
->prev
= unused_rs
;
811 insn_ptr
= read_uleb128 (insn_ptr
, &fs
->cfa_reg
);
812 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
813 fs
->cfa_offset
= utmp
;
814 fs
->cfa_how
= CFA_REG_OFFSET
;
817 case DW_CFA_def_cfa_register
:
818 insn_ptr
= read_uleb128 (insn_ptr
, &fs
->cfa_reg
);
819 fs
->cfa_how
= CFA_REG_OFFSET
;
822 case DW_CFA_def_cfa_offset
:
823 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
824 fs
->cfa_offset
= utmp
;
825 /* cfa_how deliberately not set. */
828 case DW_CFA_def_cfa_expression
:
829 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
830 fs
->cfa_exp
= insn_ptr
;
831 fs
->cfa_how
= CFA_EXP
;
835 case DW_CFA_expression
:
836 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
837 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
838 fs
->regs
.reg
[reg
].how
= REG_SAVED_EXP
;
839 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
843 /* From the 2.1 draft. */
844 case DW_CFA_offset_extended_sf
:
845 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
846 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
847 offset
= stmp
* fs
->data_align
;
848 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
849 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
852 case DW_CFA_def_cfa_sf
:
853 insn_ptr
= read_uleb128 (insn_ptr
, &fs
->cfa_reg
);
854 insn_ptr
= read_sleb128 (insn_ptr
, &fs
->cfa_offset
);
855 fs
->cfa_how
= CFA_REG_OFFSET
;
858 case DW_CFA_def_cfa_offset_sf
:
859 insn_ptr
= read_sleb128 (insn_ptr
, &fs
->cfa_offset
);
860 /* cfa_how deliberately not set. */
863 case DW_CFA_GNU_window_save
:
864 /* ??? Hardcoded for SPARC register window configuration. */
865 for (reg
= 16; reg
< 32; ++reg
)
867 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
868 fs
->regs
.reg
[reg
].loc
.offset
= (reg
- 16) * sizeof (void *);
872 case DW_CFA_GNU_args_size
:
873 insn_ptr
= read_uleb128 (insn_ptr
, &context
->args_size
);
876 case DW_CFA_GNU_negative_offset_extended
:
877 /* Obsoleted by DW_CFA_offset_extended_sf, but used by
878 older PowerPC code. */
879 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
880 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
881 offset
= (_Unwind_Word
) utmp
* fs
->data_align
;
882 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
883 fs
->regs
.reg
[reg
].loc
.offset
= -offset
;
892 static _Unwind_Reason_Code
893 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
895 struct dwarf_fde
*fde
;
896 struct dwarf_cie
*cie
;
897 const unsigned char *aug
, *insn
, *end
;
899 memset (fs
, 0, sizeof (*fs
));
900 context
->args_size
= 0;
903 fde
= _Unwind_Find_FDE (context
->ra
- 1, &context
->bases
);
906 /* Couldn't find frame unwind info for this function. Try a
907 target-specific fallback mechanism. This will necessarily
908 not provide a personality routine or LSDA. */
909 #ifdef MD_FALLBACK_FRAME_STATE_FOR
910 MD_FALLBACK_FRAME_STATE_FOR (context
, fs
, success
);
911 return _URC_END_OF_STACK
;
913 return _URC_NO_REASON
;
915 return _URC_END_OF_STACK
;
919 fs
->pc
= context
->bases
.func
;
922 insn
= extract_cie_info (cie
, context
, fs
);
924 /* CIE contained unknown augmentation. */
925 return _URC_FATAL_PHASE1_ERROR
;
927 /* First decode all the insns in the CIE. */
928 end
= (unsigned char *) next_fde ((struct dwarf_fde
*) cie
);
929 execute_cfa_program (insn
, end
, context
, fs
);
931 /* Locate augmentation for the fde. */
932 aug
= (unsigned char *) fde
+ sizeof (*fde
);
933 aug
+= 2 * size_of_encoded_value (fs
->fde_encoding
);
938 aug
= read_uleb128 (aug
, &i
);
941 if (fs
->lsda_encoding
!= DW_EH_PE_omit
)
942 aug
= read_encoded_value (context
, fs
->lsda_encoding
, aug
,
943 (_Unwind_Ptr
*) &context
->lsda
);
945 /* Then the insns in the FDE up to our target PC. */
948 end
= (unsigned char *) next_fde (fde
);
949 execute_cfa_program (insn
, end
, context
, fs
);
951 return _URC_NO_REASON
;
954 typedef struct frame_state
960 long reg_or_offset
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
961 unsigned short cfa_reg
;
962 unsigned short retaddr_column
;
963 char saved
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
966 struct frame_state
* __frame_state_for (void *, struct frame_state
*);
968 /* Called from pre-G++ 3.0 __throw to find the registers to restore for
969 a given PC_TARGET. The caller should allocate a local variable of
970 `struct frame_state' and pass its address to STATE_IN. */
973 __frame_state_for (void *pc_target
, struct frame_state
*state_in
)
975 struct _Unwind_Context context
;
976 _Unwind_FrameState fs
;
979 memset (&context
, 0, sizeof (struct _Unwind_Context
));
980 context
.ra
= pc_target
+ 1;
982 if (uw_frame_state_for (&context
, &fs
) != _URC_NO_REASON
)
985 /* We have no way to pass a location expression for the CFA to our
986 caller. It wouldn't understand it anyway. */
987 if (fs
.cfa_how
== CFA_EXP
)
990 for (reg
= 0; reg
< PRE_GCC3_DWARF_FRAME_REGISTERS
+ 1; reg
++)
992 state_in
->saved
[reg
] = fs
.regs
.reg
[reg
].how
;
993 switch (state_in
->saved
[reg
])
996 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.reg
;
998 case REG_SAVED_OFFSET
:
999 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.offset
;
1002 state_in
->reg_or_offset
[reg
] = 0;
1007 state_in
->cfa_offset
= fs
.cfa_offset
;
1008 state_in
->cfa_reg
= fs
.cfa_reg
;
1009 state_in
->retaddr_column
= fs
.retaddr_column
;
1010 state_in
->args_size
= context
.args_size
;
1011 state_in
->eh_ptr
= fs
.eh_ptr
;
1017 uw_update_context_1 (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1019 struct _Unwind_Context orig_context
= *context
;
1023 /* Compute this frame's CFA. */
1024 switch (fs
->cfa_how
)
1026 case CFA_REG_OFFSET
:
1027 /* Special handling here: Many machines do not use a frame pointer,
1028 and track the CFA only through offsets from the stack pointer from
1029 one frame to the next. In this case, the stack pointer is never
1030 stored, so it has no saved address in the context. What we do
1031 have is the CFA from the previous stack frame. */
1032 if (context
->reg
[fs
->cfa_reg
] == NULL
)
1035 cfa
= (void *) (_Unwind_Ptr
) _Unwind_GetGR (context
, fs
->cfa_reg
);
1036 cfa
+= fs
->cfa_offset
;
1040 /* ??? No way of knowing what register number is the stack pointer
1041 to do the same sort of handling as above. Assume that if the
1042 CFA calculation is so complicated as to require a stack program
1043 that this will not be a problem. */
1045 const unsigned char *exp
= fs
->cfa_exp
;
1048 exp
= read_uleb128 (exp
, &len
);
1049 cfa
= (void *) (_Unwind_Ptr
)
1050 execute_stack_op (exp
, exp
+ len
, context
, 0);
1059 /* Compute the addresses of all registers saved in this frame. */
1060 for (i
= 0; i
< DWARF_FRAME_REGISTERS
+ 1; ++i
)
1061 switch (fs
->regs
.reg
[i
].how
)
1065 case REG_SAVED_OFFSET
:
1066 context
->reg
[i
] = cfa
+ fs
->regs
.reg
[i
].loc
.offset
;
1069 context
->reg
[i
] = orig_context
.reg
[fs
->regs
.reg
[i
].loc
.reg
];
1073 const unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1077 exp
= read_uleb128 (exp
, &len
);
1078 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1080 context
->reg
[i
] = (void *) val
;
1087 uw_update_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1089 uw_update_context_1 (context
, fs
);
1091 /* Compute the return address now, since the return address column
1092 can change from frame to frame. */
1093 context
->ra
= __builtin_extract_return_addr
1094 ((void *) (_Unwind_Ptr
) _Unwind_GetGR (context
, fs
->retaddr_column
));
1097 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
1098 level will be the return address and the CFA. */
1100 #define uw_init_context(CONTEXT) \
1103 /* Do any necessary initialization to access arbitrary stack frames. \
1104 On the SPARC, this means flushing the register windows. */ \
1105 __builtin_unwind_init (); \
1106 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
1107 __builtin_return_address (0)); \
1112 uw_init_context_1 (struct _Unwind_Context
*context
,
1113 void *outer_cfa
, void *outer_ra
)
1115 void *ra
= __builtin_extract_return_addr (__builtin_return_address (0));
1116 _Unwind_FrameState fs
;
1118 memset (context
, 0, sizeof (struct _Unwind_Context
));
1121 if (uw_frame_state_for (context
, &fs
) != _URC_NO_REASON
)
1124 /* Force the frame state to use the known cfa value. */
1125 context
->cfa
= outer_cfa
;
1126 fs
.cfa_how
= CFA_REG_OFFSET
;
1130 uw_update_context_1 (context
, &fs
);
1132 /* If the return address column was saved in a register in the
1133 initialization context, then we can't see it in the given
1134 call frame data. So have the initialization context tell us. */
1135 context
->ra
= __builtin_extract_return_addr (outer_ra
);
1139 /* Install TARGET into CURRENT so that we can return to it. This is a
1140 macro because __builtin_eh_return must be invoked in the context of
1143 #define uw_install_context(CURRENT, TARGET) \
1146 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
1147 void *handler = __builtin_frob_return_addr ((TARGET)->ra); \
1148 __builtin_eh_return (offset, handler); \
1153 init_dwarf_reg_size_table (void)
1155 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table
);
1159 uw_install_context_1 (struct _Unwind_Context
*current
,
1160 struct _Unwind_Context
*target
)
1166 static __gthread_once_t once_regsizes
= __GTHREAD_ONCE_INIT
;
1167 if (__gthread_once (&once_regsizes
, init_dwarf_reg_size_table
) != 0
1168 || dwarf_reg_size_table
[0] == 0)
1169 init_dwarf_reg_size_table ();
1172 if (dwarf_reg_size_table
[0] == 0)
1173 init_dwarf_reg_size_table ();
1176 for (i
= 0; i
< DWARF_FRAME_REGISTERS
; ++i
)
1178 void *c
= current
->reg
[i
];
1179 void *t
= target
->reg
[i
];
1180 if (t
&& c
&& t
!= c
)
1181 memcpy (c
, t
, dwarf_reg_size_table
[i
]);
1184 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
1185 if (STACK_GROWS_DOWNWARD
)
1186 return target
->cfa
- current
->cfa
+ target
->args_size
;
1188 return current
->cfa
- target
->cfa
- target
->args_size
;
1191 static inline _Unwind_Ptr
1192 uw_identify_context (struct _Unwind_Context
*context
)
1194 return _Unwind_GetIP (context
);
1198 #include "unwind.inc"
1200 #endif /* !USING_SJLJ_EXCEPTIONS */