mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
more work on mi.
This commit is contained in:
parent
d5f1ab4560
commit
e2cae76b26
10 changed files with 283 additions and 39 deletions
|
@ -13,6 +13,13 @@ public class MISession {
|
||||||
|
|
||||||
InputStream in;
|
InputStream in;
|
||||||
OutputStream out;
|
OutputStream out;
|
||||||
|
|
||||||
|
Thread txThread;
|
||||||
|
Thread rxThread;
|
||||||
|
|
||||||
|
Queue txQueue;
|
||||||
|
Queue rxQueue;
|
||||||
|
|
||||||
Reader consoleStream = null;
|
Reader consoleStream = null;
|
||||||
Reader targetStream = null;
|
Reader targetStream = null;
|
||||||
Reader logStream = null;
|
Reader logStream = null;
|
||||||
|
@ -23,6 +30,12 @@ public class MISession {
|
||||||
MISession(InputStream i, OutputStream o) {
|
MISession(InputStream i, OutputStream o) {
|
||||||
in = i;
|
in = i;
|
||||||
out = o;
|
out = o;
|
||||||
|
txQueue = new Queue();
|
||||||
|
rxQueue = new Queue();
|
||||||
|
txThread = new TxThread(this);
|
||||||
|
rxThread = new RxThread(this);
|
||||||
|
txThread.start();
|
||||||
|
rxThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +59,23 @@ public class MISession {
|
||||||
logStream = log;
|
logStream = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Queue getTxQueue() {
|
||||||
|
return txQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Queue getRxQueue() {
|
||||||
|
return rxQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream getInputStream() {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputStream getOutputStream() {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
MIOutput parse(String buffer) {
|
MIOutput parse(String buffer) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package org.eclipse.cdt.debug.mi.core;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.mi.core.command.Command;
|
||||||
|
|
||||||
|
public class Queue {
|
||||||
|
|
||||||
|
private List list;
|
||||||
|
|
||||||
|
public Queue() {
|
||||||
|
list = Collections.synchronizedList(new LinkedList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command removeCommand(String id) {
|
||||||
|
//print("in removeCommand(" + id + ") - entering");
|
||||||
|
synchronized (list) {
|
||||||
|
int size = list.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
Command cmd = (Command)list.get(i);
|
||||||
|
String token = cmd.getToken();
|
||||||
|
if (token.equals(id)) {
|
||||||
|
list.remove(cmd);
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command removeCommand() throws InterruptedException {
|
||||||
|
//print("in removeCommand() - entering");
|
||||||
|
synchronized (list) {
|
||||||
|
while (list.isEmpty()) {
|
||||||
|
//print("in removeCommand() - about to wait()");
|
||||||
|
list.wait();
|
||||||
|
//print("in removeCommand() - done with wait()");
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract the new first cmd
|
||||||
|
Command cmd = (Command)list.remove(0);
|
||||||
|
|
||||||
|
//print("in removeCommand() - leaving");
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void addCommand(Command cmd) {
|
||||||
|
//print("in addCommand() - entering");
|
||||||
|
synchronized (list) {
|
||||||
|
// There will always be room to add to this List
|
||||||
|
// because it expands as needed.
|
||||||
|
list.add(cmd);
|
||||||
|
//print("in addCommand - just added: '" + cmd + "'");
|
||||||
|
|
||||||
|
// After adding, notify any and all waiting
|
||||||
|
// threads that the list has changed.
|
||||||
|
list.notifyAll();
|
||||||
|
//print("in addCommand() - just notified");
|
||||||
|
}
|
||||||
|
//print("in addCommand() - leaving");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void print(String msg) {
|
||||||
|
String name = Thread.currentThread().getName();
|
||||||
|
System.out.println(name + ": " + msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package org.eclipse.cdt.debug.mi.core;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.mi.core.command.Command;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.output.MIOOBRecord;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class RxThread extends Thread {
|
||||||
|
|
||||||
|
MISession session;
|
||||||
|
|
||||||
|
public RxThread(MISession s) {
|
||||||
|
super("MI RX Thread");
|
||||||
|
session = s;
|
||||||
|
setDaemon(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the response, parse the output, dispatch for OOB
|
||||||
|
* search for the corresponding token in rxQueue.
|
||||||
|
*/
|
||||||
|
public void run () {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(session.getInputStream()));
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (line.equals("(gdb)")) {
|
||||||
|
processMIOutput(buffer.toString());
|
||||||
|
buffer = new StringBuffer();
|
||||||
|
}
|
||||||
|
buffer.append(line).append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void processMIOutput(String buffer) {
|
||||||
|
MIOutput response = session.parse(buffer);
|
||||||
|
if (response != null) {
|
||||||
|
String id = response.getToken();
|
||||||
|
Queue rxQueue = session.getRxQueue();
|
||||||
|
Command cmd = rxQueue.removeCommand(id);
|
||||||
|
if (cmd != null) {
|
||||||
|
cmd.setMIOutput(response);
|
||||||
|
cmd.notifyAll();
|
||||||
|
}
|
||||||
|
MIOOBRecord[] oobs = response.getMIOOBRecords();
|
||||||
|
if (oobs != null && oobs.length > 0) {
|
||||||
|
processMIOOBRecords(oobs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void processMIOOBRecords(MIOOBRecord[] oobs) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.eclipse.cdt.debug.mi.core;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.mi.core.command.Command;
|
||||||
|
|
||||||
|
public class TxThread extends Thread {
|
||||||
|
|
||||||
|
MISession session;
|
||||||
|
int token;
|
||||||
|
|
||||||
|
public TxThread(MISession s) {
|
||||||
|
super("MI TX Thread");
|
||||||
|
session = s;
|
||||||
|
token = 1;
|
||||||
|
setDaemon(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run () {
|
||||||
|
while (true) {
|
||||||
|
Command cmd = null;
|
||||||
|
Queue txQueue = session.getTxQueue();
|
||||||
|
// The removeCommand will block until a command is available.
|
||||||
|
try {
|
||||||
|
cmd = txQueue.removeCommand();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// The command is then:
|
||||||
|
// - given a Id/token
|
||||||
|
// - shove in the pipe
|
||||||
|
// - Remove from the TxQueue
|
||||||
|
// - Move to the RxQueue
|
||||||
|
if (cmd != null) {
|
||||||
|
OutputStream out = session.getOutputStream();
|
||||||
|
cmd.setToken(Integer.toString(token));
|
||||||
|
//System.out.println("Tx " + cmd.toString());
|
||||||
|
try {
|
||||||
|
out.write(cmd.toString().getBytes());
|
||||||
|
out.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
|
Queue rxQueue = session.getRxQueue();
|
||||||
|
rxQueue.addCommand(cmd);
|
||||||
|
token++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
package org.eclipse.cdt.debug.mi.core.command;
|
package org.eclipse.cdt.debug.mi.core.command;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.mi.core.MIInfo;
|
import org.eclipse.cdt.debug.mi.core.MIInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
|
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -18,20 +18,31 @@ import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
|
||||||
*/
|
*/
|
||||||
public class CLICommand extends Command
|
public class CLICommand extends Command
|
||||||
{
|
{
|
||||||
|
String token = "";
|
||||||
|
MIOutput miOutput = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the text representation of this command.
|
* Returns the text representation of this command.
|
||||||
*
|
*
|
||||||
* @return the text representation of this command
|
* @return the text representation of this command
|
||||||
*/
|
*/
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return "";
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken(String t) {
|
||||||
|
token = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public MIInfo getInfo (MIResultRecord rr) {
|
public void setMIOutput(MIOutput mi) {
|
||||||
return new MIInfo(rr);
|
miOutput = mi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MIInfo getInfo () {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
package org.eclipse.cdt.debug.mi.core.command;
|
package org.eclipse.cdt.debug.mi.core.command;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.mi.core.MIInfo;
|
import org.eclipse.cdt.debug.mi.core.MIInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
|
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -24,8 +24,12 @@ public abstract class Command
|
||||||
* @return the identifier of this request
|
* @return the identifier of this request
|
||||||
*/
|
*/
|
||||||
public abstract String getToken();
|
public abstract String getToken();
|
||||||
|
|
||||||
|
public abstract void setToken(String token);
|
||||||
|
|
||||||
public abstract String toString();
|
public abstract String toString();
|
||||||
|
|
||||||
public abstract MIInfo getInfo(MIResultRecord rr);
|
public abstract void setMIOutput(MIOutput mi);
|
||||||
|
|
||||||
|
public abstract MIInfo getInfo();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
package org.eclipse.cdt.debug.mi.core.command;
|
package org.eclipse.cdt.debug.mi.core.command;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.mi.core.MIInfo;
|
import org.eclipse.cdt.debug.mi.core.MIInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
|
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -22,7 +22,8 @@ public class MICommand extends Command
|
||||||
String[] options = empty;
|
String[] options = empty;
|
||||||
String[] parameters = empty;
|
String[] parameters = empty;
|
||||||
String operation = "";
|
String operation = "";
|
||||||
String token;
|
String token = "";
|
||||||
|
MIOutput miOutput = null;
|
||||||
|
|
||||||
public MICommand(String oper) {
|
public MICommand(String oper) {
|
||||||
this.operation = oper;
|
this.operation = oper;
|
||||||
|
@ -91,7 +92,7 @@ public class MICommand extends Command
|
||||||
command += " " + parameters[i];
|
command += " " + parameters[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return command;
|
return command + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
|
@ -102,7 +103,11 @@ public class MICommand extends Command
|
||||||
token = t;
|
token = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MIInfo getInfo (MIResultRecord rr) {
|
public void setMIOutput(MIOutput mi) {
|
||||||
return new MIInfo(rr);
|
miOutput = mi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MIInfo getInfo () {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package org.eclipse.cdt.debug.mi.core.output;
|
package org.eclipse.cdt.debug.mi.core.output;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alain
|
|
||||||
*
|
*
|
||||||
* To change this generated comment edit the template variable "typecomment":
|
|
||||||
* Window>Preferences>Java>Templates.
|
|
||||||
* To enable and disable the creation of type comments go to
|
|
||||||
* Window>Preferences>Java>Code Generation.
|
|
||||||
*/
|
*/
|
||||||
public class MIOOBRecord extends MIOutput {
|
public class MIOOBRecord {
|
||||||
|
|
||||||
public final int ASYNC_STOPPED = 0;
|
public final int ASYNC_STOPPED = 0;
|
||||||
|
|
||||||
|
@ -23,7 +18,7 @@ public class MIOOBRecord extends MIOutput {
|
||||||
return ASYNC_STOPPED;
|
return ASYNC_STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MIResult getResult() {
|
public MIResult[] getResults() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
package org.eclipse.cdt.debug.mi.core.output;
|
package org.eclipse.cdt.debug.mi.core.output;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alain
|
|
||||||
*
|
|
||||||
* To change this generated comment edit the template variable "typecomment":
|
|
||||||
* Window>Preferences>Java>Templates.
|
|
||||||
* To enable and disable the creation of type comments go to
|
|
||||||
* Window>Preferences>Java>Code Generation.
|
|
||||||
*/
|
*/
|
||||||
public class MIOutput {
|
public class MIOutput {
|
||||||
|
|
||||||
public static final String terminator = "(gdb)\n";
|
public static final String terminator = "(gdb)\n";
|
||||||
|
String token = "";
|
||||||
public boolean interpret() {
|
|
||||||
return false;
|
public String getToken() {
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken() {
|
public MIResultRecord getMIResultRecord() {
|
||||||
return "";
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MIOOBRecord[] getMIOOBRecords() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
package org.eclipse.cdt.debug.mi.core.output;
|
package org.eclipse.cdt.debug.mi.core.output;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alain
|
|
||||||
*
|
|
||||||
* To change this generated comment edit the template variable "typecomment":
|
|
||||||
* Window>Preferences>Java>Templates.
|
|
||||||
* To enable and disable the creation of type comments go to
|
|
||||||
* Window>Preferences>Java>Code Generation.
|
|
||||||
*/
|
*/
|
||||||
public class MIResultRecord extends MIOutput {
|
public class MIResultRecord {
|
||||||
|
|
||||||
|
String resultClass = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
|
||||||
*/
|
*/
|
||||||
public boolean interpret() {
|
public String getResultClass() {
|
||||||
return false;
|
return resultClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MIResult[] getResults() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue