diff options
author | Alain Magloire | 2005-04-29 20:36:54 +0000 |
---|---|---|
committer | Alain Magloire | 2005-04-29 20:36:54 +0000 |
commit | 75853dfdbce9995ae195bbe4b237c7d65d7a521a (patch) | |
tree | 108f3b4eb354ee68c1fcc8e07a1ba3871a3a43b4 | |
parent | 2f580eb05473a00a8f95bec6b14bdb998c0d1761 (diff) | |
download | org.eclipse.cdt-75853dfdbce9995ae195bbe4b237c7d65d7a521a.tar.gz org.eclipse.cdt-75853dfdbce9995ae195bbe4b237c7d65d7a521a.tar.xz org.eclipse.cdt-75853dfdbce9995ae195bbe4b237c7d65d7a521a.zip |
2005-04-29 Alain Magloire
Fix PR 90090 PR 93317
* cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManger.java
* cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java
* cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java
* cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ExitedEvent.java
* cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Breakpoint.java
* mi/org/eclipse/cdt/debug/mi/core/MISession.java
7 files changed, 167 insertions, 70 deletions
diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index a9c543e424a..aa254bb078f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,12 @@ +2005-04-29 Alain Magloire + Fix PR 90090 PR 93317 + * cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManger.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ExitedEvent.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Breakpoint.java + * mi/org/eclipse/cdt/debug/mi/core/MISession.java + 2005-02-01 Alain Magloire Part of Fix for PR 84165 We check in the expression is a number and diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java index 1ecee3eac4e..9c779fc5ead 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java @@ -33,6 +33,8 @@ import org.eclipse.cdt.debug.mi.core.cdi.model.Exceptionpoint; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; import org.eclipse.cdt.debug.mi.core.cdi.model.Watchpoint; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MIBreakAfter; +import org.eclipse.cdt.debug.mi.core.command.MIBreakCondition; 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; @@ -298,12 +300,20 @@ public class BreakpointManager extends Manager { boolean success = false; try { bpt.setCondition0(newCondition); - setLocationBreakpoint(bpt); + if (bpt instanceof Watchpoint) { + setWatchpoint((Watchpoint)bpt); + } else { + setLocationBreakpoint(bpt); + } success = true; } finally { if (!success) { bpt.setCondition0(oldCondition); - setLocationBreakpoint(bpt); + if (bpt instanceof Watchpoint) { + setWatchpoint((Watchpoint)bpt); + } else { + setLocationBreakpoint(bpt); + } } } @@ -571,42 +581,40 @@ public class BreakpointManager extends Manager { threadIds = condition.getThreadIds(); } - if (bkpt.getLocation() != null) { - ICDILocation location = bkpt.getLocation(); + ICDILocation location = bkpt.getLocation(); + if (bkpt.isLineBreakpoint()) { String file = location.getFile(); - String function = location.getFunction(); if (file != null && file.length() > 0) { line.append(file).append(':'); - if (function != null && function.length() > 0) { - // GDB does not seem to accept function arguments when - // we use file name: - // (gdb) break file.c:Test(int) - // Will fail, altought it can accept this - // (gdb) break file.c:main - // so fall back to the line number or - // just the name of the function if lineno is invalid. - int paren = function.indexOf('('); - if (paren != -1) { - int no = location.getLineNumber(); - if (no <= 0) { - String func = function.substring(0, paren); - line.append(func); - } else { - line.append(no); - } - } else { - line.append(function); - } + } + line.append(location.getLineNumber()); + } else if (bkpt.isFunctionBreakpoint()) { + String file = location.getFile(); + if (file != null && file.length() > 0) { + line.append(file).append(':'); + } + String function = location.getFunction(); + // GDB does not seem to accept function arguments when + // we use file name: + // (gdb) break file.c:Test(int) + // Will fail, altought it can accept this + // (gdb) break file.c:main + // so fall back to the line number or + // just the name of the function if lineno is invalid. + int paren = function.indexOf('('); + if (paren != -1) { + int no = location.getLineNumber(); + if (no <= 0) { + String func = function.substring(0, paren); + line.append(func); } else { - line.append(location.getLineNumber()); + line.append(no); } - } else if (function != null && function.length() > 0) { - line.append(function); - } else if (location.getLineNumber() != 0) { - line.append(location.getLineNumber()); } else { - line.append('*').append(location.getAddress()); + line.append(function); } + } else if (bkpt.isAddressBreakpoint()) { + line.append('*').append(location.getAddress()); } MIBreakInsert[] miBreakInserts; @@ -693,11 +701,6 @@ public class BreakpointManager extends Manager { public ICDIWatchpoint setWatchpoint(Target target, int type, int watchType, String expression, ICDICondition condition) throws CDIException { - boolean access = ( (watchType & ICDIWatchpoint.WRITE) == ICDIWatchpoint.WRITE && - (watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ ); - boolean read = ( !((watchType & ICDIWatchpoint.WRITE) == ICDIWatchpoint.WRITE) && - (watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ ); - try { // Check if this an address watchpoint, and add a '*' Integer.decode(expression); @@ -706,6 +709,25 @@ public class BreakpointManager extends Manager { // } + Watchpoint bkpt = new Watchpoint(target, expression, type, watchType, condition); + setWatchpoint(bkpt); + List bList = getBreakpointsList(target); + bList.add(bkpt); + + // Fire a created Event. + MIBreakpoint[] miBreakpoints = bkpt.getMIBreakpoints(); + if (miBreakpoints != null && miBreakpoints.length > 0) { + MISession miSession = target.getMISession(); + miSession.fireEvent(new MIBreakpointCreatedEvent(miSession, miBreakpoints[0].getNumber())); + } + return bkpt; + } + + public void setWatchpoint(Watchpoint wp) throws CDIException { + Target target = (Target)wp.getTarget(); + boolean access = wp.isReadType() || wp.isWriteType(); + boolean read = wp.isReadType() && ! wp.isWriteType(); + String expression = wp.getWatchExpression(); MISession miSession = target.getMISession(); boolean state = suspendInferior(target); CommandFactory factory = miSession.getCommandFactory(); @@ -714,29 +736,53 @@ public class BreakpointManager extends Manager { MIBreakpoint[] points = null; try { miSession.postCommand(breakWatch); - MIBreakWatchInfo info = breakWatch.getMIBreakWatchInfo(); - points = info.getMIBreakpoints(); - if (info == null) { + MIBreakWatchInfo winfo = breakWatch.getMIBreakWatchInfo(); + points = winfo.getMIBreakpoints(); + if (winfo == null) { throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ } if (points == null || points.length == 0) { throw new CDIException(CdiResources.getString("cdi.BreakpointManager.Parsing_Error")); //$NON-NLS-1$ } + + int no = points[0].getNumber(); + + // Put the condition now. + String exprCond = null; + int ignoreCount = 0; + String[] threadIds = null; + StringBuffer line = new StringBuffer(); + + ICDICondition condition = wp.getCondition(); + if (condition != null) { + exprCond = condition.getExpression(); + ignoreCount = condition.getIgnoreCount(); + threadIds = condition.getThreadIds(); + } + if (exprCond != null && exprCond.length() > 0) { + MIBreakCondition breakCondition = factory.createMIBreakCondition(no, exprCond); + miSession.postCommand(breakCondition); + MIInfo info = breakCondition.getMIInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + } + if (ignoreCount > 0) { + MIBreakAfter breakAfter = factory.createMIBreakAfter(no, ignoreCount); + miSession.postCommand(breakAfter); + MIInfo info = breakAfter.getMIInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + } + // how to deal with threads ??? + } catch (MIException e) { throw new MI2CDIException(e); } finally { resumeInferior(target, state); } - Watchpoint bkpt = new Watchpoint(target, expression, type, watchType, condition); - bkpt.setMIBreakpoints(points); - List bList = getBreakpointsList(target); - bList.add(bkpt); - - // Fire a created Event. - MIBreakpoint[] miBreakpoints = bkpt.getMIBreakpoints(); - if (miBreakpoints != null && miBreakpoints.length > 0) - miSession.fireEvent(new MIBreakpointCreatedEvent(miSession, miBreakpoints[0].getNumber())); - return bkpt; + wp.setMIBreakpoints(points); } Breakpoint[] exceptionBps = new Breakpoint[2]; diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java index 4763f97dc3d..fcd841ead4c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java @@ -165,6 +165,7 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs if (target != null) { session.removeTargets(new Target[] { target }); } + cdiList.add(new ExitedEvent(session, (MIGDBExitEvent)miEvent)); } else if (miEvent instanceof MIDetachedEvent) { cdiList.add(new DisconnectedEvent(session, (MIDetachedEvent)miEvent)); } else if (miEvent instanceof MIBreakpointDeletedEvent) { @@ -322,6 +323,9 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs } } catch (CDIException e) { //System.out.println(e); + if (currentTarget.getMISession().getMIInferior().isTerminated()) { + return false; + } } return true; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java index 23c62b9fd32..586f71bb701 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java @@ -20,12 +20,9 @@ import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.ICDISessionObject; import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MISession; import org.eclipse.cdt.debug.mi.core.cdi.event.DestroyedEvent; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; -import org.eclipse.cdt.debug.mi.core.command.CommandFactory; -import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory; /** * @see org.eclipse.cdt.debug.core.cdi.ICDISession @@ -209,18 +206,6 @@ public class Session implements ICDISession, ICDISessionObject { eMgr.removeEventListeners(); } - public void addSearchPaths(Target target, String[] dirs) throws CDIException { - MISession miSession = target.getMISession(); - CommandFactory factory = miSession.getCommandFactory(); - MIEnvironmentDirectory dir = factory.createMIEnvironmentDirectory(dirs); - try { - miSession.postCommand(dir); - dir.getMIInfo(); - } catch (MIException e) { - throw new MI2CDIException(e); - } - } - /** * @deprecated * @see org.eclipse.cdt.debug.core.cdi.ICDISession#getSessionProcess() diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ExitedEvent.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ExitedEvent.java index 1da1976fe72..b3c3160a381 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ExitedEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ExitedEvent.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.debug.mi.core.cdi.Session; import org.eclipse.cdt.debug.mi.core.cdi.SignalExitInfo; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; import org.eclipse.cdt.debug.mi.core.event.MIEvent; +import org.eclipse.cdt.debug.mi.core.event.MIGDBExitEvent; import org.eclipse.cdt.debug.mi.core.event.MIInferiorExitEvent; import org.eclipse.cdt.debug.mi.core.event.MIInferiorSignalExitEvent; @@ -37,7 +38,12 @@ public class ExitedEvent implements ICDIExitedEvent { session = s; event = e; } - + + public ExitedEvent(Session s, MIGDBExitEvent e) { + session = s; + event = e; + } + /** * @see org.eclipse.cdt.debug.core.cdi.event.ICDIExitedEvent#getExitInfo() */ diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Breakpoint.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Breakpoint.java index da7ad1e720b..22f994b1706 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Breakpoint.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Breakpoint.java @@ -31,16 +31,23 @@ import org.eclipse.cdt.debug.mi.core.output.MIBreakpoint; */ public class Breakpoint extends CObject implements ICDILocationBreakpoint { + static final int LINE_BP = 0x01; + static final int FUNCTION_BP = 0x02; + static final int ADDRESS_BP = 0x04; + static final int WATCH_BP =0x08; + ICDILocation fLocation; ICDICondition condition; MIBreakpoint[] miBreakpoints; - int type; + int fType; boolean enable; + int fKind; - public Breakpoint(Target target, int kind, ICDILocation loc, ICDICondition cond) { + public Breakpoint(Target target, int type, ICDILocation loc, ICDICondition cond) { super(target); - type = kind; + fType = type; fLocation = loc; + setKind(fLocation); condition = cond; enable = true; } @@ -92,14 +99,14 @@ public class Breakpoint extends CObject implements ICDILocationBreakpoint { * @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpoint#isHardware() */ public boolean isHardware() { - return (type == ICDIBreakpoint.HARDWARE); + return (fType == ICDIBreakpoint.HARDWARE); } /** * @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpoint#isTemporary() */ public boolean isTemporary() { - return (type == ICDIBreakpoint.TEMPORARY); + return (fType == ICDIBreakpoint.TEMPORARY); } /** @@ -156,4 +163,35 @@ public class Breakpoint extends CObject implements ICDILocationBreakpoint { public void setLocation(ICDILocation loc) { fLocation = loc; } + + void setKind(ICDILocation loc) { + if (loc != null) { + int line = loc.getLineNumber(); + String func = loc.getFunction(); + BigInteger addr = loc.getAddress(); + if (line > 0) { + fKind = LINE_BP; + } else if (func != null && func.length() > 0) { + fKind = FUNCTION_BP; + } else if (addr != null && !BigInteger.ZERO.equals(addr)) { + fKind = ADDRESS_BP; + } + } + } + + public boolean isFunctionBreakpoint() { + return (fKind & FUNCTION_BP) != 0; + } + + public boolean isLineBreakpoint() { + return (fKind & LINE_BP) != 0; + } + + public boolean isAddressBreakpoint() { + return (fKind & ADDRESS_BP) != 0; + } + + public boolean isWatchpoint() { + return (this instanceof Watchpoint); + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java index 4d278fa6f5d..77ca92a0a9b 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.debug.mi.core.command.CommandFactory; import org.eclipse.cdt.debug.mi.core.command.MIExecInterrupt; import org.eclipse.cdt.debug.mi.core.command.MIGDBExit; import org.eclipse.cdt.debug.mi.core.command.MIGDBSet; +import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowPrompt; import org.eclipse.cdt.debug.mi.core.command.MIInterpreterExecConsole; import org.eclipse.cdt.debug.mi.core.event.MIEvent; @@ -343,6 +344,14 @@ public class MISession extends Observable { } } + if (inferior.isTerminated()) { + // the only thing that can call postCommand when the inferior is in a TERMINATED + // state is MIGDBShowExitCode, for when MIInferior is computing error code. + if (!(cmd instanceof MIGDBShowExitCode)) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Inferior_Terminated")); + } + } + if (isTerminated()) { throw new MIException(MIPlugin.getResourceString("src.MISession.Session_terminated")); //$NON-NLS-1$ } |