diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java index a528ddec425..5bf2e3abc31 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java @@ -4,9 +4,15 @@ */ package org.eclipse.cdt.debug.mi.core; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.eclipse.cdt.debug.core.cdi.ICSession; +import org.eclipse.cdt.debug.mi.core.cdi.CSession; +import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MITargetAttach; +import org.eclipse.cdt.debug.mi.core.output.MIInfo; import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.Plugin; @@ -39,4 +45,36 @@ public class MIPlugin extends Plugin { public MISession createMISession(InputStream in, OutputStream out) { return new MISession(in, out); } + + public ICSession createCSession(String program) throws IOException { + String[]args = new String[]{"gdb", "--quiet", "-i", "mi", program}; + Process gdb = Runtime.getRuntime().exec(args); + MISession session = createMISession(gdb.getInputStream(), gdb.getOutputStream()); + return new CSession(session); + } + + public ICSession createCSession(String program, String core) throws IOException { + String[]args = new String[]{"gdb", "--quiet", "-i", "mi", program, core}; + Process gdb = Runtime.getRuntime().exec(args); + MISession session = createMISession(gdb.getInputStream(), gdb.getOutputStream()); + return new CSession(session); + } + + public ICSession createCSession(String program, int pid) throws IOException { + String[]args = new String[]{"gdb", "--quiet", "-i", "mi", program}; + Process gdb = Runtime.getRuntime().exec(args); + MISession session = createMISession(gdb.getInputStream(), gdb.getOutputStream()); + try { + CommandFactory factory = session.getCommandFactory(); + MITargetAttach attach = factory.createMITargetAttach(pid); + session.postCommand(attach); + MIInfo info = attach.getMIInfo(); + if (info == null) { + throw new IOException("Failed to attach"); + } + } catch (MIException e) { + throw new IOException("Failed to attach"); + } + return new CSession(session); + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcess.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcess.java new file mode 100644 index 00000000000..f559ed0db5c --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcess.java @@ -0,0 +1,149 @@ +package org.eclipse.cdt.debug.mi.core; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.eclipse.cdt.debug.mi.core.command.CLICommand; +import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MIExecAbort; +import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode; +import org.eclipse.cdt.debug.mi.core.output.MIGDBShowExitCodeInfo; + +/** + * @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 MIProcess extends Process { + + public final static int SUSPENDED = 1; + public final static int RUNNING = 2; + public final static int TERMINATED = 3; + + int state = 0; + MISession session; + OutputStream out; + + MIProcess(MISession mi) { + session = mi; + out = new OutputStream() { + StringBuffer buf = new StringBuffer(); + public void write(int b) throws IOException { + buf.append(b); + if (b == '\n') { + flush(); + } + } + public void flush() throws IOException { + CLICommand cmd = new CLICommand(buf.toString()) { + public void setToken(int token) { + // override to do nothing; + } + }; + try { + session.postCommand(cmd); + } catch (MIException e) { + throw new IOException("no mi session"); + } + } + }; + } + + /** + * @see java.lang.Process#getOutputStream() + */ + public OutputStream getOutputStream() { + return out; + } + + /** + * @see java.lang.Process#getInputStream() + */ + public InputStream getInputStream() { + return session.getTargetStream(); + } + + /** + * @see java.lang.Process#getErrorStream() + */ + public InputStream getErrorStream() { + // FIXME the same as output?? + return session.getTargetStream(); + } + + /** + * @see java.lang.Process#waitFor() + */ + public int waitFor() throws InterruptedException { + if (!isTerminated()) { + synchronized (this) { + wait(); + } + } + return exitValue(); + } + + /** + * @see java.lang.Process#exitValue() + */ + public int exitValue() { + if (isTerminated()) { + CommandFactory factory = session.getCommandFactory(); + MIGDBShowExitCode code = factory.createMIGDBShowExitCode(); + try { + session.postCommand(code); + MIGDBShowExitCodeInfo info = code.getMIGDBShowExitCodeInfo(); + return info.getCode(); + } catch (MIException e) { + return 0; + } + } + throw new IllegalThreadStateException(); + } + + /** + * @see java.lang.Process#destroy() + */ + public void destroy() { + CommandFactory factory = session.getCommandFactory(); + MIExecAbort abort = factory.createMIExecAbort(); + CLICommand yes = new CLICommand("yes") { + public void setToken() { } + }; + try { + session.postCommand(abort); + session.postCommand(yes); + } catch (MIException e) { + } + // Do not wait for answer. + } + + public synchronized boolean isSuspended() { + return state == SUSPENDED; + } + + public synchronized boolean isRunning() { + return state == RUNNING; + } + + public synchronized boolean isTerminated() { + return state == TERMINATED; + } + + public synchronized void setSuspended() { + state = SUSPENDED; + } + + public synchronized void setRunning() { + state = RUNNING; + } + + public synchronized void setTerminated() { + state = TERMINATED; + notifyAll(); + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java index 35496f279a2..11444f31bc6 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java @@ -7,6 +7,8 @@ package org.eclipse.cdt.debug.mi.core; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; import java.util.Observable; import org.eclipse.cdt.debug.mi.core.command.Command; @@ -31,9 +33,12 @@ public class MISession extends Observable { Queue txQueue; Queue rxQueue; - OutputStream consoleStream = null; - OutputStream targetStream = null; - OutputStream logStream = null; + PipedInputStream miInPipe; + PipedOutputStream miOutPipe; + PipedInputStream targetInPipe; + PipedOutputStream targetOutPipe; + PipedInputStream logInPipe; + PipedOutputStream logOutPipe; CommandFactory factory; @@ -41,10 +46,7 @@ public class MISession extends Observable { long cmdTimeout = 10000; // 10 * 1000 (~ 10 secs); - final int STOPPED = 0; - final int RUNNING = 1; - final int SUSPENDED = 1; - int state = STOPPED; + MIProcess process; /** * Create the gdb session. @@ -63,48 +65,40 @@ public class MISession extends Observable { rxThread = new RxThread(this); txThread.start(); rxThread.start(); - } - /** - * Set Console Stream. - */ - public void setConsoleStream(OutputStream console) { - consoleStream = console; + try { + miOutPipe = new PipedOutputStream(); + miInPipe = new PipedInputStream(miOutPipe); + targetOutPipe = new PipedOutputStream(); + targetInPipe = new PipedInputStream(targetOutPipe); + logOutPipe = new PipedOutputStream(); + logInPipe = new PipedInputStream(logOutPipe); + } catch (IOException e) { + } + + process = new MIProcess(this); } /** * get Console Stream. */ - OutputStream getConsoleStream() { - return consoleStream; + public InputStream getMIStream() { + return miInPipe; } - /** - * Set Target Stream. - */ - public void setTargetStream(OutputStream target) { - targetStream = target; - } /** * Get Target Stream. */ - OutputStream getTargetStream() { - return targetStream; - } - - /** - * Set Log Stream - */ - public void setLogStream(OutputStream log) { - logStream = log; + public InputStream getTargetStream() { + return targetInPipe; } /** * Get Log Stream */ - OutputStream getLogStream() { - return logStream; + public InputStream getLogStream() { + return logInPipe; } /** @@ -179,6 +173,10 @@ public class MISession extends Observable { } } + public MIProcess getMIProcess() { + return process; + } + public boolean isTerminated() { return (!txThread.isAlive() || !rxThread.isAlive()); } @@ -188,6 +186,8 @@ public class MISession extends Observable { */ public void terminate() { + process.destroy(); + // Closing the channel will kill the RxThread. try { inChannel.close(); @@ -199,7 +199,8 @@ public class MISession extends Observable { outChannel.close(); } catch (IOException e) { } - outChannel = null; // This is needed to stop the txThread. + // This is __needed__ to stop the txThread. + outChannel = null; try { if (txThread.isAlive()) { @@ -218,53 +219,6 @@ public class MISession extends Observable { } } - /** - * The session is in STOPPED state. - * It means the 'run/-exec-run' command was not issued. - * Or the program exited, via a signal or normally. - * It is not the same as gdb/MI *stopped async-class - * gdb/MI stopped means suspended here. - */ - public boolean isStopped() { - return state == STOPPED; - } - - /** - * The session is in SUSPENDED state. - * State after hitting a breakpoint or after attach. - */ - public boolean isSuspended() { - return state == SUSPENDED; - } - - /** - * The session is in RUNNING state. - */ - public boolean isRunning() { - return state == RUNNING; - } - - /** - * Set the state STOPPED. - */ - public void setStopped() { - state = STOPPED; - } - - /** - * Set the state SUSPENDED. - */ - public void setSuspended() { - state = SUSPENDED; - } - - /** - * Set the state STOPPED. - */ - public void setRunning() { - state = RUNNING; - } - /** * Notify the observers of new MI OOB events. */ @@ -273,6 +227,19 @@ public class MISession extends Observable { super.notifyObservers(arg); } + + OutputStream getConsolePipe() { + return miOutPipe; + } + + OutputStream getTargetPipe() { + return targetOutPipe; + } + + OutputStream getLogPipe() { + return logOutPipe; + } + Queue getTxQueue() { return txQueue; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/RxThread.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/RxThread.java index 66cc5541f55..7c89415bc1d 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/RxThread.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/RxThread.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.debug.mi.core.event.MIBreakpointEvent; import org.eclipse.cdt.debug.mi.core.event.MIEvent; import org.eclipse.cdt.debug.mi.core.event.MIExitEvent; import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent; +import org.eclipse.cdt.debug.mi.core.event.MIInferiorExitEvent; import org.eclipse.cdt.debug.mi.core.event.MISignalEvent; import org.eclipse.cdt.debug.mi.core.event.MIStepEvent; import org.eclipse.cdt.debug.mi.core.event.MIWatchpointEvent; @@ -70,12 +71,18 @@ public class RxThread extends Thread { // discard termination processMIOutput(buffer.toString()); buffer = new StringBuffer(); + } else if (line.startsWith(MITargetStreamOutput.startTag)) { + // Process Target output immediately. + processMIOutput(line + "\n"); } else { buffer.append(line).append('\n'); } } } } catch (IOException e) { + MIEvent event = new MIExitEvent(); + Thread eventTread = new EventThread(session, new MIEvent[]{event}); + eventTread.start(); //e.printStackTrace(); } } @@ -98,9 +105,9 @@ public class RxThread extends Thread { // Check if the state changed. String state = rr.getResultClass(); if ("running".equals(state)) { - session.setRunning(); + session.getMIProcess().setRunning(); } else if ("exit".equals(state)) { - session.setStopped(); + session.getMIProcess().setTerminated(); } int id = rr.geToken(); @@ -149,7 +156,7 @@ public class RxThread extends Thread { // Change of state. String state = exec.getAsyncClass(); if ("stopped".equals(state)) { - session.setSuspended(); + session.getMIProcess().setSuspended(); } MIResult[] results = exec.getMIResults(); @@ -175,7 +182,7 @@ public class RxThread extends Thread { void processMIOOBRecord(MIStreamRecord stream) { if (stream instanceof MIConsoleStreamOutput) { - OutputStream console = session.getConsoleStream(); + OutputStream console = session.getConsolePipe(); if (console != null) { MIConsoleStreamOutput out = (MIConsoleStreamOutput)stream; String str = out.getString(); @@ -188,7 +195,7 @@ public class RxThread extends Thread { } } } else if (stream instanceof MITargetStreamOutput) { - OutputStream target = session.getTargetStream(); + OutputStream target = session.getTargetPipe(); if (target != null) { MITargetStreamOutput out = (MITargetStreamOutput)stream; String str = out.getString(); @@ -201,7 +208,7 @@ public class RxThread extends Thread { } } } else if (stream instanceof MILogStreamOutput) { - OutputStream log = session.getLogStream(); + OutputStream log = session.getLogPipe(); if (log != null) { MILogStreamOutput out = (MILogStreamOutput)stream; String str = out.getString(); @@ -252,45 +259,39 @@ public class RxThread extends Thread { } else if (rr != null) { event = new MIBreakpointEvent(rr); } - session.setSuspended(); } else if ("watchpoint-trigger".equals(reason)) { if (exec != null) { event = new MIWatchpointEvent(exec); } else if (rr != null) { event = new MIWatchpointEvent(rr); } - session.setSuspended(); } else if ("end-stepping-range".equals(reason)) { if (exec != null) { event = new MIStepEvent(exec); } else if (rr != null) { event = new MIStepEvent(rr); } - session.setSuspended(); } else if ("signal-received".equals(reason)) { if (exec != null) { event = new MISignalEvent(exec); } else if (rr != null) { event = new MISignalEvent(rr); } - session.setStopped(); } else if ("location-reached".equals(reason)) { if (exec != null) { event = new MISignalEvent(exec); } else if (rr != null) { event = new MISignalEvent(rr); } - session.setSuspended(); } else if ("function-finished".equals(reason)) { if (exec != null) { event = new MIFunctionFinishedEvent(exec); } else if (rr != null) { event = new MIFunctionFinishedEvent(rr); } - session.setSuspended(); } else if ("exited-normally".equals(reason)) { - event = new MIExitEvent(); - session.setStopped(); + session.getMIProcess().setTerminated(); + event = new MIInferiorExitEvent(); } return event; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/TxThread.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/TxThread.java index 035d727e1d6..fa82c213627 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/TxThread.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/TxThread.java @@ -22,6 +22,7 @@ public class TxThread extends Thread { public TxThread(MISession s) { super("MI TX Thread"); session = s; + // start at one, zero is special means no token. token = 1; } @@ -49,9 +50,13 @@ public class TxThread extends Thread { OutputStream out = session.getChannelOutputStream(); out.write(str.getBytes()); out.flush(); - // Move to the RxQueue - Queue rxQueue = session.getRxQueue(); - rxQueue.addCommand(cmd); + // Move to the RxQueue only if we have + // a valid token, this is to permit input(HACK!) + // or commands that do not want to wait for responses. + if (cmd.getToken() > 0) { + Queue rxQueue = session.getRxQueue(); + rxQueue.addCommand(cmd); + } } } } catch (IOException e) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Argument.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Argument.java new file mode 100644 index 00000000000..ec57a1792e9 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Argument.java @@ -0,0 +1,86 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.model.ICArgument; +import org.eclipse.cdt.debug.core.cdi.model.ICObject; +import org.eclipse.cdt.debug.core.cdi.model.ICTarget; +import org.eclipse.cdt.debug.core.cdi.model.ICValue; +import org.eclipse.cdt.debug.mi.core.output.MIArg; + +/** + * @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 Argument implements ICArgument { + + MIArg arg; + + public Argument(MIArg a) { + arg = a; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#getName() + */ + public String getName() throws CDIException { + return arg.getName(); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#getValue() + */ + public ICValue getValue() throws CDIException { + return new Value(arg.getValue()); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#hasValueChanged() + */ + public boolean hasValueChanged() throws CDIException { + return false; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#setValue(ICValue) + */ + public void setValue(ICValue value) throws CDIException { + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#setValue(String) + */ + public void setValue(String expression) throws CDIException { + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getCDITarget() + */ + public ICTarget getCDITarget() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getId() + */ + public String getId() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getParent() + */ + public ICObject getParent() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#getTypeName() + */ + public String getTypeName() throws CDIException { + return ""; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Breakpoint.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Breakpoint.java index 3da6407e3c3..779a539ac21 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Breakpoint.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Breakpoint.java @@ -1,9 +1,12 @@ package org.eclipse.cdt.debug.mi.core.cdi; import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.ICCatchEvent; +import org.eclipse.cdt.debug.core.cdi.ICCatchpoint; import org.eclipse.cdt.debug.core.cdi.ICCondition; import org.eclipse.cdt.debug.core.cdi.ICLocation; import org.eclipse.cdt.debug.core.cdi.ICLocationBreakpoint; +import org.eclipse.cdt.debug.core.cdi.ICWatchpoint; import org.eclipse.cdt.debug.core.cdi.model.ICInstruction; import org.eclipse.cdt.debug.mi.core.output.MIBreakPoint; @@ -15,11 +18,11 @@ import org.eclipse.cdt.debug.mi.core.output.MIBreakPoint; * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ -public class Breakpoint extends SessionObject implements ICLocationBreakpoint { +public class Breakpoint extends SessionObject implements ICLocationBreakpoint, + ICCatchpoint, ICWatchpoint { ICLocation location; ICCondition condition; - String threadId = ""; MIBreakPoint miBreakPoint; BreakpointManager mgr; @@ -60,7 +63,7 @@ public class Breakpoint extends SessionObject implements ICLocationBreakpoint { * @see org.eclipse.cdt.debug.core.cdi.ICBreakpoint#getThreadId() */ public String getThreadId() throws CDIException { - return threadId; + return miBreakPoint.getThreadId(); } /** @@ -74,14 +77,14 @@ public class Breakpoint extends SessionObject implements ICLocationBreakpoint { * @see org.eclipse.cdt.debug.core.cdi.ICBreakpoint#isHardware() */ public boolean isHardware() { - return miBreakPoint.getType().startsWith("hw"); + return miBreakPoint.isHardware(); } /** * @see org.eclipse.cdt.debug.core.cdi.ICBreakpoint#isTemporary() */ public boolean isTemporary() { - return miBreakPoint.getDisposition().equals("del"); + return miBreakPoint.isTemporary(); } /** @@ -152,4 +155,32 @@ public class Breakpoint extends SessionObject implements ICLocationBreakpoint { return location; } + /** + * @see org.eclipse.cdt.debug.core.cdi.ICCatchpoint#getEvent() + */ + public ICCatchEvent getEvent() throws CDIException { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICWatchpoint#getWatchExpression() + */ + public String getWatchExpression() throws CDIException { + return miBreakPoint.getWhat(); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICWatchpoint#isReadType() + */ + public boolean isReadType() { + return miBreakPoint.isReadWatchpoint(); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICWatchpoint#isWriteType() + */ + public boolean isWriteType() { + return miBreakPoint.isAccessWatchpoint(); + } + } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java index e5ebdf88316..c652b82637e 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java @@ -19,11 +19,14 @@ import org.eclipse.cdt.debug.core.cdi.ICLocationBreakpoint; import org.eclipse.cdt.debug.core.cdi.ICWatchpoint; import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MIBreakDelete; import org.eclipse.cdt.debug.mi.core.command.MIBreakDisable; import org.eclipse.cdt.debug.mi.core.command.MIBreakEnable; import org.eclipse.cdt.debug.mi.core.command.MIBreakInsert; +import org.eclipse.cdt.debug.mi.core.command.MIBreakWatch; import org.eclipse.cdt.debug.mi.core.output.MIBreakInsertInfo; import org.eclipse.cdt.debug.mi.core.output.MIBreakPoint; +import org.eclipse.cdt.debug.mi.core.output.MIBreakWatchInfo; import org.eclipse.cdt.debug.mi.core.output.MIInfo; /** @@ -56,11 +59,35 @@ public class BreakpointManager extends SessionObject implements ICBreakpointMana * @see org.eclipse.cdt.debug.core.cdi.ICBreakpointManager#deleteBreakpoints(ICBreakpoint[]) */ public void deleteBreakpoints(ICBreakpoint[] breakpoints) throws CDIException { + int[] numbers = new int[breakpoints.length]; + for (int i = 0; i < numbers.length; i++) { + if (breakpoints[i] instanceof Breakpoint + && breakList.contains(breakpoints[i])) { + numbers[i] = ((Breakpoint)breakpoints[i]).getMIBreakPoint().getNumber(); + } else { + //throw new CDIException(); + } + } + CSession s = getCSession(); + CommandFactory factory = s.getMISession().getCommandFactory(); + MIBreakDelete breakDelete = factory.createMIBreakDelete(numbers); + try { + s.getMISession().postCommand(breakDelete); + MIInfo info = breakDelete.getMIInfo(); + if (info == null) { + //throw new CDIException(); + } + } catch (MIException e) { + // throw new CDIException(e); + } + for (int i = 0; i < breakpoints.length; i++) { + breakList.remove(breakpoints[i]); + } } public void enableBreakpoint(ICBreakpoint breakpoint) throws CDIException { int number = 0; - if (breakpoint instanceof Breakpoint) { + if (breakpoint instanceof Breakpoint && breakList.contains(breakpoint)) { number = ((Breakpoint)breakpoint).getMIBreakPoint().getNumber(); } else { //throw new CDIException(); @@ -82,7 +109,7 @@ public class BreakpointManager extends SessionObject implements ICBreakpointMana public void disableBreakpoint(ICBreakpoint breakpoint) throws CDIException { int number = 0; - if (breakpoint instanceof Breakpoint) { + if (breakpoint instanceof Breakpoint && breakList.contains(breakpoint)) { number = ((Breakpoint)breakpoint).getMIBreakPoint().getNumber(); } else { // throw new CDIException(); @@ -114,6 +141,7 @@ public class BreakpointManager extends SessionObject implements ICBreakpointMana */ public ICCatchpoint setCatchpoint(int type, ICCatchEvent event, String expression, ICCondition condition) throws CDIException { + // throw new CDIException(); return null; } @@ -176,6 +204,29 @@ public class BreakpointManager extends SessionObject implements ICBreakpointMana */ public ICWatchpoint setWatchpoint(int type, int watchType, String expression, ICCondition condition) throws CDIException { - return null; + boolean access = (type == ICWatchpoint.WRITE); + boolean read = (type == ICWatchpoint.READ); + + CSession s = getCSession(); + CommandFactory factory = s.getMISession().getCommandFactory(); + MIBreakWatch breakWatch = factory.createMIBreakWatch(access, read, expression); + MIBreakPoint[] points = null; + try { + s.getMISession().postCommand(breakWatch); + MIBreakWatchInfo info = breakWatch.getMIBreakWatchInfo(); + if (info == null) { + //throw new CDIException(); + } + points = info.getBreakPoints(); + if (points == null || points.length == 0) { + //throw new CDIException(); + } + } catch (MIException e) { + // throw new CDIException(e); + } + + Breakpoint bkpt= new Breakpoint(this, points[0]); + breakList.add(bkpt); + return bkpt; } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CSession.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CSession.java index bb7427c53ab..c377292b447 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CSession.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CSession.java @@ -108,6 +108,10 @@ public class CSession implements ICSession { return new ICTarget[]{ctarget}; } + public ICTarget getCTarget() { + return ctarget; + } + /** * @see org.eclipse.cdt.debug.core.cdi.ICSession#isTerminated() */ diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CTarget.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CTarget.java index f0d3178c9e9..75eceff635b 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CTarget.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/CTarget.java @@ -9,7 +9,6 @@ import java.io.InputStream; import java.io.OutputStream; import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICSession; import org.eclipse.cdt.debug.core.cdi.model.ICExpression; import org.eclipse.cdt.debug.core.cdi.model.ICGlobalVariable; import org.eclipse.cdt.debug.core.cdi.model.ICMemoryBlock; @@ -18,6 +17,20 @@ import org.eclipse.cdt.debug.core.cdi.model.ICRegisterGroup; import org.eclipse.cdt.debug.core.cdi.model.ICSharedLibrary; import org.eclipse.cdt.debug.core.cdi.model.ICTarget; import org.eclipse.cdt.debug.core.cdi.model.ICThread; +import org.eclipse.cdt.debug.core.cdi.model.ICValue; +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.mi.core.MISession; +import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MIExecContinue; +import org.eclipse.cdt.debug.mi.core.command.MIExecFinish; +import org.eclipse.cdt.debug.mi.core.command.MIExecInterrupt; +import org.eclipse.cdt.debug.mi.core.command.MIExecNext; +import org.eclipse.cdt.debug.mi.core.command.MIExecNextInstruction; +import org.eclipse.cdt.debug.mi.core.command.MIExecRun; +import org.eclipse.cdt.debug.mi.core.command.MIExecStep; +import org.eclipse.cdt.debug.mi.core.command.MIExecStepInstruction; +import org.eclipse.cdt.debug.mi.core.command.MITargetDetach; +import org.eclipse.cdt.debug.mi.core.output.MIInfo; /** * @author alain @@ -37,6 +50,18 @@ public class CTarget extends SessionObject implements ICTarget { * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#disconnect() */ public void disconnect() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MITargetDetach detach = factory.createMITargetDetach(); + try { + mi.postCommand(detach); + MIInfo info = detach.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** @@ -58,6 +83,18 @@ public class CTarget extends SessionObject implements ICTarget { * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#finish() */ public void finish() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIExecFinish finish = factory.createMIExecFinish(); + try { + mi.postCommand(finish); + MIInfo info = finish.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** @@ -72,27 +109,27 @@ public class CTarget extends SessionObject implements ICTarget { * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#getErrorStream() */ public InputStream getErrorStream() { - return null; - } - - /** - * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#getGlobalVariables() - */ - public ICGlobalVariable[] getGlobalVariables() throws CDIException { - return null; + return getCSession().getMISession().getMIProcess().getErrorStream(); } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#getInputStream() */ public InputStream getInputStream() { - return null; + return getCSession().getMISession().getMIProcess().getInputStream(); } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#getOutputStream() */ public OutputStream getOutputStream() { + return getCSession().getMISession().getMIProcess().getOutputStream(); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#getGlobalVariables() + */ + public ICGlobalVariable[] getGlobalVariables() throws CDIException { return null; } @@ -107,7 +144,7 @@ public class CTarget extends SessionObject implements ICTarget { * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#getSharedLibraries() */ public ICSharedLibrary[] getSharedLibraries() throws CDIException { - return null; + return new ICSharedLibrary[0]; } /** @@ -135,76 +172,165 @@ public class CTarget extends SessionObject implements ICTarget { * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#isStepping() */ public boolean isStepping() { - return false; + return getCSession().getMISession().getMIProcess().isRunning(); } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#isSuspended() */ public boolean isSuspended() { - return false; + return getCSession().getMISession().getMIProcess().isSuspended(); } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#isTerminated() */ public boolean isTerminated() { - return false; + return getCSession().getMISession().getMIProcess().isTerminated(); } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#restart() */ public void restart() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIExecRun run = factory.createMIExecRun(new String[0]); + try { + mi.postCommand(run); + MIInfo info = run.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#resume() */ public void resume() throws CDIException { + MISession mi = getCSession().getMISession(); + if (mi.getMIProcess().isSuspended()) { + CommandFactory factory = mi.getCommandFactory(); + MIExecContinue cont = factory.createMIExecContinue(); + try { + mi.postCommand(cont); + MIInfo info = cont.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } + } else { + restart(); + } } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#stepInto() */ public void stepInto() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIExecStep step = factory.createMIExecStep(); + try { + mi.postCommand(step); + MIInfo info = step.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#stepIntoInstruction() */ public void stepIntoInstruction() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIExecStepInstruction stepi = factory.createMIExecStepInstruction(); + try { + mi.postCommand(stepi); + MIInfo info = stepi.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#stepOver() */ public void stepOver() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIExecNext next = factory.createMIExecNext(); + try { + mi.postCommand(next); + MIInfo info = next.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#stepOverInstruction() */ public void stepOverInstruction() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIExecNextInstruction nexti = factory.createMIExecNextInstruction(); + try { + mi.postCommand(nexti); + MIInfo info = nexti.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#suspend() */ public void suspend() throws CDIException { + MISession mi = getCSession().getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIExecInterrupt interrupt = factory.createMIExecInterrupt(); + try { + mi.postCommand(interrupt); + MIInfo info = interrupt.getMIInfo(); + if (info == null) { + // throw new CDIException(); + } + } catch (MIException e) { + //throw new CDIException(e); + } } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#terminate() */ public void terminate() throws CDIException { + getCSession().getMISession().getMIProcess().destroy(); } /** * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getCDITarget() */ public ICTarget getCDITarget() { - return null; + return this; } /** @@ -221,4 +347,20 @@ public class CTarget extends SessionObject implements ICTarget { return null; } + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#evaluateExpressionToString(String) + */ + public String evaluateExpressionToString(String expressionText) + throws CDIException { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICTarget#evaluateExpressionToValue(String) + */ + public ICValue evaluateExpressionToValue(String expressionText) + throws CDIException { + return null; + } + } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventAdapter.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventAdapter.java new file mode 100644 index 00000000000..cda2d729eaf --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventAdapter.java @@ -0,0 +1,37 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.event.ICEvent; +import org.eclipse.cdt.debug.mi.core.event.MIBreakpointEvent; +import org.eclipse.cdt.debug.mi.core.event.MIEvent; +import org.eclipse.cdt.debug.mi.core.event.MIExitEvent; +import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent; +import org.eclipse.cdt.debug.mi.core.event.MIInferiorExitEvent; +import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent; +import org.eclipse.cdt.debug.mi.core.event.MISignalEvent; +import org.eclipse.cdt.debug.mi.core.event.MIStepEvent; +import org.eclipse.cdt.debug.mi.core.event.MIWatchpointEvent; + +/** + * @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 EventAdapter { + + public static ICEvent getCEvent(final CSession session, final MIEvent miEvent) { + if (miEvent instanceof MIBreakpointEvent) { + return new SuspendedEvent(session, (MIBreakpointEvent)miEvent); + } else if (miEvent instanceof MIInferiorExitEvent) { + } else if (miEvent instanceof MIExitEvent) { + } else if (miEvent instanceof MIFunctionFinishedEvent) { + } else if (miEvent instanceof MILocationReachedEvent) { + } else if (miEvent instanceof MISignalEvent) { + } else if (miEvent instanceof MIStepEvent) { + } else if (miEvent instanceof MIWatchpointEvent) { + } + return null; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java index 48d1f59f10d..3a8544c570c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java @@ -5,9 +5,16 @@ */ package org.eclipse.cdt.debug.mi.core.cdi; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Observable; +import java.util.Observer; + import org.eclipse.cdt.debug.core.cdi.ICEventManager; -import org.eclipse.cdt.debug.core.cdi.ICSession; import org.eclipse.cdt.debug.core.cdi.event.ICEventListener; +import org.eclipse.cdt.debug.mi.core.MISession; +import org.eclipse.cdt.debug.mi.core.event.MIEvent; /** * @author alain @@ -19,6 +26,21 @@ import org.eclipse.cdt.debug.core.cdi.event.ICEventListener; */ public class EventManager extends SessionObject implements ICEventManager { + Map map = Collections.synchronizedMap(new HashMap()); + + class CDIObserver implements Observer { + ICEventListener listener; + public CDIObserver(ICEventListener l) { + listener = l; + } + public void update(Observable o, Object args) { + MIEvent[] events = (MIEvent[])args; + for (int i = 0; i < events.length; i++) { + // listener.handleDebugEvent(new CEventAdapter(events[i])); + } + } + } + public EventManager(CSession session) { super(session); } @@ -27,12 +49,20 @@ public class EventManager extends SessionObject implements ICEventManager { * @see org.eclipse.cdt.debug.core.cdi.ICEventManager#addEventListener(ICEventListener) */ public void addEventListener(ICEventListener listener) { + CDIObserver cdiObserver = new CDIObserver(listener); + map.put(listener, cdiObserver); + MISession session = getCSession().getMISession(); + session.addObserver(cdiObserver); } /** * @see org.eclipse.cdt.debug.core.cdi.ICEventManager#removeEventListener(ICEventListener) */ public void removeEventListener(ICEventListener listener) { + CDIObserver cdiObserver = (CDIObserver)map.remove(listener); + if (cdiObserver != null) { + MISession session = getCSession().getMISession(); + session.deleteObserver(cdiObserver); + } } - } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Expression.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Expression.java new file mode 100644 index 00000000000..fb6a1bad5dd --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Expression.java @@ -0,0 +1,54 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.model.ICExpression; +import org.eclipse.cdt.debug.core.cdi.model.ICObject; +import org.eclipse.cdt.debug.core.cdi.model.ICTarget; +import org.eclipse.cdt.debug.core.cdi.model.ICValue; + +/** + * @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 Expression implements ICExpression { + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICExpression#getExpressionText() + */ + public String getExpressionText() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICExpression#getValue() + */ + public ICValue getValue() throws CDIException { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getCDITarget() + */ + public ICTarget getCDITarget() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getId() + */ + public String getId() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getParent() + */ + public ICObject getParent() { + return null; + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Location.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Location.java new file mode 100644 index 00000000000..50d439e8c61 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Location.java @@ -0,0 +1,70 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.ICLocation; +import org.eclipse.cdt.debug.core.cdi.model.ICInstruction; + +/** + * @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 Location implements ICLocation { + + long addr; + String file = ""; + String function = ""; + int line; + + public Location(String f, String fnct, int l, long a) { + file = f; + function = fnct; + line = l; + addr = a; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICLocation#getAddress() + */ + public long getAddress() { + return addr; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICLocation#getFile() + */ + public String getFile() { + return file; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICLocation#getFunction() + */ + public String getFunction() { + return function; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICLocation#getInstructions() + */ + public ICInstruction[] getInstructions() throws CDIException { + return new ICInstruction[0]; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICLocation#getInstructions(int) + */ + public ICInstruction[] getInstructions(int maxCount) throws CDIException { + return new ICInstruction[0]; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.ICLocation#getLineNumber() + */ + public int getLineNumber() { + return line; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/StackFrame.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/StackFrame.java new file mode 100644 index 00000000000..c6cbf792be2 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/StackFrame.java @@ -0,0 +1,107 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.ICLocation; +import org.eclipse.cdt.debug.core.cdi.model.ICArgument; +import org.eclipse.cdt.debug.core.cdi.model.ICObject; +import org.eclipse.cdt.debug.core.cdi.model.ICStackFrame; +import org.eclipse.cdt.debug.core.cdi.model.ICTarget; +import org.eclipse.cdt.debug.core.cdi.model.ICVariable; +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.mi.core.MISession; +import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MIStackListLocals; +import org.eclipse.cdt.debug.mi.core.output.MIArg; +import org.eclipse.cdt.debug.mi.core.output.MIFrame; +import org.eclipse.cdt.debug.mi.core.output.MIStackListLocalsInfo; + +/** + * @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 StackFrame implements ICStackFrame { + + CSession session; + MIFrame frame; + + public StackFrame(CSession s, MIFrame f) { + session = s; + frame = f; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICStackFrame#getArguments() + */ + public ICArgument[] getArguments() throws CDIException { + MIArg[] args = frame.getArgs(); + ICArgument[] cargs = new ICArgument[args.length]; + for (int i = 0; i < cargs.length; i++) { + cargs[i] = new Argument(args[i]); + } + return cargs; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICStackFrame#getLocalVariables() + */ + public ICVariable[] getLocalVariables() throws CDIException { + MIArg[] args = null; + ICVariable[] variables = null; + MISession mi = session.getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIStackListLocals locals = factory.createMIStackListLocals(true); + try { + mi.postCommand(locals); + MIStackListLocalsInfo info = locals.getMIStackListLocalsInfo(); + if (info == null) { + // throw new CDIException(); + } + args = info.getLocals(); + + } catch (MIException e) { + //throw new CDIException(e); + } + if (args != null) { + variables = new ICVariable[args.length]; + for (int i = 0; i < variables.length; i++) { + variables[i] = new Variable(args[i]); + } + } else { + variables = new ICVariable[0]; + } + return variables; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICStackFrame#getLocation() + */ + public ICLocation getLocation() { + return new Location(frame.getFile(), frame.getFunction(), + frame.getLine(), frame.getAddress()); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getCDITarget() + */ + public ICTarget getCDITarget() { + return session.getCTarget(); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getId() + */ + public String getId() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getParent() + */ + public ICObject getParent() { + return null; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SuspendedEvent.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SuspendedEvent.java new file mode 100644 index 00000000000..48af4e6c57f --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SuspendedEvent.java @@ -0,0 +1,53 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.ICLocation; +import org.eclipse.cdt.debug.core.cdi.ICSessionObject; +import org.eclipse.cdt.debug.core.cdi.event.ICEvent; +import org.eclipse.cdt.debug.core.cdi.event.ICSuspendedEvent; +import org.eclipse.cdt.debug.core.cdi.model.ICArgument; +import org.eclipse.cdt.debug.core.cdi.model.ICObject; +import org.eclipse.cdt.debug.core.cdi.model.ICStackFrame; +import org.eclipse.cdt.debug.core.cdi.model.ICTarget; +import org.eclipse.cdt.debug.core.cdi.model.ICVariable; +import org.eclipse.cdt.debug.mi.core.event.MIBreakpointEvent; +import org.eclipse.cdt.debug.mi.core.event.MIEvent; +import org.eclipse.cdt.debug.mi.core.event.MIExitEvent; +import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent; +import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent; +import org.eclipse.cdt.debug.mi.core.event.MISignalEvent; +import org.eclipse.cdt.debug.mi.core.event.MIStepEvent; +import org.eclipse.cdt.debug.mi.core.event.MIWatchpointEvent; + +/** + * @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 SuspendedEvent implements ICSuspendedEvent { + + MIBreakpointEvent event; + CSession session; + + public SuspendedEvent(CSession s, MIBreakpointEvent e) { + session = s; + event = e; + } + + public ICSessionObject getReason() { + return new SessionObject(session); + } + + public ICStackFrame getStackFrame() { + return new StackFrame(session, event.getMIFrame()); + } + /** + * @see org.eclipse.cdt.debug.core.cdi.event.ICEvent#getSource() + */ + public ICObject getSource() { + return null; + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Value.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Value.java new file mode 100644 index 00000000000..e4433ab4bd6 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Value.java @@ -0,0 +1,66 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.model.ICObject; +import org.eclipse.cdt.debug.core.cdi.model.ICTarget; +import org.eclipse.cdt.debug.core.cdi.model.ICValue; +import org.eclipse.cdt.debug.core.cdi.model.ICVariable; + +/** + * @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 Value implements ICValue { + + String val = ""; + + public Value(String s) { + val = s; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICValue#getTypeName() + */ + public String getTypeName() throws CDIException { + return ""; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICValue#getValueString() + */ + public String getValueString() throws CDIException { + return val; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICValue#getVariables() + */ + public ICVariable[] getVariables() throws CDIException { + return new ICVariable[0]; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getCDITarget() + */ + public ICTarget getCDITarget() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getId() + */ + public String getId() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getParent() + */ + public ICObject getParent() { + return null; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Variable.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Variable.java new file mode 100644 index 00000000000..ad4bea587a3 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/Variable.java @@ -0,0 +1,86 @@ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.model.ICObject; +import org.eclipse.cdt.debug.core.cdi.model.ICTarget; +import org.eclipse.cdt.debug.core.cdi.model.ICValue; +import org.eclipse.cdt.debug.core.cdi.model.ICVariable; +import org.eclipse.cdt.debug.mi.core.output.MIArg; + +/** + * @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 Variable implements ICVariable { + + MIArg arg; + + public Variable(MIArg a) { + arg = a; + } + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#getName() + */ + public String getName() throws CDIException { + return arg.getName(); + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#getTypeName() + */ + public String getTypeName() throws CDIException { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#getValue() + */ + public ICValue getValue() throws CDIException { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#hasValueChanged() + */ + public boolean hasValueChanged() throws CDIException { + return false; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#setValue(ICValue) + */ + public void setValue(ICValue value) throws CDIException { + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICVariable#setValue(String) + */ + public void setValue(String expression) throws CDIException { + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getCDITarget() + */ + public ICTarget getCDITarget() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getId() + */ + public String getId() { + return null; + } + + /** + * @see org.eclipse.cdt.debug.core.cdi.model.ICObject#getParent() + */ + public ICObject getParent() { + return null; + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CLICommand.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CLICommand.java index ce5025bbce9..78cebd135cf 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CLICommand.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CLICommand.java @@ -27,8 +27,15 @@ public class CLICommand extends Command * @return the text representation of this command */ public String toString(){ - if (operation.endsWith("\n")) - return operation; - return operation + "\n"; + String str = null; + int t = getToken(); + if (t > 0) { + str = Integer.toString(t) + " " + operation; + } else { + str = operation; + } + if (str.endsWith("\n")) + return str; + return str + "\n"; } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java index 94975cd0acf..6cb29f2fd01 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java @@ -94,6 +94,10 @@ public class CommandFactory { return new MIEnvironmentPWD(); } + public MIExecAbort createMIExecAbort() { + return new MIExecAbort(); + } + public MIExecArguments createMIExecArguments(String[] args) { return new MIExecArguments(args); } @@ -158,6 +162,10 @@ public class CommandFactory { return new MIGDBShow(params); } + public MIGDBShowExitCode createMIGDBShowExitCode() { + return new MIGDBShowExitCode(); + } + public MIStackInfoDepth createMIStackInfoDepth(int depth) { return new MIStackInfoDepth(depth); } @@ -182,6 +190,10 @@ public class CommandFactory { return new MIStackSelectFrame(frameNum); } + public MITargetAttach createMITargetAttach(int pid) { + return new MITargetAttach(pid); + } + public MITargetDetach createMITargetDetach() { return new MITargetDetach(); } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIBreakWatch.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIBreakWatch.java index 3b535559039..6e396646c24 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIBreakWatch.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIBreakWatch.java @@ -40,6 +40,10 @@ public class MIBreakWatch extends MICommand setParameters(new String[]{expr}); } + public MIBreakWatchInfo getMIBreakWatchInfo() throws MIException { + return (MIBreakWatchInfo)getMIInfo(); + } + public MIInfo getMIInfo() throws MIException { MIInfo info = null; MIOutput out = getMIOutput(); diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIExecAbort.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIExecAbort.java new file mode 100644 index 00000000000..58a24d28075 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIExecAbort.java @@ -0,0 +1,23 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.mi.core.command; + +/** + * + * -exec-finish + * + * Asynchronous command. Resumes the execution of the inferior program + * until the current function is exited. Displays the results returned by + * the function. + * + */ +public class MIExecAbort extends CLICommand +{ + public MIExecAbort() { + super("kill"); + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShow.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShow.java index 8e09c1e4d95..5353d5b525a 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShow.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShow.java @@ -18,8 +18,7 @@ import org.eclipse.cdt.debug.mi.core.output.MIOutput; * Show the current value of a GDB variable. * */ -public class MIGDBShow extends MICommand -{ +public class MIGDBShow extends MICommand { public MIGDBShow(String[] params) { super("-gdb-show", params); } @@ -34,5 +33,5 @@ public class MIGDBShow extends MICommand } } return info; - } + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShowExitCode.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShowExitCode.java new file mode 100644 index 00000000000..cc07c6a8747 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShowExitCode.java @@ -0,0 +1,40 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.mi.core.command; + +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.mi.core.output.MIGDBShowExitCodeInfo; +import org.eclipse.cdt.debug.mi.core.output.MIInfo; +import org.eclipse.cdt.debug.mi.core.output.MIOutput; + +/** + * + * -gdb-show + * + * Show the current value of a GDB variable. + * + */ +public class MIGDBShowExitCode extends MIGDBShow { + public MIGDBShowExitCode() { + super(new String[] { "convenience", "$_exitcode" }); + } + + public MIGDBShowExitCodeInfo getMIGDBShowExitCodeInfo() throws MIException { + return (MIGDBShowExitCodeInfo)getMIInfo(); + } + public MIInfo getMIInfo() throws MIException { + MIInfo info = null; + MIOutput out = getMIOutput(); + if (out != null) { + info = new MIGDBShowExitCodeInfo(out); + if (info.isError()) { + throw new MIException(info.getErrorMsg()); + } + } + return info; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIStackListLocals.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIStackListLocals.java index fe9f31f8441..bbd57bc3452 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIStackListLocals.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIStackListLocals.java @@ -31,6 +31,10 @@ public class MIStackListLocals extends MICommand } } + public MIStackListLocalsInfo getMIStackListLocalsInfo() throws MIException { + return (MIStackListLocalsInfo)getMIInfo(); + } + public MIInfo getMIInfo() throws MIException { MIInfo info = null; MIOutput out = getMIOutput(); diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MITargetAttach.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MITargetAttach.java index 9d997b5e65c..00d458e2969 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MITargetAttach.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MITargetAttach.java @@ -14,9 +14,9 @@ package org.eclipse.cdt.debug.mi.core.command; * Attach to a process PID or a file FILE outside of GDB. * */ -public class MITargetAttach extends MICommand +public class MITargetAttach extends CLICommand { public MITargetAttach(int pid) { - super("-target-attach", new String[]{Integer.toString(pid)}); + super("attach " + Integer.toString(pid)); } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIBreakpointEvent.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIBreakpointEvent.java index f409f4187d7..3dd6f25131f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIBreakpointEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIBreakpointEvent.java @@ -39,7 +39,7 @@ public class MIBreakpointEvent extends MIEvent { return threadId; } - public MIFrame getFrame() { + public MIFrame getMIFrame() { return frame; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIExitEvent.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIExitEvent.java index 44b5fef41c7..6af72797e6b 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIExitEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIExitEvent.java @@ -3,8 +3,7 @@ package org.eclipse.cdt.debug.mi.core.event; /** - * *stopped,reason="exited-normally" - * + * Gdb Session terminated. */ public class MIExitEvent extends MIEvent { } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIInferiorExitEvent.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIInferiorExitEvent.java new file mode 100644 index 00000000000..545f0f7aff5 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/event/MIInferiorExitEvent.java @@ -0,0 +1,10 @@ +package org.eclipse.cdt.debug.mi.core.event; + + + +/** + * *stopped,reason="exited-normally" + * + */ +public class MIInferiorExitEvent extends MIEvent { +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakInsertInfo.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakInsertInfo.java index 9ce860a80ab..1a516bd3410 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakInsertInfo.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakInsertInfo.java @@ -12,6 +12,12 @@ import java.util.List; /** * -break-insert main * ^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x08048468",func="main",file="hello.c",line="4",times="0"} + * -break-insert -a p + * ^done,hw-awpt={number="2",exp="p"} + * -break-watch -r p + * ^done,hw-rwpt={number="4",exp="p"} + * -break-watch p + * ^done,wpt={number="6",exp="p"} */ public class MIBreakInsertInfo extends MIInfo { @@ -26,11 +32,28 @@ public class MIBreakInsertInfo extends MIInfo { MIResult[] results = rr.getMIResults(); for (int i = 0; i < results.length; i++) { String var = results[i].getVariable(); + MIValue val = results[i].getMIValue(); + MIBreakPoint bpt = null; if (var.equals("bkpt")) { - MIValue val = results[i].getMIValue(); if (val instanceof MITuple) { - aList.add(new MIBreakPoint((MITuple)val)); + bpt = new MIBreakPoint((MITuple)val); + bpt.setEnabled(true); } + } else if (var.equals("hw-awpt")) { + if (val instanceof MITuple) { + bpt = new MIBreakPoint((MITuple)val); + bpt.setAccessWatchpoint(true); + bpt.setEnabled(true); + } + } else if (var.equals("hw-rwpt")) { + if (val instanceof MITuple) { + bpt = new MIBreakPoint((MITuple)val); + bpt.setReadWatchpoint(true); + bpt.setEnabled(true); + } + } + if (bpt != null) { + aList.add(bpt); } } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakListInfo.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakListInfo.java index aa4e898a961..14af1421d14 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakListInfo.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakListInfo.java @@ -12,6 +12,8 @@ import java.util.List; * A -break-list result-record is the form: *
  * ^done,BreakpointTable={nr_rows="1",nr_cols="6",hdr=[..],body=[brkpt={},brkpt={}]}
+ *-break-list
+^done,BreakpointTable={nr_rows="6",nr_cols="6",hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",times="0"},bkpt={number="2",type="breakpoint",disp="del",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",times="0"},bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",cond="1",times="0"},bkpt={number="4",type="hw breakpoint",disp="keep",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",times="0"},bkpt={number="5",type="breakpoint",disp="keep",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",thread="0",thread="0",times="0"},bkpt={number="6",type="breakpoint",disp="keep",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",thread="1",thread="1",times="0"}]}
  * 
*/ public class MIBreakListInfo extends MIInfo { diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakPoint.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakPoint.java index 953debf3dff..330f63028a1 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakPoint.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakPoint.java @@ -7,12 +7,40 @@ package org.eclipse.cdt.debug.mi.core.output; /** * Contain info about the GDB/MI breakpoint info. - * -break-insert -t -c 2 main - * ^done,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",cond="2",times="0"} - * (gdb) - * -break-insert -h -i 2 main - * ^done,bkpt={number="2",type="hw breakpoint",disp="keep",enabled="y",addr="0x0804846b",func="main",file="hello.c",line="4",times="0",ignore="2"} - * (gdb) + * */ public class MIBreakPoint { @@ -24,11 +52,16 @@ public class MIBreakPoint { String func = ""; String file = ""; int line; + String cond = ""; int times; String what = ""; - String cond = ""; + String threadId = ""; int ignore; + boolean isWpt; + boolean isAWpt; + boolean isRWpt; + public MIBreakPoint(MITuple tuple) { parse(tuple); } @@ -41,6 +74,40 @@ public class MIBreakPoint { return type; } + public boolean isHardware() { + return getType().startsWith("hw") || isWatchpoint(); + } + + public boolean isTemporary() { + return getDisposition().equals("del"); + } + + public boolean isWatchpoint() { + return isWpt; + } + + public void setWatcpoint(boolean w) { + isWpt = w; + } + + public boolean isAccessWatchpoint() { + return isAWpt; + } + + public void setAccessWatchpoint(boolean a) { + isWpt = a; + isAWpt = a; + } + + public boolean isReadWatchpoint() { + return isRWpt; + } + + public void setReadWatchpoint(boolean r) { + isWpt = r; + isRWpt = r; + } + public String getDisposition() { return disp; } @@ -85,6 +152,10 @@ public class MIBreakPoint { return cond; } + public String getThreadId() { + return threadId; + } + void parse(MITuple tuple) { MIResult[] results = tuple.getMIResults(); for (int i = 0; i < results.length; i++) { @@ -115,6 +186,8 @@ public class MIBreakPoint { func = str; } else if (var.equals("file")) { file = str; + } else if (var.equals("thread")) { + threadId = str; } else if (var.equals("line")) { try { line = Integer.parseInt(str.trim()); diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakWatchInfo.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakWatchInfo.java index 601913ecca9..fe627293e66 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakWatchInfo.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIBreakWatchInfo.java @@ -5,50 +5,14 @@ package org.eclipse.cdt.debug.mi.core.output; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.debug.mi.core.command.MIBreakInsert; - /** * -break-watch buf * ^done,wpt={number="2",exp="buf"} */ -public class MIBreakWatchInfo extends MIInfo { - - MIBreakPoint[] watchpoints = null; +public class MIBreakWatchInfo extends MIBreakInsertInfo { public MIBreakWatchInfo(MIOutput rr) { super(rr); } - - public MIBreakPoint[] getBreakpoints () { - if (watchpoints == null) { - parse(); - } - return watchpoints; - } - - - void parse() { - List aList = new ArrayList(1); - if (isDone()) { - MIOutput out = getMIOutput(); - MIResultRecord rr = out.getMIResultRecord(); - if (rr != null) { - MIResult[] results = rr.getMIResults(); - for (int i = 0; i < results.length; i++) { - String var = results[i].getVariable(); - if (var.equals("wpt")) { - MIValue val = results[i].getMIValue(); - if (val instanceof MITuple) { - aList.add(new MIBreakPoint((MITuple)val)); - } - } - } - } - } - watchpoints = (MIBreakPoint[])aList.toArray(new MIBreakPoint[aList.size()]); - } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIFrame.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIFrame.java index 7e1e22ddcce..5c1a4474a8c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIFrame.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIFrame.java @@ -11,8 +11,8 @@ public class MIFrame { int level; long addr; - String func; - String file; + String func = ""; + String file = ""; int line; MIArg[] args = new MIArg[0]; @@ -24,10 +24,22 @@ public class MIFrame { return args; } + public String getFile() { + return file; + } + public String getFunction() { return func; } + public int getLine() { + return line; + } + + public long getAddress() { + return addr; + } + public int getLevel() { return level; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIGDBShowExitCodeInfo.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIGDBShowExitCodeInfo.java new file mode 100644 index 00000000000..1fb6c5e423f --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIGDBShowExitCodeInfo.java @@ -0,0 +1,54 @@ +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.mi.core.output; + +import java.util.ArrayList; +import java.util.List; + + +/** + * GDB/MI show parsing. + * (gdb) + * -gdb-show convenience $_exitcode + * ~"$_exitcode = 0" + * ~"\n" + * ^done + */ +public class MIGDBShowExitCodeInfo extends MIInfo { + + int code; + + public MIGDBShowExitCodeInfo(MIOutput o) { + super(o); + parse(); + } + + public int getCode() { + return code; + } + + void parse() { + if (isDone()) { + MIOutput out = getMIOutput(); + MIOOBRecord[] oobs = out.getMIOOBRecords(); + for (int i = 0; i < oobs.length; i++) { + if (oobs[i] instanceof MIConsoleStreamOutput) { + MIStreamRecord cons = (MIStreamRecord)oobs[i]; + String str = cons.getString(); + if (str.startsWith("$_exitcode")) { + int j = str.indexOf('='); + if (j != -1) { + String sub = str.substring(j + 1).trim(); + try { + code = Integer.parseInt(sub); + } catch (NumberFormatException e) { + } + } + } + } + } + } + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIStackListLocalsInfo.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIStackListLocalsInfo.java index c3dd0c64917..b9ce70df853 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIStackListLocalsInfo.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIStackListLocalsInfo.java @@ -7,6 +7,8 @@ package org.eclipse.cdt.debug.mi.core.output; /** * GDB/MI stack list locals parsing. + * -stack-list-locals 1 + * ^done,locals=[{name="p",value="0x8048600 \"ghislaine\""},{name="buf",value="\"'\", 'x' , \"i,xxxxxxxxx\", 'a' "},{name="buf2",value="\"\\\"?'\\\\()~\""},{name="buf3",value="\"alain\""},{name="buf4",value="\"\\t\\t\\n\\f\\r\""},{name="i",value="0"}] */ public class MIStackListLocalsInfo extends MIInfo { diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MITargetStreamOutput.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MITargetStreamOutput.java index 2b6d25626b7..d1a5f442eb1 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MITargetStreamOutput.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MITargetStreamOutput.java @@ -8,4 +8,6 @@ package org.eclipse.cdt.debug.mi.core.output; * @see MIStreamRecord */ public class MITargetStreamOutput extends MIStreamRecord { + + public static final String startTag = "@"; }