1/*
2 * Copyright (c) 1998, 2016, 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
47static void **l1Array;
48
49void
50debugDispatch_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 l1Array[JDWP_COMMAND_SET(ModuleReference)] = (void *)ModuleReference_Cmds;
87}
88
89void
90debugDispatch_reset(void)
91{
92}
93
94CommandHandler
95debugDispatch_getHandler(int cmdSet, int cmd)
96{
97 void **l2Array;
98
99 if (cmdSet > JDWP_HIGHEST_COMMAND_SET) {
100 return NULL;
101 }
102
103 l2Array = (void **)l1Array[cmdSet];
104
105 /*
106 * If there is no such CommandSet or the Command
107 * is greater than the nummber of commands (the first
108 * element) in the CommandSet, indicate this is invalid.
109 */
110 /*LINTED*/
111 if (l2Array == NULL || cmd > (int)(intptr_t)(void*)l2Array[0]) {
112 return NULL;
113 }
114
115 return (CommandHandler)l2Array[cmd];
116}
117