From: motse Date: Thu, 25 May 2006 21:59:49 +0000 (+0000) Subject: src/vm/vm.c(usage): added information for jvmti agent for jdwp X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=f514dd691a68bfe0a24bd88b01dd7cb55a039781;p=cacao.git src/vm/vm.c(usage): added information for jvmti agent for jdwp (vm_create): jdwp code move to jvmti agent for jdwp (VMjdwp.c) src/cacao/cacao.c (main): jdwp code move to jvmti agent for jdwp. execute jvmti_set_phase only if needed src/native/jvmti/cacaodbg.c (setup_jdwp_thread): jdwp code move to jvmti agent for jdwp src/native/jvmti/VMjdwp.c: change this to a jvmti complaint agent by using jni/jvmti function instead of cacao specific functions and implement a Agent_OnLoad as main entry point. Include setup_jdwp_thread function. src/native/jvmti/Makefile.am: add libjdwp.so src/native/jvmti/cacaodbg.h: remove no more needed global jdwp related variables src/native/jvmti/jvmti.c: (Resume/SuspendThread(List)): add temporary implementation for trying jdwp (jvmti_agentload): bugfix in getting/passing libname/arguments --- diff --git a/src/cacao/cacao.c b/src/cacao/cacao.c index 57a51f635..19bfeccdf 100644 --- a/src/cacao/cacao.c +++ b/src/cacao/cacao.c @@ -31,7 +31,7 @@ Philipp Tomsich Christian Thalinger - $Id: cacao.c 4944 2006-05-23 15:31:19Z motse $ + $Id: cacao.c 4954 2006-05-25 21:59:49Z motse $ */ @@ -217,7 +217,7 @@ int main(int argc, char **argv) #if defined(ENABLE_JVMTI) pthread_mutex_init(&dbgcomlock,NULL); - jvmti_set_phase(JVMTI_PHASE_START); + if (jvmti) jvmti_set_phase(JVMTI_PHASE_START); #endif /* do we have a main class? */ @@ -308,19 +308,6 @@ int main(int argc, char **argv) /*class_showmethods(currentThread->group->header.vftbl->class); */ #if defined(ENABLE_JVMTI) - /* start the jdwp listening thread*/ - if (jdwp) { - log_text("cacao vm - init VMjdwp"); - if (!jvmti_VMjdwpInit()) exit(1); - setup_jdwp_thread(transport); - if (!suspend) { - fprintf(stderr,"suspend false -> continue debuggee\n"); - } else { - fprintf(stderr,"suspend true -> do no continue debuggee(todo)\n"); - /* XXX todo*/ - } - } - jvmti_set_phase(JVMTI_PHASE_LIVE); #endif diff --git a/src/native/jvmti/Makefile.am b/src/native/jvmti/Makefile.am index 114a1f438..04fd2eacb 100644 --- a/src/native/jvmti/Makefile.am +++ b/src/native/jvmti/Makefile.am @@ -28,7 +28,7 @@ ## ## Changes: ## -## $Id: Makefile.am 4944 2006-05-23 15:31:19Z motse $ +## $Id: Makefile.am 4954 2006-05-25 21:59:49Z motse $ ## Process this file with automake to produce Makefile.in @@ -39,8 +39,6 @@ noinst_LTLIBRARIES = libjvmti.la libjvmti_la_SOURCES = \ jvmti.c \ jvmti.h \ - VMjdwp.c \ - VMjdwp.h \ dbg.h\ cacaodbg.h \ cacaodbg.c @@ -54,6 +52,15 @@ cacaodbgserver_SOURCES = \ cacaodbgserver_LDADD = \ libjvmti.la + +lib_LTLIBRARIES = \ + libjdwp.la + +libjdwp_la_SOURCES = \ + VMjdwp.c \ + VMjdwp.h + + ## Local variables: ## mode: Makefile ## indent-tabs-mode: t diff --git a/src/native/jvmti/VMjdwp.c b/src/native/jvmti/VMjdwp.c index b4b013394..9bcde095b 100644 --- a/src/native/jvmti/VMjdwp.c +++ b/src/native/jvmti/VMjdwp.c @@ -29,155 +29,45 @@ Changes: - $Id: VMjdwp.c 4944 2006-05-23 15:31:19Z motse $ + $Id: VMjdwp.c 4954 2006-05-25 21:59:49Z motse $ */ #include "native/jvmti/jvmti.h" -#include "native/jvmti/cacaodbg.h" #include "native/jvmti/VMjdwp.h" -#include "vm/loader.h" -#include "vm/exceptions.h" -#include "vm/jit/asmpart.h" #include +#include -static methodinfo *notifymid = NULL; -static classinfo *Jdwpclass = NULL; +static jmethodID notifymid = NULL; +static jclass Jdwpclass = NULL; -#define FINDCLASS(jni_env,class,classname) \ - class = load_class_from_sysloader(utf_new_char(classname)); \ - if (!class) throw_main_exception_exit(); - - -#define GETJNIMETHOD(jni_env,class,classname,method,methodname,methodsig) \ - FINDCLASS(jni_env,class,classname) \ - method = class_resolveclassmethod (class,utf_new_char(methodname), \ - utf_new_char(methodsig), \ - class_java_lang_Object,true); \ - if (!method) throw_main_exception_exit(); - -#define GETJNISTATICMETHOD(jni_env,class,classname,method,methodname,methodsig) \ - FINDCLASS(jni_env,class,classname) \ - method = class_resolveclassmethod (class,utf_new_char(methodname), \ - utf_new_char(methodsig), \ - class_java_lang_Object,true); \ - if (!method) throw_main_exception_exit(); - - -static void notify (JNIEnv* env, jobject event){ - log_text("VMjdwp notfiy called"); +static void notify (JNIEnv* jni_env, jobject event){ + fprintf(stderr,"VMjdwp notfiy called"); if (notifymid == NULL) { - GETJNISTATICMETHOD(env,Jdwpclass,"gnu/classpath/jdwp/Jdwp",notifymid, - "notify","(Lgnu/classpath/jdwp/event/Event;)V"); - + notifymid = (*jni_env)-> + GetStaticMethodID(jni_env,Jdwpclass, + "notify","(Lgnu/classpath/jdwp/event/Event;)V"); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"could not get notify method\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } } - vm_call_method(notifymid, NULL ,event); - if (*exceptionptr) - throw_main_exception_exit(); - -} - - -static void SingleStep (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location) { - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void Breakpoint (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location) { - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void FieldAccess (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location, - jclass field_klass, - jobject object, - jfieldID field) -{ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void FieldModification (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location, - jclass field_klass, - jobject object, - jfieldID field, - char signature_type, - jvalue new_value) { - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void FramePop (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jboolean was_popped_by_exception){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void MethodEntry (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void MethodExit (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jboolean was_popped_by_exception, - jvalue return_value){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void NativeMethodBind (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - void* address, - void** new_address_ptr){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} - -static void Exception (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location, - jobject exception, - jmethodID catch_method, - jlocation catch_location){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + (*jni_env)->CallStaticVoidMethod(jni_env,Jdwpclass,notifymid,event); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"Exception occourred in notify mehtod\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } -static void ExceptionCatch (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location, - jobject exception){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); } -static void ThreadStart (jvmtiEnv *jvmti_env, +/*static void ThreadStart (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread){ jclass cl; @@ -198,241 +88,283 @@ static void ThreadStart (jvmtiEnv *jvmti_env, throw_main_exception_exit(); notify (jni_env,obj); -} + } */ -static void ThreadEnd (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} -static void ClassLoad (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} +/* setup_jdwp_thread ********************************************************** -static void ClassPrepare (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + Helper function to start JDWP listening thread -static void ClassFileLoadHook (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jclass class_being_redefined, - jobject loader, - const char* name, - jobject protection_domain, - jint class_data_len, - const unsigned char* class_data, - jint* new_class_data_len, - unsigned char** new_class_data){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} +*******************************************************************************/ -static void VMStart (jvmtiEnv *jvmti_env, - JNIEnv* jni_env) { - log_text ("JVMTI-Event:VMStart IMPLEMENT ME!!!"); -} - -static void VMInit (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread) { - classinfo* cl; - methodinfo* cc; - java_objectheader* obj; +static void setup_jdwp_thread(JNIEnv* jni_env) { + jobject o; + jmethodID m; + jstring s; - log_text ("JVMTI-Event:VMInit"); + /* new gnu.classpath.jdwp.Jdwp() */ + Jdwpclass = (*jni_env)->FindClass(jni_env, "gnu/classpath/jdwp/Jdwp"); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"could not find gnu/classpath/jdwp/Jdwp\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } - GETJNIMETHOD(jni_env,cl,"gnu/classpath/jdwp/event/VmInitEvent",cc,"", - "(Ljava/lang/Thread;)V"); + + m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,"","()V"); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"could not get Jdwp constructor\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } + + o = (*jni_env)->NewObject(jni_env, Jdwpclass, m); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"error calling Jdwp constructor\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } + + + /* configure(jdwpoptions) */ + m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,"configure", + "(Ljava/lang/String;)V"); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"could not get Jdwp configure method\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } - fprintf(stderr,"VMjdwp:VMInit: 1\n"); - obj = builtin_new(cl); - if (!obj) throw_main_exception_exit(); + s = (*jni_env)->NewStringUTF(jni_env,jdwpoptions); + if (s == NULL) { + fprintf(stderr,"could not get new java string from jdwp options\n"); + exit(1); + } - fprintf(stderr,"VMjdwp:VMInit: thread %p\n",thread); - fflush(stderr); + free(jdwpoptions); + + (*jni_env)->CallVoidMethod(jni_env,o,m,s); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"Exception occourred in Jdwp configure\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } - vm_call_method((methodinfo*)cc, obj, thread); + m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,"_doInitialization","()V"); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"could not get Jdwp _doInitialization method\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } - if (*exceptionptr) - throw_main_exception_exit(); - notify (jni_env,obj); + (*jni_env)->CallVoidMethod(jni_env,o,m); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"Exception occourred in Jdwp _doInitialization\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } } -static void VMDeath (jvmtiEnv *jvmti_env, - JNIEnv* jni_env) { - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} +static void VMInit (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread) { + jclass cl; + jmethodID m; + jobject eventobj; -static void CompiledMethodLoad (jvmtiEnv *jvmti_env, - jmethodID method, - jint code_size, - const void* code_addr, - jint map_length, - const jvmtiAddrLocationMap* map, - const void* compile_info) { - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + fprintf(stderr,"JDWP VMInit\n"); -static void CompiledMethodUnload (jvmtiEnv *jvmti_env, - jmethodID method, - const void* code_addr){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + /* startup gnu classpath jdwp thread */ + setup_jdwp_thread(jni_env); -static void DynamicCodeGenerated (jvmtiEnv *jvmti_env, - const char* name, - const void* address, - jint length){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + fprintf(stderr,"JDWP listening thread started\n"); -static void DataDumpRequest (jvmtiEnv *jvmti_env){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + cl = (*jni_env)->FindClass(jni_env, + "gnu/classpath/jdwp/event/VmInitEvent"); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"could not find class VMInitEvent\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } -static void MonitorContendedEnter (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jobject object){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + m = (*jni_env)->GetMethodID(jni_env,cl,"", + "(Ljava/lang/Thread;)V"); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"could not get VmInitEvent constructor\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } -static void MonitorContendedEntered (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jobject object){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + eventobj = (*jni_env)->NewObject(jni_env, cl, m, thread); + if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { + fprintf(stderr,"error calling VmInitEvent constructor\n"); + (*jni_env)->ExceptionDescribe(jni_env); + exit(1); + } -static void MonitorWait (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jobject object, - jlong timeout){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} -static void MonitorWaited (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jobject object, - jboolean timed_out){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); -} + notify (jni_env,eventobj); -static void VMObjectAlloc (jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jobject object, - jclass object_klass, - jlong size){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); + if (suspend) { + fprintf(stderr,"suspend true -> do not continue debuggee\n"); + if (JVMTI_ERROR_NONE!=(*jvmti_env)->SuspendThread(jvmti_env,thread)) + fprintf(stderr,"error suspending initial thread\n"); + } } -static void ObjectFree (jvmtiEnv *jvmti_env, - jlong tag){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); +static void VMDeath (jvmtiEnv *jvmti_env, + JNIEnv* jni_env) { + fprintf(stderr,"JVMTI-Event: IMPLEMENT ME!!!"); } -static void GarbageCollectionStart (jvmtiEnv *jvmti_env){ - log_text ("JVMTI-Event: IMPLEMENT ME!!!"); +static void usage() { + puts("usage jdwp:[help]|(