diff options
author | rmathew <rmathew@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-07-14 17:14:55 +0000 |
---|---|---|
committer | rmathew <rmathew@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-07-14 17:14:55 +0000 |
commit | 8d33073e7284d3b26f4b0762d16b5577f014613f (patch) | |
tree | 1ac7aeccd28a2e9650dfd7a152bfcbe590ed728e | |
parent | 199f9baaccc96ea58ddbe7e7d17d8dbf897fc199 (diff) | |
download | gcc-8d33073e7284d3b26f4b0762d16b5577f014613f.tar.gz |
* stacktrace.cc (_Jv_StackTrace::GetStackTrace): Unconditionally use
_Unwind_Backtrace().
(_Jv_StackTrace::GetCallerInfo): Enable even for targets using SJLJ
EH.
(_Jv_StackTrace::GetClassContext): Unconditionally use
_Unwind_Backtrace().
(_Jv_StackTrace::GetFirstNonSystemClassLoader): Likewise.
* sysdep/i386/backtrace.h (HAVE_FALLBACK_BACKTRACE): Do not define.
(_Unwind_GetIPInfo): Define macro if SJLJ EH is in use.
(_Unwind_GetRegionStart): Likewise.
(_Unwind_Backtrace): Likewise.
(fallback_backtrace): Accept additional unwind trace function
argument. Call it during unwinding. Stop when any of _Jv_RunMain(),
_Jv_ThreadStart() or main() is seen during unwinding.
* sysdep/generic/backtrace.h (fallback_backtrace): Accept an
additional unwind trace function argument.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@115449 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libjava/ChangeLog | 19 | ||||
-rw-r--r-- | libjava/stacktrace.cc | 22 | ||||
-rw-r--r-- | libjava/sysdep/generic/backtrace.h | 11 | ||||
-rw-r--r-- | libjava/sysdep/i386/backtrace.h | 74 |
4 files changed, 77 insertions, 49 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index ba4f72cb153..4e1710515fb 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,22 @@ +2006-07-14 Ranjit Mathew <rmathew@gcc.gnu.org> + + * stacktrace.cc (_Jv_StackTrace::GetStackTrace): Unconditionally use + _Unwind_Backtrace(). + (_Jv_StackTrace::GetCallerInfo): Enable even for targets using SJLJ + EH. + (_Jv_StackTrace::GetClassContext): Unconditionally use + _Unwind_Backtrace(). + (_Jv_StackTrace::GetFirstNonSystemClassLoader): Likewise. + * sysdep/i386/backtrace.h (HAVE_FALLBACK_BACKTRACE): Do not define. + (_Unwind_GetIPInfo): Define macro if SJLJ EH is in use. + (_Unwind_GetRegionStart): Likewise. + (_Unwind_Backtrace): Likewise. + (fallback_backtrace): Accept additional unwind trace function + argument. Call it during unwinding. Stop when any of _Jv_RunMain(), + _Jv_ThreadStart() or main() is seen during unwinding. + * sysdep/generic/backtrace.h (fallback_backtrace): Accept an + additional unwind trace function argument. + 2006-07-14 Gary Benson <gbenson@redhat.com> * java/io/File.java (internalExists): New method. diff --git a/libjava/stacktrace.cc b/libjava/stacktrace.cc index ed0700bd629..ba971ddc13e 100644 --- a/libjava/stacktrace.cc +++ b/libjava/stacktrace.cc @@ -153,13 +153,7 @@ _Jv_StackTrace::GetStackTrace(void) _Jv_UnwindState state (trace_size); state.frames = (_Jv_StackFrame *) &frames; -#ifdef SJLJ_EXCEPTIONS - // The Unwind interface doesn't work with the SJLJ exception model. - // Fall back to a platform-specific unwinder. - fallback_backtrace (&state); -#else /* SJLJ_EXCEPTIONS */ _Unwind_Backtrace (UnwindTraceFn, &state); -#endif /* SJLJ_EXCEPTIONS */ // Copy the trace and return it. int traceSize = sizeof (_Jv_StackTrace) + @@ -423,7 +417,6 @@ void _Jv_StackTrace::GetCallerInfo (jclass checkClass, jclass *caller_class, _Jv_Method **caller_meth) { -#ifndef SJLJ_EXCEPTIONS int trace_size = 20; _Jv_StackFrame frames[trace_size]; _Jv_UnwindState state (trace_size); @@ -447,9 +440,6 @@ _Jv_StackTrace::GetCallerInfo (jclass checkClass, jclass *caller_class, *caller_class = trace_data.foundClass; if (caller_meth) *caller_meth = trace_data.foundMeth; -#else - return; -#endif } // Return a java array containing the Java classes on the stack above CHECKCLASS. @@ -466,13 +456,7 @@ _Jv_StackTrace::GetClassContext (jclass checkClass) //JvSynchronized (ncodeMap); UpdateNCodeMap (); -#ifdef SJLJ_EXCEPTIONS - // The Unwind interface doesn't work with the SJLJ exception model. - // Fall back to a platform-specific unwinder. - fallback_backtrace (&state); -#else /* SJLJ_EXCEPTIONS */ _Unwind_Backtrace (UnwindTraceFn, &state); -#endif /* SJLJ_EXCEPTIONS */ // Count the number of Java frames on the stack. int jframe_count = 0; @@ -543,13 +527,7 @@ _Jv_StackTrace::GetFirstNonSystemClassLoader () //JvSynchronized (ncodeMap); UpdateNCodeMap (); -#ifdef SJLJ_EXCEPTIONS - // The Unwind interface doesn't work with the SJLJ exception model. - // Fall back to a platform-specific unwinder. - fallback_backtrace (&state); -#else /* SJLJ_EXCEPTIONS */ _Unwind_Backtrace (UnwindTraceFn, &state); -#endif /* SJLJ_EXCEPTIONS */ if (state.trace_data) return (ClassLoader *) state.trace_data; diff --git a/libjava/sysdep/generic/backtrace.h b/libjava/sysdep/generic/backtrace.h index fe9d68f1b70..21138aef775 100644 --- a/libjava/sysdep/generic/backtrace.h +++ b/libjava/sysdep/generic/backtrace.h @@ -1,6 +1,6 @@ // backtrace.h - Fallback backtrace implementation. default implementation. -/* Copyright (C) 2005 Free Software Foundation +/* Copyright (C) 2005, 2006 Free Software Foundation This file is part of libgcj. @@ -13,10 +13,11 @@ details. */ #include <java-stack.h> -/* Store return addresses of the current program stack in - STATE and return the exact number of values stored. */ -void -fallback_backtrace (_Jv_UnwindState *) +/* Unwind through the call stack calling TRACE_FN with STATE for every stack + frame. Returns the reason why the unwinding was stopped. */ +_Unwind_Reason_Code +fallback_backtrace (_Unwind_Trace_Fn, _Jv_UnwindState *) { + return _URC_NO_REASON; } #endif diff --git a/libjava/sysdep/i386/backtrace.h b/libjava/sysdep/i386/backtrace.h index 3b951634efb..9fe12b118a9 100644 --- a/libjava/sysdep/i386/backtrace.h +++ b/libjava/sysdep/i386/backtrace.h @@ -13,21 +13,46 @@ details. */ #include <java-stack.h> -#define HAVE_FALLBACK_BACKTRACE +extern int main (int, char **); -/* Store return addresses of the current program stack in - STATE and return the exact number of values stored. */ -void -fallback_backtrace (_Jv_UnwindState *state) +/* The context used to keep track of our position while unwinding through + the call stack. */ +struct _Unwind_Context +{ + /* The starting address of the method. */ + _Jv_uintptr_t meth_addr; + + /* The return address in the method. */ + _Jv_uintptr_t ret_addr; +}; + +#ifdef SJLJ_EXCEPTIONS + +#undef _Unwind_GetIPInfo +#define _Unwind_GetIPInfo(ctx,ip_before_insn) \ + (*(ip_before_insn) = 1, (ctx)->ret_addr) + +#undef _Unwind_GetRegionStart +#define _Unwind_GetRegionStart(ctx) \ + ((ctx)->meth_addr) + +#undef _Unwind_Backtrace +#define _Unwind_Backtrace(trace_fn,state_ptr) \ + (fallback_backtrace (trace_fn, state_ptr)) + +#endif /* SJLJ_EXCEPTIONS */ + +/* Unwind through the call stack calling TRACE_FN with STATE for each stack + frame. Returns the reason why the unwinding was stopped. */ +_Unwind_Reason_Code +fallback_backtrace (_Unwind_Trace_Fn trace_fn, _Jv_UnwindState *state) { register _Jv_uintptr_t *_ebp __asm__ ("ebp"); register _Jv_uintptr_t _esp __asm__ ("esp"); _Jv_uintptr_t rfp; + _Unwind_Context ctx; - int i = state->pos; - for (rfp = *_ebp; - rfp && i < state->length; - rfp = *(_Jv_uintptr_t *)rfp) + for (rfp = *_ebp; rfp; rfp = *(_Jv_uintptr_t *)rfp) { /* Sanity checks to eliminate dubious-looking frame pointer chains. The frame pointer should be a 32-bit word-aligned stack address. @@ -42,12 +67,7 @@ fallback_backtrace (_Jv_UnwindState *state) /* Get the return address in the calling function. This is stored on the stack just before the value of the old frame pointer. */ - _Jv_uintptr_t ret_addr - = *(_Jv_uintptr_t *)(rfp + sizeof (_Jv_uintptr_t)); - - state->frames[i].type = frame_native; - state->frames[i].ip = (void *)(ret_addr - 1); - state->frames[i].start_ip = NULL; + ctx.ret_addr = *(_Jv_uintptr_t *)(rfp + sizeof (_Jv_uintptr_t)); /* Try to locate a "pushl %ebp; movl %esp, %ebp" function prologue by scanning backwards at even addresses below the return address. @@ -56,7 +76,8 @@ fallback_backtrace (_Jv_UnwindState *state) FIXME: This is not robust and will probably give us false positives, but this is about the best we can do if we do not have DWARF-2 unwind information based exception handling. */ - _Jv_uintptr_t scan_addr = (ret_addr & 0xFFFFFFFE) - 2; + ctx.meth_addr = (_Jv_uintptr_t)NULL; + _Jv_uintptr_t scan_addr = (ctx.ret_addr & 0xFFFFFFFE) - 2; _Jv_uintptr_t limit_addr = (scan_addr > 1024 * 1024) ? (scan_addr - 1024 * 1024) : 2; for ( ; scan_addr >= limit_addr; scan_addr -= 2) @@ -65,17 +86,26 @@ fallback_backtrace (_Jv_UnwindState *state) if (scan_bytes[0] == 0x55 && scan_bytes[1] == 0x89 && scan_bytes[2] == 0xE5) { - state->frames[i].start_ip = (void *)scan_addr; + ctx.meth_addr = scan_addr; break; } } - /* No need to unwind beyond JvRunMain(). */ - if (state->frames[i].start_ip == (void *)JvRunMain) - break; + /* Now call the unwinder callback function. */ + if (trace_fn != NULL) + (*trace_fn) (&ctx, state); - i++; + /* No need to unwind beyond _Jv_RunMain(), _Jv_ThreadStart or + main(). */ + void *jv_runmain + = (void *)(void (*)(JvVMInitArgs *, jclass, const char *, int, + const char **, bool))_Jv_RunMain; + if (ctx.meth_addr == (_Jv_uintptr_t)jv_runmain + || ctx.meth_addr == (_Jv_uintptr_t)_Jv_ThreadStart + || (ctx.meth_addr - (_Jv_uintptr_t)main) < 16) + break; } - state->pos = i; + + return _URC_NO_REASON; } #endif |