Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbArgumentHandler.java
41161 views
1
/*
2
* Copyright (c) 2002, 2020, 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
* Parser for <code>jdb</code> test's specific command-line arguments.
35
* This class also parses JDI specific command-line arguments.
36
* <p>
37
* <code>JdbArgumentHandler</code> handles <code>jdb</code> test's specific
38
* arguments related to launching of <code>jdb</code> to debugged VM
39
* in addition to general arguments recognized by <code>ArgumentHandler</code>,
40
* <code>DebugeeArgumentHandler</code> and <code>ArgumentParser</code>.
41
* <p>
42
* Following is the list of specific options recognized by <code>AgrumentHandler</code>:
43
* <ul>
44
* <li> <code>-jdb=JAVA_SDK_HOME_PATH/bin/$JDB</code> - <br>
45
* full path to <code>jdb</code> binaries. There is no default value. <br>
46
* <li> <code>-workdir=CURRENT_TEST_DIRECTORY_PATH</code> -
47
* full path to current test directory. There is no default value.
48
* <li> <code>-jdb.option=JDB_COMMAND_LINE_OPTIONS</code> -
49
* jdb options (see <code>jdb -help</code>) except these ones:
50
* <ul>
51
* <li><code>-attach [address] </code></li>
52
* <li><code>-listen [address] </code></li>
53
* <li><code>-connect [connector-name]:[name1]=[value1],... </code></li>
54
* </ul>
55
* </ul>
56
* <p>
57
* See also list of arguments recognized by the base <code>ArgumentHandler</code>,
58
* <code>DebugeeArgumentHandler</code> and <code>ArgumentParser</code> classes.
59
* <p>
60
* See also description of <code>ArgumentParser</code> how to work with
61
* command line arguments and options.
62
*
63
* @see nsk.share.ArgumentParser
64
* @see nsk.share.jpda.DebugeeArgumentHandler
65
* @see nsk.share.jdi.ArgumentHandler
66
*/
67
public class JdbArgumentHandler extends nsk.share.jdi.ArgumentHandler {
68
69
/**
70
* Keep a copy of raw command-line arguments and parse them;
71
* but throw an exception on parsing error.
72
*
73
* @param args Array of the raw command-line arguments.
74
*
75
* @throws NullPointerException If <code>args==null</code>.
76
* @throws IllegalArgumentException If Binder or Log options
77
* are set incorrectly.
78
*
79
* @see #setRawArguments(String[])
80
*/
81
public JdbArgumentHandler(String args[]) {
82
super(args);
83
}
84
85
86
/**
87
* Checks if an option is admissible and has proper value.
88
* This method is invoked by <code>parseArguments()</code>
89
*
90
* @param option option name
91
* @param value string representation of value (could be an empty string)
92
* null if this option has no value
93
* @return <i>true</i> if option is admissible and has proper value
94
* <i>false</i> if option is not admissible
95
*
96
* @throws <i>BadOption</i> if option has illegal value
97
*
98
* @see #parseArguments()
99
*/
100
protected boolean checkOption(String option, String value) {
101
102
if (option.equals("jdb")) {
103
if (value == null) {
104
throw new BadOption(option + ": value must be not null");
105
}
106
return true;
107
}
108
109
if (option.equals("workdir")) {
110
if (value == null) {
111
throw new BadOption(option + ": value must be not null");
112
}
113
return true;
114
}
115
116
if (option.equals("java.options")) {
117
return true;
118
}
119
120
if (option.equals("jdb.option")) {
121
if (value != null) {
122
if (value.indexOf("-attach") > 0) {
123
throw new BadOption("jdb option -attach is not admissible: " + value);
124
}
125
if (value.indexOf("-listen") > 0) {
126
throw new BadOption("jdb option -listen is not admissible: " + value);
127
}
128
if (value.indexOf("-connect") > 0) {
129
throw new BadOption("jdb option -connect is not admissible: " + value);
130
}
131
if (value.indexOf("-help") > 0) {
132
throw new BadOption("jdb option -help is not admissible: " + value);
133
}
134
if (value.indexOf("-listenany") > 0) {
135
throw new BadOption("jdb option -listenany is not admissible: " + value);
136
}
137
if (value.indexOf("-launch") > 0) {
138
throw new BadOption("jdb option -launch is not admissible: " + value);
139
}
140
if (value.indexOf("-tclient") > 0) {
141
throw new BadOption("jdb option -tclient is not admissible: " + value);
142
}
143
if (value.indexOf("-tserver") > 0) {
144
throw new BadOption("jdb option -tserver is not admissible: " + value);
145
}
146
}
147
return true;
148
}
149
150
return super.checkOption(option, value);
151
}
152
153
/**
154
* Checks options against inconcistence.
155
* This method is invoked by <code>parseArguments()</code>
156
*
157
* @see #parseArguments()
158
*/
159
protected void checkOptions() {
160
161
super.checkOptions();
162
}
163
164
/**
165
* Returns the path to current test directory.
166
*/
167
168
public String getWorkDir() {
169
return options.getProperty("workdir", "");
170
}
171
172
/**
173
* Return sfull path to jdb executable.
174
*
175
*/
176
public String getJdbExecPath() {
177
return options.getProperty("jdb");
178
}
179
180
/**
181
* Returns command line options <code>jdb</code> was launched with.
182
*/
183
public String getJdbOptions() {
184
String value = options.getProperty("jdb.option", "").trim();
185
if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) {
186
value = value.substring(1, value.length() - 1).trim();
187
}
188
return value;
189
}
190
191
/**
192
* Adds "<code>-J</code>" prefix to each Java option, so that
193
* <code>jdb</code> could apply them to the target Java VM.
194
*/
195
public static List<String> enwrapJavaOptions(String javaOptions) {
196
List<String> result = new ArrayList<String>();
197
for (String option : javaOptions.split("\\s+"))
198
if (option.length() > 0)
199
result.add("-J" + option);
200
return result;
201
}
202
203
/**
204
* Returns adjusted additional options for debuggee VM with launching connector.
205
*/
206
public String getDebuggeeOptions() {
207
StringBuilder sb = new StringBuilder();
208
String value = options.getProperty("debugee.vmkeys", "").trim();
209
if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) {
210
value = value.substring(1, value.length() - 1).trim();
211
}
212
for (String option : value.split("\\s+")) {
213
if (option.length() > 0) {
214
sb.append(checkAndQuote(option, ","));
215
sb.append(" ");
216
}
217
}
218
return sb.toString();
219
}
220
221
/**
222
* Returns options for debugger VM.
223
*/
224
public String getJavaOptions() {
225
String value = options.getProperty("java.options", "").trim();
226
if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) {
227
value = value.substring(1, value.length() - 1).trim();
228
}
229
return value;
230
}
231
232
/**
233
* Remove "<code>-server</code>" or "<code>-client</code>" from options string,
234
* if anything of them are presented.
235
*/
236
public static String removeVMFlavorOption(String javaOptions) {
237
StringBuffer result = new StringBuffer();
238
StringTokenizer tokenizer = new StringTokenizer(javaOptions);
239
while (tokenizer.hasMoreTokens()) {
240
String option = tokenizer.nextToken();
241
if (!option.equals("-server") && !option.equals("-client")) {
242
result.append( (result.length() > 0 ? " " : "") + option);
243
}
244
};
245
return result.toString();
246
}
247
248
/**
249
* @return "<code>-tserver</code>" if "<code>-server</code>" is presented in options string.
250
* @return "<code>-tclient</code>" if "<code>-client</code>" is presented in options string.
251
* @return empty string otherwise.
252
*/
253
public static String stripVMFlavorOption(String javaOptions) {
254
String result = "";
255
StringTokenizer tokenizer = new StringTokenizer(javaOptions);
256
while (tokenizer.hasMoreTokens()) {
257
String option = tokenizer.nextToken();
258
if (option.equals("-server")) {
259
result = "-tserver";
260
break;
261
} else if (option.equals("-client")) {
262
result = "-tclient";
263
break;
264
}
265
};
266
return result;
267
}
268
269
// check if target substring exists and quote value if needed
270
// ex for subString == "," and value == disk=true,dumponexit=true
271
// return 'disk=true,dumponexit=true'
272
private static String checkAndQuote(String value, String subString) {
273
if (NO_SUBSTR_MATCH == value.indexOf(subString)) {
274
// return as-is
275
return value;
276
}
277
// already single quoted 'value' ?
278
if (isEnclosed(value, "'")) {
279
return value;
280
}
281
// already double quoted "value" ?
282
if (isEnclosed(value, "\"")) {
283
// change to 'value'
284
return value.replaceAll("\"", "'");
285
}
286
// else single quote the value
287
return "'" + value + "'";
288
}
289
290
private static boolean isEnclosed(String value,
291
String enclosingChar) {
292
int firstEnclosePos = value.indexOf(enclosingChar);
293
if (0 == firstEnclosePos) {
294
int lastEnclosePos = value.lastIndexOf(enclosingChar);
295
if (lastEnclosePos > firstEnclosePos && lastEnclosePos == value.length() - 1) {
296
//already quoted
297
return true;
298
}
299
//only a single quote? subString outside quotes? Wrongly quoted, needs fix
300
throw new BadOption(value + " not correctly quoted");
301
}
302
return false;
303
}
304
305
private static final int NO_SUBSTR_MATCH = -1;
306
}
307
308