|
1 #!/bin/sh |
|
2 |
|
3 # |
|
4 # Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved. |
|
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
6 # |
|
7 # This code is free software; you can redistribute it and/or modify it |
|
8 # under the terms of the GNU General Public License version 2 only, as |
|
9 # published by the Free Software Foundation. |
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 # CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 # have any questions. |
|
24 # |
|
25 |
|
26 # @test |
|
27 # @bug 6202891 |
|
28 # @summary TTY: Add support for method exit event return values to jdb |
|
29 # @author Jim Holmlund |
|
30 # @run shell JdbMethodExitTest.sh |
|
31 |
|
32 # These are variables that can be set to control execution |
|
33 |
|
34 #pkg=untitled7 |
|
35 classname=JdbMethodExitTest |
|
36 compileOptions=-g |
|
37 #java="java_g" |
|
38 #set -x |
|
39 |
|
40 createJavaFile() |
|
41 { |
|
42 cat <<EOF > $classname.java.1 |
|
43 import java.util.*; |
|
44 import java.net.URLClassLoader; |
|
45 import java.net.URL; |
|
46 |
|
47 /* |
|
48 * This tests the jdb trace command |
|
49 */ |
|
50 |
|
51 class $classname { |
|
52 // These are the values that will be returned by the methods |
|
53 static URL[] urls = new URL[1]; |
|
54 public static byte byteValue = 89; |
|
55 public static char charValue = 'x'; |
|
56 public static double doubleValue = 2.2; |
|
57 public static float floatValue = 3.3f; |
|
58 public static int intValue = 1; |
|
59 public static short shortValue = 8; |
|
60 public static boolean booleanValue = false; |
|
61 |
|
62 public static Class classValue = Object.class; |
|
63 public static ClassLoader classLoaderValue; |
|
64 { |
|
65 try { |
|
66 urls[0] = new URL("hi there"); |
|
67 } catch (java.net.MalformedURLException ee) { |
|
68 } |
|
69 classLoaderValue = new URLClassLoader(urls); |
|
70 } |
|
71 |
|
72 public static Thread threadValue; |
|
73 public static ThreadGroup threadGroupValue; |
|
74 public static String stringValue = "abc"; |
|
75 public static int[] intArrayValue = new int[] {1, 2, 3}; |
|
76 |
|
77 public static $classname objectValue = |
|
78 new $classname(); |
|
79 public String ivar = stringValue; |
|
80 |
|
81 // These are the instance methods |
|
82 public byte i_bytef() { return byteValue; } |
|
83 public char i_charf() { return charValue; } |
|
84 public double i_doublef() { return doubleValue; } |
|
85 public float i_floatf() { return floatValue; } |
|
86 public int i_intf() { return intValue; } |
|
87 public short i_shortf() { return shortValue; } |
|
88 public boolean i_booleanf() { return booleanValue; } |
|
89 public String i_stringf() { return stringValue; } |
|
90 public Class i_classf() { return classValue; } |
|
91 public ClassLoader i_classLoaderf() |
|
92 { return classLoaderValue; } |
|
93 public Thread i_threadf() { return threadValue = Thread.currentThread(); } |
|
94 public ThreadGroup i_threadGroupf() |
|
95 { return threadGroupValue = threadValue.getThreadGroup(); } |
|
96 public int[] i_intArrayf() { return intArrayValue; } |
|
97 public Object i_nullObjectf() { return null; } |
|
98 public Object i_objectf() { return objectValue; } |
|
99 public void i_voidf() {} |
|
100 |
|
101 static void doit($classname xx) { |
|
102 |
|
103 xx.i_bytef(); |
|
104 xx.i_charf(); |
|
105 xx.i_doublef(); |
|
106 xx.i_floatf(); |
|
107 xx.i_intf(); |
|
108 xx.i_shortf(); |
|
109 xx.i_booleanf(); |
|
110 xx.i_stringf(); |
|
111 xx.i_intArrayf(); |
|
112 xx.i_classf(); |
|
113 xx.i_classLoaderf(); |
|
114 xx.i_threadf(); |
|
115 xx.i_threadGroupf(); |
|
116 xx.i_nullObjectf(); |
|
117 xx.i_objectf(); |
|
118 xx.i_voidf(); |
|
119 |
|
120 // Prove it works for native methods too |
|
121 StrictMath.sin(doubleValue); |
|
122 stringValue.intern(); |
|
123 } |
|
124 |
|
125 public static void bkpt() { |
|
126 int i = 0; //@1 breakpoint |
|
127 } |
|
128 |
|
129 public static String traceMethods() { |
|
130 return "traceMethods"; |
|
131 } |
|
132 |
|
133 public static String traceMethods1() { |
|
134 return "traceMethods1"; |
|
135 } |
|
136 |
|
137 public static String traceExits() { |
|
138 return "traceExits"; |
|
139 } |
|
140 |
|
141 public static String traceExits1() { |
|
142 return "traceExits1"; |
|
143 } |
|
144 |
|
145 public static String traceExit() { |
|
146 return "traceExit"; |
|
147 } |
|
148 |
|
149 public static String traceExit1() { |
|
150 return "traceExit1"; |
|
151 } |
|
152 |
|
153 public static void main(String[] args) { |
|
154 // The debugger will stop at the start of main, |
|
155 // enable method exit events, and then do |
|
156 // a resume. |
|
157 |
|
158 $classname xx = new $classname(); |
|
159 |
|
160 bkpt(); |
|
161 |
|
162 // test all possible return types |
|
163 doit(xx); |
|
164 bkpt(); |
|
165 |
|
166 // test trace methods |
|
167 traceMethods(); |
|
168 |
|
169 // test trace go methods |
|
170 traceMethods1(); |
|
171 bkpt(); |
|
172 |
|
173 // test trace method exits |
|
174 traceExits(); |
|
175 |
|
176 // test trace method exits |
|
177 traceExits1(); |
|
178 bkpt(); |
|
179 |
|
180 // test trace method exit |
|
181 traceExit(); |
|
182 |
|
183 // test trace method exit |
|
184 traceExit1(); |
|
185 bkpt(); |
|
186 |
|
187 } |
|
188 } |
|
189 EOF |
|
190 } |
|
191 |
|
192 |
|
193 # drive jdb by sending cmds to it and examining its output |
|
194 dojdbCmds() |
|
195 { |
|
196 setBkpts @1 |
|
197 |
|
198 # test all possible return types |
|
199 runToBkpt @1 |
|
200 cmd untrace |
|
201 |
|
202 cmd trace methods |
|
203 cmd trace |
|
204 jdbFailIfNotPresent "trace methods in effect" |
|
205 |
|
206 cmd trace go methods |
|
207 cmd trace |
|
208 jdbFailIfNotPresent "trace go methods in effect" |
|
209 |
|
210 cmd trace method exits |
|
211 cmd trace |
|
212 jdbFailIfNotPresent "trace method exits in effect" |
|
213 |
|
214 cmd trace go method exits |
|
215 cmd trace |
|
216 jdbFailIfNotPresent "trace go method exits in effect" |
|
217 |
|
218 cmd trace method exit |
|
219 cmd trace |
|
220 jdbFailIfNotPresent "trace method exit in effect for JdbMethodExitTest.bkpt" |
|
221 |
|
222 cmd trace go method exit |
|
223 cmd trace |
|
224 jdbFailIfNotPresent "trace go method exit in effect for JdbMethodExitTest.bkpt" |
|
225 |
|
226 |
|
227 # trace exit of methods with all the return values |
|
228 # (but just check a couple of them) |
|
229 cmd trace go exits |
|
230 cmd cont |
|
231 jdbFailIfNotPresent "instance of JdbMethodExitTest" |
|
232 jdbFailIfNotPresent "return value = 8" |
|
233 |
|
234 # Get out of bkpt back to the call to traceMethods |
|
235 cmd step up |
|
236 |
|
237 |
|
238 cmd trace methods |
|
239 cmd cont |
|
240 jdbFailIfNotPresent "Method entered:" |
|
241 cmd cont |
|
242 jdbFailIfNotPresent "Method exited: return value = \"traceMethods\"" |
|
243 cmd step up |
|
244 |
|
245 |
|
246 cmd trace go methods |
|
247 cmd cont |
|
248 jdbFailIfNotPresent "Method entered: \"thread=main\", JdbMethodExitTest.traceMethods1" |
|
249 jdbFailIfNotPresent 'Method exited: .* JdbMethodExitTest.traceMethods1' |
|
250 cmd untrace |
|
251 cmd step up |
|
252 |
|
253 |
|
254 cmd trace method exits |
|
255 cmd cont |
|
256 jdbFailIfNotPresent "Method exited: return value = \"traceExits\"" |
|
257 cmd untrace |
|
258 cmd step up |
|
259 |
|
260 |
|
261 cmd trace go method exits |
|
262 cmd cont |
|
263 jdbFailIfNotPresent 'Method exited: .* JdbMethodExitTest.traceExits1' |
|
264 cmd untrace |
|
265 cmd step up |
|
266 |
|
267 |
|
268 cmd step # step into traceExit() |
|
269 cmd trace method exit |
|
270 cmd cont |
|
271 jdbFailIfNotPresent "Method exited: return value = \"traceExit\"" |
|
272 cmd untrace |
|
273 cmd step up |
|
274 |
|
275 |
|
276 cmd step |
|
277 cmd step # skip over setting return value in caller :-( |
|
278 cmd trace go method exit |
|
279 cmd cont |
|
280 jdbFailIfNotPresent 'Method exited: .*JdbMethodExitTest.traceExit1' |
|
281 cmd quit |
|
282 } |
|
283 |
|
284 |
|
285 mysetup() |
|
286 { |
|
287 if [ -z "$TESTSRC" ] ; then |
|
288 TESTSRC=. |
|
289 fi |
|
290 |
|
291 for ii in . $TESTSRC $TESTSRC/.. ; do |
|
292 if [ -r "$ii/ShellScaffold.sh" ] ; then |
|
293 . $ii/ShellScaffold.sh |
|
294 break |
|
295 fi |
|
296 done |
|
297 } |
|
298 |
|
299 # You could replace this next line with the contents |
|
300 # of ShellScaffold.sh and this script will run just the same. |
|
301 mysetup |
|
302 |
|
303 runit |
|
304 jdbFailIfNotPresent "Breakpoint hit" |
|
305 pass |