diff options
author | Jb Evain <jb@evain.net> | 2021-06-24 07:54:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-24 07:54:15 +0300 |
commit | fbb3c444bba3086f26c03bca8928307dd4ac6883 (patch) | |
tree | 9866e39d8b1df3c2d7a72eeb97fbbf33a1d15182 | |
parent | 0dd5556af12ab8fd053f9072a1f8e80d7a9608a7 (diff) |
Add support for reading symbols of modules with multiple codeview debug entries (#770)
-rw-r--r-- | Mono.Cecil.Cil/PortablePdb.cs | 24 | ||||
-rw-r--r-- | Test/Mono.Cecil.Tests/SymbolTests.cs | 9 | ||||
-rw-r--r-- | Test/Resources/assemblies/System.Private.Xml.dll | bin | 0 -> 8422792 bytes | |||
-rw-r--r-- | Test/Resources/assemblies/System.Private.Xml.pdb | bin | 0 -> 1284024 bytes | |||
-rw-r--r-- | symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs | 43 |
5 files changed, 44 insertions, 32 deletions
diff --git a/Mono.Cecil.Cil/PortablePdb.cs b/Mono.Cecil.Cil/PortablePdb.cs index 744c274..aff6b29 100644 --- a/Mono.Cecil.Cil/PortablePdb.cs +++ b/Mono.Cecil.Cil/PortablePdb.cs @@ -70,8 +70,20 @@ namespace Mono.Cecil.Cil { if (image == module.Image) return true; - var entry = header.GetCodeViewEntry (); - if (entry == null) + foreach (var entry in header.Entries) { + if (!IsMatchingEntry (image.PdbHeap, entry)) + continue; + + ReadModule (); + return true; + } + + return false; + } + + static bool IsMatchingEntry (PdbHeap heap, ImageDebugHeaderEntry entry) + { + if (entry.Directory.Type != ImageDebugType.CodeView) return false; var data = entry.Data; @@ -88,15 +100,11 @@ namespace Mono.Cecil.Cil { var module_guid = new Guid (buffer); - Buffer.BlockCopy (image.PdbHeap.Id, 0, buffer, 0, 16); + Buffer.BlockCopy (heap.Id, 0, buffer, 0, 16); var pdb_guid = new Guid (buffer); - if (module_guid != pdb_guid) - return false; - - ReadModule (); - return true; + return module_guid == pdb_guid; } static int ReadInt32 (byte [] bytes, int start) diff --git a/Test/Mono.Cecil.Tests/SymbolTests.cs b/Test/Mono.Cecil.Tests/SymbolTests.cs index 941f4a1..691581e 100644 --- a/Test/Mono.Cecil.Tests/SymbolTests.cs +++ b/Test/Mono.Cecil.Tests/SymbolTests.cs @@ -128,5 +128,14 @@ namespace Mono.Cecil.Tests { } } } + + [Test] + public void MultipleCodeViewEntries () + { + using (var module = GetResourceModule ("System.Private.Xml.dll", new ReaderParameters { ReadSymbols = true })) { + Assert.IsTrue (module.HasSymbols); + Assert.IsNotNull (module.SymbolReader); + } + } } } diff --git a/Test/Resources/assemblies/System.Private.Xml.dll b/Test/Resources/assemblies/System.Private.Xml.dll Binary files differnew file mode 100644 index 0000000..82bc088 --- /dev/null +++ b/Test/Resources/assemblies/System.Private.Xml.dll diff --git a/Test/Resources/assemblies/System.Private.Xml.pdb b/Test/Resources/assemblies/System.Private.Xml.pdb Binary files differnew file mode 100644 index 0000000..9790d8d --- /dev/null +++ b/Test/Resources/assemblies/System.Private.Xml.pdb diff --git a/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs b/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs index 2d6b1ba..91f1f3e 100644 --- a/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs +++ b/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs @@ -22,7 +22,6 @@ namespace Mono.Cecil.Pdb { public class NativePdbReader : ISymbolReader { - int age; Guid guid; readonly Disposable<Stream> pdb_file; @@ -52,13 +51,26 @@ namespace Mono.Cecil.Pdb { if (!header.HasEntries) return false; - var entry = header.GetCodeViewEntry (); - if (entry == null) - return false; + using (pdb_file) { + var info = PdbFile.LoadFunctions (pdb_file.value); + + foreach (var entry in header.Entries) { + if (!IsMatchingEntry (info, entry)) + continue; + + foreach (var function in info.Functions) + functions.Add (function.token, function); - var directory = entry.Directory; + return true; + } + } + + return false; + } - if (directory.Type != ImageDebugType.CodeView) + static bool IsMatchingEntry (PdbInfo info, ImageDebugHeaderEntry entry) + { + if (entry.Directory.Type != ImageDebugType.CodeView) return false; var data = entry.Data; @@ -73,10 +85,7 @@ namespace Mono.Cecil.Pdb { var guid_bytes = new byte [16]; Buffer.BlockCopy (data, 4, guid_bytes, 0, 16); - this.guid = new Guid (guid_bytes); - this.age = ReadInt32 (data, 20); - - return PopulateFunctions (); + return info.Guid == new Guid (guid_bytes); } static int ReadInt32 (byte [] bytes, int start) @@ -87,20 +96,6 @@ namespace Mono.Cecil.Pdb { | (bytes [start + 3] << 24)); } - bool PopulateFunctions () - { - using (pdb_file) { - var info = PdbFile.LoadFunctions (pdb_file.value); - - if (this.guid != info.Guid) - return false; - - foreach (PdbFunction function in info.Functions) - functions.Add (function.token, function); - } - - return true; - } public MethodDebugInformation Read (MethodDefinition method) { |