backport 62601 (#62816)
authorThays Grazia <thaystg@gmail.com>
Mon, 7 Feb 2022 18:42:11 +0000 (15:42 -0300)
committerGitHub <noreply@github.com>
Mon, 7 Feb 2022 18:42:11 +0000 (10:42 -0800)
src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs
src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs
src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs
src/mono/wasm/debugger/tests/debugger-test/debugger-evaluate-test.cs

index c2d8f54..08ca2a9 100644 (file)
@@ -514,12 +514,13 @@ namespace Microsoft.WebAssembly.Diagnostics
         internal PEReader peReader;
         internal MemoryStream asmStream;
         internal MemoryStream pdbStream;
-        public int DebugId { get; set; }
+        private int debugId;
 
         public bool TriedToLoadSymbolsOnDemand { get; set; }
 
         public unsafe AssemblyInfo(string url, byte[] assembly, byte[] pdb)
         {
+            debugId = -1;
             this.id = Interlocked.Increment(ref next_id);
             asmStream = new MemoryStream(assembly);
             peReader = new PEReader(asmStream);
@@ -549,7 +550,19 @@ namespace Microsoft.WebAssembly.Diagnostics
             }
             Populate();
         }
+        public async Task<int> GetDebugId(SessionId sessionId, MonoSDBHelper sdbAgent, CancellationToken token)
+        {
+            if (debugId > 0)
+                return debugId;
+            debugId = await sdbAgent.GetAssemblyId(sessionId, Name, token);
+            return debugId;
+        }
 
+        public void SetDebugId(int id)
+        {
+            if (debugId <= 0 && debugId != id)
+                debugId = id;
+        }
         public bool EnC(byte[] meta, byte[] pdb)
         {
             var asmStream = new MemoryStream(meta);
index 5589667..9469cac 100644 (file)
@@ -124,7 +124,7 @@ namespace Microsoft.WebAssembly.Diagnostics
                     var type = asm.GetTypeByName(classNameToFind);
                     if (type != null)
                     {
-                        typeId = await sdbHelper.GetTypeIdFromToken(sessionId, asm.DebugId, type.Token, token);
+                        typeId = await sdbHelper.GetTypeIdFromToken(sessionId, await asm.GetDebugId(sessionId, sdbHelper, token), type.Token, token);
                     }
                 }
             }
index a484cc4..3787ca4 100644 (file)
@@ -756,7 +756,7 @@ namespace Microsoft.WebAssembly.Diagnostics
                     return null;
                 }
             }
-            asm.DebugId = assemblyId;
+            asm.SetDebugId(assemblyId);
             assemblies[assemblyId] = asm;
             return asm;
         }
index 0b613dc..724648c 100644 (file)
@@ -641,6 +641,28 @@ namespace DebuggerTests
                 );
             });
 
+        [Fact]
+        public async Task EvaluateStaticAttributeInAssemblyNotRelatedButLoaded() => await CheckInspectLocalsAtBreakpointSite(
+            "DebuggerTests.EvaluateTestsClass/TestEvaluate", "EvaluateLocalsFromAnotherAssembly", 5, "EvaluateLocalsFromAnotherAssembly",
+            "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocalsFromAnotherAssembly'); })",
+            wait_for_event_fn: async (pause_location) =>
+           {
+               var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
+               await EvaluateOnCallFrameAndCheck(id, 
+                   ("DebuggerTests.ClassToBreak.valueToCheck", TNumber(10)));
+           });
+
+        [Fact]
+        public async Task EvaluateLocalObjectFromAssemblyNotRelatedButLoaded()
+         => await CheckInspectLocalsAtBreakpointSite(
+            "DebuggerTests.EvaluateTestsClass/TestEvaluate", "EvaluateLocalsFromAnotherAssembly", 5, "EvaluateLocalsFromAnotherAssembly",
+            "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocalsFromAnotherAssembly'); })",
+            wait_for_event_fn: async (pause_location) =>
+           {
+               var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
+               await EvaluateOnCallFrameAndCheck(id, 
+                   ("a.valueToCheck", TNumber(20)));
+           });
     }
 
 }
index af90df3..53b80df 100644 (file)
@@ -8,5 +8,14 @@ namespace DebuggerTests
         {
             return 50;
         }
+        public static int valueToCheck = 10;
     }
-}
+    public class ClassToCheckFieldValue
+    {
+        public int valueToCheck;
+        public ClassToCheckFieldValue()
+        {
+            valueToCheck = 20;
+        }
+    }
+}
\ No newline at end of file
index 01bdda2..75e9631 100644 (file)
@@ -28,6 +28,13 @@ namespace DebuggerTests
                 b = b + 1;
                 c = c + 1;
             }
+            public void EvaluateLocalsFromAnotherAssembly()
+            {
+                var asm = System.Reflection.Assembly.LoadFrom("debugger-test-with-source-link.dll");
+                var myType = asm.GetType("DebuggerTests.ClassToCheckFieldValue");
+                var myMethod = myType.GetConstructor(new Type[] { });
+                var a = myMethod.Invoke(new object[]{});
+            }
         }
 
         public static void EvaluateLocals()
@@ -41,6 +48,11 @@ namespace DebuggerTests
             var f_g_s = new EvaluateTestsGenericStruct<int>();
             f_g_s.EvaluateTestsGenericStructInstanceMethod(100, 200, "test");
         }
+        public static void EvaluateLocalsFromAnotherAssembly()
+        {
+            TestEvaluate eval = new TestEvaluate();
+            eval.EvaluateLocalsFromAnotherAssembly();
+        }
 
     }