Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Launcher.java
41161 views
1
/*
2
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
package nsk.share.jdb;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.ArgumentHandler;
29
30
import java.io.*;
31
import java.util.*;
32
33
/**
34
* This class provides launching of <code>jdb</code> and debuggee in local
35
* or remote mode according to test command line options.
36
*/
37
38
public class Launcher extends DebugeeBinder {
39
40
/* Delay in milliseconds after launching jdb.*/
41
static final long DEBUGGEE_START_DELAY = 5 * 1000;
42
43
protected static Jdb jdb;
44
45
protected static Debuggee debuggee;
46
47
/** Pattern for message of jdb has started. */
48
protected static String JDB_STARTED = "Initializing jdb";
49
50
/**
51
* Get version string.
52
*/
53
public static String getVersion () {
54
return "@(#)Launcher.java %I% %E%";
55
}
56
57
// -------------------------------------------------- //
58
59
/**
60
* Handler of command line arguments.
61
*/
62
protected static JdbArgumentHandler argumentHandler = null;
63
64
/**
65
* Return <code>argumentHandler</code> of this binder.
66
*/
67
public static JdbArgumentHandler getJdbArgumentHandler() {
68
return argumentHandler;
69
}
70
71
/**
72
* Return <code>jdb</code> mirror of this binder.
73
*/
74
public static Jdb getJdb() {
75
return jdb;
76
}
77
78
/**
79
* Return debuggee mirror of this binder.
80
*/
81
public static Debuggee getDebuggee() {
82
return debuggee;
83
}
84
85
/**
86
* Incarnate new Launcher obeying the given
87
* <code>argumentHandler</code>; and assign the given
88
* <code>log</code>.
89
*/
90
public Launcher (JdbArgumentHandler argumentHandler, Log log) {
91
super(argumentHandler, log);
92
setLogPrefix("launcher > ");
93
this.argumentHandler = argumentHandler;
94
}
95
96
/**
97
* Defines mode (local or remote) and type of connector (default, launching,
98
* raw launching, attaching or listening) according to options
99
* parsed by <code>JdbArgumentHandler</code>. And then launches <code>jdb</code>
100
* and debuggee in defined mode.
101
*/
102
public void launchJdbAndDebuggee (String classToExecute) throws IOException {
103
104
String[] jdbCmdArgs = makeJdbCmdLine(classToExecute);
105
106
if (argumentHandler.isLaunchedLocally()) {
107
108
if (argumentHandler.isDefaultConnector()) {
109
110
localDefaultLaunch(jdbCmdArgs, classToExecute);
111
112
} else if (argumentHandler.isRawLaunchingConnector()) {
113
114
localRawLaunch(jdbCmdArgs, classToExecute);
115
116
} else if (argumentHandler.isLaunchingConnector()) {
117
118
localLaunch(jdbCmdArgs, classToExecute);
119
120
} else if (argumentHandler.isAttachingConnector()) {
121
122
localLaunchAndAttach(jdbCmdArgs, classToExecute);
123
124
} else if (argumentHandler.isListeningConnector()) {
125
126
localLaunchAndListen(jdbCmdArgs, classToExecute);
127
128
} else {
129
throw new TestBug("Unexpected connector type for local launch mode"
130
+ argumentHandler.getConnectorType());
131
}
132
133
} else if (argumentHandler.isLaunchedRemotely()) {
134
135
connectToBindServer(classToExecute);
136
137
if (argumentHandler.isAttachingConnector()) {
138
139
remoteLaunchAndAttach(jdbCmdArgs, classToExecute);
140
141
} else if (argumentHandler.isListeningConnector()) {
142
143
remoteLaunchAndListen(jdbCmdArgs, classToExecute);
144
145
} else {
146
throw new TestBug("Unexpected connector type for remote launch mode"
147
+ argumentHandler.getConnectorType());
148
}
149
} else {
150
throw new Failure("Unexpected launching mode: " + argumentHandler.getLaunchMode());
151
}
152
}
153
154
/**
155
* Creates String array to launch <code>jdb</code> according to options
156
* parsed by <code>JdbArgumentHandler</code>.
157
*/
158
private String[] makeJdbCmdLine (String classToExecute) {
159
160
Vector<String> args = new Vector<String>();
161
162
String jdbExecPath = argumentHandler.getJdbExecPath();
163
args.add(jdbExecPath.trim());
164
args.addAll(argumentHandler.enwrapJavaOptions(argumentHandler.getJavaOptions()));
165
166
String jdbOptions = argumentHandler.getJdbOptions();
167
if (jdbOptions.trim().length() > 0) {
168
StringTokenizer tokenizer = new StringTokenizer(jdbOptions);
169
while (tokenizer.hasMoreTokens()) {
170
String option = tokenizer.nextToken();
171
args.add(option);
172
}
173
}
174
if (classToExecute == null)
175
return args.toArray(new String[args.size()]);
176
args.add("-connect");
177
StringBuffer connect = new StringBuffer();
178
179
if (argumentHandler.isLaunchingConnector()) {
180
181
// Do not need to use quote symbol.
182
// String quote = '\"';
183
// connect.append(quote + argumentHandler.getConnectorName() + ":");
184
connect.append(argumentHandler.getConnectorName() + ":");
185
186
String connectorAddress;
187
String vmAddress = makeTransportAddress();;
188
189
if (argumentHandler.isRawLaunchingConnector()) {
190
191
if (argumentHandler.isSocketTransport()) {
192
if (argumentHandler.isLaunchedLocally()) {
193
connectorAddress = argumentHandler.getTransportPort();
194
} else {
195
connectorAddress = argumentHandler.getDebugeeHost() + ":" + argumentHandler.getTransportPort();
196
}
197
} else if (argumentHandler.isShmemTransport() ) {
198
connectorAddress = argumentHandler.getTransportSharedName();
199
} else {
200
throw new TestBug("Launcher: Undefined transport type for RawLaunchingConnector");
201
}
202
203
connect.append("address=" + connectorAddress.trim());
204
connect.append(",command=" + makeCommandLineString(classToExecute, vmAddress, " ").trim());
205
206
} else /* LaunchingConnector or DefaultConnector */ {
207
208
connect.append("vmexec=" + argumentHandler.getLaunchExecName().trim());
209
String debuggeeOpts = argumentHandler.getDebuggeeOptions();
210
if (debuggeeOpts.trim().length() > 0) {
211
//connect.append(",options=" + debuggeeOpts.trim());
212
connect.append(",options=");
213
for (String arg : debuggeeOpts.split("\\s+")) {
214
connect.append(" \"");
215
connect.append(arg);
216
connect.append("\"");
217
}
218
}
219
String cmdline = classToExecute + " " + ArgumentHandler.joinArguments(argumentHandler.getArguments(), " ");
220
connect.append(",main=" + cmdline.trim());
221
222
}
223
224
// connect.append(quote);
225
226
} else {
227
228
connect.append(argumentHandler.getConnectorName() + ":");
229
230
if (argumentHandler.isAttachingConnector()) {
231
232
if (argumentHandler.isSocketTransport()) {
233
connect.append("port=" + argumentHandler.getTransportPort().trim());
234
if (argumentHandler.isLaunchedRemotely())
235
connect.append(",hostname=" + argumentHandler.getDebugeeHost().trim());
236
} else if (argumentHandler.isShmemTransport()) {
237
connect.append("name=" + argumentHandler.getTransportSharedName().trim());
238
} else {
239
throw new TestBug("Launcher: Undefined transport type for AttachingConnector");
240
}
241
242
243
} else if (argumentHandler.isListeningConnector()) {
244
245
if (!argumentHandler.isTransportAddressDynamic()) {
246
if (argumentHandler.isSocketTransport()) {
247
connect.append("port=" + argumentHandler.getTransportPort().trim());
248
} else if (argumentHandler.isShmemTransport()) {
249
connect.append("name=" + argumentHandler.getTransportSharedName().trim());
250
} else {
251
throw new TestBug("Launcher: Undefined transport type for AttachingConnector");
252
}
253
}
254
255
} else {
256
throw new TestBug("Launcher: Undefined connector type");
257
}
258
259
}
260
261
args.add(connect.toString().trim());
262
263
String[] argsArray = new String[args.size()];
264
for (int i = 0; i < args.size(); i++) {
265
argsArray[i] = (String) args.elementAt(i);
266
}
267
268
return argsArray;
269
}
270
271
// ---------------------------------------------- //
272
273
/**
274
* Run test in local mode using default connector.
275
*/
276
private void localDefaultLaunch
277
(String[] jdbCmdArgs, String classToExecute) throws IOException {
278
localLaunch(jdbCmdArgs, classToExecute);
279
}
280
281
/**
282
* Run test in local mode using raw launching connector.
283
*/
284
private void localRawLaunch
285
(String[] jdbCmdArgs, String classToExecute) throws IOException {
286
localLaunch(jdbCmdArgs, classToExecute);
287
}
288
289
/**
290
* Run test in local mode using launching connector.
291
*/
292
private void localLaunch
293
(String[] jdbCmdArgs, String classToExecute) throws IOException {
294
295
jdb = new Jdb(this);
296
display("Starting jdb launching local debuggee");
297
jdb.launch(jdbCmdArgs);
298
299
if (classToExecute != null)
300
jdb.waitForMessage(0, JDB_STARTED);
301
// jdb.waitForPrompt(0, false);
302
303
}
304
305
/**
306
* Run test in local mode using attaching connector.
307
*/
308
private void localLaunchAndAttach
309
(String[] jdbCmdArgs, String classToExecute) throws IOException {
310
311
debuggee = new LocalLaunchedDebuggee(this);
312
String address = makeTransportAddress();
313
String[] javaCmdArgs = makeCommandLineArgs(classToExecute, address);
314
debuggee.launch(javaCmdArgs);
315
316
display("Start jdb attaching to local debuggee");
317
jdb = Jdb.startAttachingJdb (this, jdbCmdArgs, JDB_STARTED);
318
// jdb.waitForPrompt(0, false);
319
}
320
321
/**
322
* Run test in local mode using listening connector.
323
*/
324
private void localLaunchAndListen
325
(String[] jdbCmdArgs, String classToExecute) throws IOException {
326
327
jdb = new Jdb(this);
328
display("Starting jdb listening to local debuggee");
329
jdb.launch(jdbCmdArgs);
330
String address = jdb.waitForListeningJdb();
331
display("Listening address found: " + address);
332
333
debuggee = new LocalLaunchedDebuggee(this);
334
String[] javaCmdArgs = makeCommandLineArgs(classToExecute, address);
335
debuggee.launch(javaCmdArgs);
336
337
// jdb.waitForPrompt(0, false);
338
}
339
340
/**
341
* Run test in remote mode using attaching connector.
342
*/
343
private void remoteLaunchAndAttach
344
(String[] jdbCmdArgs, String classToExecute) throws IOException {
345
346
debuggee = new RemoteLaunchedDebuggee(this);
347
String address = makeTransportAddress();
348
String[] javaCmdArgs = makeCommandLineArgs(classToExecute, address);
349
try {
350
debuggee.launch(javaCmdArgs);
351
} catch (IOException e) {
352
throw new Failure("Caught exception while launching debuggee VM process:\n\t"
353
+ e);
354
};
355
356
display("Start jdb attaching to remote debuggee");
357
jdb = Jdb.startAttachingJdb (this, jdbCmdArgs, JDB_STARTED);
358
// jdb.waitForPrompt(0, false);
359
}
360
361
/**
362
* Run test in remote mode using listening connector.
363
*/
364
private void remoteLaunchAndListen
365
(String[] jdbCmdArgs, String classToExecute) throws IOException {
366
367
jdb = new Jdb(this);
368
display("Starting jdb listening to remote debuggee");
369
jdb.launch(jdbCmdArgs);
370
String address = jdb.waitForListeningJdb();
371
display("Listening address found: " + address);
372
373
debuggee = new RemoteLaunchedDebuggee(this);
374
String[] javaCmdArgs = makeCommandLineArgs(classToExecute);
375
try {
376
debuggee.launch(javaCmdArgs);
377
} catch (IOException e) {
378
throw new Failure("Caught exception while launching debuggee VM process:\n\t"
379
+ e);
380
};
381
382
jdb.waitForMessage(0, JDB_STARTED);
383
// jdb.waitForPrompt(0, false);
384
}
385
386
} // End of Launcher
387
388