fa10beec52
gcc/ * cgraph.c: Fix typos in comments. (cgraph_availability_names): Fix string typo. * fold-const.c: Fix typos in comments. (fold_binary): Fix typo in warning. * genautomata.c: Fix typos in comments. (check_presence_pattern_sets): Fix typo in local variable. (output_description): Fix typo in output. * ggc-zone.c (ggc_pch_finish): Fix typo in error message. * hwint.h: Likewise. * matrix-reorg.c (check_allocation_function): Likewise. * omega.c (smooth_weird_equations): Likewise. * auto-inc-dec.c: Fix typos in comments. * bb-reorder.c: Likewise. * builtins.c: Likewise. * c-common.c: Likewise. * c-cppbuiltin.c: Likewise. * c-parser.c: Likewise. * c-pretty-print.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfglayout.c: Likewise. * cfgloopmanip.c: Likewise. * cgraphunit.c: Likewise. * coverage.c: Likewise. * dbxout.c: Likewise. * df-byte-scan.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dominance.c: Likewise. * domwalk.c: Likewise. * dse.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * et-forest.c: Likewise. * function.c: Likewise. * function.h: Likewise. * gcc.c: Likewise. * gcov-io.c: Likewise. * gcov.c: Likewise. * gcse.c: Likewise. * genattrtab.c: Likewise. * ggc-page.c: Likewise. * gimplify.c: Likewise. * gthr-lynx.h: Likewise. * haifa-sched.c: Likewise. * ipa-cp.c: Likewise. * ipa-inline.c: Likewise. * ipa-prop.h: Likewise. * ipa-pure-const.c: Likewise. * ipa-struct-reorg.c: Likewise. * ipa-struct-reorg.h: Likewise. * ipa-type-escape.c: Likewise. * ipa.c: Likewise. * loop-doloop.c: Likewise. * mips-tfile.c: Likewise. * mkmap-flat.awk: Likewise. * mkmap-symver.awk: Likewise. * modulo-sched.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * optabs.h: Likewise. * opts.c: Likewise. * passes.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * pretty-print.h: Likewise. * profile.c: Likewise. * protoize.c: Likewise. * ra-conflict.c: Likewise. * real.c: Likewise. * recog.c: Likewise. * regclass.c: Likewise. * regs.h: Likewise. * reload.c: Likewise. * rtl-error.c: Likewise. * rtlanal.c: Likewise. * scan.h: Likewise. * sched-rgn.c: Likewise. * see.c: Likewise. * stmt.c: Likewise. * target.h: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-flow-inline.h: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-parloops.c: Likewise. * tree-pass.h: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-alias-warnings.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-live.h: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-vect-analyze.c: Likewise. * tree-vect-transform.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vn.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tree.def: Likewise. * tree.h: Likewise. * unwind-dw2-fde.c: Likewise. * unwind.inc: Likewise. * value-prof.c: Likewise. * vmsdbgout.c: Likewise. From-SVN: r136425
313 lines
9.5 KiB
C
313 lines
9.5 KiB
C
/* Exception handling and frame unwind runtime interface routines. -*- C -*-
|
|
Copyright (C) 2001, 2003, 2008 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
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.
|
|
|
|
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 GCC; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
|
02110-1301, USA. */
|
|
|
|
/* This is derived from the C++ ABI for IA-64. Where we diverge
|
|
for cross-architecture compatibility are noted with "@@@".
|
|
This file is included from unwind-dw2.c, unwind-sjlj.c or
|
|
unwind-ia64.c. */
|
|
|
|
/* Subroutine of _Unwind_RaiseException also invoked from _Unwind_Resume.
|
|
|
|
Unwind the stack calling the personality routine to find both the
|
|
exception handler and intermediary cleanup code. We'll only locate
|
|
the first such frame here. Cleanup code will call back into
|
|
_Unwind_Resume and we'll continue Phase 2 there. */
|
|
|
|
static _Unwind_Reason_Code
|
|
_Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc,
|
|
struct _Unwind_Context *context)
|
|
{
|
|
_Unwind_Reason_Code code;
|
|
|
|
while (1)
|
|
{
|
|
_Unwind_FrameState fs;
|
|
int match_handler;
|
|
|
|
code = uw_frame_state_for (context, &fs);
|
|
|
|
/* Identify when we've reached the designated handler context. */
|
|
match_handler = (uw_identify_context (context) == exc->private_2
|
|
? _UA_HANDLER_FRAME : 0);
|
|
|
|
if (code != _URC_NO_REASON)
|
|
/* Some error encountered. Usually the unwinder doesn't
|
|
diagnose these and merely crashes. */
|
|
return _URC_FATAL_PHASE2_ERROR;
|
|
|
|
/* Unwind successful. Run the personality routine, if any. */
|
|
if (fs.personality)
|
|
{
|
|
code = (*fs.personality) (1, _UA_CLEANUP_PHASE | match_handler,
|
|
exc->exception_class, exc, context);
|
|
if (code == _URC_INSTALL_CONTEXT)
|
|
break;
|
|
if (code != _URC_CONTINUE_UNWIND)
|
|
return _URC_FATAL_PHASE2_ERROR;
|
|
}
|
|
|
|
/* Don't let us unwind past the handler context. */
|
|
gcc_assert (!match_handler);
|
|
|
|
uw_update_context (context, &fs);
|
|
}
|
|
|
|
return code;
|
|
}
|
|
|
|
/* Raise an exception, passing along the given exception object. */
|
|
|
|
_Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
|
|
_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;
|
|
|
|
/* Phase 1: Search. Unwind the stack, calling the personality routine
|
|
with the _UA_SEARCH_PHASE flag set. Do not modify the stack yet. */
|
|
while (1)
|
|
{
|
|
_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)
|
|
/* Hit end of stack with no handler found. */
|
|
return _URC_END_OF_STACK;
|
|
|
|
if (code != _URC_NO_REASON)
|
|
/* Some error encountered. Usually the unwinder doesn't
|
|
diagnose these and merely crashes. */
|
|
return _URC_FATAL_PHASE1_ERROR;
|
|
|
|
/* Unwind successful. Run the personality routine, if any. */
|
|
if (fs.personality)
|
|
{
|
|
code = (*fs.personality) (1, _UA_SEARCH_PHASE, exc->exception_class,
|
|
exc, &cur_context);
|
|
if (code == _URC_HANDLER_FOUND)
|
|
break;
|
|
else if (code != _URC_CONTINUE_UNWIND)
|
|
return _URC_FATAL_PHASE1_ERROR;
|
|
}
|
|
|
|
/* Update cur_context to describe the same frame as fs. */
|
|
uw_update_context (&cur_context, &fs);
|
|
}
|
|
|
|
/* Indicate to _Unwind_Resume and associated subroutines that this
|
|
is not a forced unwind. Further, note where we found a handler. */
|
|
exc->private_1 = 0;
|
|
exc->private_2 = uw_identify_context (&cur_context);
|
|
|
|
cur_context = this_context;
|
|
code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
|
|
if (code != _URC_INSTALL_CONTEXT)
|
|
return code;
|
|
|
|
uw_install_context (&this_context, &cur_context);
|
|
}
|
|
|
|
|
|
/* 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_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. */
|
|
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;
|
|
|
|
/* Stop didn't want to do anything. Invoke the personality
|
|
handler, if applicable, to run cleanups. */
|
|
if (code == _URC_END_OF_STACK)
|
|
break;
|
|
|
|
if (fs.personality)
|
|
{
|
|
code = (*fs.personality) (1, _UA_FORCE_UNWIND | _UA_CLEANUP_PHASE,
|
|
exc->exception_class, exc, context);
|
|
if (code == _URC_INSTALL_CONTEXT)
|
|
break;
|
|
if (code != _URC_CONTINUE_UNWIND)
|
|
return _URC_FATAL_PHASE2_ERROR;
|
|
}
|
|
|
|
/* Update cur_context to describe the same frame as fs, and discard
|
|
the previous context if necessary. */
|
|
uw_advance_context (context, &fs);
|
|
}
|
|
|
|
return code;
|
|
}
|
|
|
|
|
|
/* Raise an exception for forced unwinding. */
|
|
|
|
_Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
|
|
_Unwind_ForcedUnwind (struct _Unwind_Exception *exc,
|
|
_Unwind_Stop_Fn stop, void * stop_argument)
|
|
{
|
|
struct _Unwind_Context this_context, cur_context;
|
|
_Unwind_Reason_Code code;
|
|
|
|
uw_init_context (&this_context);
|
|
cur_context = this_context;
|
|
|
|
exc->private_1 = (_Unwind_Ptr) stop;
|
|
exc->private_2 = (_Unwind_Ptr) stop_argument;
|
|
|
|
code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
|
|
if (code != _URC_INSTALL_CONTEXT)
|
|
return code;
|
|
|
|
uw_install_context (&this_context, &cur_context);
|
|
}
|
|
|
|
|
|
/* Resume propagation of an existing exception. This is used after
|
|
e.g. executing cleanup code, and not to implement rethrowing. */
|
|
|
|
void LIBGCC2_UNWIND_ATTRIBUTE
|
|
_Unwind_Resume (struct _Unwind_Exception *exc)
|
|
{
|
|
struct _Unwind_Context this_context, cur_context;
|
|
_Unwind_Reason_Code code;
|
|
|
|
uw_init_context (&this_context);
|
|
cur_context = this_context;
|
|
|
|
/* Choose between continuing to process _Unwind_RaiseException
|
|
or _Unwind_ForcedUnwind. */
|
|
if (exc->private_1 == 0)
|
|
code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
|
|
else
|
|
code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
|
|
|
|
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 LIBGCC2_UNWIND_ATTRIBUTE
|
|
_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)
|
|
{
|
|
if (exc->exception_cleanup)
|
|
(*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc);
|
|
}
|
|
|
|
|
|
/* Perform stack backtrace through unwind data. */
|
|
|
|
_Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
|
|
_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;
|
|
}
|