Skip to content

Commit 2658a0b

Browse files
thaystgradical
andauthored
[wasm][debugger] Avoiding assert on mono runtime (#62601)
* Avoiding assert on mono runtime * Update src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs Co-authored-by: Ankit Jain <[email protected]> * Addressing @radical comments. Removing unused fields in another test case. Co-authored-by: Ankit Jain <[email protected]>
1 parent 4174c20 commit 2658a0b

File tree

8 files changed

+57
-12
lines changed

8 files changed

+57
-12
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ internal class AssemblyInfo
530530
internal MetadataReader asmMetadataReader { get; }
531531
internal MetadataReader pdbMetadataReader { get; set; }
532532
internal List<MetadataReader> enCMetadataReader = new List<MetadataReader>();
533-
public int DebugId { get; set; }
533+
private int debugId;
534534
internal int PdbAge { get; }
535535
internal System.Guid PdbGuid { get; }
536536
internal string PdbName { get; }
@@ -539,6 +539,7 @@ internal class AssemblyInfo
539539

540540
public unsafe AssemblyInfo(MonoProxy monoProxy, SessionId sessionId, string url, byte[] assembly, byte[] pdb, CancellationToken token)
541541
{
542+
debugId = -1;
542543
this.id = Interlocked.Increment(ref next_id);
543544
using var asmStream = new MemoryStream(assembly);
544545
peReader = new PEReader(asmStream);
@@ -579,6 +580,20 @@ public unsafe AssemblyInfo(MonoProxy monoProxy, SessionId sessionId, string url,
579580
Populate();
580581
}
581582

583+
public async Task<int> GetDebugId(MonoSDBHelper sdbAgent, CancellationToken token)
584+
{
585+
if (debugId > 0)
586+
return debugId;
587+
debugId = await sdbAgent.GetAssemblyId(Name, token);
588+
return debugId;
589+
}
590+
591+
public void SetDebugId(int id)
592+
{
593+
if (debugId <= 0 && debugId != id)
594+
debugId = id;
595+
}
596+
582597
public bool EnC(byte[] meta, byte[] pdb)
583598
{
584599
var asmStream = new MemoryStream(meta);

src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async Task<int> FindStaticTypeId(string typeName)
163163
if (type == null)
164164
continue;
165165

166-
int id = await context.SdbAgent.GetTypeIdFromToken(asm.DebugId, type.Token, token);
166+
int id = await context.SdbAgent.GetTypeIdFromToken(await asm.GetDebugId(context.SdbAgent, token), type.Token, token);
167167
if (id != -1)
168168
return id;
169169
}

src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ public async Task<AssemblyInfo> GetAssemblyInfo(int assemblyId, CancellationToke
749749
return null;
750750
}
751751
}
752-
asm.DebugId = assemblyId;
752+
asm.SetDebugId(assemblyId);
753753
assemblies[assemblyId] = asm;
754754
return asm;
755755
}

src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,26 @@ await RuntimeEvaluateAndCheck(
855855
("\"15\"", TString("15")));
856856
});
857857

858+
[Fact]
859+
public async Task EvaluateStaticAttributeInAssemblyNotRelatedButLoaded() => await CheckInspectLocalsAtBreakpointSite(
860+
"DebuggerTests.EvaluateTestsClass", "EvaluateLocals", 9, "EvaluateLocals",
861+
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })",
862+
wait_for_event_fn: async (pause_location) =>
863+
{
864+
await RuntimeEvaluateAndCheck(
865+
("ClassToBreak.valueToCheck", TNumber(10)));
866+
});
867+
868+
[Fact]
869+
public async Task EvaluateLocalObjectFromAssemblyNotRelatedButLoaded()
870+
=> await CheckInspectLocalsAtBreakpointSite(
871+
"DebuggerTests.EvaluateTestsClass", "EvaluateLocalsFromAnotherAssembly", 5, "EvaluateLocalsFromAnotherAssembly",
872+
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocalsFromAnotherAssembly'); })",
873+
wait_for_event_fn: async (pause_location) =>
874+
{
875+
await RuntimeEvaluateAndCheck(
876+
("a.valueToCheck", TNumber(20)));
877+
});
858878
}
859879

860880
}

src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -905,14 +905,7 @@ await EvaluateAndCheck(
905905
[Fact]
906906
public async Task InspectLocalsUsingClassFromLibraryUsingDebugTypeFull()
907907
{
908-
byte[] bytes = File.ReadAllBytes(Path.Combine(DebuggerTestAppPath, "debugger-test-with-full-debug-type.dll"));
909-
string asm_base64 = Convert.ToBase64String(bytes);
910-
911-
string pdb_base64 = null;
912-
bytes = File.ReadAllBytes(Path.Combine(DebuggerTestAppPath, "debugger-test-with-full-debug-type.pdb"));
913-
pdb_base64 = Convert.ToBase64String(bytes);
914-
915-
var expression = $"{{ let asm_b64 = '{asm_base64}'; let pdb_b64 = '{pdb_base64}'; invoke_static_method('[debugger-test] DebugTypeFull:CallToEvaluateLocal', asm_b64, pdb_b64); }}";
908+
var expression = $"{{ invoke_static_method('[debugger-test] DebugTypeFull:CallToEvaluateLocal'); }}";
916909

917910
await EvaluateAndCheck(
918911
"window.setTimeout(function() {" + expression + "; }, 1);",

src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,14 @@ public static int TestBreakpoint()
88
{
99
return 50;
1010
}
11+
public static int valueToCheck = 10;
12+
}
13+
public class ClassToCheckFieldValue
14+
{
15+
public int valueToCheck;
16+
public ClassToCheckFieldValue()
17+
{
18+
valueToCheck = 20;
19+
}
1120
}
1221
}

src/mono/wasm/debugger/tests/debugger-test/debugger-evaluate-test.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public static void EvaluateLocals()
4343
f_g_s.EvaluateTestsGenericStructInstanceMethod(100, 200, "test");
4444
}
4545

46+
public static void EvaluateLocalsFromAnotherAssembly()
47+
{
48+
var asm = System.Reflection.Assembly.LoadFrom("debugger-test-with-source-link.dll");
49+
var myType = asm.GetType("DebuggerTests.ClassToCheckFieldValue");
50+
var myMethod = myType.GetConstructor(new Type[] { });
51+
var a = myMethod.Invoke(new object[]{});
52+
}
53+
4654
}
4755

4856
public struct EvaluateTestsGenericStruct<T>

src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ public static void RunDebuggerBreak()
852852

853853
public class DebugTypeFull
854854
{
855-
public static void CallToEvaluateLocal(string asm_base64, string pdb_base64)
855+
public static void CallToEvaluateLocal()
856856
{
857857
var asm = System.Reflection.Assembly.LoadFrom("debugger-test-with-full-debug-type.dll");
858858
var myType = asm.GetType("DebuggerTests.ClassToInspectWithDebugTypeFull");

0 commit comments

Comments
 (0)