/** File to log emulated <i>jdb</i> session composed from commands and <i>jdb</i> replies on them */ staticfinal String JDB_SESSION_FILE = "jdb.session";
/** Pattern for message of listening at address. */ publicstaticfinal String LISTENING_AT_ADDRESS = "Listening at address:";
/** Pattern for message of a breakpoint hit. */ publicstaticfinal String BREAKPOINT_HIT = "Breakpoint hit:";
/** Pattern for message of an application exit. */ publicstaticfinal String APPLICATION_EXIT = "The application exited";
/** Pattern for message of an application disconnect. */ publicstaticfinal String APPLICATION_DISCONNECTED = "The application has been disconnected";
/** Pattern for message of connector name in the supported connectors list. */ publicstaticfinal String SUPPORTED_CONNECTOR_NAME = "Connector:";
/** Pattern for message of transport name in the supported connectors list. */ publicstaticfinal String SUPPORTED_TRANSPORT_NAME = "Transport: ";
/** This is jdb's prompt when debuggee is not started nor suspended after breakpoint */ publicstaticfinal String SIMPLE_PROMPT = "> ";
// Send reply to the logfile. This complements sendCommand(), which does the same. for (int i = 0; i < replyArr.length; i++) {
launcher.getLog().display("reply[" + i + "]: " + replyArr[i]);
}
long delta = 200; // time in milliseconds to wait at every iteration. long total = 0; // total time has waited. long max = getLauncher().getJdbArgumentHandler().getWaitTime() * 60 * 1000; // maximum time to wait.
if (count <= 0) { thrownew TestBug("Wrong number of prompts count in Jdb.waitForPrompt(): " + count);
}
Object dummy = new Object(); while ((total += delta) <= max) { int found = 0;
// check if compound prompt is found
{
found = findPrompt(stdoutBuffer, true, startPos); if (found >= count) { return found;
}
}
// check also if simple prompt is found if (!compoundPromptOnly) {
found += findPrompt(stdoutBuffer, false, startPos); if (found >= count) { return found;
}
}
// exit loop when a debugged application exited if (stdoutBuffer.indexOf(APPLICATION_EXIT) >= 0 || stdoutBuffer.indexOf(APPLICATION_DISCONNECTED) >= 0) { return found;
} elseif (startPos > 0 && !jdbStdoutReader.isAlive()) { return found;
}
// sleep for awhile synchronized(dummy) { try {
dummy.wait(delta);
} catch (InterruptedException ie) {
ie.printStackTrace(getLauncher().getLog().getOutStream()); thrownew Failure("Caught interrupted exception while waiting for jdb prompt:\n\t" + ie);
}
}
}
long delta = 200; // time in milliseconds to wait at every iteration. long total = 0; // total time has waited. long max = getLauncher().getJdbArgumentHandler().getWaitTime() * 60 * 1000; // maximum time to wait.
Object dummy = new Object(); while ((total += delta) <= max) { int found = 0;
// search for message
{
found = findMessage(startPos, message); if (found > 0) { return found;
}
}
// exit loop when a debugged application exited. if (stdoutBuffer.indexOf(APPLICATION_EXIT) >= 0 || stdoutBuffer.indexOf(APPLICATION_DISCONNECTED) >= 0) { return found;
} elseif (startPos > 0 && !jdbStdoutReader.isAlive()) { return found;
}
// spleep for awhile synchronized(dummy) { try {
dummy.wait(delta);
} catch (InterruptedException ie) {
ie.printStackTrace(getLauncher().getLog().getOutStream()); thrownew Failure("Caught interrupted exception while waiting for jdb reply:\n\t" + ie);
}
}
}
// If we never recieved the expected reply, display a warning, and also // display what we did recieve. This is accomplished by calling receiveReply().
Log log = getLauncher().getLog();
log.display("WARNING: message not recieved: " + message);
log.display("Remaining debugger output follows:");
receiveReply(startPos); thrownew Failure("Expected message not received during " + total + " milliseconds:"
+ "\n\t" + message);
}
/** *Findmessagein<i>JDB_STDOUT_FILE</i>filestartingfrom<i>startPos</i>. * *@paramstartPosstartpositionforsearchin<i>stdoutBuffer</i>. *@returnnumberofmessagesactuallyfound
*/ publicint findMessage(int startPos, String message) { int bufLength = stdoutBuffer.length(); int msgLength = message.length(); int found = 0;
// read last ' ' if (lines.charAt(pos) != ' ') { continue searching;
}
prompt.append(lines.charAt(pos++));
// check if not particular ident found if (compoundPromptIdent != null
&& !prompt.toString().startsWith(compoundPromptIdent + "[")) { continue searching;
}
// compound prompt found
found++;
}
return found;
}
/** *Splitsstringwhichmayincludelineseparatorstostringarray. *
*/ publicstatic String[] toStringArray (String string) {
Vector<String> v = new Vector<String>(); int ind; for (ind = 0; ind < string.length(); ) { int i = string.indexOf(lineSeparator, ind); if (i >= 0) {
v.add(string.substring(ind, i));
ind = i + lineSeparator.length();
} else {
v.add(string.substring(ind)); break;
}
}
String[] result = new String [v.size()];
v.toArray(result); return result;
}
Paragrep grep = new Paragrep(reply); if (grep.find("Unable to set") > 0) { thrownew Failure("jdb failed to set breakpoint in method: " + methodName);
} if (grep.find("Set breakpoint") <= 0 && grep.find("Deferring breakpoint") <= 0) { thrownew Failure("jdb did not set breakpoint in method: " + methodName);
}
}
Paragrep grep = new Paragrep(reply); if (grep.find("Unable to set") > 0) { thrownew Failure("jdb failed to set deffered breakpoint in method: " + methodName);
} if (grep.find("Set breakpoint") <= 0 && grep.find("Deferring breakpoint") <= 0) { thrownew Failure("jdb did not set deffered breakpoint in method: " + methodName);
}
}
// give one more chance to reach breakpoint if (!isAtBreakpoint(getTotalReply(), "main")) {
waitForMessage(0, BREAKPOINT_HIT);
}
}
/** *Returnsasstringarrayallid'sforagiventhreadnameof<i>threadName</i>.
*/ public String[] getThreadIdsByName(String threadName) {
Vector<String> v = new Vector<String>();
String[] reply = receiveReplyFor(JdbCommand.threads);
Paragrep grep = new Paragrep(reply);
String[] found = grep.findStrings(threadName); for (int i = 0; i < found.length; i++) {
String string = found[i]; // Check for "(java.lang.Thread)" or "(java.lang.VirtualThread)"
String searchString = "Thread)"; int j = string.indexOf(searchString); if (j >= 0) {
j += searchString.length(); // The threadID is right after the thread type
String threadId = string.substring(j, string.indexOf(" ", j));
v.add(threadId);
}
}
String[] result = new String[v.size()];
v.toArray(result); return result;
}
/** *Returnsasstringarrayallid'sforagivenclasstypeof<i>threadType</i>.
*/ public String[] getThreadIds(String threadType) {
if (!threadType.startsWith("(")) {
threadType = "(" + threadType;
} if (!threadType.endsWith(")")) {
threadType = threadType + ")";
}
Vector<String> v = new Vector<String>();
String[] reply = receiveReplyFor(JdbCommand.threads);
Paragrep grep = new Paragrep(reply);
String[] found = grep.findStrings(threadType); for (int i = 0; i < found.length; i++) {
String string = found[i]; int j = string.indexOf(threadType); if (j >= 0) {
j += threadType.length();
String threadId = string.substring(j, string.indexOf(" ", j));
v.add(threadId);
}
}
String[] result = new String [v.size()];
v.toArray(result); return result;
}
long delta = Launcher.DEBUGGEE_START_DELAY; // time in milliseconds to wait at every iteration. long max = getLauncher().getJdbArgumentHandler().getWaitTime() * 60 * 1000; // maximum time to wait.
int result = -1; boolean found = false;
long start = System.currentTimeMillis();
while (!found && (System.currentTimeMillis() - start)<= max) {
jdb = new Jdb(launcher);
jdb.launch(jdbCmdArgs);
while (!found && (System.currentTimeMillis() - start)<= max) {
try { Thread.currentThread().sleep(delta);
} catch (InterruptedException ie) {
ie.printStackTrace(getLauncher().getLog().getOutStream()); thrownew Failure("Caught unexpected InterruptedException while sleep in waiting for debuggee's start:\n\t"
+ ie);
}
System.out.println("Unsuccessful launch of attaching jdb. Next try..."); try {
jdb.finalize();
} catch (Throwable t) {
t.printStackTrace(getLauncher().getLog().getOutStream()); thrownew Failure("Caught unexpected error while finalizing jdb: " + t);
} break;
} elseif (stdoutBuffer.length() > 0) {
result = stdoutBuffer.indexOf(message); if (result >= 0) {
found = true; // exit loop
}
}
}
}
if (result < 0) { thrownew Failure("Launched jdb could not attach to debuggee during " + max + " milliseconds.");
}
return jdb;
}
/** *Waitsforjdbtoprintmessageaboutlisteningataddressforconnection, *andreturnsthisaddressstring.
*/ public String waitForListeningJdb() {
waitForMessage(0, LISTENING_AT_ADDRESS); int msgStart = stdoutBuffer.indexOf(LISTENING_AT_ADDRESS); int msgEnd = stdoutBuffer.indexOf("\n", msgStart); int promptLen = LISTENING_AT_ADDRESS.length();
try { if (bin != null) {
bin.close();
}
} catch (IOException ioe) {
ioe.printStackTrace(jdb.getLauncher().getLog().getOutStream()); thrownew Failure("Caught unexpected IOException while closing jdb stderr stream: " + ioe);
} if (!empty) { // Should not throw exception here because of non-empty stderr in case of unsuccessful launch of attaching jdb.
jdb.getLauncher().getLog().display("JdbStderrReader: jdb's stderr is not empty. Check jdb.stderr file");
}
}
public String getFileName () { returnthis.fileName;
}
publicvoid logToFile(String line) { synchronized (fout) {
fout.println(line);
fout.flush();
}
}
} // end of JdbStderrReader
} // end of Jdb
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.