Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Putting a draft framework for GDB console prompt

	Framework for having a gdb console.  The idea is to reuse
	the eclipse console and save a lot of work.  We "adapt"
	the gdb Process to what eclipse debug LaunchView wants(IProcess).
	So when this fake "gdb process" is selected we can grab the
	input/output of the console and redirect everything to raw gdb.

	* src/.../core/GDBProcess.java: New file, it implements Eclipse
	debug class IProcess.
	* src/.../core/GDBStreamMonitor: New file, it implements Eclipse
	debug class IStreamMonitor.
	* src/.../core/GDBStreamsProxy: New file, it implements Eclipse
	debug class IStreamsProxy.
	* src/../core/MISession.java (getMIConsoleStream): New method
	to return the mi console stream output that we get from gdb/mi.
	(getMILogStream): New method, to return the mi log stream output
	that we get from gdb/mi.
	(terminate): close the fake MI Console and Log streams. 
	* src/../core/RxThread.java (processMIOOBRecord): Redirect the
	console and the log stream to a buffer pipe.



Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/ChangeLog,v
retrieving revision 1.13
diff -u -r1.13 ChangeLog
--- ChangeLog	21 Oct 2002 20:38:32 -0000	1.13
+++ ChangeLog	21 Oct 2002 21:22:05 -0000
@@ -1,5 +1,27 @@
 2002-10-21 Alain Magloire
 
+	Framework for having a gdb console.  The idea is to reuse
+	the eclipse console and save a lot of work.  We "adapt"
+	the gdb Process to what eclipse debug LaunchView wants(IProcess).
+	So when this fake "gdb process" is selected we can grab the
+	input/output of the console and redirect everything to raw gdb.
+
+	* src/.../core/GDBProcess.java: New file, it implements Eclipse
+	debug class IProcess.
+	* src/.../core/GDBStreamMonitor: New file, it implements Eclipse
+	debug class IStreamMonitor.
+	* src/.../core/GDBStreamsProxy: New file, it implements Eclipse
+	debug class IStreamsProxy.
+	* src/../core/MISession.java (getMIConsoleStream): New method
+	to return the mi console stream output that we get from gdb/mi.
+	(getMILogStream): New method, to return the mi log stream output
+	that we get from gdb/mi.
+	(terminate): close the fake MI Console and Log streams. 
+	* src/../core/RxThread.java (processMIOOBRecord): Redirect the
+	console and the log stream to a buffer pipe.
+
+2002-10-21 Alain Magloire
+
 	* src/.../core/cdi/EventManager.java (update): Only
 	fire the event for MemoryChangedEvent if the block was
 	not frozen.
Index: src/org/eclipse/cdt/debug/mi/core/GDBProcess.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/GDBProcess.java
diff -N src/org/eclipse/cdt/debug/mi/core/GDBProcess.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/GDBProcess.java	21 Oct 2002 21:22:05 -0000
@@ -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();
+	}
+
+}
Index: src/org/eclipse/cdt/debug/mi/core/GDBStreamMonitor.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/GDBStreamMonitor.java
diff -N src/org/eclipse/cdt/debug/mi/core/GDBStreamMonitor.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/GDBStreamMonitor.java	21 Oct 2002 21:22:05 -0000
@@ -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);
+	}
+
+}
Index: src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java
diff -N src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java	21 Oct 2002 21:22:05 -0000
@@ -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());
+	}
+}
Index: src/org/eclipse/cdt/debug/mi/core/MISession.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java,v
retrieving revision 1.36
diff -u -r1.36 MISession.java
--- src/org/eclipse/cdt/debug/mi/core/MISession.java	21 Oct 2002 02:55:21 -0000	1.36
+++ src/org/eclipse/cdt/debug/mi/core/MISession.java	21 Oct 2002 21:22:05 -0000
@@ -64,8 +64,11 @@
 	CommandQueue rxQueue;
 	Queue eventQueue;
 
-	PipedInputStream miInPipe;
-	PipedOutputStream miOutPipe;
+	PipedInputStream miInConsolePipe;
+	PipedOutputStream miOutConsolePipe;
+	PipedInputStream miInLogPipe;
+	PipedOutputStream miOutLogPipe;
+
 
 	CommandFactory factory;
 
@@ -133,17 +136,31 @@
 	 * get MI Console Stream.
 	 * The parser will make available the MI console stream output.
 	 */
-	public InputStream getMIStream() {
-		if (miInPipe == null) {
+	public InputStream getMIConsoleStream() {
+		if (miInConsolePipe == null) {
 			try {
-				miOutPipe = new PipedOutputStream();
-				miInPipe = new PipedInputStream(miOutPipe);
+				miOutConsolePipe = new PipedOutputStream();
+				miInConsolePipe = new PipedInputStream(miOutConsolePipe);
 			} catch (IOException e) {
 			}
 		}
-		return miInPipe;
+		return miInConsolePipe;
 	}
 
+	/**
+	 * get MI Console Stream.
+	 * The parser will make available the MI console stream output.
+	 */
+	public InputStream getMILogStream() {
+		if (miInLogPipe == null) {
+			try {
+				miOutLogPipe = new PipedOutputStream();
+				miInLogPipe = new PipedInputStream(miOutLogPipe);
+			} catch (IOException e) {
+			}
+		}
+		return miInLogPipe;
+	}
 
 	/**
 	 * For example the CDI/MI bridge uses the command
@@ -349,9 +366,18 @@
 
 		// Destroy the MI console stream.
 		try {
-			miInPipe = null;
-			if (miOutPipe != null) {
-				miOutPipe.close();
+			miInConsolePipe = null;
+			if (miOutConsolePipe != null) {
+				miOutConsolePipe.close();
+			}
+		} catch (IOException e) {
+		}
+
+		// Destroy the MI log stream.
+		try {
+			miInLogPipe = null;
+			if (miOutLogPipe != null) {
+				miOutLogPipe.close();
 			}
 		} catch (IOException e) {
 		}
@@ -394,7 +420,11 @@
 
 
 	OutputStream getConsolePipe() {
-		return miOutPipe;
+		return miOutConsolePipe;
+	}
+
+	OutputStream getLogPipe() {
+		return miOutLogPipe;
 	}
 
 	CommandQueue getTxQueue() {
Index: src/org/eclipse/cdt/debug/mi/core/RxThread.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/RxThread.java,v
retrieving revision 1.33
diff -u -r1.33 RxThread.java
--- src/org/eclipse/cdt/debug/mi/core/RxThread.java	21 Oct 2002 02:55:39 -0000	1.33
+++ src/org/eclipse/cdt/debug/mi/core/RxThread.java	21 Oct 2002 21:22:05 -0000
@@ -267,9 +267,8 @@
 				}
 			}
 		} else if (stream instanceof MILogStreamOutput) {
-			/*
 			// This is meant for the gdb console.
-			OutputStream log = session.getMIInferior().getPipedErrorStream();
+			OutputStream log = session.getLogPipe();
 			if (log != null) {
 				MILogStreamOutput out = (MILogStreamOutput)stream;
 				String str = out.getString();
@@ -281,7 +280,6 @@
 					}
 				}
 			}
-			*/
 		}
 	}
 



Back to the top