[wasm][debugger] Fix line number = 16777215 (#42640)
authorThays Grazia <thaystg@gmail.com>
Thu, 24 Sep 2020 19:50:34 +0000 (16:50 -0300)
committerGitHub <noreply@github.com>
Thu, 24 Sep 2020 19:50:34 +0000 (16:50 -0300)
* Fix line number = 16777215.

* Trying to get the line number before the hidden offset.

* Adding comments.

* Adding test case

* Removing extra new line

* Fixing line number

src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs
src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs

index 99b0804..8b0cd0a 100644 (file)
@@ -323,9 +323,16 @@ namespace Microsoft.WebAssembly.Diagnostics
             SequencePoint prev = null;
             foreach (SequencePoint sp in DebugInformation.SequencePoints)
             {
-                if (sp.Offset > pos)
+                if (sp.Offset > pos) {
+                    //get the earlier line number if the offset is in a hidden sequence point and has a earlier line number available
+                    // if is doesn't continue and get the next line number that is not in a hidden sequence point
+                    if (sp.IsHidden && prev == null)
+                        continue;
                     break;
-                prev = sp;
+                }
+
+                if (!sp.IsHidden)
+                    prev = sp;
             }
 
             if (prev != null)
index e517b6d..e77e7a0 100644 (file)
@@ -999,5 +999,34 @@ namespace DebuggerTests
                 await StepAndCheck(StepKind.Resume, source_file, 56, 12, "MoveNext");
             });
         }
+
+        [Fact]
+        public async Task StepOverHiddenSequencePoint()
+        {
+            var insp = new Inspector();
+
+            //Collect events
+            var scripts = SubscribeToScripts(insp);
+
+            await Ready();
+            await insp.Ready(async (cli, token) =>
+            {
+                ctx = new DebugTestContext(cli, insp, token, scripts);
+
+                var bp = await SetBreakpointInMethod("debugger-test.dll", "HiddenSequencePointTest", "StepOverHiddenSP2", 0);
+                
+                var pause_location = await EvaluateAndCheck(
+                    "window.setTimeout(function() { invoke_static_method ('[debugger-test] HiddenSequencePointTest:StepOverHiddenSP'); }, 1);",
+                    "dotnet://debugger-test.dll/debugger-test.cs", 546, 4,
+                    "StepOverHiddenSP2");
+                
+                var top_frame = pause_location["callFrames"][1];
+                Assert.Equal("StepOverHiddenSP", top_frame["functionName"].Value<string>());
+                Assert.Contains("debugger-test.cs", top_frame["url"].Value<string>());
+
+                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 537, 8, scripts, top_frame["location"]);
+
+            });
+        }
     }
 }
index 633cba1..b7021e2 100644 (file)
@@ -531,3 +531,20 @@ public class LoadDebuggerTest {
         Console.WriteLine($"Loaded - {loadedAssembly}");
     }
 }
+
+public class HiddenSequencePointTest {
+    public static void StepOverHiddenSP()
+    {
+        Console.WriteLine("first line");
+        #line hidden
+        Console.WriteLine("second line");
+        StepOverHiddenSP2();
+        #line default
+        Console.WriteLine("third line");
+
+    }
+    public static void StepOverHiddenSP2()
+    {
+        Console.WriteLine("StepOverHiddenSP2");
+    }
+}