(libjdwp_la_SOURCES): Removed.
* src/native/jvmti/VMjdwp.c: Removed.
* src/native/jvmti/VMjdwp.h: Likewise.
* src/native/vm/Makefile.am [ENABLE_JVMTI] (lib_LTLIBRARIES): Added
libjdwp.la.
(libjdwp_la_SOURCES): Added.
* src/native/vm/VMFrame.c: Removed.
* src/native/vm/VMMethod.c: Likewise.
* src/native/vm/VMVirtualMachine.c: Likewise.
* src/native/vm/VMjdwp.c: Added.
* src/native/vm/VMjdwp.h: Likewise.
* src/native/vm/gnu_classpath_jdwp_VMVirtualMachine.c: Likewise.
* src/native/vm/gnu_classpath_jdwp_VMFrame.c: Likewise.
* src/native/vm/gnu_classpath_jdwp_VMMethod.c: Likewise.
--HG--
rename : src/native/jvmti/VMjdwp.c => src/native/vm/VMjdwp.c
rename : src/native/jvmti/VMjdwp.h => src/native/vm/VMjdwp.h
rename : src/native/vm/VMFrame.c => src/native/vm/gnu_classpath_jdwp_VMFrame.c
rename : src/native/vm/VMMethod.c => src/native/vm/gnu_classpath_jdwp_VMMethod.c
rename : src/native/vm/VMVirtualMachine.c => src/native/vm/gnu_classpath_jdwp_VMVirtualMachine.c
##
## Changes:
##
-## $Id: Makefile.am 5001 2006-05-31 22:07:13Z twisti $
+## $Id: Makefile.am 5157 2006-07-18 11:09:47Z twisti $
## Process this file with automake to produce Makefile.in
LIBS =
-noinst_LTLIBRARIES = libjvmti.la
+noinst_LTLIBRARIES = \
+ libjvmti.la
libjvmti_la_SOURCES = \
jvmti.c \
libjvmti.la
-lib_LTLIBRARIES = \
- libjdwp.la
-
-libjdwp_la_SOURCES = \
- VMjdwp.c \
- VMjdwp.h
-
## Local variables:
## mode: Makefile
## indent-tabs-mode: t
+++ /dev/null
-/* src/native/vm/VMjdwp.c - jvmti->jdwp interface
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Author: Martin Platter
-
- Changes:
-
-
- $Id: VMjdwp.c 5156 2006-07-18 11:02:28Z motse $
-
-*/
-
-#include "native/jvmti/jvmti.h"
-#include "native/jvmti/VMjdwp.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-void printjvmtierror(char *desc, jvmtiError err) {
- char* errdesc;
-
- if (err == JVMTI_ERROR_NONE) return;
- (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
- fprintf(stderr,"%s: jvmti error %s\n",desc, errdesc);
- fflush(stderr);
- (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
-}
-
-
-/* class and method IDs */
-static jclass Jdwpclass, threadstartclass,threadendclass, classprepareclass, vmmethodclass, locationclass, breakpointclass;
-static jmethodID notifymid, threadstartmid,threadendmid, classpreparemid,
- vmmethodmid, locationmid, breakpointmid;
-
-static void notify (JNIEnv* jni_env, jobject event){
- fprintf(stderr,"VMjdwp notfiy called\n");
-
- (*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);
- }
-
-}
-
-static void ThreadStart (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
- jthread thread){
- jobject obj;
-
- obj = (*jni_env)->
- NewObject(jni_env, threadstartclass, threadstartmid, thread);
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
- fprintf(stderr,"error calling ThreadStartEvent constructor\n");
- (*jni_env)->ExceptionDescribe(jni_env);
- return;
- }
-
- fprintf(stderr,"VMjdwp:ThreadStart: thread %p\n",thread);
- fflush(stderr);
-
- notify (jni_env,obj);
-}
-
-
-static void ThreadEnd (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
- jthread thread){
- jobject obj;
-
-
- obj = (*jni_env)->NewObject(jni_env, threadendclass, threadendmid, thread);
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
- fprintf(stderr,"error calling ThreadEndEvent constructor\n");
- (*jni_env)->ExceptionDescribe(jni_env);
- return;
- }
-
- fprintf(stderr,"VMjdwp:ThreadEnd: thread %p\n",thread);
- fflush(stderr);
-
- notify (jni_env,obj);
-}
-
-
-static void ClassPrepare (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
- jthread thread, jclass klass) {
- jobject obj;
- int classstatus;
- jvmtiError e;
-
- if (JVMTI_ERROR_NONE !=
- (e = (*jvmtienv)->GetClassStatus(jvmtienv, klass, &classstatus))) {
- printjvmtierror("unable to get class status", e);
- return;
- }
-
- obj = (*jni_env)->NewObject(jni_env, classprepareclass, classpreparemid, thread, klass, classstatus);
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
- fprintf(stderr,"error calling ClassPrepareEvent constructor\n");
- (*jni_env)->ExceptionDescribe(jni_env);
- return;
- }
-
- fprintf(stderr,"VMjdwp:ClassPrepareEvent: thread %p\n",thread);
- fflush(stderr);
-
- notify (jni_env,obj);
-}
-
-static void Exception (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
- jmethodID method, jlocation location, jobject exception,
- jmethodID catch_method, jlocation catch_location) {
- /* gnu classpath jdwp has no ExceptionEvent yet */
- fprintf(stderr,"VMjdwp:Exception: thread %p\n",thread);
- fflush(stderr);
-
-}
-
-static void Breakpoint (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
- jmethodID method, jlocation location) {
- jobject vmmethod, loc, ev;
- jclass mcl;
- jvmtiError e;
-
- if (JVMTI_ERROR_NONE !=
- (e = (*jvmtienv)->GetMethodDeclaringClass(jvmtienv,
- method,
- &mcl))){
- printjvmtierror("unable to get declaring class", e);
- return;
- }
-
- vmmethod = (*jni_env)->NewObject(jni_env, vmmethodclass, vmmethodmid,
- mcl, method);
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
- fprintf(stderr,"error calling VMMethod constructor\n");
- (*jni_env)->ExceptionDescribe(jni_env);
- return;
- }
-
- loc = (*jni_env)->NewObject(jni_env, locationclass, locationmid,
- vmmethod, location);
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
- fprintf(stderr,"error calling location constructor\n");
- (*jni_env)->ExceptionDescribe(jni_env);
- return;
- }
-
- /* XXX todo: get object instance - needs jvmti local variable support */
- ev = (*jni_env)->NewObject(jni_env, breakpointclass, breakpointmid,
- thread, loc,NULL);
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
- fprintf(stderr,"error calling breakpoint constructor\n");
- (*jni_env)->ExceptionDescribe(jni_env);
- return;
- }
-
- fprintf(stderr,"VMjdwp:Breakpoint: thread %p\n",thread);
- fflush(stderr);
-
- notify (jni_env,ev);
-}
-
-
-static void MethodEntry (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
- jthread thread, jmethodID method) {
- /* do not report gnu/classpath/jdwp method entries */
-}
-
-
-static void VMDeath (jvmtiEnv *jvmti_env,
- JNIEnv* jni_env) {
- fprintf(stderr,"JVMTI-Event: IMPLEMENT ME!!!");
-}
-
-
-/* setup_jdwp_thread **********************************************************
-
- Helper function to start JDWP listening thread
-
-*******************************************************************************/
-
-static void setup_jdwp_thread(JNIEnv* jni_env) {
- jobject o;
- jmethodID m;
- jstring s;
-
- /* new gnu.classpath.jdwp.Jdwp() */
- 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);
- }
-
- jdwpthread = (jthread)o;
-
-
- /* 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);
- }
-
-
- s = (*jni_env)->NewStringUTF(jni_env,jdwpoptions);
- if (s == NULL) {
- fprintf(stderr,"could not get new java string from jdwp options\n");
- exit(1);
- }
-
- 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);
- }
-
- 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);
- }
-
-
- (*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);
- }
-}
-
-#define FINDCLASSWITHEXCEPTION(CLASS,SIGNATURE) \
- CLASS = (*jni_env)->FindClass(jni_env, SIGNATURE); \
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { \
- fprintf(stderr,"could not find %s\n", SIGNATURE); \
- (*jni_env)->ExceptionDescribe(jni_env); \
- exit(1); \
- }
-#define GETMIDWITHEXCEPTION(CLASS, CLASSNAME, MID, METHODNAME, METHODSIG) \
- FINDCLASSWITHEXCEPTION(CLASS, CLASSNAME); \
- MID = (*jni_env)->GetMethodID(jni_env, CLASS, METHODNAME, METHODSIG); \
- if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { \
- fprintf(stderr,"could not get %s %s\n",CLASSNAME, METHODNAME); \
- (*jni_env)->ExceptionDescribe(jni_env); \
- exit(1); \
- }
-
-
-static void fillidcache(JNIEnv* jni_env) {
- FINDCLASSWITHEXCEPTION(Jdwpclass, "gnu/classpath/jdwp/Jdwp");
-
- 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);
- }
-
- GETMIDWITHEXCEPTION(threadstartclass,
- "gnu/classpath/jdwp/event/ThreadStartEvent",
- threadstartmid, "<init>", "(Ljava/lang/Thread;)V");
-
-
- GETMIDWITHEXCEPTION(threadendclass,
- "gnu/classpath/jdwp/event/ThreadEndEvent",
- threadendmid, "<init>", "(Ljava/lang/Thread;)V");
-
-
- GETMIDWITHEXCEPTION(classprepareclass,
- "gnu/classpath/jdwp/event/ClassPrepareEvent",
- classpreparemid, "<init>",
- "(Ljava/lang/Thread;Ljava/lang/Class;I)V");
-
-
- GETMIDWITHEXCEPTION(vmmethodclass, "gnu/classpath/jdwp/VMMethod",
- vmmethodmid, "<init>", "(Ljava/lang/Class;J)V");
-
- GETMIDWITHEXCEPTION(locationclass, "gnu/classpath/jdwp/util/Location",
- locationmid, "<init>",
- "(Lgnu/classpath/jdwp/VMMethod;J)V");
-
-
- GETMIDWITHEXCEPTION(
- breakpointclass,
- "gnu/classpath/jdwp/event/BreakpointEvent",
- breakpointmid, "<init>",
- "(Ljava/lang/Thread;Lgnu/classpath/jdwp/util/Location;Ljava/lang/Object;)V");
-
-}
-
-static void VMInit (jvmtiEnv *jvmti_env,
- JNIEnv* jni_env,
- jthread thread) {
- jclass cl;
- jmethodID m;
- jobject eventobj;
- jvmtiError err;
-
- fprintf(stderr,"JDWP VMInit\n");
-
- /* get needed jmethodIDs and jclasses for callbacks */
- fillidcache(jni_env);
-
- /* startup gnu classpath jdwp thread */
- setup_jdwp_thread(jni_env);
-
- fprintf(stderr,"JDWP listening thread started\n");
-
- /* send VmInitEvent */
- 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);
- }
-
- 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);
- }
-
- 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);
- }
-
-
- notify (jni_env,eventobj);
-
- if (suspend) {
- fprintf(stderr,"suspend initial thread\n");
- err = (*jvmti_env)->SuspendThread(jvmti_env,thread);
- printjvmtierror("error suspending initial thread",err);
- }
-}
-
-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 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;
-}
-
-
-JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
- jint rc;
- jvmtiCapabilities cap;
- jvmtiError e;
-
-
- 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 !=
- (e = (*jvmtienv)->SetEventCallbacks(jvmtienv,
- &jvmti_jdwp_EventCallbacks,
- sizeof(jvmtiEventCallbacks)))){
- printjvmtierror("jdwp: unable to setup event callbacks", e);
- return -1;
- }
-
- e = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &cap);
- printjvmtierror("jdwp: unable to get potential capabilities", e);
- if (e == JVMTI_ERROR_NONE)
- e = (*jvmtienv)->AddCapabilities(jvmtienv, &cap);
- if (e != JVMTI_ERROR_NONE) {
- printjvmtierror("jdwp: error adding jvmti capabilities", e);
- return -1;
- }
-
- /* only enable needed events. VMVirtualMachine.registerEvent will
- be used to enable other events by need */
- if (JVMTI_ERROR_NONE != (e = (*jvmtienv)->
- SetEventNotificationMode(jvmtienv, JVMTI_ENABLE,
- JVMTI_EVENT_VM_INIT,
- NULL))) {
- printjvmtierror("jdwp unable to enable vm init callback",e);
- return -1;
- }
-
- return 0;
-}
-
-
-jvmtiEventCallbacks jvmti_jdwp_EventCallbacks = {
- &VMInit,
- &VMDeath,
- &ThreadStart,
- &ThreadEnd,
- NULL, /* &ClassFileLoadHook, */
- NULL, /* &ClassLoad, */
- &ClassPrepare,
- NULL, /* &VMStart */
- &Exception,
- NULL, /* &ExceptionCatch, */
- NULL, /* &SingleStep, */
- NULL, /* &FramePop, */
- &Breakpoint,
- NULL, /* &FieldAccess, */
- NULL, /* &FieldModification, */
- &MethodEntry,
- NULL, /* &MethodExit, */
- NULL, /* &NativeMethodBind, */
- NULL, /* &CompiledMethodLoad, */
- NULL, /* &CompiledMethodUnload, */
- NULL, /* &DynamicCodeGenerated, */
- NULL, /* &DataDumpRequest, */
- NULL,
- NULL, /* &MonitorWait, */
- NULL, /* &MonitorWaited, */
- NULL, /* &MonitorContendedEnter, */
- NULL, /* &MonitorContendedEntered, */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* &GarbageCollectionStart, */
- NULL, /* &GarbageCollectionFinish, */
- NULL, /* &ObjectFree, */
- NULL, /* &VMObjectAlloc, */
-};
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMjdwp.c - jvmti->jdwp interface
-
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Contact: cacao@cacaojvm.org
-
- Author: Martin Platter
-
- Changes:
-
-
- $Id: VMjdwp.c 4661 2006-03-21 00:04:59Z motse $
-
-*/
-
-#ifndef _VMJDWP_H
-#define _VMJDWP_H
-
-#include "native/jvmti/jvmti.h"
-
-jvmtiEnv* jvmtienv;
-extern jvmtiEventCallbacks jvmti_jdwp_EventCallbacks;
-char* jdwpoptions;
-bool suspend; /* should the virtual machine suspend on startup? */
-jthread jdwpthread;
-
-void printjvmtierror(char *desc, jvmtiError err);
-#endif
##
## Changes:
##
-## $Id: Makefile.am 5153 2006-07-18 08:19:24Z twisti $
+## $Id: Makefile.am 5157 2006-07-18 11:09:47Z twisti $
## Process this file with automake to produce Makefile.in
LIBS =
-noinst_LTLIBRARIES = libnativevm.la
+noinst_LTLIBRARIES = \
+ libnativevm.la
+
+if ENABLE_JVMTI
+lib_LTLIBRARIES = \
+ libjdwp.la
+endif
libnativevm_la_SOURCES = \
gnu_classpath_VMStackWalker.c \
java_security_VMAccessController.c
if ENABLE_JVMTI
-libnativevm_la_SOURCES += \
- VMFrame.c \
- VMVirtualMachine.c \
- VMMethod.c
+libjdwp_la_SOURCES = \
+ gnu_classpath_jdwp_VMFrame.c \
+ gnu_classpath_jdwp_VMMethod.c \
+ gnu_classpath_jdwp_VMVirtualMachine.c \
+ VMjdwp.c \
+ VMjdwp.h
endif
+++ /dev/null
-/* src/native/vm/VMFrame.c - jdwp->jvmti interface
-
-Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
-C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-J. Wenninger, Institut f. Computersprachen - TU Wien
-
-This file is part of CACAO.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 2, or (at
-your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.
-
-Contact: cacao@cacaojvm.org
-
-Authors: Martin Platter
-
-Changes:
-
-
-$Id: VMFrame.c 4996 2006-05-31 13:53:16Z motse $
-
-*/
-
-#include "toolbox/logging.h"
-#include "native/jni.h"
-#include "native/include/gnu_classpath_jdwp_VMFrame.h"
-
-
-/*
- * Class: gnu/classpath/jdwp/VMFrame
- * Method: getValue
- * Signature: (I)Ljava/lang/Object;
- */
-JNIEXPORT struct java_lang_Object* JNICALL Java_gnu_classpath_jdwp_VMFrame_getValue(JNIEnv *env, struct gnu_classpath_jdwp_VMFrame* this, s4 par1) {
- log_text ("JVMTI-Call: IMPLEMENT ME!!!");
- return 0;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMFrame
- * Method: setValue
- * Signature: (ILjava/lang/Object;)V
- */
-JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMFrame_setValue(JNIEnv *env, struct gnu_classpath_jdwp_VMFrame* this, s4 par1, struct java_lang_Object* par2) {
- log_text ("JVMTI-Call: IMPLEMENT ME!!!");
- return 0;
-}
+++ /dev/null
-/* src/native/vm/VMMethod.c - jdwp->jvmti interface
-
-Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
-C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-J. Wenninger, Institut f. Computersprachen - TU Wien
-
-This file is part of CACAO.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 2, or (at
-your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.
-
-Contact: cacao@cacaojvm.org
-
-Authors: Samuel Vinson
- Martin Platter
-
-
-Changes:
-
-
-$Id: VMMethod.c $
-
-*/
-
-#include "native/jni.h"
-#include "native/include/gnu_classpath_jdwp_VMMethod.h"
-#include "native/jvmti/jvmti.h"
-#include "native/jvmti/VMjdwp.h"
-
-
-void printjvmtierror(char *desc, jvmtiError err) {
- char* errdesc;
-
- if (err == JVMTI_ERROR_NONE) return;
- (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
- fprintf(stderr,"%s: jvmti error %s\n",desc, errdesc);
- fflush(stderr);
- (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
-}
-
-
-
-/*
- * Class: gnu/classpath/jdwp/VMMethod
- * Method: getName
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getName(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
-{
- jvmtiError err;
- char *name;
- jstring stringname;
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
- GetMethodName(jvmtienv,
- (jmethodID)(long)this->_methodId,
- &name,NULL, NULL))) {
- printjvmtierror("VMMethod.getName GetMethodName",err);
- return NULL;
- }
-
- stringname = (*env)->NewStringUTF(env,name);
- (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)name);
-
- return stringname;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMMethod
- * Method: getSignature
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getSignature(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
-{
- jvmtiError err;
- char *signature;
- jstring stringsignature;
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
- GetMethodName(jvmtienv,
- (jmethodID)(long)this->_methodId,
- NULL, &signature, NULL))) {
- printjvmtierror("VMMethod.getSignature GetMethodName",err);
- return NULL;
- }
-
- stringsignature = (*env)->NewStringUTF(env,signature);
- (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)signature);
-
- return stringsignature;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMMethod
- * Method: getModifiers
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMMethod_getModifiers(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
-{
- jvmtiError err;
- jint modifiers;
-
- if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)->
- GetMethodModifiers(jvmtienv,
- (jmethodID)(long)this->_methodId,
- &modifiers))) {
- printjvmtierror("VMMethod.getModifiers GetMethodModifiers",err);
- return 0;
- }
-
- return modifiers;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMMethod
- * Method: getLineTable
- * Signature: ()Lgnu/classpath/jdwp/util/LineTable;
- */
-JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getLineTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
-{
- jclass cl;
- jmethodID m;
- jobject ol;
- jlongArray jlineCI;
- jintArray jlineNum;
- jint count = 0, i;
- int *lineNum;
- long *lineCI;
- jvmtiLineNumberEntry *lne;
- jlocation start,end;
-
- jvmtiError err;
-
- if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)->
- GetLineNumberTable(jvmtienv,
- (jmethodID)(long)this->_methodId,
- &count, &lne))) {
- printjvmtierror("VMMethod.getlinetable GetLineNumberTable",err);
- return NULL;
- }
-
- cl = (*env)->FindClass(env,"gnu.classpath.jdwp.util.LineTable");
- if (!cl) return NULL;
-
- m = (*env)->GetMethodID(env, cl, "<init>", "(JJ[I[J)V");
- if (!m) return NULL;
-
- jlineNum = (*env)->NewIntArray(env, count);
- if (!jlineNum) return NULL;
- jlineCI = (*env)->NewLongArray(env, count);
- if (!jlineCI) return NULL;
- lineNum = (*env)->GetIntArrayElements(env, jlineNum, NULL);
- lineCI = (*env)->GetLongArrayElements(env, jlineCI, NULL);
- for (i = 0; i < count; ++i) {
- lineNum[i] = lne[i].line_number;
- lineCI[i] = lne[i].start_location;
- }
- (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0);
- (*env)->ReleaseIntArrayElements(env, jlineNum, lineNum, 0);
- (*jvmtienv)->Deallocate(jvmtienv, lne);
-
- if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)->
- GetMethodLocation(jvmtienv,
- (jmethodID)(long)this->_methodId,
- &start, &end))) {
- printjvmtierror("VMMethod.getlinetable GetMethodLocation",err);
- return NULL;
- }
-
- ol = (*env)->NewObject(env, cl, m, start,
- end, jlineNum, jlineCI);
-
- return (struct gnu_classpath_jdwp_util_LineTable*)ol;
-
-}
-
-static bool fillVariableTable(JNIEnv *env, jvmtiLocalVariableEntry* entries,
- int count, jlongArray *jlineCI,
- jobjectArray *names, jobjectArray *sigs,
- jintArray *jlengths, jintArray *jslot) {
- jint *lengths, *slot,i;
- jclass cl;
- jlong *lineCI;
-
- *jlineCI = (*env)->NewLongArray(env, count);
- if (!*jlineCI) return false;
-
- cl=(*env)->FindClass(env,"java/lang/String");
- if (!cl) return false;
-
- *names = (*env)->NewObjectArray(env, count, cl, NULL);
- if (names) return false;
- sigs = (*env)->NewObjectArray(env, count, cl, NULL);
- if (sigs) return false;
-
- jlengths = (*env)->NewIntArray(env, count);
- if (!lengths) return false;
-
- jslot = (*env)->NewIntArray(env, count);
- if (!slot) return false;
-
- lineCI = (*env)->GetLongArrayElements(env, *jlineCI, NULL);
- lengths = (*env)->GetIntArrayElements(env, *jlengths, NULL);
- slot = (*env)->GetIntArrayElements(env, jslot, NULL);
-
- for (i=0; i<count; i++) {
- (*env)->
- SetObjectArrayElement(env, *names, i,
- (*env)->NewStringUTF(env,entries[i].name));
- (*env)->
- SetObjectArrayElement(env, *sigs, i, (*env)->NewStringUTF(
- env,entries[i].signature));
- lineCI[i]=entries[i].start_location;
- lengths[i]=entries[i].length;
- slot[i]=entries[i].slot;
- }
- (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0);
- (*env)->ReleaseIntArrayElements(env, jlengths, lengths, 0);
- (*env)->ReleaseIntArrayElements(env, jslot, slot, 0);
- return true;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMMethod
- * Method: getVariableTable
- * Signature: ()Lgnu/classpath/jdwp/util/VariableTable;
- */
-JNIEXPORT struct gnu_classpath_jdwp_util_VariableTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getVariableTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
-{
- jvmtiLocalVariableEntry* localvarentries;
- jint entry_count, argCnt, slots;
- jclass cl;
- jmethodID m, vmmethodid;
- jobject o;
- jobjectArray names, sigs;
- jvmtiError err;
- jlongArray jlineCI;
- jintArray jlengths, jslot;
-
- vmmethodid = (jmethodID)(long)this->_methodId;
-
- err= (*jvmtienv)->GetLocalVariableTable(jvmtienv,
- vmmethodid,
- &entry_count,
- &localvarentries);
- if (JVMTI_ERROR_NONE != err) {
- if (err == JVMTI_ERROR_ABSENT_INFORMATION) {
- /* no local variable table available for this method.
- return an empty local variable table */
- argCnt = slots = 0;
- names = sigs = jlineCI = jlengths = jslot = NULL;
- } else {
- printjvmtierror("VMMethod.getVariableTable GetLocalVariableTable",err);
- return NULL;
- }
- } else {
- if (JVMTI_ERROR_NONE != (err=
- (*jvmtienv)->GetArgumentsSize(jvmtienv,
- vmmethodid,
- &argCnt))) {
- printjvmtierror("VMMethod.getVariableTable GetArgumentsSize",err);
- return NULL;
- }
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->GetMaxLocals(jvmtienv,
- vmmethodid,
- &slots))) {
- printjvmtierror("VMMethod.getVariableTable GetMaxLocals",err);
- return NULL;
- }
-
- slots = slots - argCnt;
- if (!fillVariableTable(env, localvarentries, entry_count, &jlineCI,
- &names, &sigs, &jlengths, &jslot))
- return NULL;
- (*jvmtienv)->
- Deallocate(jvmtienv, (unsigned char*)localvarentries->signature);
- (*jvmtienv)->
- Deallocate(jvmtienv, (unsigned char*)localvarentries->name);
- if (localvarentries->generic_signature != NULL)
- (*jvmtienv)-> Deallocate(jvmtienv, (unsigned char*)
- localvarentries->generic_signature);
-
-
- (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)localvarentries);
- }
-
- cl = (*env)->FindClass(env,"gnu.classpath.jdwp.util.VariableTable");
- if (!cl) return NULL;
-
- m = (*env)->
- GetMethodID(env, cl,"<init>",
- "(II[J[Ljava/lang/String;[Ljava/lang/String;[I[I)V");
- if (!m) return NULL;
-
- o = (*env)->NewObject(env, cl, m, argCnt, slots, jlineCI,
- names, sigs, jlengths, jslot);
-
- return (struct gnu_classpath_jdwp_util_VariableTable*) o;
-}
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
+++ /dev/null
-/* src/native/vm/VMVirtualMachine.c - jdwp->jvmti interface
-
-Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
-C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-J. Wenninger, Institut f. Computersprachen - TU Wien
-
-This file is part of CACAO.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 2, or (at
-your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.
-
-Contact: cacao@cacaojvm.org
-
-Authors: Martin Platter
-
-Changes: Samuel Vinson
-
-
-$Id: VMVirtualMachine.c 5019 2006-06-06 21:13:41Z motse $
-
-*/
-
-#include "toolbox/logging.h"
-#include "native/jni.h"
-#include "native/include/java_lang_Thread.h"
-#include "native/include/java_nio_ByteBuffer.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_ClassLoader.h"
-#include "native/include/java_lang_reflect_Method.h"
-#include "native/include/gnu_classpath_jdwp_event_EventRequest.h"
-#include "native/include/gnu_classpath_jdwp_VMVirtualMachine.h"
-#include "native/jvmti/jvmti.h"
-#include "native/jvmti/VMjdwp.h"
-#include <string.h>
-
-
-/*
- * Class: gnu_classpath_jdwp_VMVirtualMachine
- * Method: suspendThread
- * Signature: (Ljava/lang/Thread;)V
- */
-JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1)
-{
- jvmtiError err;
-
- err = (*jvmtienv)->SuspendThread(jvmtienv, (jthread) par1);
- printjvmtierror("VMVirtualMachine.suspendThread SuspendThread", err);
-}
-
-/*
- * Class: gnu_classpath_jdwp_VMVirtualMachine
- * Method: resumeThread
- * Signature: (Ljava/lang/Thread;)V
- */
-JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_resumeThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1)
-{
- jvmtiError err;
-
- err = (*jvmtienv)->ResumeThread(jvmtienv, (jthread) par1);
- printjvmtierror("VMVirtualMachine.resumethread ResumeThread", err);
-}
-
-
-/*
- * Class: gnu_classpath_jdwp_VMVirtualMachine
- * Method: getSuspendCount
- * Signature: (Ljava/lang/Thread;)I
- */
-JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getSuspendCount(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
- log_text ("VMVirtualMachine_getSuspendCount: not supported");
- return 1;
-}
-
-/*
- * Class: gnu_classpath_jdwp_VMVirtualMachine
- * Method: getAllLoadedClassesCount
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClassesCount(JNIEnv *env, jclass clazz) {
- jint count;
- jclass* classes;
- jvmtiError err;
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
- GetLoadedClasses(jvmtienv, &count, &classes))) {
- printjvmtierror("VMVirtualMachine_getAllLoadedClassCount GetLoadedClasses",err);
- return 0;
- }
- (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)classes);
- return count;
-}
-
-/*
- * Class: gnu_classpath_jdwp_VMVirtualMachine
- * Method: getAllLoadedClasses
- * Signature: ()Ljava/util/Iterator
- */
-JNIEXPORT struct java_util_Iterator* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClasses(JNIEnv *env, jclass clazz) {
- jclass *classes, *cl;
- jint classcount;
- jobjectArray joa;
-/* jthrowable e;*/
- jmethodID m;
- jobject *ol,*oi;
- int i;
- jvmtiError err;
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
- GetLoadedClasses(jvmtienv, &classcount, &classes))) {
- printjvmtierror("VMVirtualMachine_getAllLoadedClasses GetLoadedClasses",err);
-
- /* we should throw JDWP Exception INTERNAL = 113;*/
-/* env->ThrowNew(env,ec,"jvmti error occoured"); */
- return NULL;
- }
-
- cl = (*env)->FindClass(env,"java.lang.Class");
- if (!cl) return NULL;
-
- /* Arrays.asList(Object[] classes)->List.Iterator()->Iterator */
- joa = (*env)->NewObjectArray(env, (jsize)classcount, cl , NULL);
- if (!joa) return NULL;
-
- for (i = 0; i < classcount; i++)
- (*env)->SetObjectArrayElement(env,joa,(jsize)i, (jobject)classes[i]);
- (*jvmtienv)->Deallocate(jvmtienv, (unsigned char*)classes);
-
- cl = (*env)->FindClass(env,"java.util.Arrays");
- if (!cl) return NULL;
-
- m = (*env)->GetStaticMethodID(env, cl, "asList", "([Ljava/lang/Object;)Ljava/util/List;");
- if (!m) return NULL;
-
- ol = (*env)->CallStaticObjectMethod(env,(jclass)cl,m,joa);
- if (!ol) return NULL;
-
- cl = (*env)->FindClass(env,"java.util.List");
- if (!cl) return NULL;
- m = (*env)->GetMethodID(env,cl,"iterator","()Ljava/util/Iterator;");
- if (!m) return NULL;
- oi = (*env)->CallObjectMethod(env,ol,m);
-
- return (struct java_util_Iterator*)oi;
-}
-
-/* Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getClassStatus
- * Signature: (Ljava/lang/Class;)I
- */
-JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getClassStatus(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
- jint status;
- jvmtiError err;
-
- err = (*jvmtienv)->GetClassStatus(jvmtienv, (jclass) par1, &status);
- printjvmtierror("VMVirtualMachine_getClassStatus GetClassStatus", err);
-
- return status;
-}
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getAllClassMethods
- * Signature: (Ljava/lang/Class;)[Lgnu/classpath/jdwp/VMMethod;
- */
-JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllClassMethods(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
- jint count;
- jmethodID* methodID, m;
- jvmtiError err;
-
- jclass *cl;
- jobject *ol;
- jobjectArray joa;
- int i;
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
- GetClassMethods(jvmtienv, (jclass) par1,
- &count, &methodID))) {
- printjvmtierror("VMVirtualMachine_getAllClassMethods GetClassMethods", err);
- return NULL;
- }
-
- m = (*env)->
- GetStaticMethodID(env, clazz, "getClassMethod",
- "(Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;");
- if (!m) return NULL;
-
- cl = (*env)->FindClass(env,"gnu.classpath.jdwp.VMMethod");
- if (!cl) return NULL;
-
- joa = (*env)->NewObjectArray(env, (jsize)count, cl , NULL);
- if (!joa) return NULL;
-
- for (i = 0; i < count; i++) {
- ol = (*env)->
- CallStaticObjectMethod(env,clazz,m,(jobject)par1, methodID[i]);
- if (!ol) return NULL;
- (*env)->SetObjectArrayElement(env,joa,(jsize)i, ol);
- }
- return joa;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getClassMethod
- * Signature: (Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;
- */
-JNIEXPORT struct gnu_classpath_jdwp_VMMethod* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getClassMethod(JNIEnv *env, jclass clazz, struct java_lang_Class* par1, s8 par2) {
- jclass *cl;
- jmethodID m;
- jobject *ol;
-
- cl = (*env)->FindClass(env,"gnu.classpath.jdwp.VMMethod");
- if (!cl) return NULL;
-
- m = (*env)->GetMethodID(env, cl, "<init>", "(Ljava/lang/Class;J)V");
- if (!m) return NULL;
-
- ol = (*env)->NewObject(env, cl, m, par1, par2);
-
- return (struct gnu_classpath_jdwp_VMMethod*)ol;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getFrames
- * Signature: (Ljava/lang/Thread;II)Ljava/util/ArrayList;
- */
-JNIEXPORT struct java_util_ArrayList* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrames(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1, s4 par2, s4 par3) {
- log_text ("VMVirtualMachine_getFrames - IMPLEMENT ME!!!");
-/* jclass ec = (*env)->FindClass(env,"gnu/classpath/jdwp/JdwpInternalErrorException");
- if (JVMTI_ERROR_NONE != (*jvmtienv)->GetClassStatus(jvmtienv, par1, &status))
- env->ThrowNew(env,ec,"jvmti error occoured");*/
- return 0;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getFrame
- * Signature: (Ljava/lang/Thread;Ljava/nio/ByteBuffer;)Lgnu/classpath/jdwp/VMFrame;
- */
-JNIEXPORT struct gnu_classpath_jdwp_VMFrame* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrame(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1, struct java_nio_ByteBuffer* par2) {
- log_text ("VMVirtualMachine_getFrame - IMPLEMENT ME!!!");
- return 0;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getFrameCount
- * Signature: (Ljava/lang/Thread;)I
- */
-JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
- jint count;
- jvmtiError err;
- err = (*jvmtienv)->GetFrameCount(jvmtienv, (jthread)par1, &count);
- printjvmtierror("VMVirtualMachine_getFrameCount GetFrameCount", err);
- return count;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getThreadStatus
- * Signature: (Ljava/lang/Thread;)I
- */
-JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getThreadStatus(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
- jint status;
- jvmtiError err;
- if (JVMTI_ERROR_NONE != (err = (*jvmtienv)->GetThreadState(jvmtienv, (jthread)par1, &status))) {
- printjvmtierror("VMVirtualMachine_getThreadStatus GetThreadState", err);
- return 0;
- }
- if (status && JVMTI_THREAD_STATE_ALIVE) {
- if (status && JVMTI_THREAD_STATE_WAITING) {
- return 4; /* WAIT - see JdwpConstants */
- }
- if (status && JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) {
- return 3; /* MONITOR - see JdwpConstants */
- }
- if (status && JVMTI_THREAD_STATE_SLEEPING) {
- return 2; /* SLEEPING - see JdwpConstants */
- }
- return 1; /* RUNNING - see JdwpConstants */
- } else
- return 0; /* ZOMBIE - see JdwpConstants */
- return -1; /* some error */
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getLoadRequests
- * Signature: (Ljava/lang/ClassLoader;)Ljava/util/ArrayList;
- */
-JNIEXPORT struct java_util_ArrayList* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getLoadRequests(JNIEnv *env, jclass clazz, struct java_lang_ClassLoader* par1) {
- log_text ("VMVirtualMachine_getLoadRequests(");
- return 0;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: executeMethod
- * Signature: (Ljava/lang/Object;Ljava/lang/Thread;Ljava/lang/Class;Ljava/lang/reflect/Method;[Ljava/lang/Object;Z)Lgnu/classpath/jdwp/util/MethodResult;
- */
-JNIEXPORT struct gnu_classpath_jdwp_util_MethodResult* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_executeMethod(JNIEnv *env, jclass clazz, struct java_lang_Object* par1, struct java_lang_Thread* par2, struct java_lang_Class* par3, struct java_lang_reflect_Method* par4, java_objectarray* par5, s4 par6) {
- log_text ("VMVirtualMachine_executeMethod");
- return 0;
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: getSourceFile
- * Signature: (Ljava/lang/Class;)Ljava/lang/String;
- */
-JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getSourceFile(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
- char* srcname;
- jstring str;
- jvmtiError err;
-
- if (JVMTI_ERROR_NONE !=(err=(*jvmtienv)->
- GetSourceFileName(jvmtienv, (jclass)par1, &srcname))) {
- printjvmtierror("VMVirtualMachine.getSourceFile GetSourceFileName", err);
- return NULL;
- }
-
- str = (*env)->NewString(env,(jchar*)srcname,(jsize)strlen(srcname));
-
- return (struct java_lang_String*)str;
-}
-
-/* match JdwpConstants.EventKind to jvmtiEvent constants */
-static jvmtiEvent EventKind2jvmtiEvent(jbyte kind){
- switch (kind) {
- case /* SINGLE_STEP */ 1: return JVMTI_EVENT_SINGLE_STEP;
- case /* BREAKPOINT */ 2: return JVMTI_EVENT_BREAKPOINT;
- case /* FRAME_POP */ 3: return JVMTI_EVENT_FRAME_POP;
- case /* EXCEPTION */ 4: return JVMTI_EVENT_EXCEPTION;
- case /* USER_DEFINED */ 5: return -1; /* can this be matched ? */
- case /* THREAD_START */ 6: return JVMTI_EVENT_THREAD_START;
- case /* THREAD_END */ 7: return JVMTI_EVENT_THREAD_END;
- case /* CLASS_PREPARE */ 8: return JVMTI_EVENT_CLASS_PREPARE;
- case /* CLASS_UNLOAD */ 9: return -1; /* can this be matched ? */
- case /* CLASS_LOAD */ 10: return JVMTI_EVENT_CLASS_LOAD;
- case /* FIELD_ACCESS */ 20: return JVMTI_EVENT_FIELD_ACCESS;
- case /* FIELD_MODIFICATION */ 21: return JVMTI_EVENT_FIELD_MODIFICATION;
- case /* EXCEPTION_CATCH */ 30: return JVMTI_EVENT_EXCEPTION_CATCH;
- case /* METHOD_ENTRY */ 40: return JVMTI_EVENT_METHOD_ENTRY;
- case /* METHOD_EXIT */ 41: return JVMTI_EVENT_METHOD_EXIT;
- case /* VM_INIT */ 90: return JVMTI_EVENT_VM_INIT;
- case /* VM_DEATH */ 99: return JVMTI_EVENT_VM_DEATH;
- case /* VM_DISCONNECTED */ 100: return -1; /* can this be matched ? */
- default: return -1;
- }
-}
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: registerEvent
- * Signature: (Lgnu/classpath/jdwp/event/EventRequest;)V
- */
-JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent(JNIEnv *env, jclass clazz, struct gnu_classpath_jdwp_event_EventRequest* par1) {
- jbyte kind;
- jfieldID kindid;
- jclass erc;
- jvmtiError err;
-
- erc = (*env)->FindClass(env,"gnu.classpath.jdwp.event.EventRequest");
-
- kindid = (*env)->GetFieldID(env, erc, "_kind", "B");
- kind = (*env)->GetByteField(env, (jobject)par1, kindid);
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
- SetEventNotificationMode(jvmtienv, JVMTI_ENABLE,
- EventKind2jvmtiEvent(kind), NULL)))
- printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
-
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: unregisterEvent
- * Signature: (Lgnu/classpath/jdwp/event/EventRequest;)V
- */
-JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent(JNIEnv *env, jclass clazz, struct gnu_classpath_jdwp_event_EventRequest* par1) {
- jbyte kind;
- jfieldID kindid;
- jclass erc;
- jvmtiError err;
-
- erc = (*env)->FindClass(env,"gnu.classpath.jdwp.event.EventRequest");
-
- kindid = (*env)->GetFieldID(env, erc, "_kind", "B");
- kind = (*env)->GetByteField(env, (jobject)par1, kindid);
-
- if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
- SetEventNotificationMode(jvmtienv, JVMTI_DISABLE,
- EventKind2jvmtiEvent(kind), NULL)))
- printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
-
-}
-
-
-/*
- * Class: gnu/classpath/jdwp/VMVirtualMachine
- * Method: clearEvents
- * Signature: (B)V
- */
-JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_clearEvents(JNIEnv *env, jclass clazz, s4 par1) {
- /* jvmti events are not saved - there is nothing to clear */
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
--- /dev/null
+/* src/native/vm/VMjdwp.c - jvmti->jdwp interface
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Author: Martin Platter
+
+ Changes:
+
+
+ $Id: VMjdwp.c 5157 2006-07-18 11:09:47Z twisti $
+
+*/
+
+#include "native/jvmti/jvmti.h"
+#include "native/jvmti/VMjdwp.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+void printjvmtierror(char *desc, jvmtiError err) {
+ char* errdesc;
+
+ if (err == JVMTI_ERROR_NONE) return;
+ (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
+ fprintf(stderr,"%s: jvmti error %s\n",desc, errdesc);
+ fflush(stderr);
+ (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
+}
+
+
+/* class and method IDs */
+static jclass Jdwpclass, threadstartclass,threadendclass, classprepareclass, vmmethodclass, locationclass, breakpointclass;
+static jmethodID notifymid, threadstartmid,threadendmid, classpreparemid,
+ vmmethodmid, locationmid, breakpointmid;
+
+static void notify (JNIEnv* jni_env, jobject event){
+ fprintf(stderr,"VMjdwp notfiy called\n");
+
+ (*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);
+ }
+
+}
+
+static void ThreadStart (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+ jthread thread){
+ jobject obj;
+
+ obj = (*jni_env)->
+ NewObject(jni_env, threadstartclass, threadstartmid, thread);
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+ fprintf(stderr,"error calling ThreadStartEvent constructor\n");
+ (*jni_env)->ExceptionDescribe(jni_env);
+ return;
+ }
+
+ fprintf(stderr,"VMjdwp:ThreadStart: thread %p\n",thread);
+ fflush(stderr);
+
+ notify (jni_env,obj);
+}
+
+
+static void ThreadEnd (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+ jthread thread){
+ jobject obj;
+
+
+ obj = (*jni_env)->NewObject(jni_env, threadendclass, threadendmid, thread);
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+ fprintf(stderr,"error calling ThreadEndEvent constructor\n");
+ (*jni_env)->ExceptionDescribe(jni_env);
+ return;
+ }
+
+ fprintf(stderr,"VMjdwp:ThreadEnd: thread %p\n",thread);
+ fflush(stderr);
+
+ notify (jni_env,obj);
+}
+
+
+static void ClassPrepare (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+ jthread thread, jclass klass) {
+ jobject obj;
+ int classstatus;
+ jvmtiError e;
+
+ if (JVMTI_ERROR_NONE !=
+ (e = (*jvmtienv)->GetClassStatus(jvmtienv, klass, &classstatus))) {
+ printjvmtierror("unable to get class status", e);
+ return;
+ }
+
+ obj = (*jni_env)->NewObject(jni_env, classprepareclass, classpreparemid, thread, klass, classstatus);
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+ fprintf(stderr,"error calling ClassPrepareEvent constructor\n");
+ (*jni_env)->ExceptionDescribe(jni_env);
+ return;
+ }
+
+ fprintf(stderr,"VMjdwp:ClassPrepareEvent: thread %p\n",thread);
+ fflush(stderr);
+
+ notify (jni_env,obj);
+}
+
+static void Exception (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
+ jmethodID method, jlocation location, jobject exception,
+ jmethodID catch_method, jlocation catch_location) {
+ /* gnu classpath jdwp has no ExceptionEvent yet */
+ fprintf(stderr,"VMjdwp:Exception: thread %p\n",thread);
+ fflush(stderr);
+
+}
+
+static void Breakpoint (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
+ jmethodID method, jlocation location) {
+ jobject vmmethod, loc, ev;
+ jclass mcl;
+ jvmtiError e;
+
+ if (JVMTI_ERROR_NONE !=
+ (e = (*jvmtienv)->GetMethodDeclaringClass(jvmtienv,
+ method,
+ &mcl))){
+ printjvmtierror("unable to get declaring class", e);
+ return;
+ }
+
+ vmmethod = (*jni_env)->NewObject(jni_env, vmmethodclass, vmmethodmid,
+ mcl, method);
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+ fprintf(stderr,"error calling VMMethod constructor\n");
+ (*jni_env)->ExceptionDescribe(jni_env);
+ return;
+ }
+
+ loc = (*jni_env)->NewObject(jni_env, locationclass, locationmid,
+ vmmethod, location);
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+ fprintf(stderr,"error calling location constructor\n");
+ (*jni_env)->ExceptionDescribe(jni_env);
+ return;
+ }
+
+ /* XXX todo: get object instance - needs jvmti local variable support */
+ ev = (*jni_env)->NewObject(jni_env, breakpointclass, breakpointmid,
+ thread, loc,NULL);
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+ fprintf(stderr,"error calling breakpoint constructor\n");
+ (*jni_env)->ExceptionDescribe(jni_env);
+ return;
+ }
+
+ fprintf(stderr,"VMjdwp:Breakpoint: thread %p\n",thread);
+ fflush(stderr);
+
+ notify (jni_env,ev);
+}
+
+
+static void MethodEntry (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+ jthread thread, jmethodID method) {
+ /* do not report gnu/classpath/jdwp method entries */
+}
+
+
+static void VMDeath (jvmtiEnv *jvmti_env,
+ JNIEnv* jni_env) {
+ fprintf(stderr,"JVMTI-Event: IMPLEMENT ME!!!");
+}
+
+
+/* setup_jdwp_thread **********************************************************
+
+ Helper function to start JDWP listening thread
+
+*******************************************************************************/
+
+static void setup_jdwp_thread(JNIEnv* jni_env) {
+ jobject o;
+ jmethodID m;
+ jstring s;
+
+ /* new gnu.classpath.jdwp.Jdwp() */
+ 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);
+ }
+
+ jdwpthread = (jthread)o;
+
+
+ /* 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);
+ }
+
+
+ s = (*jni_env)->NewStringUTF(jni_env,jdwpoptions);
+ if (s == NULL) {
+ fprintf(stderr,"could not get new java string from jdwp options\n");
+ exit(1);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+
+ (*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);
+ }
+}
+
+#define FINDCLASSWITHEXCEPTION(CLASS,SIGNATURE) \
+ CLASS = (*jni_env)->FindClass(jni_env, SIGNATURE); \
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { \
+ fprintf(stderr,"could not find %s\n", SIGNATURE); \
+ (*jni_env)->ExceptionDescribe(jni_env); \
+ exit(1); \
+ }
+#define GETMIDWITHEXCEPTION(CLASS, CLASSNAME, MID, METHODNAME, METHODSIG) \
+ FINDCLASSWITHEXCEPTION(CLASS, CLASSNAME); \
+ MID = (*jni_env)->GetMethodID(jni_env, CLASS, METHODNAME, METHODSIG); \
+ if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) { \
+ fprintf(stderr,"could not get %s %s\n",CLASSNAME, METHODNAME); \
+ (*jni_env)->ExceptionDescribe(jni_env); \
+ exit(1); \
+ }
+
+
+static void fillidcache(JNIEnv* jni_env) {
+ FINDCLASSWITHEXCEPTION(Jdwpclass, "gnu/classpath/jdwp/Jdwp");
+
+ 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);
+ }
+
+ GETMIDWITHEXCEPTION(threadstartclass,
+ "gnu/classpath/jdwp/event/ThreadStartEvent",
+ threadstartmid, "<init>", "(Ljava/lang/Thread;)V");
+
+
+ GETMIDWITHEXCEPTION(threadendclass,
+ "gnu/classpath/jdwp/event/ThreadEndEvent",
+ threadendmid, "<init>", "(Ljava/lang/Thread;)V");
+
+
+ GETMIDWITHEXCEPTION(classprepareclass,
+ "gnu/classpath/jdwp/event/ClassPrepareEvent",
+ classpreparemid, "<init>",
+ "(Ljava/lang/Thread;Ljava/lang/Class;I)V");
+
+
+ GETMIDWITHEXCEPTION(vmmethodclass, "gnu/classpath/jdwp/VMMethod",
+ vmmethodmid, "<init>", "(Ljava/lang/Class;J)V");
+
+ GETMIDWITHEXCEPTION(locationclass, "gnu/classpath/jdwp/util/Location",
+ locationmid, "<init>",
+ "(Lgnu/classpath/jdwp/VMMethod;J)V");
+
+
+ GETMIDWITHEXCEPTION(
+ breakpointclass,
+ "gnu/classpath/jdwp/event/BreakpointEvent",
+ breakpointmid, "<init>",
+ "(Ljava/lang/Thread;Lgnu/classpath/jdwp/util/Location;Ljava/lang/Object;)V");
+
+}
+
+static void VMInit (jvmtiEnv *jvmti_env,
+ JNIEnv* jni_env,
+ jthread thread) {
+ jclass cl;
+ jmethodID m;
+ jobject eventobj;
+ jvmtiError err;
+
+ fprintf(stderr,"JDWP VMInit\n");
+
+ /* get needed jmethodIDs and jclasses for callbacks */
+ fillidcache(jni_env);
+
+ /* startup gnu classpath jdwp thread */
+ setup_jdwp_thread(jni_env);
+
+ fprintf(stderr,"JDWP listening thread started\n");
+
+ /* send VmInitEvent */
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+
+ notify (jni_env,eventobj);
+
+ if (suspend) {
+ fprintf(stderr,"suspend initial thread\n");
+ err = (*jvmti_env)->SuspendThread(jvmti_env,thread);
+ printjvmtierror("error suspending initial thread",err);
+ }
+}
+
+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 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;
+}
+
+
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
+ jint rc;
+ jvmtiCapabilities cap;
+ jvmtiError e;
+
+
+ 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 !=
+ (e = (*jvmtienv)->SetEventCallbacks(jvmtienv,
+ &jvmti_jdwp_EventCallbacks,
+ sizeof(jvmtiEventCallbacks)))){
+ printjvmtierror("jdwp: unable to setup event callbacks", e);
+ return -1;
+ }
+
+ e = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &cap);
+ printjvmtierror("jdwp: unable to get potential capabilities", e);
+ if (e == JVMTI_ERROR_NONE)
+ e = (*jvmtienv)->AddCapabilities(jvmtienv, &cap);
+ if (e != JVMTI_ERROR_NONE) {
+ printjvmtierror("jdwp: error adding jvmti capabilities", e);
+ return -1;
+ }
+
+ /* only enable needed events. VMVirtualMachine.registerEvent will
+ be used to enable other events by need */
+ if (JVMTI_ERROR_NONE != (e = (*jvmtienv)->
+ SetEventNotificationMode(jvmtienv, JVMTI_ENABLE,
+ JVMTI_EVENT_VM_INIT,
+ NULL))) {
+ printjvmtierror("jdwp unable to enable vm init callback",e);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+jvmtiEventCallbacks jvmti_jdwp_EventCallbacks = {
+ &VMInit,
+ &VMDeath,
+ &ThreadStart,
+ &ThreadEnd,
+ NULL, /* &ClassFileLoadHook, */
+ NULL, /* &ClassLoad, */
+ &ClassPrepare,
+ NULL, /* &VMStart */
+ &Exception,
+ NULL, /* &ExceptionCatch, */
+ NULL, /* &SingleStep, */
+ NULL, /* &FramePop, */
+ &Breakpoint,
+ NULL, /* &FieldAccess, */
+ NULL, /* &FieldModification, */
+ &MethodEntry,
+ NULL, /* &MethodExit, */
+ NULL, /* &NativeMethodBind, */
+ NULL, /* &CompiledMethodLoad, */
+ NULL, /* &CompiledMethodUnload, */
+ NULL, /* &DynamicCodeGenerated, */
+ NULL, /* &DataDumpRequest, */
+ NULL,
+ NULL, /* &MonitorWait, */
+ NULL, /* &MonitorWaited, */
+ NULL, /* &MonitorContendedEnter, */
+ NULL, /* &MonitorContendedEntered, */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* &GarbageCollectionStart, */
+ NULL, /* &GarbageCollectionFinish, */
+ NULL, /* &ObjectFree, */
+ NULL, /* &VMObjectAlloc, */
+};
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMjdwp.c - jvmti->jdwp interface
+
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Contact: cacao@cacaojvm.org
+
+ Author: Martin Platter
+
+ Changes:
+
+
+ $Id: VMjdwp.c 4661 2006-03-21 00:04:59Z motse $
+
+*/
+
+#ifndef _VMJDWP_H
+#define _VMJDWP_H
+
+#include "native/jvmti/jvmti.h"
+
+jvmtiEnv* jvmtienv;
+extern jvmtiEventCallbacks jvmti_jdwp_EventCallbacks;
+char* jdwpoptions;
+bool suspend; /* should the virtual machine suspend on startup? */
+jthread jdwpthread;
+
+void printjvmtierror(char *desc, jvmtiError err);
+#endif
--- /dev/null
+/* src/native/vm/VMFrame.c - jdwp->jvmti interface
+
+Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+J. Wenninger, Institut f. Computersprachen - TU Wien
+
+This file is part of CACAO.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+Contact: cacao@cacaojvm.org
+
+Authors: Martin Platter
+
+Changes:
+
+
+$Id: gnu_classpath_jdwp_VMFrame.c 5157 2006-07-18 11:09:47Z twisti $
+
+*/
+
+#include "toolbox/logging.h"
+#include "native/jni.h"
+#include "native/include/gnu_classpath_jdwp_VMFrame.h"
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMFrame
+ * Method: getValue
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT struct java_lang_Object* JNICALL Java_gnu_classpath_jdwp_VMFrame_getValue(JNIEnv *env, struct gnu_classpath_jdwp_VMFrame* this, s4 par1) {
+ log_text ("JVMTI-Call: IMPLEMENT ME!!!");
+ return 0;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMFrame
+ * Method: setValue
+ * Signature: (ILjava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMFrame_setValue(JNIEnv *env, struct gnu_classpath_jdwp_VMFrame* this, s4 par1, struct java_lang_Object* par2) {
+ log_text ("JVMTI-Call: IMPLEMENT ME!!!");
+ return 0;
+}
--- /dev/null
+/* src/native/vm/VMMethod.c - jdwp->jvmti interface
+
+Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+J. Wenninger, Institut f. Computersprachen - TU Wien
+
+This file is part of CACAO.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+Contact: cacao@cacaojvm.org
+
+Authors: Samuel Vinson
+ Martin Platter
+
+
+Changes:
+
+
+$Id: VMMethod.c $
+
+*/
+
+#include "native/jni.h"
+#include "native/include/gnu_classpath_jdwp_VMMethod.h"
+#include "native/jvmti/jvmti.h"
+#include "native/jvmti/VMjdwp.h"
+
+
+void printjvmtierror(char *desc, jvmtiError err) {
+ char* errdesc;
+
+ if (err == JVMTI_ERROR_NONE) return;
+ (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
+ fprintf(stderr,"%s: jvmti error %s\n",desc, errdesc);
+ fflush(stderr);
+ (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
+}
+
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMMethod
+ * Method: getName
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getName(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+{
+ jvmtiError err;
+ char *name;
+ jstring stringname;
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+ GetMethodName(jvmtienv,
+ (jmethodID)(long)this->_methodId,
+ &name,NULL, NULL))) {
+ printjvmtierror("VMMethod.getName GetMethodName",err);
+ return NULL;
+ }
+
+ stringname = (*env)->NewStringUTF(env,name);
+ (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)name);
+
+ return stringname;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMMethod
+ * Method: getSignature
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getSignature(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+{
+ jvmtiError err;
+ char *signature;
+ jstring stringsignature;
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+ GetMethodName(jvmtienv,
+ (jmethodID)(long)this->_methodId,
+ NULL, &signature, NULL))) {
+ printjvmtierror("VMMethod.getSignature GetMethodName",err);
+ return NULL;
+ }
+
+ stringsignature = (*env)->NewStringUTF(env,signature);
+ (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)signature);
+
+ return stringsignature;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMMethod
+ * Method: getModifiers
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMMethod_getModifiers(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+{
+ jvmtiError err;
+ jint modifiers;
+
+ if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)->
+ GetMethodModifiers(jvmtienv,
+ (jmethodID)(long)this->_methodId,
+ &modifiers))) {
+ printjvmtierror("VMMethod.getModifiers GetMethodModifiers",err);
+ return 0;
+ }
+
+ return modifiers;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMMethod
+ * Method: getLineTable
+ * Signature: ()Lgnu/classpath/jdwp/util/LineTable;
+ */
+JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getLineTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+{
+ jclass cl;
+ jmethodID m;
+ jobject ol;
+ jlongArray jlineCI;
+ jintArray jlineNum;
+ jint count = 0, i;
+ int *lineNum;
+ long *lineCI;
+ jvmtiLineNumberEntry *lne;
+ jlocation start,end;
+
+ jvmtiError err;
+
+ if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)->
+ GetLineNumberTable(jvmtienv,
+ (jmethodID)(long)this->_methodId,
+ &count, &lne))) {
+ printjvmtierror("VMMethod.getlinetable GetLineNumberTable",err);
+ return NULL;
+ }
+
+ cl = (*env)->FindClass(env,"gnu.classpath.jdwp.util.LineTable");
+ if (!cl) return NULL;
+
+ m = (*env)->GetMethodID(env, cl, "<init>", "(JJ[I[J)V");
+ if (!m) return NULL;
+
+ jlineNum = (*env)->NewIntArray(env, count);
+ if (!jlineNum) return NULL;
+ jlineCI = (*env)->NewLongArray(env, count);
+ if (!jlineCI) return NULL;
+ lineNum = (*env)->GetIntArrayElements(env, jlineNum, NULL);
+ lineCI = (*env)->GetLongArrayElements(env, jlineCI, NULL);
+ for (i = 0; i < count; ++i) {
+ lineNum[i] = lne[i].line_number;
+ lineCI[i] = lne[i].start_location;
+ }
+ (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0);
+ (*env)->ReleaseIntArrayElements(env, jlineNum, lineNum, 0);
+ (*jvmtienv)->Deallocate(jvmtienv, lne);
+
+ if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)->
+ GetMethodLocation(jvmtienv,
+ (jmethodID)(long)this->_methodId,
+ &start, &end))) {
+ printjvmtierror("VMMethod.getlinetable GetMethodLocation",err);
+ return NULL;
+ }
+
+ ol = (*env)->NewObject(env, cl, m, start,
+ end, jlineNum, jlineCI);
+
+ return (struct gnu_classpath_jdwp_util_LineTable*)ol;
+
+}
+
+static bool fillVariableTable(JNIEnv *env, jvmtiLocalVariableEntry* entries,
+ int count, jlongArray *jlineCI,
+ jobjectArray *names, jobjectArray *sigs,
+ jintArray *jlengths, jintArray *jslot) {
+ jint *lengths, *slot,i;
+ jclass cl;
+ jlong *lineCI;
+
+ *jlineCI = (*env)->NewLongArray(env, count);
+ if (!*jlineCI) return false;
+
+ cl=(*env)->FindClass(env,"java/lang/String");
+ if (!cl) return false;
+
+ *names = (*env)->NewObjectArray(env, count, cl, NULL);
+ if (names) return false;
+ sigs = (*env)->NewObjectArray(env, count, cl, NULL);
+ if (sigs) return false;
+
+ jlengths = (*env)->NewIntArray(env, count);
+ if (!lengths) return false;
+
+ jslot = (*env)->NewIntArray(env, count);
+ if (!slot) return false;
+
+ lineCI = (*env)->GetLongArrayElements(env, *jlineCI, NULL);
+ lengths = (*env)->GetIntArrayElements(env, *jlengths, NULL);
+ slot = (*env)->GetIntArrayElements(env, jslot, NULL);
+
+ for (i=0; i<count; i++) {
+ (*env)->
+ SetObjectArrayElement(env, *names, i,
+ (*env)->NewStringUTF(env,entries[i].name));
+ (*env)->
+ SetObjectArrayElement(env, *sigs, i, (*env)->NewStringUTF(
+ env,entries[i].signature));
+ lineCI[i]=entries[i].start_location;
+ lengths[i]=entries[i].length;
+ slot[i]=entries[i].slot;
+ }
+ (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0);
+ (*env)->ReleaseIntArrayElements(env, jlengths, lengths, 0);
+ (*env)->ReleaseIntArrayElements(env, jslot, slot, 0);
+ return true;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMMethod
+ * Method: getVariableTable
+ * Signature: ()Lgnu/classpath/jdwp/util/VariableTable;
+ */
+JNIEXPORT struct gnu_classpath_jdwp_util_VariableTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getVariableTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+{
+ jvmtiLocalVariableEntry* localvarentries;
+ jint entry_count, argCnt, slots;
+ jclass cl;
+ jmethodID m, vmmethodid;
+ jobject o;
+ jobjectArray names, sigs;
+ jvmtiError err;
+ jlongArray jlineCI;
+ jintArray jlengths, jslot;
+
+ vmmethodid = (jmethodID)(long)this->_methodId;
+
+ err= (*jvmtienv)->GetLocalVariableTable(jvmtienv,
+ vmmethodid,
+ &entry_count,
+ &localvarentries);
+ if (JVMTI_ERROR_NONE != err) {
+ if (err == JVMTI_ERROR_ABSENT_INFORMATION) {
+ /* no local variable table available for this method.
+ return an empty local variable table */
+ argCnt = slots = 0;
+ names = sigs = jlineCI = jlengths = jslot = NULL;
+ } else {
+ printjvmtierror("VMMethod.getVariableTable GetLocalVariableTable",err);
+ return NULL;
+ }
+ } else {
+ if (JVMTI_ERROR_NONE != (err=
+ (*jvmtienv)->GetArgumentsSize(jvmtienv,
+ vmmethodid,
+ &argCnt))) {
+ printjvmtierror("VMMethod.getVariableTable GetArgumentsSize",err);
+ return NULL;
+ }
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->GetMaxLocals(jvmtienv,
+ vmmethodid,
+ &slots))) {
+ printjvmtierror("VMMethod.getVariableTable GetMaxLocals",err);
+ return NULL;
+ }
+
+ slots = slots - argCnt;
+ if (!fillVariableTable(env, localvarentries, entry_count, &jlineCI,
+ &names, &sigs, &jlengths, &jslot))
+ return NULL;
+ (*jvmtienv)->
+ Deallocate(jvmtienv, (unsigned char*)localvarentries->signature);
+ (*jvmtienv)->
+ Deallocate(jvmtienv, (unsigned char*)localvarentries->name);
+ if (localvarentries->generic_signature != NULL)
+ (*jvmtienv)-> Deallocate(jvmtienv, (unsigned char*)
+ localvarentries->generic_signature);
+
+
+ (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)localvarentries);
+ }
+
+ cl = (*env)->FindClass(env,"gnu.classpath.jdwp.util.VariableTable");
+ if (!cl) return NULL;
+
+ m = (*env)->
+ GetMethodID(env, cl,"<init>",
+ "(II[J[Ljava/lang/String;[Ljava/lang/String;[I[I)V");
+ if (!m) return NULL;
+
+ o = (*env)->NewObject(env, cl, m, argCnt, slots, jlineCI,
+ names, sigs, jlengths, jslot);
+
+ return (struct gnu_classpath_jdwp_util_VariableTable*) o;
+}
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/native/vm/VMVirtualMachine.c - jdwp->jvmti interface
+
+Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+J. Wenninger, Institut f. Computersprachen - TU Wien
+
+This file is part of CACAO.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+Contact: cacao@cacaojvm.org
+
+Authors: Martin Platter
+
+Changes: Samuel Vinson
+
+
+$Id: gnu_classpath_jdwp_VMVirtualMachine.c 5157 2006-07-18 11:09:47Z twisti $
+
+*/
+
+#include "toolbox/logging.h"
+#include "native/jni.h"
+#include "native/include/java_lang_Thread.h"
+#include "native/include/java_nio_ByteBuffer.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_ClassLoader.h"
+#include "native/include/java_lang_reflect_Method.h"
+#include "native/include/gnu_classpath_jdwp_event_EventRequest.h"
+#include "native/include/gnu_classpath_jdwp_VMVirtualMachine.h"
+#include "native/jvmti/jvmti.h"
+#include "native/jvmti/VMjdwp.h"
+#include <string.h>
+
+
+/*
+ * Class: gnu_classpath_jdwp_VMVirtualMachine
+ * Method: suspendThread
+ * Signature: (Ljava/lang/Thread;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1)
+{
+ jvmtiError err;
+
+ err = (*jvmtienv)->SuspendThread(jvmtienv, (jthread) par1);
+ printjvmtierror("VMVirtualMachine.suspendThread SuspendThread", err);
+}
+
+/*
+ * Class: gnu_classpath_jdwp_VMVirtualMachine
+ * Method: resumeThread
+ * Signature: (Ljava/lang/Thread;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_resumeThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1)
+{
+ jvmtiError err;
+
+ err = (*jvmtienv)->ResumeThread(jvmtienv, (jthread) par1);
+ printjvmtierror("VMVirtualMachine.resumethread ResumeThread", err);
+}
+
+
+/*
+ * Class: gnu_classpath_jdwp_VMVirtualMachine
+ * Method: getSuspendCount
+ * Signature: (Ljava/lang/Thread;)I
+ */
+JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getSuspendCount(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
+ log_text ("VMVirtualMachine_getSuspendCount: not supported");
+ return 1;
+}
+
+/*
+ * Class: gnu_classpath_jdwp_VMVirtualMachine
+ * Method: getAllLoadedClassesCount
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClassesCount(JNIEnv *env, jclass clazz) {
+ jint count;
+ jclass* classes;
+ jvmtiError err;
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+ GetLoadedClasses(jvmtienv, &count, &classes))) {
+ printjvmtierror("VMVirtualMachine_getAllLoadedClassCount GetLoadedClasses",err);
+ return 0;
+ }
+ (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)classes);
+ return count;
+}
+
+/*
+ * Class: gnu_classpath_jdwp_VMVirtualMachine
+ * Method: getAllLoadedClasses
+ * Signature: ()Ljava/util/Iterator
+ */
+JNIEXPORT struct java_util_Iterator* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClasses(JNIEnv *env, jclass clazz) {
+ jclass *classes, *cl;
+ jint classcount;
+ jobjectArray joa;
+/* jthrowable e;*/
+ jmethodID m;
+ jobject *ol,*oi;
+ int i;
+ jvmtiError err;
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+ GetLoadedClasses(jvmtienv, &classcount, &classes))) {
+ printjvmtierror("VMVirtualMachine_getAllLoadedClasses GetLoadedClasses",err);
+
+ /* we should throw JDWP Exception INTERNAL = 113;*/
+/* env->ThrowNew(env,ec,"jvmti error occoured"); */
+ return NULL;
+ }
+
+ cl = (*env)->FindClass(env,"java.lang.Class");
+ if (!cl) return NULL;
+
+ /* Arrays.asList(Object[] classes)->List.Iterator()->Iterator */
+ joa = (*env)->NewObjectArray(env, (jsize)classcount, cl , NULL);
+ if (!joa) return NULL;
+
+ for (i = 0; i < classcount; i++)
+ (*env)->SetObjectArrayElement(env,joa,(jsize)i, (jobject)classes[i]);
+ (*jvmtienv)->Deallocate(jvmtienv, (unsigned char*)classes);
+
+ cl = (*env)->FindClass(env,"java.util.Arrays");
+ if (!cl) return NULL;
+
+ m = (*env)->GetStaticMethodID(env, cl, "asList", "([Ljava/lang/Object;)Ljava/util/List;");
+ if (!m) return NULL;
+
+ ol = (*env)->CallStaticObjectMethod(env,(jclass)cl,m,joa);
+ if (!ol) return NULL;
+
+ cl = (*env)->FindClass(env,"java.util.List");
+ if (!cl) return NULL;
+ m = (*env)->GetMethodID(env,cl,"iterator","()Ljava/util/Iterator;");
+ if (!m) return NULL;
+ oi = (*env)->CallObjectMethod(env,ol,m);
+
+ return (struct java_util_Iterator*)oi;
+}
+
+/* Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getClassStatus
+ * Signature: (Ljava/lang/Class;)I
+ */
+JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getClassStatus(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
+ jint status;
+ jvmtiError err;
+
+ err = (*jvmtienv)->GetClassStatus(jvmtienv, (jclass) par1, &status);
+ printjvmtierror("VMVirtualMachine_getClassStatus GetClassStatus", err);
+
+ return status;
+}
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getAllClassMethods
+ * Signature: (Ljava/lang/Class;)[Lgnu/classpath/jdwp/VMMethod;
+ */
+JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllClassMethods(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
+ jint count;
+ jmethodID* methodID, m;
+ jvmtiError err;
+
+ jclass *cl;
+ jobject *ol;
+ jobjectArray joa;
+ int i;
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+ GetClassMethods(jvmtienv, (jclass) par1,
+ &count, &methodID))) {
+ printjvmtierror("VMVirtualMachine_getAllClassMethods GetClassMethods", err);
+ return NULL;
+ }
+
+ m = (*env)->
+ GetStaticMethodID(env, clazz, "getClassMethod",
+ "(Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;");
+ if (!m) return NULL;
+
+ cl = (*env)->FindClass(env,"gnu.classpath.jdwp.VMMethod");
+ if (!cl) return NULL;
+
+ joa = (*env)->NewObjectArray(env, (jsize)count, cl , NULL);
+ if (!joa) return NULL;
+
+ for (i = 0; i < count; i++) {
+ ol = (*env)->
+ CallStaticObjectMethod(env,clazz,m,(jobject)par1, methodID[i]);
+ if (!ol) return NULL;
+ (*env)->SetObjectArrayElement(env,joa,(jsize)i, ol);
+ }
+ return joa;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getClassMethod
+ * Signature: (Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;
+ */
+JNIEXPORT struct gnu_classpath_jdwp_VMMethod* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getClassMethod(JNIEnv *env, jclass clazz, struct java_lang_Class* par1, s8 par2) {
+ jclass *cl;
+ jmethodID m;
+ jobject *ol;
+
+ cl = (*env)->FindClass(env,"gnu.classpath.jdwp.VMMethod");
+ if (!cl) return NULL;
+
+ m = (*env)->GetMethodID(env, cl, "<init>", "(Ljava/lang/Class;J)V");
+ if (!m) return NULL;
+
+ ol = (*env)->NewObject(env, cl, m, par1, par2);
+
+ return (struct gnu_classpath_jdwp_VMMethod*)ol;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getFrames
+ * Signature: (Ljava/lang/Thread;II)Ljava/util/ArrayList;
+ */
+JNIEXPORT struct java_util_ArrayList* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrames(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1, s4 par2, s4 par3) {
+ log_text ("VMVirtualMachine_getFrames - IMPLEMENT ME!!!");
+/* jclass ec = (*env)->FindClass(env,"gnu/classpath/jdwp/JdwpInternalErrorException");
+ if (JVMTI_ERROR_NONE != (*jvmtienv)->GetClassStatus(jvmtienv, par1, &status))
+ env->ThrowNew(env,ec,"jvmti error occoured");*/
+ return 0;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getFrame
+ * Signature: (Ljava/lang/Thread;Ljava/nio/ByteBuffer;)Lgnu/classpath/jdwp/VMFrame;
+ */
+JNIEXPORT struct gnu_classpath_jdwp_VMFrame* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrame(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1, struct java_nio_ByteBuffer* par2) {
+ log_text ("VMVirtualMachine_getFrame - IMPLEMENT ME!!!");
+ return 0;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getFrameCount
+ * Signature: (Ljava/lang/Thread;)I
+ */
+JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
+ jint count;
+ jvmtiError err;
+ err = (*jvmtienv)->GetFrameCount(jvmtienv, (jthread)par1, &count);
+ printjvmtierror("VMVirtualMachine_getFrameCount GetFrameCount", err);
+ return count;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getThreadStatus
+ * Signature: (Ljava/lang/Thread;)I
+ */
+JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getThreadStatus(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
+ jint status;
+ jvmtiError err;
+ if (JVMTI_ERROR_NONE != (err = (*jvmtienv)->GetThreadState(jvmtienv, (jthread)par1, &status))) {
+ printjvmtierror("VMVirtualMachine_getThreadStatus GetThreadState", err);
+ return 0;
+ }
+ if (status && JVMTI_THREAD_STATE_ALIVE) {
+ if (status && JVMTI_THREAD_STATE_WAITING) {
+ return 4; /* WAIT - see JdwpConstants */
+ }
+ if (status && JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) {
+ return 3; /* MONITOR - see JdwpConstants */
+ }
+ if (status && JVMTI_THREAD_STATE_SLEEPING) {
+ return 2; /* SLEEPING - see JdwpConstants */
+ }
+ return 1; /* RUNNING - see JdwpConstants */
+ } else
+ return 0; /* ZOMBIE - see JdwpConstants */
+ return -1; /* some error */
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getLoadRequests
+ * Signature: (Ljava/lang/ClassLoader;)Ljava/util/ArrayList;
+ */
+JNIEXPORT struct java_util_ArrayList* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getLoadRequests(JNIEnv *env, jclass clazz, struct java_lang_ClassLoader* par1) {
+ log_text ("VMVirtualMachine_getLoadRequests(");
+ return 0;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: executeMethod
+ * Signature: (Ljava/lang/Object;Ljava/lang/Thread;Ljava/lang/Class;Ljava/lang/reflect/Method;[Ljava/lang/Object;Z)Lgnu/classpath/jdwp/util/MethodResult;
+ */
+JNIEXPORT struct gnu_classpath_jdwp_util_MethodResult* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_executeMethod(JNIEnv *env, jclass clazz, struct java_lang_Object* par1, struct java_lang_Thread* par2, struct java_lang_Class* par3, struct java_lang_reflect_Method* par4, java_objectarray* par5, s4 par6) {
+ log_text ("VMVirtualMachine_executeMethod");
+ return 0;
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: getSourceFile
+ * Signature: (Ljava/lang/Class;)Ljava/lang/String;
+ */
+JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getSourceFile(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
+ char* srcname;
+ jstring str;
+ jvmtiError err;
+
+ if (JVMTI_ERROR_NONE !=(err=(*jvmtienv)->
+ GetSourceFileName(jvmtienv, (jclass)par1, &srcname))) {
+ printjvmtierror("VMVirtualMachine.getSourceFile GetSourceFileName", err);
+ return NULL;
+ }
+
+ str = (*env)->NewString(env,(jchar*)srcname,(jsize)strlen(srcname));
+
+ return (struct java_lang_String*)str;
+}
+
+/* match JdwpConstants.EventKind to jvmtiEvent constants */
+static jvmtiEvent EventKind2jvmtiEvent(jbyte kind){
+ switch (kind) {
+ case /* SINGLE_STEP */ 1: return JVMTI_EVENT_SINGLE_STEP;
+ case /* BREAKPOINT */ 2: return JVMTI_EVENT_BREAKPOINT;
+ case /* FRAME_POP */ 3: return JVMTI_EVENT_FRAME_POP;
+ case /* EXCEPTION */ 4: return JVMTI_EVENT_EXCEPTION;
+ case /* USER_DEFINED */ 5: return -1; /* can this be matched ? */
+ case /* THREAD_START */ 6: return JVMTI_EVENT_THREAD_START;
+ case /* THREAD_END */ 7: return JVMTI_EVENT_THREAD_END;
+ case /* CLASS_PREPARE */ 8: return JVMTI_EVENT_CLASS_PREPARE;
+ case /* CLASS_UNLOAD */ 9: return -1; /* can this be matched ? */
+ case /* CLASS_LOAD */ 10: return JVMTI_EVENT_CLASS_LOAD;
+ case /* FIELD_ACCESS */ 20: return JVMTI_EVENT_FIELD_ACCESS;
+ case /* FIELD_MODIFICATION */ 21: return JVMTI_EVENT_FIELD_MODIFICATION;
+ case /* EXCEPTION_CATCH */ 30: return JVMTI_EVENT_EXCEPTION_CATCH;
+ case /* METHOD_ENTRY */ 40: return JVMTI_EVENT_METHOD_ENTRY;
+ case /* METHOD_EXIT */ 41: return JVMTI_EVENT_METHOD_EXIT;
+ case /* VM_INIT */ 90: return JVMTI_EVENT_VM_INIT;
+ case /* VM_DEATH */ 99: return JVMTI_EVENT_VM_DEATH;
+ case /* VM_DISCONNECTED */ 100: return -1; /* can this be matched ? */
+ default: return -1;
+ }
+}
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: registerEvent
+ * Signature: (Lgnu/classpath/jdwp/event/EventRequest;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent(JNIEnv *env, jclass clazz, struct gnu_classpath_jdwp_event_EventRequest* par1) {
+ jbyte kind;
+ jfieldID kindid;
+ jclass erc;
+ jvmtiError err;
+
+ erc = (*env)->FindClass(env,"gnu.classpath.jdwp.event.EventRequest");
+
+ kindid = (*env)->GetFieldID(env, erc, "_kind", "B");
+ kind = (*env)->GetByteField(env, (jobject)par1, kindid);
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+ SetEventNotificationMode(jvmtienv, JVMTI_ENABLE,
+ EventKind2jvmtiEvent(kind), NULL)))
+ printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
+
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: unregisterEvent
+ * Signature: (Lgnu/classpath/jdwp/event/EventRequest;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent(JNIEnv *env, jclass clazz, struct gnu_classpath_jdwp_event_EventRequest* par1) {
+ jbyte kind;
+ jfieldID kindid;
+ jclass erc;
+ jvmtiError err;
+
+ erc = (*env)->FindClass(env,"gnu.classpath.jdwp.event.EventRequest");
+
+ kindid = (*env)->GetFieldID(env, erc, "_kind", "B");
+ kind = (*env)->GetByteField(env, (jobject)par1, kindid);
+
+ if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+ SetEventNotificationMode(jvmtienv, JVMTI_DISABLE,
+ EventKind2jvmtiEvent(kind), NULL)))
+ printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
+
+}
+
+
+/*
+ * Class: gnu/classpath/jdwp/VMVirtualMachine
+ * Method: clearEvents
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_clearEvents(JNIEnv *env, jclass clazz, s4 par1) {
+ /* jvmti events are not saved - there is nothing to clear */
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */