Skip to content

Commit

Permalink
Fix reading GenericInst constants in portable pdbs (#729)
Browse files Browse the repository at this point in the history
* Fix reading GenericInst constants in portable pdbs

* Add test
  • Loading branch information
jbevain authored Mar 13, 2021
1 parent 3c4ea3f commit 553506a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Mono.Cecil/AssemblyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,7 @@ ConstantDebugInformation ReadLocalConstant (uint rid)
value = new decimal (signature.ReadInt32 (), signature.ReadInt32 (), signature.ReadInt32 (), (b & 0x80) != 0, (byte) (b & 0x7f));
} else if (type.IsTypeOf ("System", "DateTime")) {
value = new DateTime (signature.ReadInt64());
} else if (type.etype == ElementType.Object || type.etype == ElementType.None || type.etype == ElementType.Class || type.etype == ElementType.Array) {
} else if (type.etype == ElementType.Object || type.etype == ElementType.None || type.etype == ElementType.Class || type.etype == ElementType.Array || type.etype == ElementType.GenericInst) {
value = null;
} else
value = signature.ReadConstantSignature (type.etype);
Expand Down
18 changes: 18 additions & 0 deletions Test/Mono.Cecil.Tests/PortablePdbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,24 @@ public void InvalidConstantRecord ()
}
}

[Test]
public void GenericInstConstantRecord ()
{
using (var module = GetResourceModule ("ReproConstGenericInst.dll", new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) {
var type = module.GetType ("ReproConstGenericInst.Program");
var method = type.GetMethod ("Main");
var symbol = method.DebugInformation;

Assert.IsNotNull (symbol);
Assert.AreEqual (1, symbol.Scope.Constants.Count);

var list = symbol.Scope.Constants [0];
Assert.AreEqual ("list", list.Name);

Assert.AreEqual ("System.Collections.Generic.List`1<System.String>", list.ConstantType.FullName);
}
}

[Test]
public void SourceLink ()
{
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 553506a

Please sign in to comment.