You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by ar...@apache.org on 2024/01/16 17:52:46 UTC

(daffodil-vscode) branch main updated: Ignore requests for stale state.

This is an automated email from the ASF dual-hosted git repository.

arosien pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git


The following commit(s) were added to refs/heads/main by this push:
     new 1ea35ef  Ignore requests for stale state.
1ea35ef is described below

commit 1ea35ef221b6be7b829b8af628a4a1c7f7fa184e
Author: Adam Rosien <ad...@rosien.net>
AuthorDate: Wed Jan 10 17:03:36 2024 -0800

    Ignore requests for stale state.
    
    During 'continue' or 'next' events the frontend makes a sequence of requests to get the current state: asking for threads, the stack frames of each thread, the scopes listing the variables, and the values of the variables. If a rapid sequence of 'continue' or 'next' requests come in during this sequence, the debugger state is advanced and late-arriving requests from previous stepping will fail.
    
    Rather than abort, we ignore the stale requests and log them. The later requests will still request the current state and the frontend will have the correct data.
    
    Fixes #844.
---
 .../org.apache.daffodil.debugger.dap/DAPodil.scala | 22 ++++++++++++++--------
 .../ErrorEvents.scala                              |  1 -
 .../org.apache.daffodil.debugger.dap/logging.scala | 10 +++++-----
 3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/DAPodil.scala b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/DAPodil.scala
index 9acfa1c..a17f9d8 100644
--- a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/DAPodil.scala
+++ b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/DAPodil.scala
@@ -368,9 +368,12 @@ class DAPodil(
           _ <- data.stack
             .findFrame(DAPodil.Frame.Id(args.frameId))
             .fold(
-              session.abort(
-                ErrorEvents.ScopeNotFoundError,
-                s"couldn't find scopes for frame ${args.frameId}: ${data.stack.frames.map(f => f.id -> f.stackFrame.name)}"
+              session.sendResponse(
+                request.respondFailure(
+                  Some(
+                    s"couldn't find scopes for frame ${args.frameId}: ${data.stack.frames.map(f => f.id -> f.stackFrame.name)}; this is likely due to the front end advancing via 'continue' or 'next' before this request was eventually made"
+                  )
+                )
               )
             ) { frame =>
               session.sendResponse(
@@ -390,9 +393,12 @@ class DAPodil(
           _ <- data.stack
             .variables(DAPodil.VariablesReference(args.variablesReference))
             .fold(
-              session.abort(
-                ErrorEvents.UnexpectedError,
-                show"couldn't find variablesReference ${args.variablesReference} in stack ${data}"
+              session.sendResponse(
+                request.respondFailure(
+                  Some(
+                    show"couldn't find variablesReference ${args.variablesReference} in stack ${data}; this is likely due to the front end advancing via 'continue' or 'next' before this request was eventually made"
+                  )
+                )
               )
             )(variables =>
               session.sendResponse(request.respondSuccess(new Responses.VariablesResponseBody(variables.asJava)))
@@ -633,8 +639,8 @@ object DAPodil extends IOApp {
             new Events.StoppedEvent("pause", 1L)
           case Debugee.State.Stopped(Debugee.State.Stopped.Reason.Step) =>
             new Events.StoppedEvent("step", 1L)
-          case Debugee.State.Stopped(Debugee.State.Stopped.Reason.BreakpointHit(_)) =>
-            new Events.StoppedEvent("breakpoint", 1L)
+          case Debugee.State.Stopped(Debugee.State.Stopped.Reason.BreakpointHit(location)) =>
+            new Events.StoppedEvent("breakpoint", 1L, false, show"Breakpoint hit at $location", null)
         }
         .onFinalizeCase(ec => Logger[IO].debug(s"deliverStoppedEvents: $ec"))
 
diff --git a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/ErrorEvents.scala b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/ErrorEvents.scala
index 1861cfd..c973f68 100644
--- a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/ErrorEvents.scala
+++ b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/ErrorEvents.scala
@@ -26,5 +26,4 @@ object ErrorEvents {
   case object LaunchArgsParseError extends DebugEvent("daffodil.error.launchargparse")
   case object RequestError extends DebugEvent("daffodil.error.request")
   case object SourceError extends DebugEvent("daffodil.error.source")
-  case object ScopeNotFoundError extends DebugEvent("daffodil.error.scopenotfound")
 }
diff --git a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/logging.scala b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/logging.scala
index 0fa69f5..063831c 100644
--- a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/logging.scala
+++ b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/logging.scala
@@ -31,14 +31,14 @@ object logging {
     case response if response.command == "source" =>
       s"#${response.request_seq} ${response.command} ${if (response.success) "success"
         else "failure"} <response body elided>"
-    case response =>
-      s"#${response.request_seq} ${response.command} ${if (response.success) "success"
-        else "failure"} ${JsonUtils
-          .toJson(response.body)}"
+    case response if response.success =>
+      s"#${response.request_seq} ${response.command} success ${JsonUtils.toJson(response.body)}"
+    case failed =>
+      s"#${failed.request_seq} ${failed.command} failure ${failed.message}"
   }
 
   implicit val eventShow: Show[DebugEvent] = {
-    case event: Events.StoppedEvent => s"${event.`type`} ${event.reason}"
+    case event: Events.StoppedEvent => s"${event.`type`} ${event.reason} ${event.description}"
     case event: Events.ThreadEvent  => s"${event.`type`} ${event.reason}"
     case event: DAPodil.LoadedSourceEvent =>
       s"${event.`type`} ${event.reason} ${JsonUtils.toJson(event.source)}"