• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1998, 2008, 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 "ObjectReferenceImpl.h"
37 #include "StringReferenceImpl.h"
38 #include "ThreadReferenceImpl.h"
39 #include "ThreadGroupReferenceImpl.h"
40 #include "ClassLoaderReferenceImpl.h"
41 #include "ClassObjectReferenceImpl.h"
42 #include "ArrayReferenceImpl.h"
43 #include "EventRequestImpl.h"
44 #include "StackFrameImpl.h"
45 #include "DDMImpl.h"
46 
47 static void **l1Array;
48 
49 void
debugDispatch_initialize(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     l1Array = jvmtiAllocate((JDWP_HIGHEST_COMMAND_SET+1) * sizeof(void *));
58 
59     if (l1Array == NULL) {
60         EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"command set array");
61     }
62 
63     (void)memset(l1Array, 0, (JDWP_HIGHEST_COMMAND_SET+1) * sizeof(void *));
64 
65     /*
66      * Create the level-two (Command) dispatch tables to the
67      * corresponding slots in the CommandSet dispatch table..
68      */
69     l1Array[JDWP_COMMAND_SET(VirtualMachine)] = (void *)VirtualMachine_Cmds;
70     l1Array[JDWP_COMMAND_SET(ReferenceType)] = (void *)ReferenceType_Cmds;
71     l1Array[JDWP_COMMAND_SET(ClassType)] = (void *)ClassType_Cmds;
72     l1Array[JDWP_COMMAND_SET(InterfaceType)] = (void *)InterfaceType_Cmds;
73     l1Array[JDWP_COMMAND_SET(ArrayType)] = (void *)ArrayType_Cmds;
74 
75     l1Array[JDWP_COMMAND_SET(Field)] = (void *)Field_Cmds;
76     l1Array[JDWP_COMMAND_SET(Method)] = (void *)Method_Cmds;
77     l1Array[JDWP_COMMAND_SET(ObjectReference)] = (void *)ObjectReference_Cmds;
78     l1Array[JDWP_COMMAND_SET(StringReference)] = (void *)StringReference_Cmds;
79     l1Array[JDWP_COMMAND_SET(ThreadReference)] = (void *)ThreadReference_Cmds;
80     l1Array[JDWP_COMMAND_SET(ThreadGroupReference)] = (void *)ThreadGroupReference_Cmds;
81     l1Array[JDWP_COMMAND_SET(ClassLoaderReference)] = (void *)ClassLoaderReference_Cmds;
82     l1Array[JDWP_COMMAND_SET(ArrayReference)] = (void *)ArrayReference_Cmds;
83     l1Array[JDWP_COMMAND_SET(EventRequest)] = (void *)EventRequest_Cmds;
84     l1Array[JDWP_COMMAND_SET(StackFrame)] = (void *)StackFrame_Cmds;
85     l1Array[JDWP_COMMAND_SET(ClassObjectReference)] = (void *)ClassObjectReference_Cmds;
86 }
87 
88 void
debugDispatch_reset(void)89 debugDispatch_reset(void)
90 {
91 }
92 
93 CommandHandler
debugDispatch_getHandler(int cmdSet,int cmd)94 debugDispatch_getHandler(int cmdSet, int cmd)
95 {
96     void **l2Array;
97 
98     // ANDROID-CHANGED: DDMS has cmdSet -57 (199u). Check for this one specifically.
99     if (cmdSet == JDWP_COMMAND_SET(DDM)) {
100         l2Array = (void **)DDM_Cmds;
101     } else if (cmdSet > JDWP_HIGHEST_COMMAND_SET || cmdSet < 0) {
102         return NULL;
103     } else {
104         l2Array = (void **)l1Array[cmdSet];
105     }
106 
107     /*
108      * If there is no such CommandSet or the Command
109      * is greater than the nummber of commands (the first
110      * element) in the CommandSet, indicate this is invalid.
111      */
112     /*LINTED*/
113     if (l2Array == NULL || cmd > (int)(intptr_t)(void*)l2Array[0]) {
114         return NULL;
115     }
116 
117     return (CommandHandler)l2Array[cmd];
118 }
119