1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
/*
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6202891
* @summary TTY: Add support for method exit event return values to jdb
* @comment converted from test/jdk/com/sun/jdi/JdbMethodExitTest.sh
*
* @library /test/lib
* @compile -g JdbMethodExitTest.java
* @run main/othervm JdbMethodExitTest
*/
import jdk.test.lib.process.OutputAnalyzer;
import lib.jdb.JdbCommand;
import lib.jdb.JdbTest;
import java.util.*;
import java.net.URLClassLoader;
import java.net.URL;
import java.util.stream.Collectors;
/*
* This tests the jdb trace command
*/
class JdbMethodExitTestTarg {
// These are the values that will be returned by the methods
static URL[] urls = new URL[1];
public static byte byteValue = 89;
public static char charValue = 'x';
public static double doubleValue = 2.2;
public static float floatValue = 3.3f;
public static int intValue = 1;
public static short shortValue = 8;
public static boolean booleanValue = false;
public static Class classValue = Object.class;
public static ClassLoader classLoaderValue;
{
try {
urls[0] = new URL("file:/foo");
} catch (java.net.MalformedURLException ee) {
}
classLoaderValue = new URLClassLoader(urls);
}
public static Thread threadValue;
public static ThreadGroup threadGroupValue;
public static String stringValue = "abc";
public static int[] intArrayValue = new int[] {1, 2, 3};
public static JdbMethodExitTestTarg objectValue =
new JdbMethodExitTestTarg();
public String ivar = stringValue;
// These are the instance methods
public byte i_bytef() { return byteValue; }
public char i_charf() { return charValue; }
public double i_doublef() { return doubleValue; }
public float i_floatf() { return floatValue; }
public int i_intf() { return intValue; }
public short i_shortf() { return shortValue; }
public boolean i_booleanf() { return booleanValue; }
public String i_stringf() { return stringValue; }
public Class i_classf() { return classValue; }
public ClassLoader i_classLoaderf()
{ return classLoaderValue; }
public Thread i_threadf() { return threadValue = Thread.currentThread(); }
public ThreadGroup i_threadGroupf()
{ return threadGroupValue = threadValue.getThreadGroup(); }
public int[] i_intArrayf() { return intArrayValue; }
public Object i_nullObjectf() { return null; }
public Object i_objectf() { return objectValue; }
public void i_voidf() {}
static void doit(JdbMethodExitTestTarg xx) {
xx.i_bytef();
xx.i_charf();
xx.i_doublef();
xx.i_floatf();
xx.i_intf();
xx.i_shortf();
xx.i_booleanf();
xx.i_stringf();
xx.i_intArrayf();
xx.i_classf();
xx.i_classLoaderf();
xx.i_threadf();
xx.i_threadGroupf();
xx.i_nullObjectf();
xx.i_objectf();
xx.i_voidf();
// Prove it works for native methods too
StrictMath.sin(doubleValue);
stringValue.intern();
}
public static void bkpt() {
int i = 0; //@1 breakpoint
}
public static String traceMethods() {
return "traceMethods";
}
public static String traceMethods1() {
return "traceMethods1";
}
public static String traceExits() {
return "traceExits";
}
public static String traceExits1() {
return "traceExits1";
}
public static String traceExit() {
return "traceExit";
}
public static String traceExit1() {
return "traceExit1";
}
public static void main(String[] args) {
// The debugger will stop at the start of main,
// enable method exit events, and then do
// a resume.
JdbMethodExitTestTarg xx = new JdbMethodExitTestTarg();
bkpt();
// test all possible return types
doit(xx);
bkpt();
// test trace methods
traceMethods();
// test trace go methods
traceMethods1();
bkpt();
// test trace method exits
traceExits();
// test trace method exits
traceExits1();
bkpt();
// test trace method exit
traceExit();
// test trace method exit
traceExit1();
bkpt();
}
}
public class JdbMethodExitTest extends JdbTest {
public static void main(String argv[]) {
new JdbMethodExitTest().run();
}
private JdbMethodExitTest() {
super(DEBUGGEE_CLASS);
}
private static final String DEBUGGEE_CLASS = JdbMethodExitTestTarg.class.getName();
@Override
protected void runCases() {
setBreakpointsFromTestSource("JdbMethodExitTest.java", 1);
// test all possible return types
execCommand(JdbCommand.run())
.shouldContain("Breakpoint hit");
// In order to find the main threadId, we need to parse a line from the "threads"
// command output that looks something like:
// (java.lang.VirtualThread)694 main running (at breakpoint)
OutputAnalyzer o = execCommand(JdbCommand.threads());
String match = o.firstMatch("^\\s*\\(.+\\)(\\d+)\\s+main\\s+running.+$", 1);
Integer threadId = Integer.parseInt(match);
jdb.command(JdbCommand.untrace());
jdb.command(JdbCommand.traceMethods(false, null));
execCommand(JdbCommand.trace())
.shouldContain("trace methods in effect");
jdb.command(JdbCommand.traceMethods(true, null));
execCommand(JdbCommand.trace())
.shouldContain("trace go methods in effect");
jdb.command(JdbCommand.traceMethodExits(false, null));
execCommand(JdbCommand.trace())
.shouldContain("trace method exits in effect");
jdb.command(JdbCommand.traceMethodExits(true, null));
execCommand(JdbCommand.trace())
.shouldContain("trace go method exits in effect");
jdb.command(JdbCommand.traceMethodExit(false, null));
execCommand(JdbCommand.trace())
.shouldContain("trace method exit in effect for JdbMethodExitTestTarg.bkpt");
jdb.command(JdbCommand.traceMethodExit(true, null));
execCommand(JdbCommand.trace())
.shouldContain("trace go method exit in effect for JdbMethodExitTestTarg.bkpt");
// trace exit of methods with all the return values
// (but just check a couple of them)
jdb.command(JdbCommand.traceMethodExits(true, threadId));
execCommand(JdbCommand.cont())
.shouldContain("instance of JdbMethodExitTestTarg")
.shouldContain("return value = 8");
// Get out of bkpt back to the call to traceMethods
jdb.command(JdbCommand.stepUp());
jdb.command(JdbCommand.traceMethods(false, threadId));
execCommand(JdbCommand.cont())
.shouldContain("Method entered:");
execCommand(JdbCommand.cont())
.shouldContain("Method exited: return value = \"traceMethods\"");
jdb.command(JdbCommand.stepUp());
List<String> reply = new LinkedList<>();
reply.addAll(jdb.command(JdbCommand.traceMethods(true, threadId)));
reply.addAll(jdb.command(JdbCommand.cont()));
reply.addAll(jdb.command(JdbCommand.cont()));
reply.addAll(jdb.command(JdbCommand.cont()));
new OutputAnalyzer(reply.stream().collect(Collectors.joining(lineSeparator)))
.shouldContain("Method entered: \"thread=main\", JdbMethodExitTestTarg.traceMethods1")
.shouldMatch("Method exited: .* JdbMethodExitTestTarg.traceMethods1");
jdb.command(JdbCommand.untrace());
jdb.command(JdbCommand.stepUp());
reply.clear();
reply.addAll(jdb.command(JdbCommand.traceMethodExits(false, threadId)));
reply.addAll(jdb.command(JdbCommand.cont()));
new OutputAnalyzer(reply.stream().collect(Collectors.joining(lineSeparator)))
.shouldContain("Method exited: return value = \"traceExits\"");
jdb.command(JdbCommand.untrace());
jdb.command(JdbCommand.stepUp());
reply.clear();
reply.addAll(jdb.command(JdbCommand.traceMethodExits(true, threadId)));
reply.addAll(jdb.command(JdbCommand.cont()));
new OutputAnalyzer(reply.stream().collect(Collectors.joining(lineSeparator)))
.shouldMatch("Method exited: .* JdbMethodExitTestTarg.traceExits1");
jdb.command(JdbCommand.untrace());
jdb.command(JdbCommand.stepUp());
reply.clear();
reply.addAll(jdb.command(JdbCommand.step())); // step into traceExit()
reply.addAll(jdb.command(JdbCommand.traceMethodExit(false, threadId)));
reply.addAll(jdb.command(JdbCommand.cont()));
new OutputAnalyzer(reply.stream().collect(Collectors.joining(lineSeparator)))
.shouldContain("Method exited: return value = \"traceExit\"");
jdb.command(JdbCommand.untrace());
jdb.command(JdbCommand.stepUp());
reply.clear();
reply.addAll(jdb.command(JdbCommand.step()));
reply.addAll(jdb.command(JdbCommand.step())); // skip over setting return value in caller :-(
reply.addAll(jdb.command(JdbCommand.traceMethodExit(true, threadId)));
reply.addAll(jdb.command(JdbCommand.cont()));
new OutputAnalyzer(reply.stream().collect(Collectors.joining(lineSeparator)))
.shouldMatch("Method exited: .*JdbMethodExitTestTarg.traceExit1");
new OutputAnalyzer(getJdbOutput())
.shouldContain("Breakpoint hit");
}
}
|