src/vm/vm.c(usage): added information for jvmti agent for jdwp
authormotse <none@none>
Thu, 25 May 2006 21:59:49 +0000 (21:59 +0000)
committermotse <none@none>
Thu, 25 May 2006 21:59:49 +0000 (21:59 +0000)
(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

src/cacao/cacao.c
src/native/jvmti/Makefile.am
src/native/jvmti/VMjdwp.c
src/native/jvmti/VMjdwp.h
src/native/jvmti/cacaodbg.c
src/native/jvmti/cacaodbg.h
src/native/jvmti/cacaodbgserver.c
src/native/jvmti/jvmti.c
src/vm/vm.c

index 57a51f63545de682b8dba8c2b35bf7bd025549b4..19bfeccdfdc7f7d8016cadb0ad5e3f9aededb20d 100644 (file)
@@ -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
 
index 114a1f438e06ca3017ccb784e9e6c0948982f3f5..04fd2eacbf17c70a6a34aa4aba911ec1a075635f 100644 (file)
@@ -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
index b4b013394087b751cbf790422f39e253d34b8644..9bcde095be206dd49de351538008f7df017579bd 100644 (file)
    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 <stdlib.h>
+#include <string.h>
 
 
-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,"<init>",
-                                "(Ljava/lang/Thread;)V"); 
+       
+       m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,"<init>","()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,"<init>",
+                                                               "(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]|(<option>=<value>),*");
+       puts("   transport=[dt_socket|...]");
+       puts("   address=<hostname:port>");
+       puts("   server=[y|n]");
+       puts("   suspend=[y|n]");
 }
 
-static void GarbageCollectionFinish (jvmtiEnv *jvmti_env){
-  log_text ("JVMTI-Event: IMPLEMENT ME!!!");
+static bool processoptions(char *options) {
+       int i,len;
+       
+       if (strncmp(options,"help",4) == 0) {
+               usage();
+               return false;
+       }
+
+       suspend = true;         /* default value */
+
+
+       /* copy options for later use in java jdwp listen thread configure */
+       jdwpoptions = malloc(sizeof(char)*strlen(options));
+       strncpy(jdwpoptions, options, sizeof(char)*strlen(options));
+
+       len = strlen(options);
+       
+       i=0;
+       while (i<len) {
+               if (strncmp("suspend=",&options[i],8)==0) {
+                       if (8>=strlen(&options[i])) {
+                               if ((options[i+8]== 'y') || (options[i+8]== 'n')) {
+                                       suspend = options[i+8]== 'y';
+                               } else {
+                                       printf("jdwp error argument: %s\n",options);
+                                       usage();
+                                       return -1;
+                               }
+                       }
+               } else {
+                       /* these options will be handled by jdwp java configure */
+                       if ((strncmp("transport=",options,10)==0) ||
+                               (strncmp("server=",options,7)==0)) {
+                       } else {
+                               printf("jdwp unkown argument: %s\n",options);
+                               usage();
+                               return false;
+                       }
+               }
+               while ((options[i]!=',')&&(i<len)) i++;
+               i++;
+       }
+       return true;    
 }
 
 
-/* it would be more apropriate to call this function from gnu-cp jdwp */
-bool jvmti_VMjdwpInit() {
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) { 
+       jint rc;
        int end, i=0;
        jvmtiCapabilities cap;
        jvmtiError e;
 
-       log_text("cacao vm - create new jvmti environment");
-       jvmtienv = jvmti_new_environment();
 
+       fprintf(stderr,"jdwp Agent_OnLoad options: %s\n",options);
+       if (!processoptions(options)) return -1;
+       
+       rc = (*vm)->GetEnv(vm, (void**)&jvmtienv, JVMTI_VERSION_1_0);
+       if (rc != JNI_OK) {         
+               fprintf(stderr, "jdwp: Unable to get jvmtiEnv error=%d\n", rc);
+               return -1;              
+       }
+       
        /* set eventcallbacks */
        if (JVMTI_ERROR_NONE != 
                (*jvmtienv)->SetEventCallbacks(jvmtienv,
-                                                          &jvmti_jdwp_EventCallbacks,
-                                                          sizeof(jvmti_jdwp_EventCallbacks))){
-               log_text("unable to setup event callbacks");
-               return false;
+                                                                          &jvmti_jdwp_EventCallbacks,
+                                                                          sizeof(jvmtiEventCallbacks))){
+               fprintf(stderr,"jdwp: unable to setup event callbacks");
+               return -1;
        }
-       
+
        e = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &cap);
        if (e == JVMTI_ERROR_NONE) {
                e = (*jvmtienv)->AddCapabilities(jvmtienv, &cap);
        }
        if (e != JVMTI_ERROR_NONE) {
-               log_text("error adding jvmti capabilities");
-               exit(1);
+               fprintf(stderr,"jdwp: error adding jvmti capabilities");
+               return -1;
        }
+       
 
-       end = sizeof(jvmti_jdwp_EventCallbacks) / sizeof(void*);
+       end = sizeof(jvmtiEventCallbacks) / sizeof(void*);
        for (i = 0; i < end; i++) {
-               /* enable standard VM callbacks  */
+               /* enable VM callbacks  */
                if (((void**)&jvmti_jdwp_EventCallbacks)[i] != NULL) {
                        e = (*jvmtienv)->SetEventNotificationMode(jvmtienv,
-                                                                                               JVMTI_ENABLE,
-                                                                                               JVMTI_EVENT_START_ENUM+i,
-                                                                                               NULL);
-
+                                                                                                         JVMTI_ENABLE,
+                                                                                                         JVMTI_EVENT_START_ENUM+i,
+                                                                                                         NULL);
+                       
                        if (JVMTI_ERROR_NONE != e) {
-                               log_text("unable to setup event notification mode");
-                               return false;
+                               fprintf(stderr,"jdwp: unable to setup event notification mode");
+                               return -1;
                        }
                }
        }
-       return true;
+
+       return 0;
 }
        
-       jvmtiEventCallbacks jvmti_jdwp_EventCallbacks = {
+
+jvmtiEventCallbacks jvmti_jdwp_EventCallbacks = {
     &VMInit,
     &VMDeath,
-    &ThreadStart,
-    &ThreadEnd,
-    &ClassFileLoadHook,
-    &ClassLoad,
-    &ClassPrepare,
+    NULL, /*    &ThreadStart,*/
+    NULL, /*    &ThreadEnd, */
+    NULL, /* &ClassFileLoadHook, */
+    NULL, /* &ClassLoad, */
+    NULL, /* &ClassPrepare,*/
     NULL, /* &VMStart */
-    &Exception,
-    &ExceptionCatch,
-    &SingleStep,
-    &FramePop,
-    &Breakpoint,
-    &FieldAccess,
-    &FieldModification,
-    &MethodEntry,
-    &MethodExit,
-    &NativeMethodBind,
-    &CompiledMethodLoad,
-    &CompiledMethodUnload,
-    &DynamicCodeGenerated,
-    &DataDumpRequest,
+    NULL, /* &Exception, */
+    NULL, /* &ExceptionCatch, */
+    NULL, /* &SingleStep, */
+    NULL, /* &FramePop, */
+    NULL, /* &Breakpoint, */
+    NULL, /* &FieldAccess, */
+    NULL, /* &FieldModification, */
+    NULL, /* &MethodEntry, */
+    NULL, /* &MethodExit, */
+    NULL, /* &NativeMethodBind, */
+    NULL, /* &CompiledMethodLoad, */
+    NULL, /* &CompiledMethodUnload, */
+    NULL, /* &DynamicCodeGenerated, */
+    NULL, /* &DataDumpRequest, */
     NULL,
-    &MonitorWait,
-    &MonitorWaited,
-    &MonitorContendedEnter,
-    &MonitorContendedEntered,
+    NULL, /* &MonitorWait, */
+    NULL, /* &MonitorWaited, */
+    NULL, /* &MonitorContendedEnter, */
+    NULL, /* &MonitorContendedEntered, */
     NULL,
     NULL,
     NULL,
     NULL,
-    &GarbageCollectionStart,
-    &GarbageCollectionFinish,
-    &ObjectFree,
-    &VMObjectAlloc,
+    NULL, /* &GarbageCollectionStart, */
+    NULL, /* &GarbageCollectionFinish, */
+    NULL, /* &ObjectFree, */
+    NULL, /* &VMObjectAlloc, */
 };
 
 
index 86e58439a6f439bd4784a9f5fb7cab450e132b72..235ddf993ad6790c735fa13d7f25c95ebfe7901d 100644 (file)
@@ -39,6 +39,8 @@
 #include "native/jvmti/jvmti.h"
 
 jvmtiEnv* jvmtienv;
-jvmtiEventCallbacks jvmti_jdwp_EventCallbacks;
+extern jvmtiEventCallbacks jvmti_jdwp_EventCallbacks;
+char* jdwpoptions;
+bool suspend;               /* should the virtual machine suspend on startup?  */
 
 #endif
index 9a2e2776d126d6e9d6cb395261cac6b4de807ffb..a685b44f0bc15c9991a624cdd2916680ed9fb238 100644 (file)
@@ -211,66 +211,6 @@ void jvmti_add_breakpoint(void* addr, jmethodID method, jlocation location) {
 }
 
 
-/* setup_jdwp_thread *****************************************************
-
-   Helper function to start JDWP threads
-
-*******************************************************************************/
-
-void setup_jdwp_thread(char* transport) {
-       java_objectheader *o;
-       methodinfo *m;
-       java_lang_String  *s;
-       classinfo *class;
-
-       /* new gnu.classpath.jdwp.Jdwp() */
-       class = load_class_from_sysloader(
-            utf_new_char("gnu.classpath.jdwp.Jdwp"));
-       if (!class)
-               throw_main_exception_exit();
-
-       o = builtin_new(class);
-
-       if (!o)
-               throw_main_exception_exit();
-       
-       m = class_resolveclassmethod(class,
-                                     utf_init, 
-                                     NULL,
-                                     class_java_lang_Object,
-                                     true);
-       if (!m)
-            throw_main_exception_exit();
-        
-       vm_call_method(m,o);
-        
-       /* configure(transport,NULL) */
-       m = class_resolveclassmethod(
-            class, utf_new_char("configure"), 
-            utf_new_char("(Ljava/lang/String;)V"),
-            class_java_lang_Object,
-            false);
-
-       s = javastring_new_from_ascii(&transport[1]);
-
-       vm_call_method(m,o,s);
-
-       if (!m)
-               throw_main_exception_exit();
-
-
-       /* _doInitialization */
-       m = class_resolveclassmethod(class,
-                                     utf_new_char("_doInitialization"), 
-                                     utf_new_char("()V"),
-                                     class,
-                                     false);
-       
-       if (!m)
-            throw_main_exception_exit();
-        
-       vm_call_method(m,o);
-}
 
 
 /* jvmti_cacaodbgserver_quit **************************************************
index 0d97a7b5ad35c87ac96a397defc0161a9742b33e..10332fdd146cead3111f86658791f7730fb39b3f 100644 (file)
@@ -121,13 +121,8 @@ typedef struct {
 
 cacaodbgcommunication *dbgcom;
 
-
-bool jdwp;                  /* debugger via jdwp                               */
 bool jvmti;                 /* jvmti agent                                     */
 
-char *transport, *agentarg; /* arguments for jdwp transport and agent load     */
-bool suspend;               /* should the virtual machine suspend on startup?  */
-
 extern pthread_mutex_t dbgcomlock;
 
 void setup_jdwp_thread(char* transport);
index fd5dd1f829e65d8419c44c38e0765f9b9813343a..02ce300b5b73c7315f9cfde852b08176ba948f68 100644 (file)
@@ -197,7 +197,7 @@ static bool commonbreakpointhandler(char* sigbuf, int sigtrap) {
                   in the cacao vm */
                fprintf(gdbout,"call jvmti_cacao_generic_breakpointhandler(%d)\n",i);
                fflush(gdbout);
-               getgdboutput(tmp,INBUFLEN);             
+               getgdboutput(tmp,INBUFLEN);
        }
        SENDCMD(CONTINUE);
        getgdboutput(tmp,INBUFLEN);
@@ -248,8 +248,17 @@ static void controlloop() {
                        continue;
                }
                        
-               if ((inbuf[0]!=LOGSTREAMOUTPUT) && (inbuf[0]!=CONSOLESTREAMOUTPUT))
+               if ((inbuf[0]!=LOGSTREAMOUTPUT) && (inbuf[0]!=CONSOLESTREAMOUTPUT)) {
                        fprintf(stderr,"gdbin not handled %s\n",inbuf);
+                       fprintf(gdbout,"bt\n");
+                       fflush(gdbout);
+                       fprintf(stderr,"not handled 1\n");
+                       fflush(stderr);
+                       getgdboutput(inbuf,INBUFLEN);
+                       fprintf(stderr,"gdbin: %s\n",inbuf);
+                       SENDCMD("-gdb-exit\n");
+                       return false;
+               }
        }
 
        free(pending_brkpts);
index 6ddd906390a49f60829452b7c849361a40587f1f..76c124aa69c6191f43ab995bf40dc3e5b8f0ebbd 100644 (file)
@@ -31,7 +31,7 @@
             Samuel Vinson
 
    
-   $Id: jvmti.c 4946 2006-05-24 11:00:38Z motse $
+   $Id: jvmti.c 4954 2006-05-25 21:59:49Z motse $
 
 */
 
@@ -584,9 +584,17 @@ SuspendThread (jvmtiEnv * env, jthread thread)
        CHECK_PHASE_END;
     CHECK_CAPABILITY(env,can_suspend);
     
-       log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
-       return JVMTI_ERROR_NOT_AVAILABLE;
+       if(thread == NULL) return JVMTI_ERROR_INVALID_THREAD;
+       if (!builtin_instanceof(thread,class_java_lang_Thread))
+               return JVMTI_ERROR_INVALID_THREAD;
+       CHECK_THREAD_IS_ALIVE(thread);
+
 
+       /* quick try - this should be changed in the future */
+       pthread_kill(((threadobject*)((java_lang_Thread*) thread)->vmThread)->tid,
+                                GC_signum1());
+       
+       
     return JVMTI_ERROR_NONE;
 }
 
@@ -604,8 +612,15 @@ ResumeThread (jvmtiEnv * env, jthread thread)
     CHECK_PHASE_END;
     CHECK_CAPABILITY(env,can_suspend);
 
-       log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
-       return JVMTI_ERROR_NOT_AVAILABLE;
+       if(thread == NULL) return JVMTI_ERROR_INVALID_THREAD;
+       if (!builtin_instanceof(thread,class_java_lang_Thread))
+               return JVMTI_ERROR_INVALID_THREAD;
+       CHECK_THREAD_IS_ALIVE(thread);
+
+
+       /* quick try - this should be changed in the future */
+       pthread_kill(((threadobject*)((java_lang_Thread*) thread)->vmThread)->tid,
+                                GC_signum2());
 
     return JVMTI_ERROR_NONE;
 }
@@ -2704,8 +2719,8 @@ IsMethodObsolete (jvmtiEnv * env, jmethodID method,
 
 
 /* SuspendThreadList **********************************************************
-
    
+   Suspend all threads in the request list.
 
 *******************************************************************************/
 
@@ -2713,13 +2728,31 @@ static jvmtiError
 SuspendThreadList (jvmtiEnv * env, jint request_count,
                   const jthread * request_list, jvmtiError * results)
 {
+       int i;
+       int suspendme = -1;
+       jthread me;
+
     CHECK_PHASE_START
     CHECK_PHASE(JVMTI_PHASE_START)
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
     CHECK_CAPABILITY(env,can_suspend);
-        
-       log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
+    
+       if (request_count<0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
+       if ((request_list==NULL) || (results == NULL)) 
+               return JVMTI_ERROR_NULL_POINTER;
+
+       me = jvmti_get_current_thread();
+
+       for (i=0;i<request_count;i++) {
+               if (request_list[i] == me) 
+                       suspendme = i;
+               else 
+                       results[i]=SuspendThread(env, request_list[i]);
+       }
+
+       if (suspendme != -1) 
+               results[suspendme]=SuspendThread(env, request_list[suspendme]);
 
     return JVMTI_ERROR_NONE;
 }
@@ -2727,7 +2760,7 @@ SuspendThreadList (jvmtiEnv * env, jint request_count,
 
 /* ResumeThreadList ***********************************************************
 
-   
+   Resumes all threads in the request list.   
 
 *******************************************************************************/
 
@@ -2735,12 +2768,19 @@ static jvmtiError
 ResumeThreadList (jvmtiEnv * env, jint request_count,
                  const jthread * request_list, jvmtiError * results)
 {
+       int i;
+
        CHECK_PHASE_START
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
     CHECK_CAPABILITY(env,can_suspend);
-        
-       log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!");
+    
+       if (request_count<0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
+       if ((request_list==NULL) || (results == NULL)) 
+               return JVMTI_ERROR_NULL_POINTER;
+
+       for (i=0;i<request_count;i++) 
+                       results[i]=ResumeThread(env, request_list[i]);
 
     return JVMTI_ERROR_NONE;
 }
@@ -3193,6 +3233,7 @@ SetEventCallbacks (jvmtiEnv * env,
 
     if (size_of_callbacks < 0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
 
+
        if (callbacks == NULL) { /* remove the existing callbacks */
         memset(&(((environment* )env)->callbacks), 0, 
                           sizeof(jvmtiEventCallbacks));
@@ -3787,8 +3828,7 @@ GetTime (jvmtiEnv * env, jlong * nanos_ptr)
 *******************************************************************************/
 
 static jvmtiError
-GetPotentialCapabilities (jvmtiEnv * env,
-                         jvmtiCapabilities * capabilities_ptr)
+GetPotentialCapabilities (jvmtiEnv * env, jvmtiCapabilities * capabilities_ptr)
 {
     CHECK_PHASE_START
     CHECK_PHASE(JVMTI_PHASE_ONLOAD)
@@ -4108,7 +4148,7 @@ static jvmtiCapabilities JVMTI_Capabilities = {
   0,                           /* can_generate_exception_events */
   0,                           /* can_generate_frame_pop_events */
   0,                           /* can_generate_breakpoint_events */
-  0,                           /* can_suspend */
+  1,                           /* can_suspend */
   0,                           /* can_redefine_any_class */
   0,                           /* can_get_current_thread_cpu_time */
   0,                           /* can_get_thread_cpu_time */
@@ -4352,24 +4392,26 @@ void jvmti_agentload(char* opt_arg, bool agentbypath, lt_dlhandle  *handle, char
        int i=0,len;
        jint retval;
 
-       
        len = strlen(opt_arg);
        
        /* separate argumtents */
-       while ((opt_arg[i]!='=')&&(i<=len)) i++;
-       arg = &opt_arg[i];
+       while ((opt_arg[i]!='=')&&(i<len)) i++;
+       if (i<len)
+               arg = &opt_arg[i+1];
+       else
+               arg = "";
 
        if (agentbypath) {
                /* -agentpath */
                *libname=heap_allocate(sizeof(char)*i,true,NULL);
-               strncpy(*libname,opt_arg,i-1);
-               (*libname)[i-1]='\0';
+               strncpy(*libname,opt_arg,i);
+               (*libname)[i]='\0';
        } else {
                /* -agentlib */
                *libname=heap_allocate(sizeof(char)*(i+7),true,NULL);
                strncpy(*libname,"lib",3);
-               strncpy(&(*libname)[3],opt_arg,i-1);
-               strncpy(&(*libname)[i+2],".so",3);
+               strncpy(&(*libname)[3],opt_arg,i);
+               strncpy(&(*libname)[i+3],".so",3);
        }
 
        /* try to open the library */
index 748890fe6ef736cadbd47a132be8940317f5b5cd..9ed89ebd577c489314799a2837ae9051b35154dd 100644 (file)
@@ -344,6 +344,7 @@ void usage(void)
 
 #ifdef ENABLE_JVMTI
        puts("    -agentlib:<agent-lib-name>=<options>  library to load containg JVMTI agent");
+       puts ("                                         for jdwp help use: -agentlib:jdwp=help");
        puts("    -agentpath:<path-to-agent>=<options>  path to library containg JVMTI agent");
 #endif
 
@@ -424,9 +425,9 @@ static void Xusage(void)
 #if defined(ENABLE_JVMTI)
     /* -Xdebug option depend on gnu classpath JDWP options. options: 
         transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
-       puts("    -Xdebug           enable remote debugging\n");
+       puts("    -Xdebug                  enable remote debugging\n");
        puts("    -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
-       puts("                      enable remote debugging\n");
+       puts("                             enable remote debugging\n");
 #endif 
 
        /* exit with error code */
@@ -518,8 +519,9 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
 #if defined(ENABLE_JVMTI)
        lt_dlhandle  handle;
-       char* libname;
-       bool agentbypath = false;;
+       char *libname, *agentarg;
+       bool jdwp,agentbypath;
+       jdwp = agentbypath = false;
 #endif
        
 
@@ -596,7 +598,7 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
 #if defined(ENABLE_JVMTI)
        /* initialize JVMTI related  **********************************************/
-       jdwp = jvmti = false;
+       jvmti = false;
 #endif
 
        /* initialize properties before commandline handling */
@@ -699,36 +701,19 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
 #if defined(ENABLE_JVMTI)
                case OPT_DEBUG:
-                       jdwp=true;
+                       /* this option exists only for compatibility reasons */
                        break;
                case OPT_NOAGENT:
                        /* I don't know yet what Xnoagent should do. This is only for 
                           compatiblity with eclipse - motse */
                        break;
                case OPT_XRUNJDWP:
-                       transport = opt_arg;
-                       j=0;
-                       while (transport[j]!='=') j++;
-                       j++;
-                       while (j<strlen(transport)) {
-                               if (strncmp("suspend=",&transport[j],8)==0) {
-                                       if ((j+8)>=strlen(transport) || 
-                                               (transport[j+8]!= 'y' && transport[j+8]!= 'n')) {
-                                               printf("bad Xrunjdwp option: -Xrunjdwp%s\n",transport);
-                                               usage();
-                                               break;
-                                       }
-                                       else {
-                                               suspend = transport[j+8] == 'y';
-                                               break;
-                                       }
-                               }
-                               while (transport[j]!=',') j++;
-                               j++;
-                       }
-                       
+                       agentbypath=jvmti=jdwp=true;
+                       i = strlen(opt_arg)+33;
+                       agentarg = MNEW(char,i);
+                       /* XXX how can I get the <prefix>/lib directory ? */
+                       snprintf(agentarg,i,"/usr/local/cacao/lib/libjdwp.so=%s",&opt_arg[1]);
                        break;
-
                case OPT_AGENTPATH:
                        agentbypath = true;
                case OPT_AGENTLIB:
@@ -1073,8 +1058,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
        if (jvmti) {
                jvmti_set_phase(JVMTI_PHASE_ONLOAD);
                jvmti_agentload(agentarg, agentbypath, &handle, &libname);
+               if (jdwp) MFREE(agentarg,char,strlen(agentarg));
+               jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
        }
-       jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
+
 #endif
 
 
@@ -1325,8 +1312,19 @@ void vm_shutdown(s4 status)
        {
                log_text("CACAO terminated by shutdown");
                dolog("Exit status: %d\n", (s4) status);
+
        }
 
+#if defined(ENABLE_JVMTI)
+       /* terminate cacaodbgserver */
+       if (dbgcom!=NULL) {
+               pthread_mutex_lock(&dbgcomlock);
+               dbgcom->running=1;
+               pthread_mutex_unlock(&dbgcomlock);
+               jvmti_cacaodbgserver_quit();
+       }       
+#endif
+
        exit(status);
 }