rendered paste body=== modified file 'pnet/engine/debugger.c'
--- pnet/engine/debugger.c
+++ pnet/engine/debugger.c
@@ -2063,7 +2063,7 @@
/* Read current position from debug info */
sourceFile = GetLocation(method, offset, &line, &col);
- //fprintf(stderr, "DebugHook method=%s offset=%d sourceFile=%s line=%d\n", ILMethod_Name(method), offset, sourceFile, line);
+ fprintf(stderr, "DebugHook method=%s.%s offset=%d sourceFile=%s line=%d\n", ILClass_Name(ILMethod_Owner(method)), ILMethod_Name(method), offset, sourceFile, line);
/* Continue if no debug info available */
if(sourceFile == 0)
=== modified file 'pnet/engine/jitc.c'
--- pnet/engine/jitc.c
+++ pnet/engine/jitc.c
@@ -39,7 +39,7 @@
/*
* For enabling extended debugging output uncomment the following define.
*/
-/* #define _IL_JIT_ENABLE_DEBUG 1 */
+#define _IL_JIT_ENABLE_DEBUG 1
/*
* For dumping the jitted function before it is compiled uncomment the
@@ -2280,11 +2280,30 @@
}
/*
+ * Debugger hook function called when breakpoint is reached.
+ */
+static void JitDebuggerHook(jit_function_t func, jit_nint data1, jit_nint data2)
+{
+ //fprintf(stderr, "hook called\n");
+
+ ILExecThread *thread = ILExecThreadCurrent();
+ _ILBreak(thread, 0);
+}
+
+/*
* Enable debug mode in a JIT coder instance.
*/
static void JITCoder_EnableDebug(ILCoder *coder)
{
- (_ILCoderToILJITCoder(coder))->debugEnabled = 1;
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+ jitCoder->debugEnabled = 1;
+ jit_debugger_set_hook(jitCoder->context, JitDebuggerHook);
+}
+
+void ILJitInsertBreakpoint(ILCoder *coder)
+{
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+ jit_insn_mark_breakpoint(jitCoder->jitFunction, 1, 2);
}
/*
=== modified file 'pnet/engine/jitc.h'
--- pnet/engine/jitc.h
+++ pnet/engine/jitc.h
@@ -168,6 +168,12 @@
ILMethod *_ILJitGetCallingMethod(ILExecThread *thread, ILUInt32 frames);
/*
+ * Get IL offset for the call frame up n slots.
+ * Returns 0 if the function at that slot is not a jitted function.
+ */
+ILInt32 _ILJitGetILOffset(ILExecThread *thread, ILUInt32 skipFrames);
+
+/*
* Get the number of stack frames associated with an ILMethod on the current
* call stack.
*/
@@ -225,6 +231,11 @@
ILObject *delegate,
ILType *delType);
+/*
+ * Insert breakpoint in current function.
+ */
+void ILJitInsertBreakpoint(ILCoder *coder);
+
#endif /* IL_USE_JIT */
#endif /* _ENGINE_JITC_H */
=== modified file 'pnet/engine/jitc_diag.c'
--- pnet/engine/jitc_diag.c
+++ pnet/engine/jitc_diag.c
@@ -81,6 +81,31 @@
};
/* And we return the ILMethod assigned to that jitFunction. */
return (ILMethod *)jit_function_get_meta(jitFunction, IL_JIT_META_METHOD);
+}
+
+/*
+ * Get IL offset for the call frame up n slots.
+ * Returns 0 if the function at that slot is not a jitted function.
+ */
+ILInt32 _ILJitGetILOffset(ILExecThread *thread, ILUInt32 skipFrames)
+{
+ ILJITCoder *jitCoder = (ILJITCoder *)(_ILExecThreadProcess(thread)->coder);
+ jit_stack_trace_t stackTrace = jit_exception_get_stack_trace();
+ ILInt32 result;
+
+ if(jitCoder && stackTrace)
+ {
+ result = jit_stack_trace_get_offset(jitCoder->context, stackTrace, skipFrames);
+ if(result == JIT_NO_OFFSET)
+ {
+ return -1;
+ }
+ else
+ {
+ return result;
+ }
+ }
+ return -1;
}
/*
=== modified file 'pnet/engine/lib_diag.c'
--- pnet/engine/lib_diag.c
+++ pnet/engine/lib_diag.c
@@ -158,28 +158,13 @@
void _ILBreak(ILExecThread *thread, int type)
{
- unsigned char *start;
ILInt32 offset;
int action;
if(thread->process->debugHookFunc)
{
- /* Consult the coder to convert the PC into an IL offset */
- if(thread->method && thread->pc != IL_INVALID_PC)
- {
- start = (unsigned char *)ILMethodGetUserData(thread->method);
- if(ILMethodIsConstructor(thread->method))
- {
- start -= ILCoderCtorOffset(thread->process->coder);
- }
- offset = (ILInt32)(ILCoderGetILOffset
- (thread->process->coder, (void *)start,
- (ILUInt32)(thread->pc - start), 0));
- }
- else
- {
- offset = -1;
- }
+ offset = _IL_StackFrame_InternalGetILOffset(thread, 0);
+ fprintf(stderr, "offset=%d\n", offset);
/* Call the debugger to process the breakpoint */
action = (*(thread->process->debugHookFunc))
@@ -311,6 +296,7 @@
ILInt32 _IL_StackFrame_InternalGetILOffset(ILExecThread *thread,
ILInt32 skipFrames)
{
+#ifdef IL_USE_CVM
ILCallFrame *frame = _ILGetCallFrame(thread, skipFrames);
unsigned char *start;
if(frame && frame->method && frame->pc != IL_INVALID_PC)
@@ -330,6 +316,10 @@
/* Probably a native function which does not have offsets */
return -1;
}
+#endif
+#ifdef IL_USE_JIT
+ return _ILJitGetILOffset(thread, skipFrames);
+#endif
}
/*
=== modified file 'pnet/engine/verify.c'
--- pnet/engine/verify.c
+++ pnet/engine/verify.c
@@ -23,6 +23,9 @@
#include "il_opcodes.h"
#include "il_align.h"
#include "il_debug.h"
+#ifdef IL_USE_JIT
+#include "jitc.h"
+#endif
#ifdef __cplusplus
extern "C" {
@@ -1129,6 +1132,10 @@
/* Advance to the next instruction */
pc += insnSize;
len -= insnSize;
+
+#ifdef IL_USE_JIT
+ ILJitInsertBreakpoint(coder);
+#endif
}
/* If the last instruction was not a jump, then the code