1 11 package org.eclipse.jdi.internal.jdwp; 12 13 14 import java.io.IOException ; 15 import java.lang.reflect.Field ; 16 import java.lang.reflect.Modifier ; 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 25 public class JdwpCommandPacket extends JdwpPacket { 26 27 public static final int CSET_VIRTUAL_MACHINE = 1; 28 public static final int CSET_REFERENCE_TYPE = 2; 29 public static final int CSET_CLASS_TYPE = 3; 30 public static final int CSET_ARRAY_TYPE = 4; 31 public static final int CSET_INTERFACE_TYPE = 5; 32 public static final int CSET_METHOD = 6; 33 public static final int CSET_FIELD = 8; 34 public static final int CSET_OBJECT_REFERENCE = 9; 35 public static final int CSET_STRING_REFERENCE = 10; 36 public static final int CSET_THREAD_REFERENCE = 11; 37 public static final int CSET_THREAD_GROUP_REFERENCE = 12; 38 public static final int CSET_ARRAY_REFERENCE = 13; 39 public static final int CSET_CLASS_LOADER_REFERENCE = 14; 40 public static final int CSET_EVENT_REQUEST = 15; 41 public static final int CSET_STACK_FRAME = 16; 42 public static final int CSET_CLASS_OBJECT_REFERENCE = 17; 43 public static final int CSET_EVENT = 64; 44 public static final int CSET_HOT_CODE_REPLACEMENT = 128; 45 46 47 public static final int VM_VERSION = 1 + (CSET_VIRTUAL_MACHINE << 8); 48 public static final int VM_CLASSES_BY_SIGNATURE = 2 + (CSET_VIRTUAL_MACHINE << 8); 49 public static final int VM_ALL_CLASSES = 3 + (CSET_VIRTUAL_MACHINE << 8); 50 public static final int VM_ALL_THREADS = 4 + (CSET_VIRTUAL_MACHINE << 8); 51 public static final int VM_TOP_LEVEL_THREAD_GROUPS = 5 + (CSET_VIRTUAL_MACHINE << 8); 52 public static final int VM_DISPOSE = 6 + (CSET_VIRTUAL_MACHINE << 8); 53 public static final int VM_ID_SIZES = 7 + (CSET_VIRTUAL_MACHINE << 8); 54 public static final int VM_SUSPEND = 8 + (CSET_VIRTUAL_MACHINE << 8); 55 public static final int VM_RESUME = 9 + (CSET_VIRTUAL_MACHINE << 8); 56 public static final int VM_EXIT = 10 + (CSET_VIRTUAL_MACHINE << 8); 57 public static final int VM_CREATE_STRING = 11 + (CSET_VIRTUAL_MACHINE << 8); 58 public static final int VM_CAPABILITIES = 12 + (CSET_VIRTUAL_MACHINE << 8); 59 public static final int VM_CLASS_PATHS = 13 + (CSET_VIRTUAL_MACHINE << 8); 60 public static final int VM_DISPOSE_OBJECTS = 14 + (CSET_VIRTUAL_MACHINE << 8); 61 public static final int VM_HOLD_EVENTS = 15 + (CSET_VIRTUAL_MACHINE << 8); 62 public static final int VM_RELEASE_EVENTS = 16 + (CSET_VIRTUAL_MACHINE << 8); 63 public static final int VM_CAPABILITIES_NEW = 17 + (CSET_VIRTUAL_MACHINE << 8); 64 public static final int VM_REDEFINE_CLASSES = 18 + (CSET_VIRTUAL_MACHINE << 8); 65 public static final int VM_SET_DEFAULT_STRATUM = 19 + (CSET_VIRTUAL_MACHINE << 8); 66 public static final int VM_ALL_CLASSES_WITH_GENERIC= 20 + (CSET_VIRTUAL_MACHINE << 8); 67 public static final int VM_INSTANCE_COUNTS = 21 + (CSET_VIRTUAL_MACHINE << 8); 68 69 70 public static final int RT_SIGNATURE = 1 + (CSET_REFERENCE_TYPE << 8); 71 public static final int RT_CLASS_LOADER = 2 + (CSET_REFERENCE_TYPE << 8); 72 public static final int RT_MODIFIERS = 3 + (CSET_REFERENCE_TYPE << 8); 73 public static final int RT_FIELDS = 4 + (CSET_REFERENCE_TYPE << 8); 74 public static final int RT_METHODS = 5 + (CSET_REFERENCE_TYPE << 8); 75 public static final int RT_GET_VALUES = 6 + (CSET_REFERENCE_TYPE << 8); 76 public static final int RT_SOURCE_FILE = 7 + (CSET_REFERENCE_TYPE << 8); 77 public static final int RT_NESTED_TYPES = 8 + (CSET_REFERENCE_TYPE << 8); 78 public static final int RT_STATUS = 9 + (CSET_REFERENCE_TYPE << 8); 79 public static final int RT_INTERFACES = 10 + (CSET_REFERENCE_TYPE << 8); 80 public static final int RT_CLASS_OBJECT = 11 + (CSET_REFERENCE_TYPE << 8); 81 public static final int RT_SOURCE_DEBUG_EXTENSION = 12 + (CSET_REFERENCE_TYPE << 8); 82 public static final int RT_SIGNATURE_WITH_GENERIC = 13 + (CSET_REFERENCE_TYPE << 8); 83 public static final int RT_FIELDS_WITH_GENERIC = 14 + (CSET_REFERENCE_TYPE << 8); 84 public static final int RT_METHODS_WITH_GENERIC = 15 + (CSET_REFERENCE_TYPE << 8); 85 public static final int RT_INSTANCES = 16 + (CSET_REFERENCE_TYPE << 8); 86 public static final int RT_CLASS_VERSION = 17 + (CSET_REFERENCE_TYPE << 8); 87 public static final int RT_CONSTANT_POOL = 18 + (CSET_REFERENCE_TYPE << 8); 88 89 90 public static final int CT_SUPERCLASS = 1 + (CSET_CLASS_TYPE << 8); 91 public static final int CT_SET_VALUES = 2 + (CSET_CLASS_TYPE << 8); 92 public static final int CT_INVOKE_METHOD = 3 + (CSET_CLASS_TYPE << 8); 93 public static final int CT_NEW_INSTANCE = 4 + (CSET_CLASS_TYPE << 8); 94 95 96 public static final int AT_NEW_INSTANCE = 1 + (CSET_ARRAY_TYPE << 8); 97 98 99 public static final int M_LINE_TABLE = 1 + (CSET_METHOD << 8); 100 public static final int M_VARIABLE_TABLE = 2 + (CSET_METHOD << 8); 101 public static final int M_BYTECODES = 3 + (CSET_METHOD << 8); 102 public static final int M_OBSOLETE = 4 + (CSET_METHOD << 8); 103 public static final int M_VARIABLE_TABLE_WITH_GENERIC = 5 + (CSET_METHOD << 8); 104 105 106 public static final int OR_REFERENCE_TYPE = 1 + (CSET_OBJECT_REFERENCE << 8); 107 public static final int OR_GET_VALUES = 2 + (CSET_OBJECT_REFERENCE << 8); 108 public static final int OR_SET_VALUES = 3 + (CSET_OBJECT_REFERENCE << 8); 109 public static final int OR_MONITOR_INFO = 5 + (CSET_OBJECT_REFERENCE << 8); 110 public static final int OR_INVOKE_METHOD = 6 + (CSET_OBJECT_REFERENCE << 8); 111 public static final int OR_DISABLE_COLLECTION = 7 + (CSET_OBJECT_REFERENCE << 8); 112 public static final int OR_ENABLE_COLLECTION = 8 + (CSET_OBJECT_REFERENCE << 8); 113 public static final int OR_IS_COLLECTED = 9 + (CSET_OBJECT_REFERENCE << 8); 114 public static final int OR_REFERRING_OBJECTS = 10 + (CSET_OBJECT_REFERENCE << 8); 115 116 117 public static final int SR_VALUE = 1 + (CSET_STRING_REFERENCE << 8); 118 119 120 public static final int TR_NAME = 1 + (CSET_THREAD_REFERENCE << 8); 121 public static final int TR_SUSPEND = 2 + (CSET_THREAD_REFERENCE << 8); 122 public static final int TR_RESUME = 3 + (CSET_THREAD_REFERENCE << 8); 123 public static final int TR_STATUS = 4 + (CSET_THREAD_REFERENCE << 8); 124 public static final int TR_THREAD_GROUP = 5 + (CSET_THREAD_REFERENCE << 8); 125 public static final int TR_FRAMES = 6 + (CSET_THREAD_REFERENCE << 8); 126 public static final int TR_FRAME_COUNT = 7 + (CSET_THREAD_REFERENCE << 8); 127 public static final int TR_OWNED_MONITORS = 8 + (CSET_THREAD_REFERENCE << 8); 128 public static final int TR_CURRENT_CONTENDED_MONITOR = 9 + (CSET_THREAD_REFERENCE << 8); 129 public static final int TR_STOP = 10 + (CSET_THREAD_REFERENCE << 8); 130 public static final int TR_INTERRUPT = 11 + (CSET_THREAD_REFERENCE << 8); 131 public static final int TR_SUSPEND_COUNT = 12 + (CSET_THREAD_REFERENCE << 8); 132 public static final int TR_OWNED_MONITOR_STACK_DEPTH = 13 + (CSET_THREAD_REFERENCE << 8); 133 public static final int TR_FORCE_EARLY_RETURN = 14 + (CSET_THREAD_REFERENCE << 8); 134 135 136 public static final int TGR_NAME = 1 + (CSET_THREAD_GROUP_REFERENCE << 8); 137 public static final int TGR_PARENT = 2 + (CSET_THREAD_GROUP_REFERENCE << 8); 138 public static final int TGR_CHILDREN = 3 + (CSET_THREAD_GROUP_REFERENCE << 8); 139 140 141 public static final int AR_LENGTH = 1 + (CSET_ARRAY_REFERENCE << 8); 142 public static final int AR_GET_VALUES = 2 + (CSET_ARRAY_REFERENCE << 8); 143 public static final int AR_SET_VALUES = 3 + (CSET_ARRAY_REFERENCE << 8); 144 145 146 public static final int CLR_VISIBLE_CLASSES = 1 + (CSET_CLASS_LOADER_REFERENCE << 8); 147 148 149 public static final int ER_SET = 1 + (CSET_EVENT_REQUEST << 8); 150 public static final int ER_CLEAR = 2 + (CSET_EVENT_REQUEST << 8); 151 public static final int ER_CLEAR_ALL_BREAKPOINTS = 3 + (CSET_EVENT_REQUEST << 8); 152 153 154 public static final int SF_GET_VALUES = 1 + (CSET_STACK_FRAME << 8); 155 public static final int SF_SET_VALUES = 2 + (CSET_STACK_FRAME << 8); 156 public static final int SF_THIS_OBJECT = 3 + (CSET_STACK_FRAME << 8); 157 public static final int SF_POP_FRAME = 4 + (CSET_STACK_FRAME << 8); 158 159 160 public static final int COR_REFLECTED_TYPE = 1 + (CSET_CLASS_OBJECT_REFERENCE << 8); 161 162 163 public static final int E_COMPOSITE = 100 + (CSET_EVENT << 8); 164 165 166 public static final int HCR_CLASSES_HAVE_CHANGED = 1 + (CSET_HOT_CODE_REPLACEMENT << 8); 167 public static final int HCR_GET_CLASS_VERSION = 2 + (CSET_HOT_CODE_REPLACEMENT << 8); 168 public static final int HCR_DO_RETURN = 3 + (CSET_HOT_CODE_REPLACEMENT << 8); 169 public static final int HCR_REENTER_ON_EXIT = 4 + (CSET_HOT_CODE_REPLACEMENT << 8); 170 public static final int HCR_CAPABILITIES = 5 + (CSET_HOT_CODE_REPLACEMENT << 8); 171 172 173 private static Map fgCommandMap = null; 174 175 176 private static int fgNextId = 1; 177 178 private int fCommand; 179 180 183 protected JdwpCommandPacket() { 184 } 185 186 189 public JdwpCommandPacket(int command) { 190 setCommand(command); 191 setId(getNewId()); 192 } 193 194 197 public static synchronized int getNewId() { 198 return fgNextId++; 199 } 200 201 204 public byte getCommandSet() { 205 return (byte)(fCommand >>> 8); 206 } 207 208 211 public int getCommand() { 212 return fCommand; 213 } 214 215 218 public void setCommand(int command) { 219 fCommand = command; 220 } 221 222 225 protected int readSpecificHeaderFields(byte[] bytes, int index) { 226 byte commandSet = bytes[index]; 227 fCommand = bytes[index+1] + (commandSet << 8); 228 return 2; 229 } 230 231 234 protected int writeSpecificHeaderFields(byte[] bytes, int index) throws IOException { 235 bytes[index] = getCommandSet(); 236 bytes[index+1] = (byte) fCommand; 237 return 2; 238 } 239 240 243 public static void getConstantMaps() { 244 if (fgCommandMap != null) { 245 return; 246 } 247 248 Field [] fields = JdwpCommandPacket.class.getDeclaredFields(); 249 250 Map setNames = new HashMap (fields.length); 252 for (int i = 0; i < fields.length; i++) { 253 Field field = fields[i]; 254 if ((field.getModifiers() & Modifier.PUBLIC) == 0 || (field.getModifiers() & Modifier.STATIC) == 0 || (field.getModifiers() & Modifier.FINAL) == 0) 255 continue; 256 257 try { 258 String name = field.getName(); 259 if (!name.startsWith("CSET_")) { continue; 262 } 263 int value = field.getInt(null); 264 setNames.put(new Integer (value), removePrefix(name)); 265 } catch (IllegalAccessException e) { 266 } catch (IllegalArgumentException e) { 268 } 272 } 273 274 fgCommandMap = new HashMap (); 276 for (int i = 0; i < fields.length; i++) { 277 Field field = fields[i]; 278 if ((field.getModifiers() & Modifier.PUBLIC) == 0 || (field.getModifiers() & Modifier.STATIC) == 0 || (field.getModifiers() & Modifier.FINAL) == 0) { 279 continue; 280 } 281 282 try { 283 String name = field.getName(); 284 285 if (name.startsWith("CSET_")) { continue; 288 } 289 Integer val = (Integer )field.get(null); 290 int value = val.intValue(); 291 int set = value >>> 8; 292 String setName = (String )setNames.get(new Integer (set)); 293 String entryName = setName + " - " + removePrefix(name); 295 fgCommandMap.put(val, entryName); 296 297 } catch (IllegalAccessException e) { 298 } 300 } 301 } 302 303 306 public static Map commandMap() { 307 getConstantMaps(); 308 return fgCommandMap; 309 } 310 311 314 public static String removePrefix(String str) { 315 int i = str.indexOf('_'); 316 if (i < 0) { 317 return str; 318 } 319 return str.substring(i + 1); 320 } 321 322 325 public String toString() { 326 StringBuffer buffer = new StringBuffer (); 327 buffer.append('['); 328 buffer.append(getId()); 329 buffer.append("] "); switch (getCommand()) { 331 332 333 case VM_VERSION: 334 buffer.append("VM_VERSION"); break; 336 case VM_CLASSES_BY_SIGNATURE: 337 buffer.append("VM_CLASSES_BY_SIGNATURE"); break; 339 case VM_ALL_CLASSES: 340 buffer.append("VM_ALL_CLASSES"); break; 342 case VM_ALL_THREADS: 343 buffer.append("VM_ALL_THREADS"); break; 345 case VM_TOP_LEVEL_THREAD_GROUPS: 346 buffer.append("VM_TOP_LEVEL_THREAD_GROUPS"); break; 348 case VM_DISPOSE: 349 buffer.append("VM_DISPOSE"); break; 351 case VM_ID_SIZES: 352 buffer.append("VM_ID_SIZES"); break; 354 case VM_SUSPEND: 355 buffer.append("VM_SUSPEND"); break; 357 case VM_RESUME: 358 buffer.append("VM_RESUME"); break; 360 case VM_EXIT: 361 buffer.append("VM_EXIT"); break; 363 case VM_CREATE_STRING: 364 buffer.append("VM_CREATE_STRING"); break; 366 case VM_CAPABILITIES: 367 buffer.append("VM_CAPABILITIES"); break; 369 case VM_CLASS_PATHS: 370 buffer.append("VM_CLASS_PATHS"); break; 372 case VM_DISPOSE_OBJECTS: 373 buffer.append("VM_DISPOSE_OBJECTS"); break; 375 case VM_HOLD_EVENTS: 376 buffer.append("VM_HOLD_EVENTS"); break; 378 case VM_RELEASE_EVENTS: 379 buffer.append("VM_RELEASE_EVENTS"); break; 381 case VM_CAPABILITIES_NEW: 382 buffer.append("VM_CAPABILITIES_NEW"); break; 384 case VM_REDEFINE_CLASSES: 385 buffer.append("VM_REDEFINE_CLASSES"); break; 387 case VM_SET_DEFAULT_STRATUM: 388 buffer.append("VM_SET_DEFAULT_STRATUM"); break; 390 case VM_ALL_CLASSES_WITH_GENERIC: 391 buffer.append("VM_ALL_CLASSES_WITH_GENERIC"); break; 393 394 395 case RT_SIGNATURE: 396 buffer.append("RT_SIGNATURE"); break; 398 case RT_CLASS_LOADER: 399 buffer.append("RT_CLASS_LOADER"); break; 401 case RT_MODIFIERS: 402 buffer.append("RT_MODIFIERS"); break; 404 case RT_FIELDS: 405 buffer.append("RT_FIELDS"); break; 407 case RT_METHODS: 408 buffer.append("RT_METHODS"); break; 410 case RT_GET_VALUES: 411 buffer.append("RT_GET_VALUES"); break; 413 case RT_SOURCE_FILE: 414 buffer.append("RT_SOURCE_FILE"); break; 416 case RT_NESTED_TYPES: 417 buffer.append("RT_NESTED_TYPES"); break; 419 case RT_STATUS: 420 buffer.append("RT_STATUS"); break; 422 case RT_INTERFACES: 423 buffer.append("RT_INTERFACES"); break; 425 case RT_CLASS_OBJECT: 426 buffer.append("RT_CLASS_OBJECT"); break; 428 case RT_SOURCE_DEBUG_EXTENSION: 429 buffer.append("RT_SOURCE_DEBUG_EXTENSION"); break; 431 case RT_SIGNATURE_WITH_GENERIC: 432 buffer.append("RT_SIGNATURE_WITH_GENERIC"); break; 434 case RT_FIELDS_WITH_GENERIC: 435 buffer.append("RT_FIELDS_WITH_GENERIC"); break; 437 case RT_METHODS_WITH_GENERIC: 438 buffer.append("RT_METHODS_WITH_GENERIC"); break; 440 441 442 case CT_SUPERCLASS: 443 buffer.append("CT_SUPERCLASS"); break; 445 case CT_SET_VALUES: 446 buffer.append("CT_SET_VALUES"); break; 448 case CT_INVOKE_METHOD: 449 buffer.append("CT_INVOKE_METHOD"); break; 451 case CT_NEW_INSTANCE: 452 buffer.append("CT_NEW_INSTANCE"); break; 454 455 456 case AT_NEW_INSTANCE: 457 buffer.append("AT_NEW_INSTANCE"); break; 459 460 461 case M_LINE_TABLE: 462 buffer.append("M_LINE_TABLE"); break; 464 case M_VARIABLE_TABLE: 465 buffer.append("M_VARIABLE_TABLE"); break; 467 case M_BYTECODES: 468 buffer.append("M_BYTECODES"); break; 470 case M_OBSOLETE: 471 buffer.append("M_OBSOLETE"); break; 473 case M_VARIABLE_TABLE_WITH_GENERIC: 474 buffer.append("M_VARIABLE_TABLE_WITH_GENERIC"); break; 476 477 478 case OR_REFERENCE_TYPE: 479 buffer.append("OR_REFERENCE_TYPE"); break; 481 case OR_GET_VALUES: 482 buffer.append("OR_GET_VALUES"); break; 484 case OR_SET_VALUES: 485 buffer.append("OR_SET_VALUES"); break; 487 case OR_MONITOR_INFO: 488 buffer.append("OR_MONITOR_INFO"); break; 490 case OR_INVOKE_METHOD: 491 buffer.append("OR_INVOKE_METHOD"); break; 493 case OR_DISABLE_COLLECTION: 494 buffer.append("OR_DISABLE_COLLECTION"); break; 496 case OR_ENABLE_COLLECTION: 497 buffer.append("OR_ENABLE_COLLECTION"); break; 499 case OR_IS_COLLECTED: 500 buffer.append("OR_IS_COLLECTED"); break; 502 503 504 case SR_VALUE: 505 buffer.append("SR_VALUE"); break; 507 508 509 case TR_NAME: 510 buffer.append("TR_NAME"); break; 512 case TR_SUSPEND: 513 buffer.append("TR_SUSPEND"); break; 515 case TR_RESUME: 516 buffer.append("TR_RESUME"); break; 518 case TR_STATUS: 519 buffer.append("TR_STATUS"); break; 521 case TR_THREAD_GROUP: 522 buffer.append("TR_THREAD_GROUP"); break; 524 case TR_FRAMES: 525 buffer.append("TR_FRAMES"); break; 527 case TR_FRAME_COUNT: 528 buffer.append("TR_FRAME_COUNT"); break; 530 case TR_OWNED_MONITORS: 531 buffer.append("TR_OWNED_MONITORS"); break; 533 case TR_CURRENT_CONTENDED_MONITOR: 534 buffer.append("TR_CURRENT_CONTENDED_MONITOR"); break; 536 case TR_STOP: 537 buffer.append("TR_STOP"); break; 539 case TR_INTERRUPT: 540 buffer.append("TR_INTERRUPT"); break; 542 case TR_SUSPEND_COUNT: 543 buffer.append("TR_SUSPEND_COUNT"); break; 545 546 547 case TGR_NAME: 548 buffer.append("TGR_NAME"); break; 550 case TGR_PARENT: 551 buffer.append("TGR_PARENT"); break; 553 case TGR_CHILDREN: 554 buffer.append("TGR_CHILDREN"); break; 556 557 558 case AR_LENGTH: 559 buffer.append("AR_LENGTH"); break; 561 case AR_GET_VALUES: 562 buffer.append("AR_GET_VALUES"); break; 564 case AR_SET_VALUES: 565 buffer.append("AR_SET_VALUES"); break; 567 568 569 case CLR_VISIBLE_CLASSES: 570 buffer.append("CLR_VISIBLE_CLASSES"); break; 572 573 574 case ER_SET: 575 buffer.append("ER_SET"); break; 577 case ER_CLEAR: 578 buffer.append("ER_CLEAR"); break; 580 case ER_CLEAR_ALL_BREAKPOINTS: 581 buffer.append("ER_CLEAR_ALL_BREAKPOINTS"); break; 583 584 585 case SF_GET_VALUES: 586 buffer.append("SF_GET_VALUES"); break; 588 case SF_SET_VALUES: 589 buffer.append("SF_SET_VALUES"); break; 591 case SF_THIS_OBJECT: 592 buffer.append("SF_THIS_OBJECT"); break; 594 case SF_POP_FRAME: 595 buffer.append("SF_POP_FRAME"); break; 597 598 599 case COR_REFLECTED_TYPE: 600 buffer.append("COR_REFLECTED_TYPE"); break; 602 603 604 case E_COMPOSITE: 605 buffer.append("E_COMPOSITE"); break; 607 608 default: 609 buffer.append("UNKNOWN COMMAND: "); buffer.append(getCommand()); 611 break; 612 } 613 return buffer.toString(); 614 } 615 } 616 | Popular Tags |