未验证 提交 7f18fd59 编写于 作者: T Thays Grazia 提交者: GitHub

[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: NAnkit Jain <radical@gmail.com>
Co-authored-by: NAnkit Jain <radical@gmail.com>
上级 8cb93a27
......@@ -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);
}
}
}
......
......@@ -972,5 +972,27 @@ public async Task InspectLocalsUsingClassFromLibraryUsingDebugTypeFull()
bp.Value["locations"][0]["columnNumber"].Value<int>(),
"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");
}
);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DebugType>portable</DebugType>
</PropertyGroup>
<Target Name="DeleteDebugSymbolFile" AfterTargets="Build">
<Message Text="Deleting $(OutDir)debugger-test-with-pdb-deleted.pdb"/>
<Delete Files="$(OutDir)debugger-test-with-pdb-deleted.pdb" />
</Target>
</Project>
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);
}
}
}
......@@ -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();
}
}
......@@ -26,6 +26,7 @@
<ProjectReference Include="..\ApplyUpdateReferencedAssembly\ApplyUpdateReferencedAssembly.csproj" />
<ProjectReference Include="..\debugger-test-with-full-debug-type\debugger-test-with-full-debug-type.csproj" Private="true"/>
<ProjectReference Include="..\debugger-test-special-char-in-path-#@\debugger-test-special-char-in-path.csproj" Private="true"/>
<ProjectReference Include="..\debugger-test-with-pdb-deleted\debugger-test-with-pdb-deleted.csproj" Private="true"/>
</ItemGroup>
<Target Name="PrepareForWasmBuildApp" DependsOnTargets="Build">
......@@ -50,6 +51,7 @@
<WasmAssemblySearchPaths Include="$(MicrosoftNetCoreAppRuntimePackRidDir)native"/>
<WasmAssemblySearchPaths Include="$(MicrosoftNetCoreAppRuntimePackRidDir)lib\$(NetCoreAppCurrent)"/>
<WasmAssembliesToBundle Include="$(OutDir)\debugger-test-special-char-in-path.dll" />
<WasmAssembliesToBundle Include="$(OutDir)\debugger-test-with-pdb-deleted.dll" />
<WasmExtraFilesToDeploy Include="@(ReferenceCopyLocalPaths)" />
</ItemGroup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册