aboutsummaryrefslogtreecommitdiff
path: root/libjava/stacktrace.cc
diff options
context:
space:
mode:
authorrmathew <rmathew@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-29 14:57:39 +0000
committerrmathew <rmathew@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-29 14:57:39 +0000
commit795a5d4021e6db957b3f2e18e1468bd7064fda28 (patch)
treec184ad263e2312d7a38fbced2682933d1ad843bc /libjava/stacktrace.cc
parenta589f7967ccc42f329a1627c541db03478c59eeb (diff)
* gcj/javaprims.h (_Jv_uintptr_t): New typedef similar to uintptr_t in
C99. * include/java-stack.h: Include stdlib.h. (_Jv_AddrInfo): New structure to hold address information. * include/posix.h (_Jv_platform_dladdr): Declare. * include/win32.h (_Jv_platform_dladdr): Declare. (backtrace): Remove declaration. * posix.cc: Include dlfcn.h if available. Include java-stack.h. (_Jv_platform_dladdr): Define. * win32.cc: Include string.h. Include java-stack.h. (backtrace): Remove. (_Jv_platform_dladdr): Define. * sysdep/i386/backtrace.h (fallback_backtrace): Check that a potential frame pointer value is 32-bit word-aligned. Use operand of the CALL instruction calling the current function to find its starting address. * stacktrace.cc: Do not include dlfcn.h. Include platform.h. (_Jv_StackTrace::getLineNumberForFrame): Use _Jv_platform_dladdr() instead of dladdr(). (_Jv_StackTrace::GetStackTraceElements): Use nCodeMap even for Windows. (_Jv_StackTrace::GetClassContext): Use fallback_backtrace() for targets with SJLJ exceptions instead of using _Unwind_Backtrace(). (_Jv_StackTrace::GetFirstNonSystemClassLoader): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@115069 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/stacktrace.cc')
-rw-r--r--libjava/stacktrace.cc51
1 files changed, 27 insertions, 24 deletions
diff --git a/libjava/stacktrace.cc b/libjava/stacktrace.cc
index 5d429e67d14..06a4dfadb98 100644
--- a/libjava/stacktrace.cc
+++ b/libjava/stacktrace.cc
@@ -9,16 +9,13 @@ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#include <config.h>
+#include <platform.h>
#include <jvm.h>
#include <gcj/cni.h>
#include <java-interp.h>
#include <java-stack.h>
-#ifdef HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
#include <stdio.h>
#include <java/lang/Class.h>
@@ -184,41 +181,36 @@ _Jv_StackTrace::getLineNumberForFrame(_Jv_StackFrame *frame, NameFinder *finder,
return;
}
#endif
- // Use dladdr() to determine in which binary the address IP resides.
-#if defined (HAVE_DLFCN_H) && defined (HAVE_DLADDR)
- Dl_info info;
+
+ // Use _Jv_platform_dladdr() to determine in which binary the address IP
+ // resides.
+ _Jv_AddrInfo info;
jstring binaryName = NULL;
const char *argv0 = _Jv_GetSafeArg(0);
void *ip = frame->ip;
_Unwind_Ptr offset = 0;
- if (dladdr (ip, &info))
+ if (_Jv_platform_dladdr (ip, &info))
{
- if (info.dli_fname)
- binaryName = JvNewStringUTF (info.dli_fname);
+ if (info.file_name)
+ binaryName = JvNewStringUTF (info.file_name);
else
return;
- if (*methodName == NULL && info.dli_sname)
- *methodName = JvNewStringUTF (info.dli_sname);
+ if (*methodName == NULL && info.sym_name)
+ *methodName = JvNewStringUTF (info.sym_name);
// addr2line expects relative addresses for shared libraries.
- if (strcmp (info.dli_fname, argv0) == 0)
+ if (strcmp (info.file_name, argv0) == 0)
offset = (_Unwind_Ptr) ip;
else
- offset = (_Unwind_Ptr) ip - (_Unwind_Ptr) info.dli_fbase;
+ offset = (_Unwind_Ptr) ip - (_Unwind_Ptr) info.base;
- //printf ("linenum ip: %p\n", ip);
- //printf ("%s: 0x%x\n", info.dli_fname, offset);
- //offset -= sizeof(void *);
-
// The unwinder gives us the return address. In order to get the right
// line number for the stack trace, roll it back a little.
offset -= 1;
- // printf ("%s: 0x%x\n", info.dli_fname, offset);
-
finder->lookup (binaryName, (jlong) offset);
*sourceFileName = finder->getSourceFile();
*lineNum = finder->getLineNum();
@@ -234,7 +226,6 @@ _Jv_StackTrace::getLineNumberForFrame(_Jv_StackFrame *frame, NameFinder *finder,
*sourceFileName = t->toString();
}
}
-#endif
}
// Look up class and method info for the given stack frame, setting
@@ -283,7 +274,7 @@ _Jv_StackTrace::GetStackTraceElements (_Jv_StackTrace *trace,
{
ArrayList *list = new ArrayList ();
-#ifdef SJLJ_EXCEPTIONS
+#if defined (SJLJ_EXCEPTIONS) && ! defined (WIN32)
// We can't use the nCodeMap without unwinder support. Instead,
// fake the method name by giving the IP in hex - better than nothing.
jstring hex = JvNewStringUTF ("0x");
@@ -302,7 +293,7 @@ _Jv_StackTrace::GetStackTraceElements (_Jv_StackTrace *trace,
list->add (element);
}
-#else /* SJLJ_EXCEPTIONS */
+#else /* SJLJ_EXCEPTIONS && !WIN32 */
//JvSynchronized (ncodeMap);
UpdateNCodeMap ();
@@ -370,7 +361,7 @@ _Jv_StackTrace::GetStackTraceElements (_Jv_StackTrace *trace,
}
finder->close();
-#endif /* SJLJ_EXCEPTIONS */
+#endif /* SJLJ_EXCEPTIONS && !WIN32 */
JArray<Object *> *array = JvNewObjectArray (list->size (),
&StackTraceElement::class$, NULL);
@@ -472,7 +463,13 @@ _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,7 +540,13 @@ _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;