Skip to content

Commit

Permalink
Merge pull request #2799 from fowl2/MoreCustomDebugInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Jun 24, 2023
2 parents ccab6f4 + a0d3dc8 commit bf0d74d
Show file tree
Hide file tree
Showing 45 changed files with 333 additions and 545 deletions.
2 changes: 2 additions & 0 deletions ICSharpCode.Decompiler/DebugInfo/KnownGuids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public static class KnownGuids
public static readonly Guid VBLanguageGuid = new Guid("3a12d0b8-c26c-11d0-b442-00a0244a1dd2");
public static readonly Guid FSharpLanguageGuid = new Guid("ab4f38c9-b6e6-43ba-be3b-58080b2ccce3");

// https://github.com/dotnet/roslyn/blob/main/src/Dependencies/CodeAnalysis.Debugging/PortableCustomDebugInfoKinds.cs
public static readonly Guid StateMachineHoistedLocalScopes = new Guid("6DA9A61E-F8C7-4874-BE62-68BC5630DF71");
public static readonly Guid DynamicLocalVariables = new Guid("83C563C4-B4F3-47D5-B824-BA5441477EA8");
public static readonly Guid DefaultNamespaces = new Guid("58b2eab6-209f-4e4e-a22c-b2d0f910c782");
public static readonly Guid EditAndContinueLocalSlotMap = new Guid("755F52A8-91C5-45BE-B4B8-209571E552BD");
public static readonly Guid EditAndContinueLambdaAndClosureMap = new Guid("A643004C-0240-496F-A783-30D64F4979DE");
public static readonly Guid EncStateMachineStateMap = new Guid("8B78CD68-2EDE-420B-980B-E15884B8AAA3");
public static readonly Guid EmbeddedSource = new Guid("0e8a571b-6926-466e-b4ad-8ab04611f5fe");
public static readonly Guid SourceLink = new Guid("CC110556-A091-4D38-9FEC-25AB9A351A6A");
public static readonly Guid MethodSteppingInformation = new Guid("54FD2AC5-E925-401A-9C2A-F94F171072F8");
Expand Down
4 changes: 2 additions & 2 deletions ILSpy/Metadata/CorTables/AssemblyRefTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ struct AssemblyRefEntry

public Version Version => assemblyRef.Version;

[StringFormat("X8")]
[ColumnInfo("X8", Kind = ColumnKind.Other)]
public AssemblyFlags Flags => assemblyRef.Flags;

public object FlagsTooltip => new FlagsTooltip((int)assemblyRef.Flags, null) {
FlagGroup.CreateMultipleChoiceGroup(typeof(AssemblyFlags), selectedValue: (int)assemblyRef.Flags, includeAll: false)
};

[StringFormat("X")]
[ColumnInfo("X8", Kind = ColumnKind.HeapOffset)]
public int PublicKeyOrToken => MetadataTokens.GetHeapOffset(assemblyRef.PublicKeyOrToken);

public string PublicKeyOrTokenTooltip {
Expand Down
4 changes: 2 additions & 2 deletions ILSpy/Metadata/CorTables/AssemblyTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ struct AssemblyEntry
+ metadata.GetTableMetadataOffset(TableIndex.Assembly)
+ metadata.GetTableRowSize(TableIndex.Assembly) * (RID - 1);

[StringFormat("X4")]
[ColumnInfo("X4", Kind = ColumnKind.Other)]
public AssemblyHashAlgorithm HashAlgorithm => assembly.HashAlgorithm;

public object HashAlgorithmTooltip => new FlagsTooltip() {
FlagGroup.CreateSingleChoiceGroup(typeof(AssemblyHashAlgorithm), selectedValue: (int)assembly.HashAlgorithm, defaultFlag: new Flag("None (0000)", 0, false), includeAny: false)
};

[StringFormat("X4")]
[ColumnInfo("X4", Kind = ColumnKind.Other)]
public AssemblyFlags Flags => assembly.Flags;

public object FlagsTooltip => new FlagsTooltip() {
Expand Down
18 changes: 6 additions & 12 deletions ILSpy/Metadata/CorTables/ClassLayoutTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,21 @@ unsafe struct ClassLayoutEntry

public int Offset { get; }

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Parent => MetadataTokens.GetToken(classLayout.Parent);

public void OnParentClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, classLayout.Parent, protocol: "metadata"));
}

public string ParentTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)classLayout.Parent).WriteTo(module, output, context);
return output.ToString();
}
}
string parentTooltip;
public string ParentTooltip => GenerateTooltip(ref parentTooltip, module, classLayout.Parent);

[StringFormat("X4")]
[ColumnInfo("X4", Kind = ColumnKind.Other)]
public ushort PackingSize => classLayout.PackingSize;

[StringFormat("X8")]
[ColumnInfo("X8", Kind = ColumnKind.Other)]
public uint ClassSize => classLayout.ClassSize;

public ClassLayoutEntry(PEFile module, byte* ptr, int metadataOffset, int row)
Expand All @@ -133,6 +126,7 @@ public ClassLayoutEntry(PEFile module, byte* ptr, int metadataOffset, int row)
+ metadata.GetTableRowSize(TableIndex.ClassLayout) * (row - 1);
this.Offset = metadataOffset + rowOffset;
this.classLayout = new ClassLayout(ptr + rowOffset, metadata.GetTableRowCount(TableIndex.TypeDef) < ushort.MaxValue ? 2 : 4);
this.parentTooltip = null;
}
}

Expand Down
18 changes: 6 additions & 12 deletions ILSpy/Metadata/CorTables/ConstantTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,23 @@ struct ConstantEntry
+ metadata.GetTableMetadataOffset(TableIndex.Constant)
+ metadata.GetTableRowSize(TableIndex.Constant) * (RID - 1);

[StringFormat("X8")]
[ColumnInfo("X8", Kind = ColumnKind.Other)]
public ConstantTypeCode Type => constant.TypeCode;

public string TypeTooltip => constant.TypeCode.ToString();

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Parent => MetadataTokens.GetToken(constant.Parent);

public void OnParentClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, constant.Parent, protocol: "metadata"));
}

public string ParentTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
constant.Parent.WriteTo(module, output, context);
return output.ToString();
}
}
string parentTooltip;
public string ParentTooltip => GenerateTooltip(ref parentTooltip, module, constant.Parent);

[StringFormat("X")]
[ColumnInfo("X8", Kind = ColumnKind.HeapOffset)]
public int Value => MetadataTokens.GetHeapOffset(constant.Value);

public string ValueTooltip {
Expand All @@ -126,6 +119,7 @@ public ConstantEntry(PEFile module, ConstantHandle handle)
this.metadata = module.Metadata;
this.handle = handle;
this.constant = metadata.GetConstant(handle);
this.parentTooltip = null;
}
}

Expand Down
30 changes: 9 additions & 21 deletions ILSpy/Metadata/CorTables/CustomAttributeTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,43 +87,29 @@ struct CustomAttributeEntry
+ metadata.GetTableMetadataOffset(TableIndex.CustomAttribute)
+ metadata.GetTableRowSize(TableIndex.CustomAttribute) * (RID - 1);

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Parent => MetadataTokens.GetToken(customAttr.Parent);

public void OnParentClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, customAttr.Parent, protocol: "metadata"));
}

public string ParentTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
customAttr.Parent.WriteTo(module, output, context);
return output.ToString();
}
}
string parentTooltip;
public string ParentTooltip => GenerateTooltip(ref parentTooltip, module, customAttr.Parent);

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Constructor => MetadataTokens.GetToken(customAttr.Constructor);

public void OnConstructorClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, customAttr.Constructor, protocol: "metadata"));
}

public string ConstructorTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
customAttr.Constructor.WriteTo(module, output, context);
return output.ToString();
}
}
string constructorTooltip;
public string ConstructorTooltip => GenerateTooltip(ref constructorTooltip, module, customAttr.Constructor);

[StringFormat("X")]
[ColumnInfo("X8", Kind = ColumnKind.HeapOffset)]
public int Value => MetadataTokens.GetHeapOffset(customAttr.Value);

public string ValueTooltip {
Expand All @@ -139,6 +125,8 @@ public CustomAttributeEntry(PEFile module, CustomAttributeHandle handle)
this.metadata = module.Metadata;
this.handle = handle;
this.customAttr = metadata.GetCustomAttribute(handle);
this.parentTooltip = null;
this.constructorTooltip = null;
}
}

Expand Down
18 changes: 6 additions & 12 deletions ILSpy/Metadata/CorTables/DeclSecurityTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,18 @@ struct DeclSecurityEntry
+ metadata.GetTableMetadataOffset(TableIndex.DeclSecurity)
+ metadata.GetTableRowSize(TableIndex.DeclSecurity) * (RID - 1);

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Parent => MetadataTokens.GetToken(declSecAttr.Parent);

public void OnParentClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, declSecAttr.Parent, protocol: "metadata"));
}

public string ParentTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
declSecAttr.Parent.WriteTo(module, output, context);
return output.ToString();
}
}
string parentTooltip;
public string ParentTooltip => GenerateTooltip(ref parentTooltip, module, declSecAttr.Parent);

[StringFormat("X8")]
[ColumnInfo("X8", Kind = ColumnKind.Other)]
public DeclarativeSecurityAction Action => declSecAttr.Action;

public string ActionTooltip {
Expand All @@ -115,7 +108,7 @@ public string ActionTooltip {
}
}

[StringFormat("X")]
[ColumnInfo("X8", Kind = ColumnKind.HeapOffset)]
public int PermissionSet => MetadataTokens.GetHeapOffset(declSecAttr.PermissionSet);

public string PermissionSetTooltip {
Expand All @@ -131,6 +124,7 @@ public DeclSecurityEntry(PEFile module, DeclarativeSecurityAttributeHandle handl
this.metadata = module.Metadata;
this.handle = handle;
this.declSecAttr = metadata.GetDeclarativeSecurityAttribute(handle);
this.parentTooltip = null;
}
}

Expand Down
28 changes: 8 additions & 20 deletions ILSpy/Metadata/CorTables/EventMapTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,41 +98,27 @@ unsafe struct EventMapEntry

public int Offset { get; }

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Parent => MetadataTokens.GetToken(eventMap.Parent);

public void OnParentClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, eventMap.Parent, protocol: "metadata"));
}

public string ParentTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)eventMap.Parent).WriteTo(module, output, context);
return output.ToString();
}
}
string parentTooltip;
public string ParentTooltip => GenerateTooltip(ref parentTooltip, module, eventMap.Parent);

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int EventList => MetadataTokens.GetToken(eventMap.EventList);

public void OnEventListClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, eventMap.EventList, protocol: "metadata"));
}

public string EventListTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)eventMap.EventList).WriteTo(module, output, context);
return output.ToString();
}
}
string eventListTooltip;
public string EventListTooltip => GenerateTooltip(ref eventListTooltip, module, eventMap.EventList);

public EventMapEntry(PEFile module, byte* ptr, int metadataOffset, int row)
{
Expand All @@ -145,6 +131,8 @@ public EventMapEntry(PEFile module, byte* ptr, int metadataOffset, int row)
int typeDefSize = metadata.GetTableRowCount(TableIndex.TypeDef) < ushort.MaxValue ? 2 : 4;
int eventDefSize = metadata.GetTableRowCount(TableIndex.Event) < ushort.MaxValue ? 2 : 4;
this.eventMap = new EventMap(ptr + rowOffset, typeDefSize, eventDefSize);
this.parentTooltip = null;
this.eventListTooltip = null;
}
}

Expand Down
15 changes: 5 additions & 10 deletions ILSpy/Metadata/CorTables/EventTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct EventDefEntry : IMemberTreeNode
+ metadata.GetTableMetadataOffset(TableIndex.Event)
+ metadata.GetTableRowSize(TableIndex.Event) * (RID - 1);

[StringFormat("X8")]
[ColumnInfo("X8", Kind = ColumnKind.Other)]
public EventAttributes Attributes => eventDef.Attributes;

public object AttributesTooltip => new FlagsTooltip {
Expand All @@ -103,22 +103,16 @@ struct EventDefEntry : IMemberTreeNode

IEntity IMemberTreeNode.Member => ((MetadataModule)module.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule).GetDefinition(handle);

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Type => MetadataTokens.GetToken(eventDef.Type);

public void OnTypeClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, eventDef.Type, protocol: "metadata"));
}

public string TypeTooltip {
get {
ITextOutput output = new PlainTextOutput();
eventDef.Type.WriteTo(module, output, default);
return output.ToString();
}
}
string typeTooltip;
public string TypeTooltip => GenerateTooltip(ref typeTooltip, module, eventDef.Type);

public EventDefEntry(PEFile module, EventDefinitionHandle handle)
{
Expand All @@ -127,6 +121,7 @@ public EventDefEntry(PEFile module, EventDefinitionHandle handle)
this.metadata = module.Metadata;
this.handle = handle;
this.eventDef = metadata.GetEventDefinition(handle);
this.typeTooltip = null;
}
}

Expand Down
18 changes: 5 additions & 13 deletions ILSpy/Metadata/CorTables/ExportedTypeTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct ExportedTypeEntry
+ metadata.GetTableMetadataOffset(TableIndex.ExportedType)
+ metadata.GetTableRowSize(TableIndex.ExportedType) * (RID - 1);

[StringFormat("X8")]
[ColumnInfo("X8", Kind = ColumnKind.Other)]
public TypeAttributes Attributes => type.Attributes;

const TypeAttributes otherFlagsMask = ~(TypeAttributes.VisibilityMask | TypeAttributes.LayoutMask | TypeAttributes.ClassSemanticsMask | TypeAttributes.StringFormatMask | TypeAttributes.CustomFormatMask);
Expand All @@ -110,25 +110,16 @@ struct ExportedTypeEntry

public string TypeNamespace => metadata.GetString(type.Namespace);

[StringFormat("X8")]
[LinkToTable]
[ColumnInfo("X8", Kind = ColumnKind.Token)]
public int Implementation => MetadataTokens.GetToken(type.Implementation);

public void OnImplementationClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(module, type.Implementation, protocol: "metadata"));
}

public string ImplementationTooltip {
get {
if (type.Implementation.IsNil)
return null;
ITextOutput output = new PlainTextOutput();
var context = new MetadataGenericContext(default(TypeDefinitionHandle), module);
type.Implementation.WriteTo(module, output, context);
return output.ToString();
}
}
string implementationTooltip;
public string ImplementationTooltip => GenerateTooltip(ref implementationTooltip, module, type.Implementation);

public ExportedTypeEntry(int metadataOffset, PEFile module, ExportedTypeHandle handle, ExportedType type)
{
Expand All @@ -137,6 +128,7 @@ public ExportedTypeEntry(int metadataOffset, PEFile module, ExportedTypeHandle h
this.metadata = module.Metadata;
this.handle = handle;
this.type = type;
this.implementationTooltip = null;
}
}

Expand Down
Loading

0 comments on commit bf0d74d

Please sign in to comment.