Browse Source

Introduce `PdbExtraTypeInfo` struct and adjusted `IDebugInfoProvider`

pull/3114/head
ElektroKill 2 years ago
parent
commit
38019ad5bf
No known key found for this signature in database
GPG Key ID: 7E3C5C084E40E3EC
  1. 8
      ICSharpCode.Decompiler/DebugInfo/IDebugInfoProvider.cs
  2. 10
      ICSharpCode.Decompiler/IL/ApplyPdbLocalTypeInfoTypeVisitor.cs
  3. 5
      ICSharpCode.Decompiler/IL/ILReader.cs
  4. 6
      ICSharpCode.ILSpyX/PdbProvider/MonoCecilDebugInfoProvider.cs
  5. 19
      ICSharpCode.ILSpyX/PdbProvider/PortableDebugInfoProvider.cs

8
ICSharpCode.Decompiler/DebugInfo/IDebugInfoProvider.cs

@ -17,13 +17,19 @@ namespace ICSharpCode.Decompiler.DebugInfo
public string Name { get; } public string Name { get; }
} }
public struct PdbExtraTypeInfo
{
public string[] TupleElementNames;
public bool[] DynamicFlags;
}
public interface IDebugInfoProvider public interface IDebugInfoProvider
{ {
string Description { get; } string Description { get; }
IList<SequencePoint> GetSequencePoints(MethodDefinitionHandle method); IList<SequencePoint> GetSequencePoints(MethodDefinitionHandle method);
IList<Variable> GetVariables(MethodDefinitionHandle method); IList<Variable> GetVariables(MethodDefinitionHandle method);
bool TryGetName(MethodDefinitionHandle method, int index, out string name); bool TryGetName(MethodDefinitionHandle method, int index, out string name);
bool TryGetExtraTypeInfo(MethodDefinitionHandle method, int index, out string[] tupleElementNames, out bool[] dynamicFlags); bool TryGetExtraTypeInfo(MethodDefinitionHandle method, int index, out PdbExtraTypeInfo extraTypeInfo);
string SourceFileName { get; } string SourceFileName { get; }
} }
} }

10
ICSharpCode.Decompiler/IL/ApplyPdbLocalTypeInfoTypeVisitor.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Immutable; using System.Collections.Immutable;
using ICSharpCode.Decompiler.DebugInfo;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation; using ICSharpCode.Decompiler.TypeSystem.Implementation;
@ -16,12 +17,19 @@ namespace ICSharpCode.Decompiler.IL
private int dynamicTypeIndex = 0; private int dynamicTypeIndex = 0;
private int tupleTypeIndex = 0; private int tupleTypeIndex = 0;
public ApplyPdbLocalTypeInfoTypeVisitor(bool[] dynamicData, string[] tupleElementNames) private ApplyPdbLocalTypeInfoTypeVisitor(bool[] dynamicData, string[] tupleElementNames)
{ {
this.dynamicData = dynamicData; this.dynamicData = dynamicData;
this.tupleElementNames = tupleElementNames; this.tupleElementNames = tupleElementNames;
} }
public static IType Apply(IType type, PdbExtraTypeInfo pdbExtraTypeInfo)
{
if (pdbExtraTypeInfo.DynamicFlags is null && pdbExtraTypeInfo.TupleElementNames is null)
return type;
return type.AcceptVisitor(new ApplyPdbLocalTypeInfoTypeVisitor(pdbExtraTypeInfo.DynamicFlags, pdbExtraTypeInfo.TupleElementNames));
}
public override IType VisitModOpt(ModifiedType type) public override IType VisitModOpt(ModifiedType type)
{ {
dynamicTypeIndex++; dynamicTypeIndex++;

5
ICSharpCode.Decompiler/IL/ILReader.cs

@ -306,10 +306,9 @@ namespace ICSharpCode.Decompiler.IL
} }
if (UseDebugSymbols && DebugInfo is not null && if (UseDebugSymbols && DebugInfo is not null &&
DebugInfo.TryGetExtraTypeInfo((MethodDefinitionHandle)method.MetadataToken, index, DebugInfo.TryGetExtraTypeInfo((MethodDefinitionHandle)method.MetadataToken, index, out var pdbExtraTypeInfo))
out string[] tupleElementNames, out bool[] dynamicFlags))
{ {
type = type.AcceptVisitor(new ApplyPdbLocalTypeInfoTypeVisitor(dynamicFlags, tupleElementNames)); type = ApplyPdbLocalTypeInfoTypeVisitor.Apply(type, pdbExtraTypeInfo);
} }
ILVariable ilVar = new ILVariable(kind, type, index); ILVariable ilVar = new ILVariable(kind, type, index);

6
ICSharpCode.ILSpyX/PdbProvider/MonoCecilDebugInfoProvider.cs

@ -136,13 +136,11 @@ namespace ICSharpCode.ILSpyX.PdbProvider
return name != null; return name != null;
} }
public bool TryGetExtraTypeInfo(SRM.MethodDefinitionHandle method, int index, public bool TryGetExtraTypeInfo(SRM.MethodDefinitionHandle method, int index, out PdbExtraTypeInfo extraTypeInfo)
[NotNullWhen(true)] out string[]? tupleElementNames, [NotNullWhen(true)] out bool[]? dynamicFlags)
{ {
// Mono.Cecil's WindowsPDB reader is unable to read tuple element names // Mono.Cecil's WindowsPDB reader is unable to read tuple element names
// and dynamic flags custom debug information. // and dynamic flags custom debug information.
tupleElementNames = null; extraTypeInfo = default;
dynamicFlags = null;
return false; return false;
} }
} }

19
ICSharpCode.ILSpyX/PdbProvider/PortableDebugInfoProvider.cs

@ -162,12 +162,10 @@ namespace ICSharpCode.ILSpyX.PdbProvider
return false; return false;
} }
public bool TryGetExtraTypeInfo(MethodDefinitionHandle method, int index, public bool TryGetExtraTypeInfo(MethodDefinitionHandle method, int index, out PdbExtraTypeInfo extraTypeInfo)
[NotNullWhen(true)] out string?[]? tupleElementNames, [NotNullWhen(true)] out bool[]? dynamicFlags)
{ {
var metadata = GetMetadataReader(); var metadata = GetMetadataReader();
tupleElementNames = null; extraTypeInfo = default;
dynamicFlags = null;
if (metadata == null) if (metadata == null)
return false; return false;
@ -200,7 +198,7 @@ namespace ICSharpCode.ILSpyX.PdbProvider
if (cdi.Value.IsNil || cdi.Kind.IsNil) if (cdi.Value.IsNil || cdi.Kind.IsNil)
continue; continue;
var kind = metadata.GetGuid(cdi.Kind); var kind = metadata.GetGuid(cdi.Kind);
if (kind == KnownGuids.TupleElementNames && tupleElementNames is null) if (kind == KnownGuids.TupleElementNames && extraTypeInfo.TupleElementNames is null)
{ {
var reader = metadata.GetBlobReader(cdi.Value); var reader = metadata.GetBlobReader(cdi.Value);
var list = new List<string?>(); var list = new List<string?>();
@ -212,25 +210,26 @@ namespace ICSharpCode.ILSpyX.PdbProvider
list.Add(string.IsNullOrWhiteSpace(s) ? null : s); list.Add(string.IsNullOrWhiteSpace(s) ? null : s);
} }
tupleElementNames = list.ToArray(); extraTypeInfo.TupleElementNames = list.ToArray();
} }
else if (kind == KnownGuids.DynamicLocalVariables && dynamicFlags is null) else if (kind == KnownGuids.DynamicLocalVariables && extraTypeInfo.DynamicFlags is null)
{ {
var reader = metadata.GetBlobReader(cdi.Value); var reader = metadata.GetBlobReader(cdi.Value);
extraTypeInfo.DynamicFlags = new bool[reader.Length * 8];
int j = 0; int j = 0;
while (reader.RemainingBytes > 0) while (reader.RemainingBytes > 0)
{ {
int b = reader.ReadByte(); int b = reader.ReadByte();
for (int i = 1; i < 0x100; i <<= 1) for (int i = 1; i < 0x100; i <<= 1)
dynamicFlags[j++] = (b & i) != 0; extraTypeInfo.DynamicFlags[j++] = (b & i) != 0;
} }
} }
if (tupleElementNames != null && dynamicFlags != null) if (extraTypeInfo.TupleElementNames != null && extraTypeInfo.DynamicFlags != null)
break; break;
} }
return tupleElementNames != null || dynamicFlags != null; return extraTypeInfo.TupleElementNames != null || extraTypeInfo.DynamicFlags != null;
} }
} }
} }

Loading…
Cancel
Save