Skip to content

Commit 2299c9f

Browse files
authored
backport 62601 (#62816)
1 parent af845cd commit 2299c9f

File tree

6 files changed

+60
-4
lines changed

6 files changed

+60
-4
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,13 @@ internal class AssemblyInfo
514514
internal PEReader peReader;
515515
internal MemoryStream asmStream;
516516
internal MemoryStream pdbStream;
517-
public int DebugId { get; set; }
517+
private int debugId;
518518

519519
public bool TriedToLoadSymbolsOnDemand { get; set; }
520520

521521
public unsafe AssemblyInfo(string url, byte[] assembly, byte[] pdb)
522522
{
523+
debugId = -1;
523524
this.id = Interlocked.Increment(ref next_id);
524525
asmStream = new MemoryStream(assembly);
525526
peReader = new PEReader(asmStream);
@@ -549,7 +550,19 @@ public unsafe AssemblyInfo(string url, byte[] assembly, byte[] pdb)
549550
}
550551
Populate();
551552
}
553+
public async Task<int> GetDebugId(SessionId sessionId, MonoSDBHelper sdbAgent, CancellationToken token)
554+
{
555+
if (debugId > 0)
556+
return debugId;
557+
debugId = await sdbAgent.GetAssemblyId(sessionId, Name, token);
558+
return debugId;
559+
}
552560

561+
public void SetDebugId(int id)
562+
{
563+
if (debugId <= 0 && debugId != id)
564+
debugId = id;
565+
}
553566
public bool EnC(byte[] meta, byte[] pdb)
554567
{
555568
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
@@ -124,7 +124,7 @@ public async Task<JObject> TryToRunOnLoadedClasses(string varName, CancellationT
124124
var type = asm.GetTypeByName(classNameToFind);
125125
if (type != null)
126126
{
127-
typeId = await sdbHelper.GetTypeIdFromToken(sessionId, asm.DebugId, type.Token, token);
127+
typeId = await sdbHelper.GetTypeIdFromToken(sessionId, await asm.GetDebugId(sessionId, sdbHelper, token), type.Token, token);
128128
}
129129
}
130130
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ public async Task<AssemblyInfo> GetAssemblyInfo(SessionId sessionId, int assembl
756756
return null;
757757
}
758758
}
759-
asm.DebugId = assemblyId;
759+
asm.SetDebugId(assemblyId);
760760
assemblies[assemblyId] = asm;
761761
return asm;
762762
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,28 @@ await EvaluateOnCallFrameFail(id,
641641
);
642642
});
643643

644+
[Fact]
645+
public async Task EvaluateStaticAttributeInAssemblyNotRelatedButLoaded() => await CheckInspectLocalsAtBreakpointSite(
646+
"DebuggerTests.EvaluateTestsClass/TestEvaluate", "EvaluateLocalsFromAnotherAssembly", 5, "EvaluateLocalsFromAnotherAssembly",
647+
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocalsFromAnotherAssembly'); })",
648+
wait_for_event_fn: async (pause_location) =>
649+
{
650+
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
651+
await EvaluateOnCallFrameAndCheck(id,
652+
("DebuggerTests.ClassToBreak.valueToCheck", TNumber(10)));
653+
});
654+
655+
[Fact]
656+
public async Task EvaluateLocalObjectFromAssemblyNotRelatedButLoaded()
657+
=> await CheckInspectLocalsAtBreakpointSite(
658+
"DebuggerTests.EvaluateTestsClass/TestEvaluate", "EvaluateLocalsFromAnotherAssembly", 5, "EvaluateLocalsFromAnotherAssembly",
659+
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocalsFromAnotherAssembly'); })",
660+
wait_for_event_fn: async (pause_location) =>
661+
{
662+
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
663+
await EvaluateOnCallFrameAndCheck(id,
664+
("a.valueToCheck", TNumber(20)));
665+
});
644666
}
645667

646668
}

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

Lines changed: 10 additions & 1 deletion
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;
1112
}
12-
}
13+
public class ClassToCheckFieldValue
14+
{
15+
public int valueToCheck;
16+
public ClassToCheckFieldValue()
17+
{
18+
valueToCheck = 20;
19+
}
20+
}
21+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public void run(int g, int h, string a, string valString, int this_a)
2828
b = b + 1;
2929
c = c + 1;
3030
}
31+
public void EvaluateLocalsFromAnotherAssembly()
32+
{
33+
var asm = System.Reflection.Assembly.LoadFrom("debugger-test-with-source-link.dll");
34+
var myType = asm.GetType("DebuggerTests.ClassToCheckFieldValue");
35+
var myMethod = myType.GetConstructor(new Type[] { });
36+
var a = myMethod.Invoke(new object[]{});
37+
}
3138
}
3239

3340
public static void EvaluateLocals()
@@ -41,6 +48,11 @@ public static void EvaluateLocals()
4148
var f_g_s = new EvaluateTestsGenericStruct<int>();
4249
f_g_s.EvaluateTestsGenericStructInstanceMethod(100, 200, "test");
4350
}
51+
public static void EvaluateLocalsFromAnotherAssembly()
52+
{
53+
TestEvaluate eval = new TestEvaluate();
54+
eval.EvaluateLocalsFromAnotherAssembly();
55+
}
4456

4557
}
4658

0 commit comments

Comments
 (0)