Skip to content

Commit 5dda80d

Browse files
committed
More progress
1 parent 5ac5820 commit 5dda80d

29 files changed

+404
-81
lines changed

src/AsmResolver.DotNet/DefaultPdbMetadataResolver.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO.Compression;
33
using System.Linq;
44
using AsmResolver.DotNet.PortablePdbs;
5+
using AsmResolver.DotNet.PortablePdbs.Serialized;
56
using AsmResolver.PE.Debug;
67

78
namespace AsmResolver.DotNet;
@@ -10,17 +11,17 @@ public class DefaultPdbMetadataResolver : IPdbMetadataResolver
1011
{
1112
public static DefaultPdbMetadataResolver Instance { get; } = new();
1213

13-
public PortablePdb? ResolvePortablePdb(ModuleDefinition module)
14+
public PdbReaderContext? ResolvePortablePdb(ModuleDefinition module)
1415
{
1516
if (module.DotNetDirectory?.Metadata is { } metadata && PortablePdb.TryFromMetadata(metadata, module, out var pdb))
1617
{
17-
return pdb;
18+
return pdb.PdbReaderContext;
1819
}
1920

2021
// System.Reflection.Metadata tries reading from a file first, so we will as well
2122
if (module.FilePath is { } path && PortablePdb.TryFromFile(Path.ChangeExtension(path, ".pdb"), module, out pdb))
2223
{
23-
return pdb;
24+
return pdb.PdbReaderContext;
2425
}
2526

2627
var pdbSection = module.DebugData.Select(dd => dd.Contents).OfType<PortablePdbDataSegment>().FirstOrDefault();
@@ -33,7 +34,7 @@ public class DefaultPdbMetadataResolver : IPdbMetadataResolver
3334
decompressStream.CopyTo(resultStream);
3435
if (PortablePdb.TryFromBytes(pdbData, module, out pdb))
3536
{
36-
return pdb;
37+
return pdb.PdbReaderContext;
3738
}
3839
}
3940

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using AsmResolver.DotNet.PortablePdbs;
2+
using AsmResolver.DotNet.PortablePdbs.Serialized;
23

34
namespace AsmResolver.DotNet
45
{
56
public interface IPdbMetadataResolver
67
{
7-
PortablePdb? ResolvePortablePdb(ModuleDefinition module);
8+
PdbReaderContext? ResolvePortablePdb(ModuleDefinition module);
89
}
910
}

src/AsmResolver.DotNet/MethodDefinition.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,16 @@ public MethodDebugInformation MethodDebugInformation
806806
set => _methodDebugInformation.SetValue(value);
807807
}
808808

809+
[LazyProperty]
810+
public partial MethodDebugInformation? MethodDebugInformation
811+
{
812+
get;
813+
set;
814+
}
815+
816+
[LazyProperty]
817+
public partial IList<LocalScope> LocalScopes { get; }
818+
809819
/// <summary>
810820
/// Creates a new private static constructor for a type that is executed when its declaring type is loaded by the CLR.
811821
/// </summary>
@@ -1036,6 +1046,10 @@ protected virtual IList<GenericParameter> GetGenericParameters() =>
10361046
/// </remarks>
10371047
protected virtual UnmanagedExportInfo? GetExportInfo() => null;
10381048

1049+
protected virtual MethodDebugInformation? GetMethodDebugInformation() => null;
1050+
1051+
protected virtual IList<LocalScope> GetLocalScopes() => new OwnedCollection<MethodDefinition, LocalScope>(this);
1052+
10391053
/// <summary>
10401054
/// Asserts whether the method's metadata is consistent with its signature.
10411055
/// </summary>

src/AsmResolver.DotNet/ModuleDefinition.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,9 @@ public IManagedEntryPoint? ManagedEntryPoint
809809
set => _managedEntryPoint.SetValue(value);
810810
}
811811

812+
[LazyProperty]
813+
public partial PortablePdb? PortablePdb { get; set; }
814+
812815
/// <summary>
813816
/// Gets the default importer instance for this module.
814817
/// </summary>
@@ -1248,6 +1251,8 @@ protected virtual IList<CustomAttribute> GetCustomAttributes() =>
12481251
/// </remarks>
12491252
protected virtual ReferenceImporter GetDefaultImporter() => new(this);
12501253

1254+
protected virtual PortablePdb? GetPortablePdb() => null;
1255+
12511256
/// <summary>
12521257
/// Detects the runtime that this module targets.
12531258
/// </summary>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using AsmResolver.Collections;
3+
using AsmResolver.PE.DotNet.Metadata.Tables;
4+
5+
namespace AsmResolver.DotNet.PortablePdbs.CustomRecords
6+
{
7+
public partial class CustomDebugInformation : IMetadataMember, IOwnedCollectionElement<IHasCustomDebugInformation>
8+
{
9+
public MetadataToken MetadataToken
10+
{
11+
get;
12+
}
13+
14+
[LazyProperty]
15+
public partial IHasCustomDebugInformation? Owner
16+
{
17+
get;
18+
set;
19+
}
20+
21+
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using AsmResolver.DotNet.Signatures;
3+
4+
namespace AsmResolver.DotNet.PortablePdbs.CustomRecords
5+
{
6+
public abstract class CustomDebugRecord : ExtendableBlobSignature
7+
{
8+
public abstract Guid Kind
9+
{
10+
get;
11+
}
12+
}
13+
}

src/AsmResolver.DotNet/PortablePdbs/Document.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@
66
namespace AsmResolver.DotNet.PortablePdbs
77
{
88
[DebuggerDisplay("{Name}")]
9-
public class Document : IMetadataMember, IOwnedCollectionElement<PortablePdb>
9+
public partial class Document : IMetadataMember, IOwnedCollectionElement<PortablePdb>
1010
{
11-
private readonly LazyVariable<Document, Utf8String?> _name;
12-
private readonly LazyVariable<Document, Guid> _hashAlgorithm;
13-
private readonly LazyVariable<Document, byte[]?> _hash;
14-
private readonly LazyVariable<Document, Guid> _language;
15-
1611
public Document() : this(new MetadataToken(TableIndex.Document, 0)) { }
1712

1813
public Document(MetadataToken token)
1914
{
2015
MetadataToken = token;
21-
22-
_name = new LazyVariable<Document, Utf8String?>(doc => doc.GetName());
23-
_hashAlgorithm = new LazyVariable<Document, Guid>(doc => doc.GetHashAlgorithm());
24-
_hash = new LazyVariable<Document, byte[]?>(doc => doc.GetHash());
25-
_language = new LazyVariable<Document, Guid>(doc => doc.GetLanguage());
2616
}
2717

2818
public MetadataToken MetadataToken { get; }
@@ -33,28 +23,32 @@ public PortablePdb? Owner
3323
set;
3424
}
3525

36-
public Utf8String? Name
26+
[LazyProperty]
27+
public partial Utf8String? Name
3728
{
38-
get => _name.GetValue(this);
39-
set => _name.SetValue(value);
29+
get;
30+
set;
4031
}
4132

42-
public Guid HashAlgorithm
33+
[LazyProperty]
34+
public partial Guid HashAlgorithm
4335
{
44-
get => _hashAlgorithm.GetValue(this);
45-
set => _hashAlgorithm.SetValue(value);
36+
get;
37+
set;
4638
}
4739

48-
public byte[]? Hash
40+
[LazyProperty]
41+
public partial byte[]? Hash
4942
{
50-
get => _hash.GetValue(this);
51-
set => _hash.SetValue(value);
43+
get;
44+
set;
5245
}
5346

54-
public Guid Language
47+
[LazyProperty]
48+
public partial Guid Language
5549
{
56-
get => _language.GetValue(this);
57-
set => _language.SetValue(value);
50+
get;
51+
set;
5852
}
5953

6054
protected virtual Utf8String? GetName() => null;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
using AsmResolver.DotNet.PortablePdbs.CustomRecords;
3+
4+
namespace AsmResolver.DotNet.PortablePdbs
5+
{
6+
public interface IHasCustomDebugInformation : IMetadataMember
7+
{
8+
IList<CustomDebugInformation> CustomDebugInformations
9+
{
10+
get;
11+
}
12+
}
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using AsmResolver.Collections;
2+
using AsmResolver.PE.DotNet.Metadata.Tables;
3+
4+
namespace AsmResolver.DotNet.PortablePdbs;
5+
6+
public partial class ImportScope : IMetadataMember, IOwnedCollectionElement<ImportScope>
7+
{
8+
public MetadataToken MetadataToken
9+
{
10+
get;
11+
}
12+
13+
[LazyProperty]
14+
public partial ImportScope? Owner
15+
{
16+
get;
17+
set;
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace AsmResolver.DotNet.PortablePdbs
4+
{
5+
public static class KnownDocumentLanguage
6+
{
7+
public static Guid CSharp { get; } = new("3f5162f8-07c6-11d3-9053-00c04fa302a1");
8+
public static Guid VisualBasic { get; } = new("3a12d0b8-c26c-11d0-b442-00a0244a1dd2");
9+
public static Guid FSharp { get; } = new("ab4f38c9-b6e6-43ba-be3b-58080b2ccce3");
10+
}
11+
}

0 commit comments

Comments
 (0)