1 /* Subroutines needed for unwinding stack frames via the libunwind API.
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* As a special exception, if you link this library with other files,
24 some of which are compiled with GCC, to produce an executable,
25 this library does not by itself cause the resulting executable
26 to be covered by the GNU General Public License.
27 This exception does not however invalidate any other reasons why
28 the executable file might be covered by the GNU General Public License. */
34 #ifndef __USING_SJLJ_EXCEPTIONS__
36 #define UNW_LOCAL_ONLY
38 #include <libunwind.h>
41 _Unwind_Personality_Fn personality
;
44 struct _Unwind_Context
{
49 /* First come the helper-routines that are needed by unwind.inc. */
51 static _Unwind_Reason_Code
52 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
56 if (unw_step (&context
->cursor
) <= 0)
57 return _URC_END_OF_STACK
;
59 unw_get_reg (&context
->cursor
, UNW_REG_HANDLER
, &handler
);
60 fs
->personality
= (_Unwind_Personality_Fn
) handler
;
62 return _URC_NO_REASON
;
65 #define uw_update_context(context,fs) do { ; } while (0)
67 static inline _Unwind_Ptr
68 uw_identify_context (struct _Unwind_Context
*context
)
71 unw_get_reg (&context
->cursor
, UNW_REG_IP
, &ip
);
72 return (_Unwind_Ptr
) ip
;
75 #define uw_init_context(context) \
79 unw_getcontext (&uc); \
80 unw_init_local (&(context)->cursor, &uc); \
84 static inline void __attribute__ ((noreturn
))
85 uw_install_context (struct _Unwind_Context
*current
__attribute__ ((unused
)),
86 struct _Unwind_Context
*target
)
88 unw_resume (&(target
)->cursor
);
93 /* Now come the helper-routines which may be called from an exception
94 handler. The interface for these routines are defined by the C++
95 ABI. See: http://www.codesourcery.com/cxx-abi/abi-eh.html */
98 _Unwind_GetGR (struct _Unwind_Context
*context
, int index
)
102 /* Note: here we depend on the fact that general registers are
103 expected to start with register number 0! */
104 unw_get_reg (&context
->cursor
, index
, &ret
);
108 /* Overwrite the saved value for register REG in CONTEXT with VAL. */
111 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
113 /* Note: here we depend on the fact that general registers are
114 expected to start with register number 0! */
115 unw_set_reg (&context
->cursor
, index
, val
);
118 /* Retrieve the return address for CONTEXT. */
121 _Unwind_GetIP (struct _Unwind_Context
*context
)
125 unw_get_reg (&context
->cursor
, UNW_REG_IP
, &ret
);
129 /* Overwrite the return address for CONTEXT with VAL. */
132 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
134 unw_set_reg (&context
->cursor
, UNW_REG_IP
, val
);
138 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
142 unw_get_reg (&context
->cursor
, UNW_REG_LSDA
, &ret
);
147 _Unwind_GetRegionStart (struct _Unwind_Context
*context
)
151 unw_get_reg (&context
->cursor
, UNW_REG_PROC_START
, &ret
);
152 return (_Unwind_Ptr
) ret
;
155 #include "unwind.inc"
157 #endif /* !__USING_SJLJ_EXCEPTIONS__ */