00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #include "virtualmachinecmdset.h"
00028
00029 namespace inspectorj {
00030 namespace agent {
00031 namespace commandset {
00032
00033 using namespace inspectorj::jdwp;
00034
00038 VirtualMachineCmdSet::VirtualMachineCmdSet(JavaVM *vm, JNIEnv *env, jvmtiEnv *jvmti)
00039 {
00040 this->vm = vm;
00041 this->env = env;
00042 this->jvmti = jvmti;
00043 }
00044
00048 VirtualMachineCmdSet::~VirtualMachineCmdSet()
00049 {
00050 }
00051
00052
00058 void VirtualMachineCmdSet::process(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00059 {
00060 int jdwpCmd = static_cast<int>(cmd->getCmd());
00061 switch (jdwpCmd) {
00062 case VM_CMD_VERSION : getVersionInfo(cmd, cbk); break;
00063 case VM_CMD_CLASSES_BY_SIGNATURE : getClassesBySignature(cmd, cbk); break;
00064 case VM_CMD_ALL_CLASSES : getAllClasses(cmd, cbk); break;
00065 case VM_CMD_ALL_THREADS : getAllThreads(cmd, cbk); break;
00066 case VM_CMD_TOP_LEVEL_THREAD_GROUPS : getTopLevelThreadGroups(cmd, cbk); break;
00067 case VM_CMD_DISPOSE : dispose(cmd, cbk); break;
00068 case VM_CMD_ID_SIZES : getIdSizes(cmd, cbk); break;
00069 case VM_CMD_SUSPEND : suspend(cmd, cbk); break;
00070 case VM_CMD_RESUME : resume(cmd, cbk); break;
00071 case VM_CMD_EXIT : exit(cmd, cbk); break;
00072 case VM_CMD_CREATE_STRING : createString(cmd, cbk); break;
00073 case VM_CMD_CAPABILITIES : capabilities(cmd, cbk); break;
00074 case VM_CMD_CLASSPATHS : classpaths(cmd, cbk); break;
00075 case VM_CMD_DISPOSE_OBJECTS : disposeObjects(cmd, cbk); break;
00076 case VM_CMD_HOLD_EVENTS : holdEvents(cmd, cbk); break;
00077 case VM_CMD_RELEASE_EVENTS : releaseEvents(cmd, cbk); break;
00078 case VM_CMD_CAPABILITIES_NEW : newCapabilities(cmd, cbk); break;
00079 case VM_CMD_REDEFINE_CLASSES : redefineClasses(cmd, cbk); break;
00080 case VM_CMD_SET_DEFAULT_STRATUM : setDefaultStratum(cmd, cbk); break;
00081 case VM_CMD_ALL_CLASSES_WITH_GENERIC : getAllClassesWithGeneric(cmd, cbk); break;
00082 default : sendNotImplementedReply(cmd, cbk); break;
00083 }
00084
00085
00086 }
00087
00093 void VirtualMachineCmdSet::getVersionInfo(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00094 {
00095 JDWPReply *reply = getJDWPReply(cmd);
00096 QString versionInfo = "Java Debug Wire Protocol - inspectorj implementation.\n";
00097
00098 jvmtiError error;
00099
00100 char* vmNameProperty = "java.vm.name";
00101 char* vmName = "";
00102 error = jvmti->GetSystemProperty(vmNameProperty, &vmName);
00103 QString vmNameString(vmName);
00104 versionInfo.append(vmNameString);
00105 versionInfo.append(" - version ");
00106 if (!error) {
00107 error = jvmti->Deallocate((unsigned char*)vmName);
00108 check_jvmti_error(jvmti, error, "[VirtualMachineCmdSet::getVersionInfo] Error: Could not deallocate memory for vmName.\n");
00109 }
00110
00111 char* javaVersionProperty = "java.vm.version";
00112 char* javaVersion = "";
00113 error = jvmti->GetSystemProperty(javaVersionProperty, &javaVersion);
00114 QString javaVersionString(javaVersion);
00115 versionInfo.append(javaVersionString);
00116 versionInfo.append("\n");
00117 if (!error) {
00118 error = jvmti->Deallocate((unsigned char*)javaVersion);
00119 check_jvmti_error(jvmti, error, "[VirtualMachineCmdSet::getVersionInfo] Error: Could not deallocate memory for javaVersion.\n");
00120 }
00121
00122 *reply << versionInfo;
00123 jint v1 = 1;
00124 jint v2 = 0;
00125 *reply << v1;
00126 *reply << v2;
00127 *reply << javaVersionString;
00128 *reply << vmNameString;
00129 cbk(reply);
00130 }
00131
00132 void VirtualMachineCmdSet::getClassesBySignature(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00133 {
00134 sendNotImplementedReply(cmd, cbk);
00135 }
00136
00137 void VirtualMachineCmdSet::getAllClasses(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00138 {
00139 JDWPCommandSet::getClassMap().clear();
00140 JDWPReply *reply = getJDWPReply(cmd);
00141 jvmtiError error;
00142 jint clsNum;
00143 jclass *classes;
00144 error = jvmti->GetLoadedClasses(&clsNum, &classes);
00145 check_jvmti_error(jvmti, error, "Error getting Loaded Classes\n");
00146 qint64 referenceId = 0;
00147
00148 *reply << clsNum;
00149 for (int i = 0; i < clsNum; i++) {
00150
00151
00152 JDWPCommandSet::getClassMap().insert(++referenceId, classes[i]);
00153
00154
00155 jboolean type = 0;
00156 jbyte _type;
00157 error = jvmti->IsInterface(classes[i], &type);
00158
00159 if (type) {
00160 jbyte _type = (jbyte) TAG_TYPE_INTERFACE;
00161 *reply << _type;
00162 } else {
00163 error = jvmti->IsArrayClass(classes[i], &type);
00164 if (type) {
00165 _type = (jbyte)TAG_TYPE_ARRAY;
00166 *reply << _type;
00167 } else {
00168 _type = (jbyte) TAG_TYPE_CLASS;
00169 *reply << _type;
00170 }
00171 }
00172
00173
00174 *reply << referenceId;
00175
00176
00177
00178 char* jniSignature;
00179 char* genericSignature;
00180
00181 error = jvmti->GetClassSignature(classes[i], &jniSignature, &genericSignature);
00182 check_jvmti_error(jvmti, error, "Error getting class signature\n");
00183 QString signature(jniSignature);
00184 *reply << signature;
00185 error = jvmti->Deallocate((unsigned char*)jniSignature);
00186 error = jvmti->Deallocate((unsigned char*)genericSignature);
00187
00188
00189 jint status;
00190 error = jvmti->GetClassStatus(classes[i], &status);
00191 check_jvmti_error(jvmti, error, "Error getting class status\n");
00192 *reply << status;
00193 }
00194 error = jvmti->Deallocate((unsigned char*)classes);
00195 check_jvmti_error(jvmti, error, "Error Deallocating classes\n");
00196 cbk(reply);
00197 }
00198
00199 void VirtualMachineCmdSet::getAllThreads(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00200 {
00201 sendNotImplementedReply(cmd, cbk);
00202 }
00203
00204 void VirtualMachineCmdSet::getTopLevelThreadGroups(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00205 {
00206 sendNotImplementedReply(cmd, cbk);
00207 }
00208
00209 void VirtualMachineCmdSet::dispose(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00210 {
00211 sendNotImplementedReply(cmd, cbk);
00212 }
00213
00214 void VirtualMachineCmdSet::getIdSizes(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00215 {
00216
00217 JDWPReply *reply = getJDWPReply(cmd);
00218
00219 qint32 size_four = 4;
00220 qint32 size_eight = 8;
00221
00222
00223 *reply << size_four;
00224
00225
00226 *reply << size_four;
00227
00228
00229 *reply << size_eight;
00230
00231
00232 *reply << size_eight;
00233
00234
00235 *reply << size_eight;
00236
00237 cbk(reply);
00238 }
00239
00240 void VirtualMachineCmdSet::suspend(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00241 {
00242 sendNotImplementedReply(cmd, cbk);
00243 }
00244
00245 void VirtualMachineCmdSet::resume(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00246 {
00247 sendNotImplementedReply(cmd, cbk);
00248 }
00249
00250 void VirtualMachineCmdSet::exit(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00251 {
00252 sendNotImplementedReply(cmd, cbk);
00253 }
00254
00255 void VirtualMachineCmdSet::createString(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00256 {
00257 sendNotImplementedReply(cmd, cbk);
00258 }
00259
00260 void VirtualMachineCmdSet::capabilities(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00261 {
00262 sendNotImplementedReply(cmd, cbk);
00263 }
00264
00265 void VirtualMachineCmdSet::classpaths(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00266 {
00267 sendNotImplementedReply(cmd, cbk);
00268 }
00269
00270 void VirtualMachineCmdSet::disposeObjects(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00271 {
00272 sendNotImplementedReply(cmd, cbk);
00273 }
00274
00275 void VirtualMachineCmdSet::holdEvents(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00276 {
00277 sendNotImplementedReply(cmd, cbk);
00278 }
00279
00280 void VirtualMachineCmdSet::releaseEvents(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00281 {
00282 sendNotImplementedReply(cmd, cbk);
00283 }
00284
00285 void VirtualMachineCmdSet::newCapabilities(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00286 {
00287 sendNotImplementedReply(cmd, cbk);
00288 }
00289
00290 void VirtualMachineCmdSet::redefineClasses(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00291 {
00292 sendNotImplementedReply(cmd, cbk);
00293 }
00294
00295 void VirtualMachineCmdSet::setDefaultStratum(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00296 {
00297 sendNotImplementedReply(cmd, cbk);
00298 }
00299
00300 void VirtualMachineCmdSet::getAllClassesWithGeneric(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00301 {
00302 sendNotImplementedReply(cmd, cbk);
00303 }
00304
00305 }
00306 }
00307 }