Added threads, stackframes, and registers to the debug model
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / launch / MachineDebugTarget.java
index a060bd5..e1efb55 100644 (file)
@@ -1,5 +1,9 @@
 package net.mograsim.plugin.launch;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
 import org.eclipse.core.resources.IMarkerDelta;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.PlatformObject;
@@ -26,23 +30,33 @@ import net.mograsim.plugin.MograsimActivator;
 
 public class MachineDebugTarget extends PlatformObject implements IDebugTarget, IMemoryBlockRetrievalExtension
 {
+       private final static boolean USE_PSEUDO_THREAD = true;
+
        private final ILaunch launch;
        private final Machine machine;
        private final LogicExecuter exec;
+       private final MachineThread thread;
 
        private boolean running;
 
+       private final List<Consumer<Double>> executionSpeedListeners;
+
        public MachineDebugTarget(ILaunch launch, MachineDefinition machineDefinition)
        {
                this.launch = launch;
                this.machine = machineDefinition.createNew();
                this.exec = new LogicExecuter(machine.getTimeline());
 
+               this.executionSpeedListeners = new ArrayList<>();
+
                exec.startLiveExecution();
                running = true;
 
                getLaunch().addDebugTarget(this);
                fireCreationEvent();
+
+               // create after creating ourself
+               this.thread = USE_PSEUDO_THREAD ? new MachineThread(this) : null;
        }
 
        public Machine getMachine()
@@ -82,7 +96,10 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget,
        public void setExecutionSpeed(double speed)
        {
                if (getExecutionSpeed() != speed)
+               {
                        exec.setSpeedFactor(speed);
+                       callExecutionSpeedListener(speed);
+               }
        }
 
        @Override
@@ -221,13 +238,28 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget,
        @Override
        public boolean hasThreads() throws DebugException
        {
-               return false;
+               return USE_PSEUDO_THREAD;
        }
 
        @Override
        public IThread[] getThreads() throws DebugException
        {
-               return new IThread[0];
+               return thread == null ? new IThread[0] : new IThread[] { thread };
+       }
+
+       public void addExecutionSpeedListener(Consumer<Double> executionSpeedListener)
+       {
+               executionSpeedListeners.add(executionSpeedListener);
+       }
+
+       public void removeExecutionSpeedListener(Consumer<Double> executionSpeedListener)
+       {
+               executionSpeedListeners.remove(executionSpeedListener);
+       }
+
+       private void callExecutionSpeedListener(double executionSpeed)
+       {
+               executionSpeedListeners.forEach(l -> l.accept(executionSpeed));
        }
 
        @SuppressWarnings("unchecked")