32 #include "native/jvmti/VMjdwp.hpp"
41 (*jvmtienv)->GetErrorName(
jvmtienv,err, &errdesc);
42 fprintf(stderr,
"%s: jvmti error %s\n",desc, errdesc);
44 (*jvmtienv)->Deallocate(
jvmtienv,(
unsigned char*)errdesc);
54 fprintf(stderr,
"VMjdwp notfiy called\n");
56 (*jni_env)->CallStaticVoidMethod(jni_env,Jdwpclass,
notifymid,event);
57 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
58 fprintf(stderr,
"Exception occourred in notify mehtod\n");
59 (*jni_env)->ExceptionDescribe(jni_env);
70 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
71 fprintf(stderr,
"error calling ThreadStartEvent constructor\n");
72 (*jni_env)->ExceptionDescribe(jni_env);
76 fprintf(stderr,
"VMjdwp:ThreadStart: thread %p\n",thread);
88 obj = (*jni_env)->NewObject(jni_env, threadendclass,
threadendmid, thread);
89 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
90 fprintf(stderr,
"error calling ThreadEndEvent constructor\n");
91 (*jni_env)->ExceptionDescribe(jni_env);
95 fprintf(stderr,
"VMjdwp:ThreadEnd: thread %p\n",thread);
109 (e = (*jvmtienv)->GetClassStatus(
jvmtienv, klass, &classstatus))) {
114 obj = (*jni_env)->NewObject(jni_env, classprepareclass,
classpreparemid, thread, klass, classstatus);
115 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
116 fprintf(stderr,
"error calling ClassPrepareEvent constructor\n");
117 (*jni_env)->ExceptionDescribe(jni_env);
121 fprintf(stderr,
"VMjdwp:ClassPrepareEvent: thread %p\n",thread);
131 fprintf(stderr,
"VMjdwp:Exception: thread %p\n",thread);
143 (e = (*jvmtienv)->GetMethodDeclaringClass(
jvmtienv,
150 vmmethod = (*jni_env)->NewObject(jni_env, vmmethodclass,
vmmethodmid,
152 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
153 fprintf(stderr,
"error calling VMMethod constructor\n");
154 (*jni_env)->ExceptionDescribe(jni_env);
158 loc = (*jni_env)->NewObject(jni_env, locationclass,
locationmid,
160 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
161 fprintf(stderr,
"error calling location constructor\n");
162 (*jni_env)->ExceptionDescribe(jni_env);
167 ev = (*jni_env)->NewObject(jni_env, breakpointclass,
breakpointmid,
169 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
170 fprintf(stderr,
"error calling breakpoint constructor\n");
171 (*jni_env)->ExceptionDescribe(jni_env);
175 fprintf(stderr,
"VMjdwp:Breakpoint: thread %p\n",thread);
190 fprintf(stderr,
"JVMTI-Event: IMPLEMENT ME!!!");
206 m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,
"<init>",
"()V");
207 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
208 fprintf(stderr,
"could not get Jdwp constructor\n");
209 (*jni_env)->ExceptionDescribe(jni_env);
213 o = (*jni_env)->NewObject(jni_env, Jdwpclass, m);
214 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
215 fprintf(stderr,
"error calling Jdwp constructor\n");
216 (*jni_env)->ExceptionDescribe(jni_env);
224 m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,
"configure",
225 "(Ljava/lang/String;)V");
226 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
227 fprintf(stderr,
"could not get Jdwp configure method\n");
228 (*jni_env)->ExceptionDescribe(jni_env);
235 fprintf(stderr,
"could not get new java string from jdwp options\n");
241 (*jni_env)->CallVoidMethod(jni_env,o,m,s);
242 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
243 fprintf(stderr,
"Exception occourred in Jdwp configure\n");
244 (*jni_env)->ExceptionDescribe(jni_env);
248 m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,
"_doInitialization",
"()V");
249 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
250 fprintf(stderr,
"could not get Jdwp _doInitialization method\n");
251 (*jni_env)->ExceptionDescribe(jni_env);
256 (*jni_env)->CallVoidMethod(jni_env,o,m);
257 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
258 fprintf(stderr,
"Exception occourred in Jdwp _doInitialization\n");
259 (*jni_env)->ExceptionDescribe(jni_env);
264 #define FINDCLASSWITHEXCEPTION(CLASS,SIGNATURE) \
265 CLASS = (*jni_env)->FindClass(jni_env, SIGNATURE); \
266 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { \
267 fprintf(stderr,"could not find %s\n", SIGNATURE); \
268 (*jni_env)->ExceptionDescribe(jni_env); \
271 #define GETMIDWITHEXCEPTION(CLASS, CLASSNAME, MID, METHODNAME, METHODSIG) \
272 FINDCLASSWITHEXCEPTION(CLASS, CLASSNAME); \
273 MID = (*jni_env)->GetMethodID(jni_env, CLASS, METHODNAME, METHODSIG); \
274 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { \
275 fprintf(stderr,"could not get %s %s\n",CLASSNAME, METHODNAME); \
276 (*jni_env)->ExceptionDescribe(jni_env); \
285 GetStaticMethodID(jni_env,Jdwpclass,
286 "notify",
"(Lgnu/classpath/jdwp/event/Event;)V");
287 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
288 fprintf(stderr,
"could not get notify method\n");
289 (*jni_env)->ExceptionDescribe(jni_env);
294 "gnu/classpath/jdwp/event/ThreadStartEvent",
299 "gnu/classpath/jdwp/event/ThreadEndEvent",
304 "gnu/classpath/jdwp/event/ClassPrepareEvent",
306 "(Ljava/lang/Thread;Ljava/lang/Class;I)V");
314 "(Lgnu/classpath/jdwp/VMMethod;J)V");
319 "gnu/classpath/jdwp/event/BreakpointEvent",
321 "(Ljava/lang/Thread;Lgnu/classpath/jdwp/util/Location;Ljava/lang/Object;)V");
333 fprintf(stderr,
"JDWP VMInit\n");
341 fprintf(stderr,
"JDWP listening thread started\n");
344 cl = (*jni_env)->FindClass(jni_env,
345 "gnu/classpath/jdwp/event/VmInitEvent");
346 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
347 fprintf(stderr,
"could not find class VMInitEvent\n");
348 (*jni_env)->ExceptionDescribe(jni_env);
352 m = (*jni_env)->GetMethodID(jni_env,cl,
"<init>",
353 "(Ljava/lang/Thread;)V");
354 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
355 fprintf(stderr,
"could not get VmInitEvent constructor\n");
356 (*jni_env)->ExceptionDescribe(jni_env);
360 eventobj = (*jni_env)->NewObject(jni_env, cl, m, thread);
361 if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
362 fprintf(stderr,
"error calling VmInitEvent constructor\n");
363 (*jni_env)->ExceptionDescribe(jni_env);
368 notify (jni_env,eventobj);
371 fprintf(stderr,
"suspend initial thread\n");
372 err = (*jvmti_env)->SuspendThread(jvmti_env,thread);
378 puts(
"usage jdwp:[help]|(<option>=<value>),*");
379 puts(
" transport=[dt_socket|...]");
380 puts(
" address=<hostname:port>");
381 puts(
" server=[y|n]");
382 puts(
" suspend=[y|n]");
388 if (strncmp(options,
"help",4) == 0) {
397 jdwpoptions = malloc(
sizeof(
char)*strlen(options));
398 strncpy(
jdwpoptions, options,
sizeof(
char)*strlen(options));
400 len = strlen(options);
404 if (strncmp(
"suspend=",&options[i],8)==0) {
405 if (8>=strlen(&options[i])) {
406 if ((options[i+8]==
'y') || (options[i+8]==
'n')) {
409 printf(
"jdwp error argument: %s\n",options);
416 if ((strncmp(
"transport=",options,10)==0) ||
417 (strncmp(
"server=",options,7)==0)) {
419 printf(
"jdwp unkown argument: %s\n",options);
424 while ((options[i]!=
',')&&(i<len)) i++;
437 fprintf(stderr,
"jdwp Agent_OnLoad options: %s\n",options);
442 fprintf(stderr,
"jdwp: Unable to get jvmtiEnv error=%d\n", rc);
448 (e = (*jvmtienv)->SetEventCallbacks(
jvmtienv,
455 e = (*jvmtienv)->GetPotentialCapabilities(
jvmtienv, &cap);
458 e = (*jvmtienv)->AddCapabilities(
jvmtienv, &cap);
static jmethodID notifymid
static jmethodID threadendmid
static jmethodID threadstartmid
static jmethodID breakpointmid
static jclass classprepareclass
static void ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass)
static jclass locationclass
struct Breakpoint Breakpoint
This structure contains information about a breakpoint.
JNIEnv jthread jclass klass
static jclass vmmethodclass
static jvmtiError SetEventNotificationMode(jvmtiEnv *env, jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread,...)
static void setup_jdwp_thread(JNIEnv *jni_env)
static void ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread)
JNIEnv jthread jmethodID jlocation jobject exception
JNIEnv jthread jmethodID jlocation jobject jmethodID catch_method
JNIEnv jthread jmethodID method
void printjvmtierror(char *desc, jvmtiError err)
static jclass threadstartclass
static void MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jmethodID method)
static void Exception(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jmethodID method, jlocation location, jobject exception, jmethodID catch_method, jlocation catch_location)
static bool processoptions(char *options)
#define GETMIDWITHEXCEPTION(CLASS, CLASSNAME, MID, METHODNAME, METHODSIG)
static jclass breakpointclass
JNIEnv jthread jmethodID jlocation jobject jmethodID jlocation catch_location
static jmethodID classpreparemid
#define JVMTI_VERSION_1_0
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
#define FINDCLASSWITHEXCEPTION(CLASS, SIGNATURE)
static void VMInit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread)
static jmethodID vmmethodmid
static void notify(JNIEnv *jni_env, jobject event)
JNIEnv jthread jmethodID jlocation location
static jmethodID locationmid
static jclass threadendclass
static void ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread)
jvmtiEventCallbacks jvmti_jdwp_EventCallbacks
static void VMDeath(jvmtiEnv *jvmti_env, JNIEnv *jni_env)
static void fillidcache(JNIEnv *jni_env)