Skip to content

Commit

Permalink
Fix mixed module ReadSymbols() (#851)
Browse files Browse the repository at this point in the history
Fix reading some pdb generated by the C++ compiler for mixed mode assemblies.

Co-authored-by: Marco Rossignoli <[email protected]>
  • Loading branch information
MarcoRossignoli and Marco Rossignoli authored Jun 15, 2022
1 parent f7b64f7 commit 2c68927
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ static Dictionary<string, int> LoadNameIndex(BitAccess bits, out int age, out Gu

BitSet present = new BitSet(bits);
BitSet deleted = new BitSet(bits);
if (!deleted.IsEmpty) {
throw new PdbDebugException("Unsupported PDB deleted bitset is not empty.");
}
//if (!deleted.IsEmpty) {
// throw new PdbDebugException("Unsupported PDB deleted bitset is not empty.");
//}

int j = 0;
for (int i = 0; i < max; i++) {
Expand Down
23 changes: 16 additions & 7 deletions symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.IO;
using System.Linq;

using Mono.Cecil.Cil;
using Mono.Cecil.Pdb;

Expand Down Expand Up @@ -56,7 +55,7 @@ .locals init (System.Int32 i, System.Int32 CS$1$0000, System.Boolean CS$4$0001)
IL_0020: ldloc.1
IL_0021: ret
", main);
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}

[Test]
Expand All @@ -82,7 +81,7 @@ public void DebuggerHiddenVariable ()
Assert.AreEqual ("i", variables [0].Name);
Assert.IsFalse (variables [0].IsDebuggerHidden);
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}

[Test]
Expand All @@ -103,7 +102,7 @@ public void Document ()
Assert.AreEqual (new byte [] { 228, 176, 152, 54, 82, 238, 238, 68, 237, 156, 5, 142, 118, 160, 118, 245 }, document.Hash);
Assert.AreEqual (DocumentLanguage.CSharp, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}

[Test]
Expand All @@ -124,7 +123,7 @@ public void BasicDocument ()
Assert.AreEqual (new byte [] { 184, 188, 100, 23, 27, 123, 187, 201, 175, 206, 110, 198, 242, 139, 154, 119 }, document.Hash);
Assert.AreEqual (DocumentLanguage.Basic, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}

[Test]
Expand Down Expand Up @@ -248,7 +247,7 @@ public void LocalConstants ()
constant = scope.Constants [1];
Assert.AreEqual ("c", constant.Name);
Assert.AreEqual ((decimal) 74, constant.Value);
Assert.AreEqual ((decimal)74, constant.Value);
Assert.AreEqual (MetadataType.ValueType, constant.ConstantType.MetadataType);
method = type.GetMethod ("Foo");
Expand Down Expand Up @@ -448,7 +447,7 @@ public void CreateMethodFromScratch ()

method.DebugInformation.SequencePoints.Add (sequence_point);

method.DebugInformation.Scope = new ScopeDebugInformation (body.Instructions [0], null) {
method.DebugInformation.Scope = new ScopeDebugInformation (body.Instructions [0], null) {
Variables = { new VariableDebugInformation (temp, "temp") }
};

Expand Down Expand Up @@ -476,5 +475,15 @@ public void TypeNameExceedingMaxPdbPath ()
Assert.IsTrue (module.HasSymbols);
}, symbolReaderProvider: typeof (NativePdbReaderProvider), symbolWriterProvider: typeof (NativePdbWriterProvider));
}

[Test]
public void ReadPdbMixedNativeCLIModule ()
{
// MixedNativeCLI.exe was copy/pasted from from https://docs.microsoft.com/en-us/cpp/preprocessor/managed-unmanaged?view=msvc-170#example
TestModule ("MixedNativeCLI.exe", module => {
module.ReadSymbols ();
}, readOnly: true);
}

}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ImageRuntimeVersion: v4.0.30319
Assembly MixedNativeCLI, Version=0.0.*, Culture=Invariant Language (Invariant Country):
hash=SHA1, flags=PublicKey
Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Binary file not shown.

0 comments on commit 2c68927

Please sign in to comment.