소스 검색

Improved Debug Model to support orthogonal States

Andreas Mülder 13 년 전
부모
커밋
41cc7292e9

+ 43 - 4
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTDebugTarget.java

@@ -11,6 +11,7 @@
 package org.yakindu.sct.simulation.core.debugmodel;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.Timer;
@@ -28,19 +29,25 @@ import org.eclipse.debug.core.model.IMemoryBlock;
 import org.eclipse.debug.core.model.IProcess;
 import org.eclipse.debug.core.model.IThread;
 import org.eclipse.emf.ecore.EObject;
+import org.yakindu.sct.model.sexec.Trace;
+import org.yakindu.sct.model.sexec.TraceStateEntered;
+import org.yakindu.sct.model.sexec.TraceStateExited;
+import org.yakindu.sct.model.sgraph.Region;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.simulation.core.extensions.ExecutionFactoryExtensions;
 import org.yakindu.sct.simulation.core.extensions.ExecutionFactoryExtensions.ExecutionFactoryDescriptor;
 import org.yakindu.sct.simulation.core.runtime.IExecutionFacade;
 import org.yakindu.sct.simulation.core.runtime.IExecutionFacadeFactory;
+import org.yakindu.sct.simulation.core.runtime.IExecutionTraceListener;
 
 /**
  * 
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget {
+public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget,
+		IExecutionTraceListener {
 
 	// TODO: Add to launch tab config
 	private static final int CYCLE_SLEEP_TIME = 100;
@@ -57,11 +64,14 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget {
 
 	private final Statechart statechart;
 
+	private List<SCTDebugThread> threads;
+
 	public SCTDebugTarget(ILaunch launch, Statechart statechart)
 			throws CoreException {
 		super(null, statechart.eResource().getURI().toPlatformString(true));
 		this.launch = launch;
 		this.statechart = statechart;
+		threads = new ArrayList<SCTDebugThread>();
 		timer = new Timer();
 		DebugPlugin.getDefault().getBreakpointManager()
 				.addBreakpointListener(this);
@@ -72,6 +82,7 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget {
 	private void createExecutionModel(Statechart statechart) {
 		IExecutionFacadeFactory factory = getExecutionFacadeFactory(statechart);
 		facade = factory.createExecutionFacade(statechart);
+		facade.addTraceListener(this);
 		facade.enter();
 		scheduleCycle();
 	}
@@ -104,12 +115,33 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget {
 	}
 
 	public IThread[] getThreads() throws DebugException {
-		List<SCTDebugThread> threads = new ArrayList<SCTDebugThread>();
+		// Collect all active regions
 		Set<Vertex> activeLeafStates = facade.getExecutionContext()
 				.getActiveLeafStates();
+		List<Region> activeRegions = new ArrayList<Region>();
 		for (Vertex vertex : activeLeafStates) {
-			threads.add(new SCTDebugThread(this, facade, getResourceString(),
-					vertex.getParentRegion()));
+			activeRegions.add(vertex.getParentRegion());
+		}
+		// Remove orphaned debug threads
+		Iterator<SCTDebugThread> iterator = threads.iterator();
+		while (iterator.hasNext()) {
+			SCTDebugThread next = iterator.next();
+			if (!activeRegions.contains(next.getRegion())) {
+				iterator.remove();
+			}
+		}
+		// Add new debug threads
+		for (Region region : activeRegions) {
+			boolean found = false;
+			for (SCTDebugThread thread : threads) {
+				if (thread.getRegion() == region) {
+					found = true;
+				}
+			}
+			if (!found) {
+				threads.add(new SCTDebugThread(this, facade,
+						getResourceString(), region));
+			}
 		}
 		return threads.toArray(new IThread[] {});
 	}
@@ -137,6 +169,7 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget {
 	public void terminate() throws DebugException {
 		fireEvent(new DebugEvent(getDebugTarget(), DebugEvent.TERMINATE));
 		terminated = true;
+		facade.removeTraceListener(this);
 		facade.tearDown();
 		timer.cancel();
 		timer.purge();
@@ -221,4 +254,10 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget {
 	public boolean isStepping() {
 		return stepping;
 	}
+
+	public void traceStepExecuted(Trace trace) {
+		if (trace instanceof TraceStateEntered
+				|| trace instanceof TraceStateExited)
+			fireChangeEvent(DebugEvent.CONTENT);
+	}
 }

+ 17 - 6
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTDebugThread.java

@@ -10,8 +10,6 @@
  */
 package org.yakindu.sct.simulation.core.debugmodel;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Set;
 
 import org.eclipse.debug.core.DebugException;
@@ -32,6 +30,7 @@ public class SCTDebugThread extends SCTDebugElement implements IThread {
 
 	private final Region region;
 	private final IExecutionFacade facade;
+	private SCTStackFrame stackFrame;
 
 	public SCTDebugThread(SCTDebugTarget target, IExecutionFacade facade,
 			String resourceString, Region region) {
@@ -45,16 +44,24 @@ public class SCTDebugThread extends SCTDebugElement implements IThread {
 	}
 
 	public IStackFrame[] getStackFrames() throws DebugException {
-		List<IStackFrame> stackFrames = new ArrayList<IStackFrame>();
 		Set<Vertex> activeLeafStates = facade.getExecutionContext()
 				.getActiveLeafStates();
+		Vertex activeState = null;
 		for (Vertex vertex : activeLeafStates) {
 			if (vertex.getParentRegion() == region) {
-				stackFrames.add(new SCTStackFrame(this, vertex,
-						getResourceString()));
+				activeState = vertex;
+				break;
 			}
 		}
-		return stackFrames.toArray(new IStackFrame[] {});
+		if (activeState != null) {
+			if (stackFrame == null || stackFrame.getState() != activeState) {
+				stackFrame = new SCTStackFrame(this, activeState,
+						getResourceString());
+			}
+		} else {
+			stackFrame = null;
+		}
+		return new IStackFrame[] { stackFrame };
 	}
 
 	public boolean hasStackFrames() throws DebugException {
@@ -144,4 +151,8 @@ public class SCTDebugThread extends SCTDebugElement implements IThread {
 		return (SCTDebugTarget) super.getDebugTarget();
 	}
 
+	public Region getRegion() {
+		return region;
+	}
+
 }

+ 6 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTStackFrame.java

@@ -163,4 +163,10 @@ public class SCTStackFrame extends SCTDebugElement implements IStackFrame {
 		return super.getAdapter(adapter);
 	}
 
+	public Vertex getState() {
+		return state;
+	}
+
+	
+	
 }