1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Cleanup and optimization of logic that records the console, target and log stream output.

This commit is contained in:
John Cortell 2010-03-16 16:27:33 +00:00
parent 3bc232083d
commit a7719f85de

View file

@ -68,7 +68,7 @@ import org.eclipse.cdt.debug.mi.core.output.MIValue;
public class RxThread extends Thread { public class RxThread extends Thread {
final MISession session; final MISession session;
LinkedList<MIStreamRecord> oobList; LinkedList<MIStreamRecord> fStreamRecords = new LinkedList<MIStreamRecord>();
CLIProcessor cli; CLIProcessor cli;
int prompt = 1; // 1 --> Primary prompt "(gdb)"; 2 --> Secondary Prompt ">" int prompt = 1; // 1 --> Primary prompt "(gdb)"; 2 --> Secondary Prompt ">"
boolean fEnableConsole = true; boolean fEnableConsole = true;
@ -77,7 +77,6 @@ public class RxThread extends Thread {
super("MI RX Thread"); //$NON-NLS-1$ super("MI RX Thread"); //$NON-NLS-1$
session = s; session = s;
cli = new CLIProcessor(session); cli = new CLIProcessor(session);
oobList = new LinkedList<MIStreamRecord>();
} }
/* /*
@ -178,10 +177,9 @@ public class RxThread extends Thread {
int id = rr.getToken(); int id = rr.getToken();
Command cmd = rxQueue.removeCommand(id); Command cmd = rxQueue.removeCommand(id);
// Clear the accumulate oobList on each new Result Command // Get a snapshot of the accumulated stream records. We clear
// response. // the collection below (with each new Result Command response).
MIOOBRecord[] oobRecords = new MIOOBRecord[oobList.size()]; MIStreamRecord[] streamRecords = fStreamRecords.toArray(new MIStreamRecord[fStreamRecords.size()]);
oobList.toArray(oobRecords);
// Check if the state changed. // Check if the state changed.
String state = rr.getResultClass(); String state = rr.getResultClass();
@ -221,7 +219,7 @@ public class RxThread extends Thread {
} else if ("error".equals(state)) { //$NON-NLS-1$ } else if ("error".equals(state)) { //$NON-NLS-1$
if (session.getMIInferior().isRunning()) { if (session.getMIInferior().isRunning()) {
session.getMIInferior().setSuspended(); session.getMIInferior().setSuspended();
MIEvent event = new MIErrorEvent(session, rr, oobRecords); MIEvent event = new MIErrorEvent(session, rr, streamRecords);
list.add(event); list.add(event);
} }
} else if ("done".equals(state) && cmd instanceof CLICommand) { //$NON-NLS-1$ } else if ("done".equals(state) && cmd instanceof CLICommand) { //$NON-NLS-1$
@ -233,12 +231,12 @@ public class RxThread extends Thread {
} }
// Set the accumulate console Stream // Set the accumulate console Stream
response.setMIOOBRecords(oobRecords); response.setMIOOBRecords(streamRecords);
// Notify the waiting command. // Notify the waiting command.
// Notify any command waiting for a ResultRecord. // Notify any command waiting for a ResultRecord.
if (cmd != null) { if (cmd != null) {
// Process the Command line to recognise patterns we may need to fire event. // Process the Command line to recognize patterns we may need to fire event.
if (cmd instanceof CLICommand) { if (cmd instanceof CLICommand) {
cli.processSettingChanges((CLICommand)cmd); cli.processSettingChanges((CLICommand)cmd);
} else if (cmd instanceof MIInterpreterExecConsole) { } else if (cmd instanceof MIInterpreterExecConsole) {
@ -251,8 +249,8 @@ public class RxThread extends Thread {
} }
} }
// Clear the accumulate oobList on each new Result Command response. // Clear the accumulated stream records on each new Result Command response.
oobList.clear(); fStreamRecords.clear();
} else { } else {
@ -261,10 +259,10 @@ public class RxThread extends Thread {
for (int i = 0; i < oobs.length; i++) { for (int i = 0; i < oobs.length; i++) {
processMIOOBRecord(oobs[i], list); processMIOOBRecord(oobs[i], list);
} }
// If not waiting for any command results, ensure the oobList doesn't // If not waiting for any command results, ensure the stream list doesn't
// get too large. See Bug 302927 for more // get too large. See Bug 302927 for more
if (rxQueue.isEmpty() && oobList.size() > 20) if (rxQueue.isEmpty() && fStreamRecords.size() > 20)
oobList.removeFirst(); fStreamRecords.removeFirst();
} }
MIEvent[] events = list.toArray(new MIEvent[list.size()]); MIEvent[] events = list.toArray(new MIEvent[list.size()]);
@ -278,7 +276,7 @@ public class RxThread extends Thread {
void processMIOOBRecord(MIOOBRecord oob, List<MIEvent> list) { void processMIOOBRecord(MIOOBRecord oob, List<MIEvent> list) {
if (oob instanceof MIAsyncRecord) { if (oob instanceof MIAsyncRecord) {
processMIOOBRecord((MIAsyncRecord) oob, list); processMIOOBRecord((MIAsyncRecord) oob, list);
oobList.clear(); fStreamRecords.clear();
} else if (oob instanceof MIStreamRecord) { } else if (oob instanceof MIStreamRecord) {
processMIOOBRecord((MIStreamRecord) oob); processMIOOBRecord((MIStreamRecord) oob);
} }
@ -370,7 +368,7 @@ public class RxThread extends Thread {
} }
// Accumulate the Console Stream Output response for parsing. // Accumulate the Console Stream Output response for parsing.
// Some commands will put valuable info in the Console Stream. // Some commands will put valuable info in the Console Stream.
oobList.add(stream); fStreamRecords.add(stream);
} else if (stream instanceof MITargetStreamOutput) { } else if (stream instanceof MITargetStreamOutput) {
OutputStream target = session.getMIInferior().getPipedOutputStream(); OutputStream target = session.getMIInferior().getPipedOutputStream();
if (target != null) { if (target != null) {
@ -387,7 +385,7 @@ public class RxThread extends Thread {
// Accumulate the Target Stream Output response for parsing. // Accumulate the Target Stream Output response for parsing.
// Some commands, e.g. 'monitor' will put valuable info in the Console Stream. // Some commands, e.g. 'monitor' will put valuable info in the Console Stream.
// This fixes bug 119370. // This fixes bug 119370.
oobList.add(stream); fStreamRecords.add(stream);
} else if (stream instanceof MILogStreamOutput) { } else if (stream instanceof MILogStreamOutput) {
// This is meant for the gdb console. // This is meant for the gdb console.
OutputStream log = session.getLogPipe(); OutputStream log = session.getLogPipe();
@ -404,7 +402,7 @@ public class RxThread extends Thread {
} }
// Accumulate the Log Stream Output response for parsing. // Accumulate the Log Stream Output response for parsing.
// Some commands will put valuable info in the Log Stream. // Some commands will put valuable info in the Log Stream.
oobList.add(stream); fStreamRecords.add(stream);
} }
} }
@ -544,17 +542,14 @@ public class RxThread extends Thread {
} }
String[] getStreamRecords() { String[] getStreamRecords() {
List<String> streamRecords = new ArrayList<String>(); List<String> streamRecords = new ArrayList<String>(fStreamRecords.size());
MIOOBRecord[] oobRecords = oobList.toArray(new MIOOBRecord[0]); for (MIStreamRecord rec : fStreamRecords) {
for (int i = 0; i < oobRecords.length; i++) { String str = rec.getString().trim();
if (oobRecords[i] instanceof MIStreamRecord) { if (str.length() > 0) {
String s = ((MIStreamRecord) oobRecords[i]).getString().trim(); streamRecords.add(str);
if (s != null && s.length() > 0) {
streamRecords.add(s);
}
} }
} }
return streamRecords.toArray(new String[0]); return streamRecords.toArray(new String[streamRecords.size()]);
} }
} }