1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00
This commit is contained in:
Alain Magloire 2002-10-22 20:27:58 +00:00
parent 19ecaa14e1
commit 120ac81741
3 changed files with 0 additions and 319 deletions

View file

@ -1,133 +0,0 @@
/*
*(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.IStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugTarget;
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;
String label;
public GDBProcess(ILaunch l, MISession s, String n) {
launch = l;
session = s;
label = n;
}
/**
* @see org.eclipse.debug.core.model.IProcess#getAttribute(String)
*/
public String getAttribute(String key) {
if (props == null) {
return null;
}
return props.getProperty(key);
}
/**
* @see org.eclipse.debug.core.model.IProcess#setAttribute(String, String)
*/
public void setAttribute(String key, String value) {
if (props == null) {
props = new Properties();
}
props.setProperty(key, value);
}
/**
* @see org.eclipse.debug.core.model.IProcess#getExitValue()
*/
public int getExitValue() throws DebugException {
try {
return session.getMIProcess().exitValue();
} catch (IllegalThreadStateException e) {
IStatus status = new Status(IStatus.ERROR,
MIPlugin.getUniqueIdentifier(), 1, "process not terminated", e);
throw new DebugException(status);
}
}
/**
* @see org.eclipse.debug.core.model.IProcess#getLabel()
*/
public String getLabel() {
return label;
}
/**
* @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.core.runtime.IAdaptable#getAdapter(Class)
*/
public Object getAdapter(Class adapter) {
if (adapter.equals(IProcess.class)) {
return this;
}
if (adapter.equals(IDebugTarget.class)) {
ILaunch launch = getLaunch();
IDebugTarget[] targets = launch.getDebugTargets();
for (int i = 0; i < targets.length; i++) {
if (this.equals(targets[i].getProcess())) {
return targets[i];
}
}
return null;
}
return super.getAdapter(adapter);
}
/**
* @see org.eclipse.debug.core.model.ITerminate#canTerminate()
*/
public boolean canTerminate() {
return !isTerminated();
}
/**
* @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();
}
}

View file

@ -1,92 +0,0 @@
/*
*(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.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IStreamMonitor;
/**
*/
public class GDBStreamMonitor implements IStreamMonitor {
List listeners = Collections.synchronizedList(new LinkedList());
StringBuffer contents = new StringBuffer();
InputStream stream;
public GDBStreamMonitor(InputStream s) {
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#removeListener(IStreamListener)
*/
public void removeListener(IStreamListener listener) {
listeners.remove(listener);
}
/**
* Notifies the listeners.
*/
private void fireStreamAppended(String text) {
IStreamListener[] array = (IStreamListener[])listeners.toArray(new IStreamListener[0]);
for (int i = 0; i < array.length; i++) {
array[i].streamAppended(text, this);
}
}
/**
* @see org.eclipse.debug.core.model.IStreamMonitor#getContents()
*/
public String getContents() {
return contents.toString();
}
/**
* Continually reads from the stream.
*/
void read() {
byte[] bytes = new byte[1024];
int count = 0;
try {
while ((count = stream.read(bytes)) >= 0) {
if (count > 0) {
String text = new String(bytes, 0, count);
contents.append(text);
fireStreamAppended(text);
}
}
stream.close();
} catch (IOException e) {
// e.printStackTrace();
} catch (NullPointerException e) {
// killing the stream monitor while reading can cause an NPE
}
}
public void startMonitoring() {
Thread thread = new Thread(new Runnable() {
public void run() {
read();
}
}, "GDB stream Monitor");
thread.setDaemon(true);
thread.start();
}
}

View file

@ -1,94 +0,0 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core;
import java.io.IOException;
import java.io.Writer;
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;
Writer out;
int offset;
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());
miLog.startMonitoring();
}
return miLog;
}
/**
* @see org.eclipse.debug.core.model.IStreamsProxy#getOutputStreamMonitor()
*/
public IStreamMonitor getOutputStreamMonitor() {
if (miConsole == null) {
miConsole = new GDBStreamMonitor(session.getMIConsoleStream());
miConsole.startMonitoring();
}
return miConsole;
}
/**
* @see org.eclipse.debug.core.model.IStreamsProxy#write(String)
*/
public void write(String input) throws IOException {
if (out == null) {
out = new Writer() {
StringBuffer buf = new StringBuffer();
public void write(char[] cbuf, int off, int len) throws IOException {
for (int i = off; i < cbuf.length && len > 0; i++, len--) {
if (cbuf[i] == '\n') {
flush();
} else {
buf.append(cbuf[i]);
}
}
}
public void close () {
buf.setLength(0);
}
// 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());
buf.setLength(0);
try {
session.postCommand(cmd);
} catch (MIException e) {
// throw new IOException("no session:" + e.getMessage());
}
}
};
}
if (input.length() > offset) {
input = input.substring(offset);
offset += input.length();
} else {
offset = input.length();
}
out.write(input);
}
}