1 // java-stack.h - Definitions for unwinding & inspecting the call stack.
3 /* Copyright (C) 2005, 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 #ifndef __JV_STACKTRACE_H__
12 #define __JV_STACKTRACE_H__
18 #include <gcj/javaprims.h>
20 #include <java-interp.h>
22 #include <java/lang/Class.h>
23 #include <java/lang/StackTraceElement.h>
24 #include <java/lang/Throwable.h>
25 #include <java/lang/Thread.h>
26 #include <java/util/IdentityHashMap.h>
28 #include <gnu/gcj/runtime/NameFinder.h>
30 using namespace gnu::gcj::runtime;
31 using namespace java::lang;
52 struct _Jv_InterpFrameInfo
54 _Jv_InterpMethod *meth;
65 _Jv_FrameType type; /* Native or interpreted. */
68 _Jv_InterpFrameInfo interp;
72 _Jv_Method *proxyMethod;
79 // _Jv_FrameInfo info; /* Frame-type specific data. */
84 typedef struct _Jv_UnwindState;
85 typedef _Unwind_Reason_Code (*_Jv_TraceFn) (_Jv_UnwindState *);
87 struct _Jv_UnwindState
89 jint length; // length of FRAMES
90 jint pos; // current position in FRAMES
91 _Jv_StackFrame *frames; // array of stack frame data to be filled.
93 _Jv_InterpFrame *interp_frame; // current frame in the interpreter stack.
95 _Jv_TraceFn trace_function; // function to call back after each frame
96 // is enumerated. May be NULL.
97 void *trace_data; // additional state data for trace_function.
99 _Jv_UnwindState (jint ln)
105 Thread *thread = Thread::currentThread();
106 // Check for NULL currentThread(), in case an exception is created
107 // very early during the runtime startup.
109 interp_frame = (_Jv_InterpFrame *) thread->interp_frame;
113 trace_function = NULL;
122 _Jv_StackFrame frames[];
124 static java::util::IdentityHashMap *ncodeMap;
125 static void UpdateNCodeMap ();
126 static jclass ClassForFrame (_Jv_StackFrame *frame);
127 static void FillInFrameInfo (_Jv_StackFrame *frame);
128 static void getLineNumberForFrame(_Jv_StackFrame *frame, NameFinder *finder,
129 jstring *sourceFileName, jint *lineNum,
130 jstring *methodName);
132 static _Unwind_Reason_Code UnwindTraceFn (struct _Unwind_Context *context,
135 static _Unwind_Reason_Code calling_class_trace_fn (_Jv_UnwindState *state);
136 static _Unwind_Reason_Code non_system_trace_fn (_Jv_UnwindState *state);
137 static _Unwind_Reason_Code accesscontrol_trace_fn (_Jv_UnwindState *state);
138 static _Unwind_Reason_Code stackwalker_trace_fn (_Jv_UnwindState *state);
139 static _Unwind_Reason_Code stackwalker_nnl_trace_fn (_Jv_UnwindState *state);
142 static _Jv_StackTrace *GetStackTrace (void);
143 static JArray< ::java::lang::StackTraceElement *>*
144 GetStackTraceElements (_Jv_StackTrace *trace,
145 java::lang::Throwable *throwable);
146 static jclass GetCallingClass (jclass);
147 static void GetCallerInfo (jclass checkClass, jclass *, _Jv_Method **);
148 static ClassLoader *GetFirstNonSystemClassLoader (void);
149 static jobjectArray GetAccessControlStack ();
150 static JArray<jclass> *GetStackWalkerStack ();
151 static jclass GetStackWalkerCallingClass ();
152 static ClassLoader *GetStackWalkerFirstNonNullLoader ();
154 friend jclass _Jv_GetMethodDeclaringClass (jmethodID);
155 friend class gnu::classpath::VMStackWalker;
158 // Information about a given address.
161 // File name of the defining module.
162 const char *file_name;
164 // Base address of the loaded module.
167 // Name of the nearest symbol.
168 const char *sym_name;
170 // Address of the nearest symbol.
175 // On systems with a real dladdr(), the file and symbol names given by
176 // _Jv_platform_dladdr() are not dynamically allocated. On Windows,
181 free ((void *)file_name);
184 free ((void *)sym_name);
189 #endif /* __JV_STACKTRACE_H__ */