From 7f18fd5960945bd2e2dd656b61239dcde47b306b Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Fri, 1 Jul 2022 00:23:44 -0300 Subject: [PATCH] [wasm][debugger] Fix get properties from an object of a library without pdb (#71505) * When we don't have pdb we still can get some information about the methods like attributes (public, private, protected, etc) which are used for a better debugger experience. * Update src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/debugger-test-with-pdb-deleted.csproj Co-authored-by: Ankit Jain Co-authored-by: Ankit Jain --- .../debugger/BrowserDebugProxy/DebugStore.cs | 49 ++++++++++--------- .../debugger/DebuggerTestSuite/MiscTests.cs | 22 +++++++++ .../debugger-test-with-pdb-deleted.csproj | 9 ++++ .../debugger-test-with-pdb-deleted/test.cs | 20 ++++++++ .../tests/debugger-test/debugger-test.cs | 11 +++++ .../tests/debugger-test/debugger-test.csproj | 2 + 6 files changed, 90 insertions(+), 23 deletions(-) create mode 100644 src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/debugger-test-with-pdb-deleted.csproj create mode 100644 src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/test.cs diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index c480fd76f1a..3cc82f28551 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -333,6 +333,7 @@ internal sealed class MethodInfo public MethodDebugInformation DebugInformation; public MethodDefinitionHandle methodDefHandle; private MetadataReader pdbMetadataReader; + private bool hasDebugInformation; public SourceLocation StartLocation { get; set; } public SourceLocation EndLocation { get; set; } @@ -345,7 +346,7 @@ internal sealed class MethodInfo public int IsAsync { get; set; } public DebuggerAttributesInfo DebuggerAttrInfo { get; set; } public TypeInfo TypeInfo { get; } - public bool HasSequencePoints { get => !DebugInformation.SequencePointsBlob.IsNil; } + public bool HasSequencePoints { get => hasDebugInformation && !DebugInformation.SequencePointsBlob.IsNil; } private ParameterInfo[] _parametersInfo; public int KickOffMethod { get; } @@ -354,13 +355,17 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, this.IsAsync = -1; this.Assembly = assembly; this.methodDef = asmMetadataReader.GetMethodDefinition(methodDefHandle); - this.DebugInformation = pdbMetadataReader.GetMethodDebugInformation(methodDefHandle.ToDebugInformationHandle()); + if (pdbMetadataReader != null && !methodDefHandle.ToDebugInformationHandle().IsNil) + { + this.DebugInformation = pdbMetadataReader.GetMethodDebugInformation(methodDefHandle.ToDebugInformationHandle()); + hasDebugInformation = true; + } this.Source = source; this.Token = token; this.methodDefHandle = methodDefHandle; this.Name = assembly.EnCGetString(methodDef.Name); this.pdbMetadataReader = pdbMetadataReader; - if (!DebugInformation.GetStateMachineKickoffMethod().IsNil) + if (hasDebugInformation && !DebugInformation.GetStateMachineKickoffMethod().IsNil) this.KickOffMethod = asmMetadataReader.GetRowNumber(DebugInformation.GetStateMachineKickoffMethod()); else this.KickOffMethod = -1; @@ -424,7 +429,8 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, } DebuggerAttrInfo.ClearInsignificantAttrFlags(); } - localScopes = pdbMetadataReader.GetLocalScopes(methodDefHandle); + if (pdbMetadataReader != null) + localScopes = pdbMetadataReader.GetLocalScopes(methodDefHandle); } public ParameterInfo[] GetParametersInfo() @@ -998,30 +1004,27 @@ private void Populate() var typeInfo = new TypeInfo(this, type, typeDefinition, asmMetadataReader, logger); TypesByName[typeInfo.FullName] = typeInfo; TypesByToken[typeInfo.Token] = typeInfo; - if (pdbMetadataReader != null) + foreach (MethodDefinitionHandle method in typeDefinition.GetMethods()) { - foreach (MethodDefinitionHandle method in typeDefinition.GetMethods()) + var methodDefinition = asmMetadataReader.GetMethodDefinition(method); + SourceFile source = null; + if (pdbMetadataReader != null) { - var methodDefinition = asmMetadataReader.GetMethodDefinition(method); - if (!method.ToDebugInformationHandle().IsNil) + MethodDebugInformation methodDebugInformation = pdbMetadataReader.GetMethodDebugInformation(method.ToDebugInformationHandle()); + if (!methodDebugInformation.Document.IsNil) { - var methodDebugInformation = pdbMetadataReader.GetMethodDebugInformation(method.ToDebugInformationHandle()); - SourceFile source = null; - if (!methodDebugInformation.Document.IsNil) - { - var document = pdbMetadataReader.GetDocument(methodDebugInformation.Document); - var documentName = pdbMetadataReader.GetString(document.Name); - source = GetOrAddSourceFile(methodDebugInformation.Document, asmMetadataReader.GetRowNumber(methodDebugInformation.Document), documentName); - } - var methodInfo = new MethodInfo(this, method, asmMetadataReader.GetRowNumber(method), source, typeInfo, asmMetadataReader, pdbMetadataReader); - methods[asmMetadataReader.GetRowNumber(method)] = methodInfo; - - if (source != null) - source.AddMethod(methodInfo); - - typeInfo.Methods.Add(methodInfo); + var document = pdbMetadataReader.GetDocument(methodDebugInformation.Document); + var documentName = pdbMetadataReader.GetString(document.Name); + source = GetOrAddSourceFile(methodDebugInformation.Document, asmMetadataReader.GetRowNumber(methodDebugInformation.Document), documentName); } } + var methodInfo = new MethodInfo(this, method, asmMetadataReader.GetRowNumber(method), source, typeInfo, asmMetadataReader, pdbMetadataReader); + methods[asmMetadataReader.GetRowNumber(method)] = methodInfo; + + if (source != null) + source.AddMethod(methodInfo); + + typeInfo.Methods.Add(methodInfo); } } } diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs index d4cbb55266e..dadac5fd1af 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs @@ -972,5 +972,27 @@ public async Task InspectLocalsUsingClassFromLibraryUsingDebugTypeFull() bp.Value["locations"][0]["columnNumber"].Value(), "Evaluate"); } + + [Fact] + public async Task InspectPropertiesOfObjectFromLibraryWithPdbDeleted() + { + var expression = $"{{ invoke_static_method('[debugger-test] DebugWithoutSymbols:Run'); }}"; + + await EvaluateAndCheck( + "window.setTimeout(function() {" + expression + "; }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", 1146, 8, + "Run", + wait_for_event_fn: async (pause_location) => + { + var exc_props = await GetObjectOnFrame(pause_location["callFrames"][0], "exc"); + await CheckProps(exc_props, new + { + propA = TNumber(10), + propB = TNumber(20), + propC = TNumber(30) + }, "exc"); + } + ); + } } } diff --git a/src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/debugger-test-with-pdb-deleted.csproj b/src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/debugger-test-with-pdb-deleted.csproj new file mode 100644 index 00000000000..15d8fcbfc27 --- /dev/null +++ b/src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/debugger-test-with-pdb-deleted.csproj @@ -0,0 +1,9 @@ + + + portable + + + + + + diff --git a/src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/test.cs b/src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/test.cs new file mode 100644 index 00000000000..eeb5291df7d --- /dev/null +++ b/src/mono/wasm/debugger/tests/debugger-test-with-pdb-deleted/test.cs @@ -0,0 +1,20 @@ +using System; + +namespace DebuggerTests +{ + public class ClassWithPdbDeleted + { + private int propA {get;} + public int propB {get;} + protected int propC {get;} + public ClassWithPdbDeleted() + { + propA = 10; + propB = 20; + propC = 30; + Console.WriteLine(propA); + Console.WriteLine(propB); + Console.WriteLine(propC); + } + } +} diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs index a3cd8f5c23f..9e33c51a0f6 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs @@ -1136,3 +1136,14 @@ public static void MethodForCallingFromDIM() } } #endregion +public class DebugWithoutSymbols +{ + public static void Run() + { + var asm = System.Reflection.Assembly.LoadFrom("debugger-test-with-pdb-deleted.dll"); + var myType = asm.GetType("DebuggerTests.ClassWithPdbDeleted"); + var myMethod = myType.GetConstructor(new Type[] { }); + var exc = myMethod.Invoke(new object[]{}); + System.Diagnostics.Debugger.Break(); + } +} diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj index 6da6376ccd3..242ec98e4aa 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj @@ -26,6 +26,7 @@ + @@ -50,6 +51,7 @@ + -- GitLab