1 /* Subroutines needed for unwinding stack frames via the libunwind API.
2 Copyright (C) 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6 This file is part of GCC.
8 GCC 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 GCC 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 GCC; 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. */
31 * $DragonFly: src/gnu/usr.bin/cc3/config/Attic/unwind-libunwind.c,v 1.1 2004/02/02 23:35:11 dillon Exp $
37 #ifndef __USING_SJLJ_EXCEPTIONS__
39 #define UNW_LOCAL_ONLY
41 #include <libunwind.h>
44 _Unwind_Personality_Fn personality;
47 struct _Unwind_Context {
52 /* First come the helper-routines that are needed by unwind.inc. */
54 static _Unwind_Reason_Code
55 uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
59 if (unw_step (&context->cursor) <= 0)
60 return _URC_END_OF_STACK;
62 unw_get_proc_info(&context->cursor, &pi);
63 fs->personality = (_Unwind_Personality_Fn) pi.handler;
65 return _URC_NO_REASON;
68 #define uw_update_context(context,fs) do { ; } while (0)
70 static inline _Unwind_Ptr
71 uw_identify_context (struct _Unwind_Context *context)
74 unw_get_reg (&context->cursor, UNW_REG_IP, &ip);
75 return (_Unwind_Ptr) ip;
78 #define uw_init_context(context) \
82 unw_getcontext (&uc); \
83 unw_init_local (&(context)->cursor, &uc); \
87 static inline void __attribute__ ((noreturn))
88 uw_install_context (struct _Unwind_Context *current __attribute__ ((unused)),
89 struct _Unwind_Context *target)
91 unw_resume (&(target)->cursor);
96 /* Now come the helper-routines which may be called from an exception
97 handler. The interface for these routines are defined by the C++
98 ABI. See: http://www.codesourcery.com/cxx-abi/abi-eh.html */
101 _Unwind_GetGR (struct _Unwind_Context *context, int index)
105 /* Note: here we depend on the fact that general registers are
106 expected to start with register number 0! */
107 unw_get_reg (&context->cursor, index, &ret);
111 /* Get the value of the CFA as saved in CONTEXT. */
114 _Unwind_GetCFA (struct _Unwind_Context *context)
116 /* ??? Is there any way to get this information? */
120 /* Overwrite the saved value for register REG in CONTEXT with VAL. */
123 _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
125 /* Note: here we depend on the fact that general registers are
126 expected to start with register number 0! */
127 unw_set_reg (&context->cursor, index, val);
130 /* Retrieve the return address for CONTEXT. */
133 _Unwind_GetIP (struct _Unwind_Context *context)
137 unw_get_reg (&context->cursor, UNW_REG_IP, &ret);
141 /* Overwrite the return address for CONTEXT with VAL. */
144 _Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
146 unw_set_reg (&context->cursor, UNW_REG_IP, val);
150 _Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
154 unw_get_proc_info(&context->cursor, &pi);
155 return (void *) pi.lsda;
159 _Unwind_GetRegionStart (struct _Unwind_Context *context)
163 unw_get_proc_info(&context->cursor, &pi);
164 return (_Unwind_Ptr) pi.start_ip;
168 _Unwind_FindEnclosingFunction (void *pc)
173 #include "unwind.inc"
175 #endif /* !__USING_SJLJ_EXCEPTIONS__ */