Skip to content

Commit

Permalink
Fix ReadSymbols in a Module that is already created (#686)
Browse files Browse the repository at this point in the history
* When I try to use ReadSymbols in a Module that is already created, for example:

var symbolReader = portablePdbReaderProvider.GetSymbolReader(asm.image, stream);
asm.image.ReadSymbols(symbolReader);

method.debug_info has a list, but it's empty, so it wasn't entering in the if, but it should, maybe we should change de if to method.debug_info == null || method.debug_info.count = 0.

* Adding test.

* Fix styling.

* Typo

Co-authored-by: Jb Evain <[email protected]>
  • Loading branch information
thaystg and jbevain authored Sep 15, 2020
1 parent 9276c6d commit 191f9fc
Show file tree
Hide file tree
Showing 4 changed files with 23 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 @@ -419,7 +419,7 @@ void ReadMethodsSymbols (TypeDefinition type, ISymbolReader symbol_reader)
for (int i = 0; i < methods.Count; i++) {
var method = methods [i];

if (method.HasBody && method.token.RID != 0 && method.debug_info == null)
if (method.HasBody && method.token.RID != 0 && (method.debug_info == null || !method.debug_info.HasSequencePoints))
method.debug_info = symbol_reader.Read (method);
}
}
Expand Down
22 changes: 22 additions & 0 deletions Test/Mono.Cecil.Tests/PortablePdbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,5 +748,27 @@ public void DoubleWriteAndReadAgainModuleWithDeterministicMvid ()
Assert.AreNotEqual (mvid1_in, mvid2_in);
Assert.AreNotEqual (mvid1_out, mvid2_out);
}

[Test]
public void LoadPdbOnDemand ()
{
var assembly = File.ReadAllBytes (GetAssemblyResourcePath ("Microsoft.AspNetCore.Components.dll"));
var pdb = File.ReadAllBytes (GetAssemblyResourcePath ("Microsoft.AspNetCore.Components.pdb"));

var module = ModuleDefinition.ReadModule (new MemoryStream (assembly), new ReaderParameters (ReadingMode.Immediate));

var type = module.GetType ("Microsoft.AspNetCore.Components.Rendering.ComponentState");
var main = type.GetMethod ("RenderIntoBatch");
var debug_info = main.DebugInformation;

var pdbReaderProvider = new PdbReaderProvider ();
var symbolReader = pdbReaderProvider.GetSymbolReader (module, new MemoryStream (pdb));
module.ReadSymbols (symbolReader);
type = module.GetType ("Microsoft.AspNetCore.Components.Rendering.ComponentState");
main = type.GetMethod ("RenderIntoBatch");
debug_info = main.DebugInformation;
Assert.AreEqual (9, debug_info.SequencePoints.Count);
}

}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 191f9fc

Please sign in to comment.