annotate agent/src/share/classes/sun/jvm/hotspot/TestDebugger.java @ 2376:c7f3d0b4570f

7017732: move static fields into Class to prepare for perm gen removal Reviewed-by: kvn, coleenp, twisti, stefank
author never
date Fri, 18 Mar 2011 16:00:34 -0700
parents c18cbe5936b8
children f6f3bb0ee072
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.dbx.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // A test of the debugger backend. This should be used to connect to
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // the helloWorld.cpp program.
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class TestDebugger {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // FIXME: make these configurable, i.e., via a dotfile
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static final String dbxPathName = "/export/home/kbr/ws/dbx_61/dev/Derived-sparcv9-S2./src/dbx/dbx";
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static final String[] dbxSvcAgentDSOPathNames =
a61af66fc99e Initial load
duke
parents:
diff changeset
37 new String[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 "/export/home/kbr/main/sa_baseline/src/os/solaris/agent/libsvc_agent_dbx.so"
a61af66fc99e Initial load
duke
parents:
diff changeset
39 };
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static void usage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 System.out.println("usage: java TestDebugger [pid]");
a61af66fc99e Initial load
duke
parents:
diff changeset
43 System.out.println("pid must be the process ID of the helloWorld process");
a61af66fc99e Initial load
duke
parents:
diff changeset
44 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (args.length != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 int pid = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 pid = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 JVMDebugger debugger = new DbxDebuggerLocal(new MachineDescriptionSPARC64Bit(),
a61af66fc99e Initial load
duke
parents:
diff changeset
62 dbxPathName, dbxSvcAgentDSOPathNames, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 debugger.attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 System.err.print("Error attaching to process ID " + pid + ": ");
a61af66fc99e Initial load
duke
parents:
diff changeset
69 if (e.getMessage() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 System.err.print(e.getMessage());
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 System.err.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // HACK: configure debugger with primitive type sizes to get
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // Java types going
a61af66fc99e Initial load
duke
parents:
diff changeset
78 debugger.configureJavaPrimitiveTypeSizes(1, 1, 2, 8, 4, 4, 8, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // FIXME: figure out how to canonicalize and/or eliminate
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // loadobject specification
a61af66fc99e Initial load
duke
parents:
diff changeset
82 String loadObjectName = "-";
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // long strAddr = debugger.lookup("helloWorld", "helloWorldString");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Address addr = debugger.lookup(loadObjectName, "helloWorldString");
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 System.err.println("Error looking up symbol \"helloWorldString\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
88 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
89 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // This is a pointer which points to the start of storage.
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Dereference it.
a61af66fc99e Initial load
duke
parents:
diff changeset
94 addr = addr.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Read the number of bytes we know we need
a61af66fc99e Initial load
duke
parents:
diff changeset
97 int helloWorldLen = 13;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 byte[] data = new byte[helloWorldLen];
a61af66fc99e Initial load
duke
parents:
diff changeset
99 for (int i = 0; i < helloWorldLen; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 data[i] = (byte) addr.getCIntegerAt(i, 1, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Convert to characters
a61af66fc99e Initial load
duke
parents:
diff changeset
104 char[] chars = new char[data.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
105 for (int i = 0; i < data.length; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 chars[i] = (char) data[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 String helloWorldStr = new String(chars);
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 System.out.println("Successfully read string \"" + helloWorldStr + "\" from target process\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // Test all Java data types (see helloWorld.cpp)
a61af66fc99e Initial load
duke
parents:
diff changeset
113 byte expectedByteValue = (byte) 132;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 short expectedShortValue = (short) 27890;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 int expectedIntValue = 1020304050;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 long expectedLongValue = 102030405060708090L;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 float expectedFloatValue = 35.4F;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 double expectedDoubleValue = 1.23456789;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 byte byteValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 short shortValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int intValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 long longValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 float floatValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 double doubleValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 addr = debugger.lookup(loadObjectName, "testByte");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 System.err.println("Error looking up symbol \"testByte\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
129 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
130 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 byteValue = addr.getJByteAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (byteValue != expectedByteValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 System.err.println("Error: unexpected byte value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
135 byteValue + ", expected " + expectedByteValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
136 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 addr = debugger.lookup(loadObjectName, "testShort");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 System.err.println("Error looking up symbol \"testShort\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
142 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 shortValue = addr.getJShortAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (shortValue != expectedShortValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 System.err.println("Error: unexpected short value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
148 shortValue + ", expected " + expectedShortValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 addr = debugger.lookup(loadObjectName, "testInt");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 System.err.println("Error looking up symbol \"testInt\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
155 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 intValue = addr.getJIntAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (intValue != expectedIntValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 System.err.println("Error: unexpected int value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
161 intValue + ", expected " + expectedIntValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 addr = debugger.lookup(loadObjectName, "testLong");
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 System.err.println("Error looking up symbol \"testLong\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
168 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
169 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 longValue = addr.getJLongAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (longValue != expectedLongValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 System.err.println("Error: unexpected long value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
174 longValue + ", expected " + expectedLongValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
175 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 addr = debugger.lookup(loadObjectName, "testFloat");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 System.err.println("Error looking up symbol \"testFloat\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
181 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
182 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 floatValue = addr.getJFloatAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (floatValue != expectedFloatValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 System.err.println("Error: unexpected float value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
187 floatValue + ", expected " + expectedFloatValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
188 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 addr = debugger.lookup(loadObjectName, "testDouble");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 System.err.println("Error looking up symbol \"testDouble\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
194 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 doubleValue = addr.getJDoubleAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (doubleValue != expectedDoubleValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 System.err.println("Error: unexpected double value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
200 doubleValue + ", expected " + expectedDoubleValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 System.err.println("All tests passed successfully.");
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 debugger.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 System.err.println("Error occurred during test:");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }