1 /* 2 * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "util.h" 27 #include "transport.h" 28 #include "debugDispatch.h" 29 #include "VirtualMachineImpl.h" 30 #include "ReferenceTypeImpl.h" 31 #include "ClassTypeImpl.h" 32 #include "InterfaceTypeImpl.h" 33 #include "ArrayTypeImpl.h" 34 #include "FieldImpl.h" 35 #include "MethodImpl.h" 36 #include "ModuleReferenceImpl.h" 37 #include "ObjectReferenceImpl.h" 38 #include "StringReferenceImpl.h" 39 #include "ThreadReferenceImpl.h" 40 #include "ThreadGroupReferenceImpl.h" 41 #include "ClassLoaderReferenceImpl.h" 42 #include "ClassObjectReferenceImpl.h" 43 #include "ArrayReferenceImpl.h" 44 #include "EventRequestImpl.h" 45 #include "StackFrameImpl.h" 46 47 static CommandSet **cmdSetsArray; 48 49 void 50 debugDispatch_initialize(void) 51 { 52 /* 53 * Create the level-one (CommandSet) dispatch table. 54 * Zero the table so that unknown CommandSets do not 55 * cause random errors. 56 */ 57 cmdSetsArray = jvmtiAllocate((JDWP_HIGHEST_COMMAND_SET+1) * sizeof(CommandSet *)); 58 59 if (cmdSetsArray == NULL) { 60 EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"command set array"); 61 } 62 63 (void)memset(cmdSetsArray, 0, (JDWP_HIGHEST_COMMAND_SET+1) * sizeof(CommandSet *)); 64 65 /* 66 * Create the level-two (Command) dispatch tables to the 67 * corresponding slots in the CommandSet dispatch table.. 68 */ 69 cmdSetsArray[JDWP_COMMAND_SET(VirtualMachine)] = &VirtualMachine_Cmds; 70 cmdSetsArray[JDWP_COMMAND_SET(ReferenceType)] = &ReferenceType_Cmds; 71 cmdSetsArray[JDWP_COMMAND_SET(ClassType)] = &ClassType_Cmds; 72 cmdSetsArray[JDWP_COMMAND_SET(InterfaceType)] = &InterfaceType_Cmds; 73 cmdSetsArray[JDWP_COMMAND_SET(ArrayType)] = &ArrayType_Cmds; 74 75 cmdSetsArray[JDWP_COMMAND_SET(Field)] = &Field_Cmds; 76 cmdSetsArray[JDWP_COMMAND_SET(Method)] = &Method_Cmds; 77 cmdSetsArray[JDWP_COMMAND_SET(ObjectReference)] = &ObjectReference_Cmds; 78 cmdSetsArray[JDWP_COMMAND_SET(StringReference)] = &StringReference_Cmds; 79 cmdSetsArray[JDWP_COMMAND_SET(ThreadReference)] = &ThreadReference_Cmds; 80 cmdSetsArray[JDWP_COMMAND_SET(ThreadGroupReference)] = &ThreadGroupReference_Cmds; 81 cmdSetsArray[JDWP_COMMAND_SET(ClassLoaderReference)] = &ClassLoaderReference_Cmds; 82 cmdSetsArray[JDWP_COMMAND_SET(ArrayReference)] = &ArrayReference_Cmds; 83 cmdSetsArray[JDWP_COMMAND_SET(EventRequest)] = &EventRequest_Cmds; 84 cmdSetsArray[JDWP_COMMAND_SET(StackFrame)] = &StackFrame_Cmds; 85 cmdSetsArray[JDWP_COMMAND_SET(ClassObjectReference)] = &ClassObjectReference_Cmds; 86 cmdSetsArray[JDWP_COMMAND_SET(ModuleReference)] = &ModuleReference_Cmds; 87 88 } 89 90 void 91 debugDispatch_reset(void) 92 { 93 } 94 95 CommandHandler 96 debugDispatch_getHandler(int cmdSetNum, int cmdNum, const char **cmdSetName_p, const char **cmdName_p) 97 { 98 CommandSet *cmd_set; 99 *cmdSetName_p = "<Invalid CommandSet>"; 100 *cmdName_p = "<Unkown Command>"; 101 102 if (cmdSetNum > JDWP_HIGHEST_COMMAND_SET) { 103 return NULL; 104 } 105 106 cmd_set = cmdSetsArray[cmdSetNum]; 107 if (cmd_set == NULL) { 108 return NULL; 109 } 110 111 *cmdSetName_p = cmd_set->cmd_set_name; 112 if (cmdNum > cmd_set->num_cmds) { 113 *cmdName_p = "<Invalid Command>"; 114 return NULL; 115 } else { 116 *cmdName_p = cmd_set->cmds[cmdNum - 1].cmd_name; 117 return cmd_set->cmds[cmdNum - 1].cmd_handler; 118 } 119 }