From da98600ac3c8e52973e57f20214731a92fd892ec Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Tue, 14 Sep 2004 14:21:02 +0000 Subject: [PATCH] workon Exception. --- .../debug/mi/core/cdi/BreakpointManager.java | 50 ++++++++++++++++++- .../cdt/debug/mi/core/cdi/EventManager.java | 21 +++++++- .../debug/mi/core/cdi/model/Breakpoint.java | 14 +++--- .../mi/core/cdi/model/Exceptionpoint.java | 4 +- 4 files changed, 78 insertions(+), 11 deletions(-) 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 55b31c5df4d..84bd7e2f37b 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 @@ -28,6 +28,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint; import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MISession; import org.eclipse.cdt.debug.mi.core.cdi.model.Breakpoint; +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; @@ -579,9 +580,56 @@ public class BreakpointManager extends Manager { return bkpt; } + Breakpoint[] exceptionBps = new Breakpoint[2]; + final int EXCEPTION_THROW_IDX = 0; + final int EXCEPTION_CATCH_IDX = 1; + final static String[] EXCEPTION_FUNCS = new String[] {"__cxa_throw", "__cxa_begin_catch"}; //$NON-NLS-1$ //$NON-NLS-2$ + + public ICDIExceptionpoint setExceptionpoint(Target target, String clazz, boolean stopOnThrow, boolean stopOnCatch) throws CDIException { - return null; + + if (!stopOnThrow && !stopOnCatch) { + throw new CDIException("Must suspend on throw or catch"); //$NON-NLS-1$ + } + + MIBreakpoint miBreakpoint = null; + + if (stopOnThrow) { + synchronized(exceptionBps) { + int id = EXCEPTION_THROW_IDX; + if (exceptionBps[EXCEPTION_THROW_IDX] == null) { + Location location = new Location(null, EXCEPTION_FUNCS[id], 0); + Breakpoint bp = new Breakpoint(target, ICDIBreakpoint.REGULAR, location, null, null); + setLocationBreakpoint(bp); + exceptionBps[id] = bp; + miBreakpoint = bp.getMIBreakpoint(); + } + } + } + if (stopOnCatch) { + synchronized(exceptionBps) { + int id = EXCEPTION_THROW_IDX; + if (exceptionBps[id] == null) { + Location location = new Location(null, EXCEPTION_FUNCS[id], 0); + Breakpoint bp = new Breakpoint(target, ICDIBreakpoint.REGULAR, location, null, null); + setLocationBreakpoint(bp); + exceptionBps[id] = bp; + miBreakpoint = bp.getMIBreakpoint(); + } + } + } + + Exceptionpoint excp = new Exceptionpoint(target, clazz, stopOnThrow, stopOnCatch); + excp.setMIBreakpoint(miBreakpoint); + List blist = getBreakpointsList(target); + blist.add(excp); + + // Fire a created Event. + MISession miSession = target.getMISession(); + miSession.fireEvent(new MIBreakpointCreatedEvent(miSession, excp.getMIBreakpoint().getNumber())); + + return excp; } /** 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 fd9e284ca7c..090c675dc65 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 @@ -48,6 +48,7 @@ import org.eclipse.cdt.debug.mi.core.command.MIThreadSelect; import org.eclipse.cdt.debug.mi.core.event.MIBreakpointChangedEvent; import org.eclipse.cdt.debug.mi.core.event.MIBreakpointCreatedEvent; import org.eclipse.cdt.debug.mi.core.event.MIBreakpointDeletedEvent; +import org.eclipse.cdt.debug.mi.core.event.MIBreakpointHitEvent; import org.eclipse.cdt.debug.mi.core.event.MIChangedEvent; import org.eclipse.cdt.debug.mi.core.event.MICreatedEvent; import org.eclipse.cdt.debug.mi.core.event.MIDestroyedEvent; @@ -272,7 +273,12 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs // Event was consumed by the shared lib processing bailout return false; } - + + if (processBreakpointHitEvent(stopped)) { + // Event was consumed, i.e. it was not the right exception. + return false; + } + int threadId = threadId = stopped.getThreadId(); currentTarget.updateState(threadId); try { @@ -506,6 +512,19 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs return false; } + boolean processBreakpointHitEvent(MIStoppedEvent stopped) { + Session session = (Session)getSession(); + if (stopped instanceof MIBreakpointHitEvent) { + MIBreakpointHitEvent bpEvent = (MIBreakpointHitEvent)stopped; + BreakpointManager bpMgr = session.getBreakpointManager(); + int bpNo = bpEvent.getNumber(); + //if (bpMgr.isExceptionBreakpoint(bpNo)) { + + //} + } + return true; + } + /** * Do any processing of before a running event. */ 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 c097a2e5e83..92992104230 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 @@ -25,7 +25,7 @@ import org.eclipse.cdt.debug.mi.core.output.MIBreakpoint; */ public class Breakpoint extends CObject implements ICDILocationBreakpoint { - ICDILocation location; + ICDILocation fLocation; ICDICondition condition; MIBreakpoint miBreakpoint; //BreakpointManager mgr; @@ -37,7 +37,7 @@ public class Breakpoint extends CObject implements ICDILocationBreakpoint { super(target); //mgr = m; type = kind; - location = loc; + fLocation = loc; condition = cond; tid = threadId; enable = true; @@ -57,7 +57,7 @@ public class Breakpoint extends CObject implements ICDILocationBreakpoint { miBreakpoint = newMIBreakpoint; // Force the reset to use GDB's values. condition = null; - location = null; + fLocation = null; } public boolean isDeferred() { @@ -148,18 +148,18 @@ public class Breakpoint extends CObject implements ICDILocationBreakpoint { * @see org.eclipse.cdt.debug.core.cdi.ICDILocationBreakpoint#getLocation() */ public ICDILocation getLocation() throws CDIException { - if (location == null) { + if (fLocation == null) { if (miBreakpoint != null) { - location = new Location (miBreakpoint.getFile(), + fLocation = new Location (miBreakpoint.getFile(), miBreakpoint.getFunction(), miBreakpoint.getLine(), miBreakpoint.getAddress()); } } - return location; + return fLocation; } public void setLocation(ICDILocation loc) { - location = loc; + fLocation = loc; } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Exceptionpoint.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Exceptionpoint.java index 47293fc129b..147e892a0af 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Exceptionpoint.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Exceptionpoint.java @@ -26,9 +26,9 @@ public class Exceptionpoint extends Breakpoint implements ICDIExceptionpoint { /** */ - public Exceptionpoint(Target target, String name, boolean stopOnThrow, boolean stopOnCatch) { + public Exceptionpoint(Target target, String clazz, boolean stopOnThrow, boolean stopOnCatch) { super(target, ICDIBreakpoint.REGULAR, null, null, null); - fClazz = name; + fClazz = clazz; fStopOnThrow = stopOnThrow; fStopOnCatch = stopOnCatch; }