mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
New file.
This commit is contained in:
parent
8cb3a11b6a
commit
6a389b25b5
3 changed files with 244 additions and 0 deletions
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
package org.eclipse.cdt.debug.mi.core;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.model.IProcess;
|
||||
import org.eclipse.debug.core.model.IStreamsProxy;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class GDBProcess extends PlatformObject implements IProcess {
|
||||
|
||||
MISession session;
|
||||
ILaunch launch;
|
||||
Properties props;
|
||||
GDBStreamsProxy streams;
|
||||
|
||||
public GDBProcess(ILaunch l, MISession s) {
|
||||
launch = l;
|
||||
session = s;
|
||||
props = new Properties();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IProcess#getAttribute(String)
|
||||
*/
|
||||
public String getAttribute(String key) {
|
||||
return props.getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IProcess#getExitValue()
|
||||
*/
|
||||
public int getExitValue() throws DebugException {
|
||||
return session.getMIProcess().exitValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IProcess#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "GDB MI Debugger";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IProcess#getLaunch()
|
||||
*/
|
||||
public ILaunch getLaunch() {
|
||||
return launch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IProcess#getStreamsProxy()
|
||||
*/
|
||||
public IStreamsProxy getStreamsProxy() {
|
||||
if (streams == null) {
|
||||
streams = new GDBStreamsProxy(session);
|
||||
}
|
||||
return streams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IProcess#setAttribute(String, String)
|
||||
*/
|
||||
public void setAttribute(String key, String value) {
|
||||
props.setProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
|
||||
*/
|
||||
public Object getAdapter(Class adapter) {
|
||||
return super.getAdapter(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.ITerminate#canTerminate()
|
||||
*/
|
||||
public boolean canTerminate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.ITerminate#isTerminated()
|
||||
*/
|
||||
public boolean isTerminated() {
|
||||
return session.isTerminated();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.ITerminate#terminate()
|
||||
*/
|
||||
public void terminate() throws DebugException {
|
||||
session.terminate();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
package org.eclipse.cdt.debug.mi.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.debug.core.IStreamListener;
|
||||
import org.eclipse.debug.core.model.IStreamMonitor;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class GDBStreamMonitor implements IStreamMonitor {
|
||||
|
||||
List listeners;
|
||||
StringBuffer buffer;
|
||||
InputStream stream;
|
||||
|
||||
public GDBStreamMonitor(InputStream s) {
|
||||
listeners = new ArrayList();
|
||||
buffer = new StringBuffer();
|
||||
stream = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IStreamMonitor#addListener(IStreamListener)
|
||||
*/
|
||||
public void addListener(IStreamListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IStreamMonitor#getContents()
|
||||
*/
|
||||
public String getContents() {
|
||||
try {
|
||||
int count = stream.available();
|
||||
byte[] bytes = new byte[count];
|
||||
count = stream.read(bytes);
|
||||
if (count > 0) {
|
||||
buffer.append(bytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IStreamMonitor#removeListener(IStreamListener)
|
||||
*/
|
||||
public void removeListener(IStreamListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
package org.eclipse.cdt.debug.mi.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.eclipse.cdt.debug.mi.core.command.CLICommand;
|
||||
import org.eclipse.debug.core.model.IStreamMonitor;
|
||||
import org.eclipse.debug.core.model.IStreamsProxy;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class GDBStreamsProxy implements IStreamsProxy {
|
||||
|
||||
MISession session;
|
||||
GDBStreamMonitor miConsole;
|
||||
GDBStreamMonitor miLog;
|
||||
OutputStream out;
|
||||
|
||||
public GDBStreamsProxy(MISession ses) {
|
||||
session = ses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IStreamsProxy#getErrorStreamMonitor()
|
||||
*/
|
||||
public IStreamMonitor getErrorStreamMonitor() {
|
||||
if (miLog == null) {
|
||||
miLog = new GDBStreamMonitor(session.getMILogStream());
|
||||
}
|
||||
return miLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IStreamsProxy#getOutputStreamMonitor()
|
||||
*/
|
||||
public IStreamMonitor getOutputStreamMonitor() {
|
||||
if (miConsole == null) {
|
||||
miConsole = new GDBStreamMonitor(session.getMIConsoleStream());
|
||||
}
|
||||
return miConsole;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.debug.core.model.IStreamsProxy#write(String)
|
||||
*/
|
||||
public void write(String input) throws IOException {
|
||||
if (out == null) {
|
||||
out = new OutputStream() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
public void write(int b) throws IOException {
|
||||
buf.append((char)b);
|
||||
if (b == '\n') {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
// Encapsulate the string sent to gdb in a fake
|
||||
// command and post it to the TxThread.
|
||||
public void flush() throws IOException {
|
||||
CLICommand cmd = new CLICommand(buf.toString()) {
|
||||
public void setToken(int token) {
|
||||
token = token;
|
||||
// override to do nothing;
|
||||
}
|
||||
};
|
||||
try {
|
||||
session.postCommand(cmd);
|
||||
} catch (MIException e) {
|
||||
throw new IOException("no session");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
out.write(input.getBytes());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue