1
1
/*
2
- * Copyright (c) 2016, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2016, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
22
22
*/
23
23
24
24
import java .util .StringTokenizer ;
25
- import jdk .test .lib .JDKToolFinder ;
26
25
import jdk .test .lib .JDWP ;
27
26
import static jdk .test .lib .Asserts .assertFalse ;
27
+ import jdk .test .lib .process .ProcessTools ;
28
28
29
29
/**
30
30
* Launches the debuggee with the necessary JDWP options and handles the output
@@ -45,21 +45,14 @@ public interface Listener {
45
45
*/
46
46
void onDebuggeeSendingCompleted ();
47
47
48
- /**
49
- * Callback to handle any debuggee error
50
- *
51
- * @param line line from the debuggee's stderr
52
- */
53
- void onDebuggeeError (String line );
54
48
}
55
49
56
50
private int jdwpPort = -1 ;
57
- private static final String CLS_DIR = System .getProperty ("test.classes" , "" ).trim ();
58
51
private static final String DEBUGGEE = "AllModulesCommandTestDebuggee" ;
52
+ private static final String JDWP_OPT = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0" ;
53
+
59
54
private Process p ;
60
55
private final Listener listener ;
61
- private StreamHandler inputHandler ;
62
- private StreamHandler errorHandler ;
63
56
64
57
/**
65
58
* @param listener the listener we report the debuggee events to
@@ -70,36 +63,20 @@ public DebuggeeLauncher(Listener listener) {
70
63
71
64
/**
72
65
* Starts the debuggee with the necessary JDWP options and handles the
73
- * debuggee's stdout and stderr outputs
66
+ * debuggee's stdout output. stderr might contain jvm output, which is just printed to the log.
74
67
*
75
68
* @throws Throwable
76
69
*/
77
70
public void launchDebuggee () throws Throwable {
78
71
79
- ProcessBuilder pb = new ProcessBuilder ( getCommand () );
72
+ ProcessBuilder pb = ProcessTools . createTestJvm ( JDWP_OPT , DEBUGGEE );
80
73
p = pb .start ();
81
- inputHandler = new StreamHandler (p .getInputStream (), this );
82
- errorHandler = new StreamHandler (p .getErrorStream (), this );
74
+ StreamHandler inputHandler = new StreamHandler (p .getInputStream (), this );
75
+ StreamHandler errorHandler = new StreamHandler (p .getErrorStream (), l -> System . out . println ( "[stderr]: " + l ) );
83
76
inputHandler .start ();
84
77
errorHandler .start ();
85
78
}
86
79
87
- /**
88
- * Command to start the debuggee with the JDWP options and using the JDK
89
- * under test
90
- *
91
- * @return the command
92
- */
93
- private String [] getCommand () {
94
- return new String []{
95
- JDKToolFinder .getTestJDKTool ("java" ),
96
- getJdwpOptions (),
97
- "-cp" ,
98
- CLS_DIR ,
99
- DEBUGGEE
100
- };
101
- }
102
-
103
80
/**
104
81
* Terminates the debuggee
105
82
*/
@@ -109,15 +86,6 @@ public void terminateDebuggee() {
109
86
}
110
87
}
111
88
112
- /**
113
- * Debuggee JDWP options
114
- *
115
- * @return the JDWP options to start the debuggee with
116
- */
117
- private static String getJdwpOptions () {
118
- return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0" ;
119
- }
120
-
121
89
/**
122
90
* Gets JDWP port debuggee is listening on.
123
91
*
@@ -129,16 +97,8 @@ public int getJdwpPort() {
129
97
}
130
98
131
99
@ Override
132
- public void onStringRead (StreamHandler handler , String line ) {
133
- if (handler .equals (errorHandler )) {
134
- terminateDebuggee ();
135
- listener .onDebuggeeError (line );
136
- } else {
137
- processDebuggeeOutput (line );
138
- }
139
- }
140
-
141
- private void processDebuggeeOutput (String line ) {
100
+ public void onStringRead (String line ) {
101
+ System .out .println ("[stdout]: " + line );
142
102
if (jdwpPort == -1 ) {
143
103
JDWP .ListenAddress addr = JDWP .parseListenAddress (line );
144
104
if (addr != null ) {
0 commit comments