X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Funwind.inc;h=dc4708ecd9c32bd25c0d73fba10dd9104ed3f7d3;hb=576aff9d272cd8ebec2b93b10dcf5eae125e9667;hp=a1d1a432f63ee764d6704167128f8af85a65757b;hpb=b251b3697c08fe8c5aed07fe87853deb0ae2ca6e;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/unwind.inc b/gcc/unwind.inc index a1d1a432f63..dc4708ecd9c 100644 --- a/gcc/unwind.inc +++ b/gcc/unwind.inc @@ -1,22 +1,31 @@ /* Exception handling and frame unwind runtime interface routines. -*- C -*- - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001, 2003 Free Software Foundation, Inc. - This file is part of GNU CC. + This file is part of GCC. - GNU CC is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - GNU CC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + In addition to the permissions in the GNU General Public License, the + Free Software Foundation gives you unlimited permission to link the + compiled version of this file into combinations with other programs, + and to distribute those combinations without any restriction coming + from the use of this file. (The General Public License restrictions + do apply in other respects; for example, they cover modification of + the file, and distribution when not linked into a combined + executable.) + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. You should have received a copy of the GNU General Public License - along with GNU CC; see the file COPYING. If not, write to - the Free Software Foundation, 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + along with GCC; see the file COPYING. If not, write to the Free + Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ /* This is derived from the C++ ABI for IA-64. Where we diverge for cross-architecture compatibility are noted with "@@@". @@ -47,7 +56,7 @@ _Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc, ? _UA_HANDLER_FRAME : 0); if (code != _URC_NO_REASON) - /* Some error encountered. Ususally the unwinder doesn't + /* Some error encountered. Usually the unwinder doesn't diagnose these and merely crashes. */ return _URC_FATAL_PHASE2_ERROR; @@ -63,8 +72,7 @@ _Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc, } /* Don't let us unwind past the handler context. */ - if (match_handler) - abort (); + gcc_assert (!match_handler); uw_update_context (context, &fs); } @@ -72,7 +80,6 @@ _Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc, return code; } - /* Raise an exception, passing along the given exception object. */ _Unwind_Reason_Code @@ -81,6 +88,7 @@ _Unwind_RaiseException(struct _Unwind_Exception *exc) struct _Unwind_Context this_context, cur_context; _Unwind_Reason_Code code; + /* Set up this_context to describe the current stack frame. */ uw_init_context (&this_context); cur_context = this_context; @@ -90,6 +98,8 @@ _Unwind_RaiseException(struct _Unwind_Exception *exc) { _Unwind_FrameState fs; + /* Set up fs to describe the FDE for the caller of cur_context. The + first time through the loop, that means __cxa_throw. */ code = uw_frame_state_for (&cur_context, &fs); if (code == _URC_END_OF_STACK) @@ -112,6 +122,7 @@ _Unwind_RaiseException(struct _Unwind_Exception *exc) return _URC_FATAL_PHASE1_ERROR; } + /* Update cur_context to describe the same frame as fs. */ uw_update_context (&cur_context, &fs); } @@ -132,24 +143,29 @@ _Unwind_RaiseException(struct _Unwind_Exception *exc) /* Subroutine of _Unwind_ForcedUnwind also invoked from _Unwind_Resume. */ static _Unwind_Reason_Code -_Unwind_ForcedUnwind_Phase2(struct _Unwind_Exception *exc, - struct _Unwind_Context *context) +_Unwind_ForcedUnwind_Phase2 (struct _Unwind_Exception *exc, + struct _Unwind_Context *context) { - _Unwind_Stop_Fn stop = (_Unwind_Stop_Fn) exc->private_1; - void *stop_argument = (void *) exc->private_2; + _Unwind_Stop_Fn stop = (_Unwind_Stop_Fn) (_Unwind_Ptr) exc->private_1; + void *stop_argument = (void *) (_Unwind_Ptr) exc->private_2; _Unwind_Reason_Code code, stop_code; while (1) { _Unwind_FrameState fs; + int action; + /* Set up fs to describe the FDE for the caller of cur_context. */ code = uw_frame_state_for (context, &fs); if (code != _URC_NO_REASON && code != _URC_END_OF_STACK) return _URC_FATAL_PHASE2_ERROR; /* Unwind successful. */ - stop_code = (*stop) (1, _UA_FORCE_UNWIND | _UA_CLEANUP_PHASE, - exc->exception_class, exc, context, stop_argument); + action = _UA_FORCE_UNWIND | _UA_CLEANUP_PHASE; + if (code == _URC_END_OF_STACK) + action |= _UA_END_OF_STACK; + stop_code = (*stop) (1, action, exc->exception_class, exc, + context, stop_argument); if (stop_code != _URC_NO_REASON) return _URC_FATAL_PHASE2_ERROR; @@ -168,6 +184,7 @@ _Unwind_ForcedUnwind_Phase2(struct _Unwind_Exception *exc, return _URC_FATAL_PHASE2_ERROR; } + /* Update cur_context to describe the same frame as fs. */ uw_update_context (context, &fs); } @@ -217,16 +234,77 @@ _Unwind_Resume (struct _Unwind_Exception *exc) else code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context); - if (code != _URC_INSTALL_CONTEXT) - abort (); + gcc_assert (code == _URC_INSTALL_CONTEXT); + + uw_install_context (&this_context, &cur_context); +} + + +/* Resume propagation of an FORCE_UNWIND exception, or to rethrow + a normal exception that was handled. */ + +_Unwind_Reason_Code +_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc) +{ + struct _Unwind_Context this_context, cur_context; + _Unwind_Reason_Code code; + + /* Choose between continuing to process _Unwind_RaiseException + or _Unwind_ForcedUnwind. */ + if (exc->private_1 == 0) + return _Unwind_RaiseException (exc); + + uw_init_context (&this_context); + cur_context = this_context; + + code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context); + + gcc_assert (code == _URC_INSTALL_CONTEXT); uw_install_context (&this_context, &cur_context); } + /* A convenience function that calls the exception_cleanup field. */ void _Unwind_DeleteException (struct _Unwind_Exception *exc) { - (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc); + if (exc->exception_cleanup) + (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc); +} + + +/* Perform stack backtrace through unwind data. */ + +_Unwind_Reason_Code +_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument) +{ + struct _Unwind_Context context; + _Unwind_Reason_Code code; + + uw_init_context (&context); + + while (1) + { + _Unwind_FrameState fs; + + /* Set up fs to describe the FDE for the caller of context. */ + code = uw_frame_state_for (&context, &fs); + if (code != _URC_NO_REASON && code != _URC_END_OF_STACK) + return _URC_FATAL_PHASE1_ERROR; + + /* Call trace function. */ + if ((*trace) (&context, trace_argument) != _URC_NO_REASON) + return _URC_FATAL_PHASE1_ERROR; + + /* We're done at end of stack. */ + if (code == _URC_END_OF_STACK) + break; + + /* Update context to describe the same frame as fs. */ + uw_update_context (&context, &fs); + } + + return code; }