Skip to content

Commit

Permalink
Debugger stop reasons (breakpoint vs. stepping etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Dobell committed Feb 24, 2019
1 parent 370dfdf commit 0994866
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
44 changes: 36 additions & 8 deletions src/MoonSharp.VsCodeDebugger/DebuggerLogic/ScriptDebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ internal class ScriptDebugSession : MoonSharpDebugSession, IAsyncDebuggerClient
const int SCOPE_LOCALS = 65536;
const int SCOPE_SELF = 65537;

const int STOP_REASON_STEP = 0;
const int STOP_REASON_BREAKPOINT = 1;
const int STOP_REASON_EXCEPTION = 2;
const int STOP_REASON_PAUSED = 3;

readonly List<DynValue> m_Variables = new List<DynValue>();
bool m_NotifyExecutionEnd = false;
private bool m_RestartOnUnbind = false;

private int stopReason = STOP_REASON_STEP;
private ScriptRuntimeException runtimeException = null;

public override string Name => Debugger.Name;
Expand Down Expand Up @@ -103,6 +110,7 @@ public override void Attach(Response response, Table arguments)

public override void Continue(Response response, Table arguments)
{
stopReason = STOP_REASON_BREAKPOINT;
Debugger.QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.Run });
SendResponse(response);
}
Expand Down Expand Up @@ -293,17 +301,19 @@ public override void Launch(Response response, Table arguments)

public override void Next(Response response, Table arguments)
{
stopReason = STOP_REASON_STEP;
Debugger.QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepOver });
SendResponse(response);
}

private StoppedEvent CreateStoppedEvent(string reason, string text = null)
private StoppedEvent CreateStoppedEvent(string reason, string description, string text = null)
{
return new StoppedEvent(0, reason, text);
return new StoppedEvent(0, reason, description, text);
}

public override void Pause(Response response, Table arguments)
{
stopReason = STOP_REASON_PAUSED;
Debugger.PauseRequested = true;
SendResponse(response);
SendText("Pause pending -- will pause at first script statement.");
Expand Down Expand Up @@ -437,12 +447,14 @@ private int getInt(Table args, string propName, int defaultValue)

public override void StepIn(Response response, Table arguments)
{
stopReason = STOP_REASON_STEP;
Debugger.QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepIn });
SendResponse(response);
}

public override void StepOut(Response response, Table arguments)
{
stopReason = STOP_REASON_STEP;
Debugger.QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepOut });
SendResponse(response);
}
Expand Down Expand Up @@ -486,13 +498,28 @@ public override void Variables(Response response, Table arguments)

void IAsyncDebuggerClient.SendStopEvent()
{
if (IsRuntimeExceptionCurrent())
{
SendEvent(CreateStoppedEvent("exception", "Paused on exception"));
}
else
switch (stopReason)
{
SendEvent(CreateStoppedEvent("step"));
case STOP_REASON_STEP:
SendEvent(CreateStoppedEvent("step", "Paused after stepping"));
break;

case STOP_REASON_BREAKPOINT:
SendEvent(CreateStoppedEvent("breakpoint", "Paused on breakpoint"));
break;

case STOP_REASON_EXCEPTION:
SendEvent(CreateStoppedEvent("exception", "Paused on exception", runtimeException?.Message));
break;

case STOP_REASON_PAUSED:
SendEvent(CreateStoppedEvent("pause", "Paused by debugger"));
break;

default:
SendEvent(CreateStoppedEvent("unknown", "Paused for an unknown reason"));
break;

}
}

Expand Down Expand Up @@ -527,6 +554,7 @@ private void SendText(string msg, params object[] args)

public void OnException(ScriptRuntimeException ex)
{
stopReason = STOP_REASON_EXCEPTION;
runtimeException = ex;
}

Expand Down
9 changes: 5 additions & 4 deletions src/MoonSharp.VsCodeDebugger/SDK/DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ public InitializedEvent()

public class StoppedEvent : Event
{
public StoppedEvent(int tid, string reasn, string txt = null)
public StoppedEvent(int threadId, string reason, string description, string text = null)
: base("stopped", new
{
threadId = tid,
reason = reasn,
text = txt
threadId,
reason,
description,
text
})
{
}
Expand Down

0 comments on commit 0994866

Please sign in to comment.