Reported by HTamura in the DukeDollars newsgroup
the JVMDI interface allows you to set a breakpoint on any bytecode and
doesn't seem to report an error setting bci
to 0,1,7 is ok
2 you get null pointer
and 3,4,6,7,9 a core dump
when code is
Method void main(java.lang.String[])
0 iconst_2
1 istore_1
2 getstatic #9 <Field java.io.PrintStream out>
5 ldc #1 <String "Hello">
7 invokevirtual #10 <Method void println(java.lang.String)>
10 return
Test.java
public class Test
{
static {
System.loadLibrary("Test");
startDebugger();
}
static native void startDebugger();
public static void main(String args[]) {
int i=2;
System.out.println("Hello");
}
}
Test.c
#include <jni.h>
#include <jvmdi.h>
#include <stdio.h>
#include "Test.h"
void Hook(JNIEnv *env, JVMDI_Event *event)
{
printf("Hook is called.\n");
if ( event->kind == JVMDI_EVENT_BREAKPOINT ) {
printf("BP hit\n");
} else {
printf("Other event occurrred.\n");
}
return;
}
JNIEXPORT void JNICALL Java_Test_startDebugger(JNIEnv *env, jclass cls)
{
jvmdiError err;
jmethodID mid;
int bci = 3; /* variable */
mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V");
if ( mid == 0 ) return;
printf("Now I'll set BP.\n");
err = JVMDI_SetBreakpoint(env, cls, mid, bci);
printf("err=",err);
if ( err != JVMDI_ERROR_NONE ) {
printf("Error\n");
return;
}
printf("Done.\n");
printf("Now I'll set hook.\n");
err = JVMDI_SetEventHook(env, Hook);
if ( err != JVMDI_ERROR_NONE ) {
printf("Error\n");
return;
}
printf("Done.\n");
}
the JVMDI interface allows you to set a breakpoint on any bytecode and
doesn't seem to report an error setting bci
to 0,1,7 is ok
2 you get null pointer
and 3,4,6,7,9 a core dump
when code is
Method void main(java.lang.String[])
0 iconst_2
1 istore_1
2 getstatic #9 <Field java.io.PrintStream out>
5 ldc #1 <String "Hello">
7 invokevirtual #10 <Method void println(java.lang.String)>
10 return
Test.java
public class Test
{
static {
System.loadLibrary("Test");
startDebugger();
}
static native void startDebugger();
public static void main(String args[]) {
int i=2;
System.out.println("Hello");
}
}
Test.c
#include <jni.h>
#include <jvmdi.h>
#include <stdio.h>
#include "Test.h"
void Hook(JNIEnv *env, JVMDI_Event *event)
{
printf("Hook is called.\n");
if ( event->kind == JVMDI_EVENT_BREAKPOINT ) {
printf("BP hit\n");
} else {
printf("Other event occurrred.\n");
}
return;
}
JNIEXPORT void JNICALL Java_Test_startDebugger(JNIEnv *env, jclass cls)
{
jvmdiError err;
jmethodID mid;
int bci = 3; /* variable */
mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V");
if ( mid == 0 ) return;
printf("Now I'll set BP.\n");
err = JVMDI_SetBreakpoint(env, cls, mid, bci);
printf("err=",err);
if ( err != JVMDI_ERROR_NONE ) {
printf("Error\n");
return;
}
printf("Done.\n");
printf("Now I'll set hook.\n");
err = JVMDI_SetEventHook(env, Hook);
if ( err != JVMDI_ERROR_NONE ) {
printf("Error\n");
return;
}
printf("Done.\n");
}