diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBProcess.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBProcess.java new file mode 100644 index 00000000000..a69aa704d64 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBProcess.java @@ -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(); + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamMonitor.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamMonitor.java new file mode 100644 index 00000000000..58747a3e4da --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamMonitor.java @@ -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); + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java new file mode 100644 index 00000000000..1743f8ddeb1 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java @@ -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()); + } +}