annotate agent/src/share/classes/sun/jvm/hotspot/TestDebugger.java @ 6641:a9fed06c01d2

7154641: Servicability agent should work on platforms other than x86, sparc Summary: Added capability to load support classes for other cpus Reviewed-by: coleenp, bobv, sla Contributed-by: Bill Pittore <bill.pittore@oracle.com>
author bpittore
date Thu, 30 Aug 2012 11:20:01 -0400
parents f6f3bb0ee072
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2011, 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.*;
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
28 import sun.jvm.hotspot.debugger.proc.*;
0
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
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static void usage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 System.out.println("usage: java TestDebugger [pid]");
a61af66fc99e Initial load
duke
parents:
diff changeset
37 System.out.println("pid must be the process ID of the helloWorld process");
a61af66fc99e Initial load
duke
parents:
diff changeset
38 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 if (args.length != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int pid = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 pid = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51 catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
55 JVMDebugger debugger = new ProcDebuggerLocal(null, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 debugger.attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 System.err.print("Error attaching to process ID " + pid + ": ");
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if (e.getMessage() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 System.err.print(e.getMessage());
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 System.err.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // HACK: configure debugger with primitive type sizes to get
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Java types going
a61af66fc99e Initial load
duke
parents:
diff changeset
71 debugger.configureJavaPrimitiveTypeSizes(1, 1, 2, 8, 4, 4, 8, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // FIXME: figure out how to canonicalize and/or eliminate
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // loadobject specification
a61af66fc99e Initial load
duke
parents:
diff changeset
75 String loadObjectName = "-";
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // long strAddr = debugger.lookup("helloWorld", "helloWorldString");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Address addr = debugger.lookup(loadObjectName, "helloWorldString");
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 System.err.println("Error looking up symbol \"helloWorldString\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
81 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
82 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // This is a pointer which points to the start of storage.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Dereference it.
a61af66fc99e Initial load
duke
parents:
diff changeset
87 addr = addr.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Read the number of bytes we know we need
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int helloWorldLen = 13;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 byte[] data = new byte[helloWorldLen];
a61af66fc99e Initial load
duke
parents:
diff changeset
92 for (int i = 0; i < helloWorldLen; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 data[i] = (byte) addr.getCIntegerAt(i, 1, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Convert to characters
a61af66fc99e Initial load
duke
parents:
diff changeset
97 char[] chars = new char[data.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
98 for (int i = 0; i < data.length; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 chars[i] = (char) data[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 String helloWorldStr = new String(chars);
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 System.out.println("Successfully read string \"" + helloWorldStr + "\" from target process\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Test all Java data types (see helloWorld.cpp)
a61af66fc99e Initial load
duke
parents:
diff changeset
106 byte expectedByteValue = (byte) 132;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 short expectedShortValue = (short) 27890;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 int expectedIntValue = 1020304050;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 long expectedLongValue = 102030405060708090L;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 float expectedFloatValue = 35.4F;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 double expectedDoubleValue = 1.23456789;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 byte byteValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 short shortValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 int intValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 long longValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 float floatValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 double doubleValue = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 addr = debugger.lookup(loadObjectName, "testByte");
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 System.err.println("Error looking up symbol \"testByte\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
122 loadObjectName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
123 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 byteValue = addr.getJByteAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (byteValue != expectedByteValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 System.err.println("Error: unexpected byte value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
128 byteValue + ", expected " + expectedByteValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 addr = debugger.lookup(loadObjectName, "testShort");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 System.err.println("Error looking up symbol \"testShort\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
135 loadObjectName + "\"");
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 shortValue = addr.getJShortAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (shortValue != expectedShortValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 System.err.println("Error: unexpected short value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
141 shortValue + ", expected " + expectedShortValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 addr = debugger.lookup(loadObjectName, "testInt");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 System.err.println("Error looking up symbol \"testInt\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
148 loadObjectName + "\"");
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 intValue = addr.getJIntAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (intValue != expectedIntValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 System.err.println("Error: unexpected int value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
154 intValue + ", expected " + expectedIntValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
155 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 addr = debugger.lookup(loadObjectName, "testLong");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 System.err.println("Error looking up symbol \"testLong\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
161 loadObjectName + "\"");
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 longValue = addr.getJLongAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (longValue != expectedLongValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 System.err.println("Error: unexpected long value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
167 longValue + ", expected " + expectedLongValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 addr = debugger.lookup(loadObjectName, "testFloat");
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 System.err.println("Error looking up symbol \"testFloat\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
174 loadObjectName + "\"");
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 floatValue = addr.getJFloatAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (floatValue != expectedFloatValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 System.err.println("Error: unexpected float value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
180 floatValue + ", expected " + expectedFloatValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
181 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 addr = debugger.lookup(loadObjectName, "testDouble");
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 System.err.println("Error looking up symbol \"testDouble\" in context \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
187 loadObjectName + "\"");
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 doubleValue = addr.getJDoubleAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (doubleValue != expectedDoubleValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 System.err.println("Error: unexpected double value (got " +
a61af66fc99e Initial load
duke
parents:
diff changeset
193 doubleValue + ", expected " + expectedDoubleValue + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 System.err.println("All tests passed successfully.");
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 debugger.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201 catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 System.err.println("Error occurred during test:");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }