Skip to content

Commit 191f9fc

Browse files
thaystgjbevain
andauthored
Fix ReadSymbols in a Module that is already created (#686)
* 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]>
1 parent 9276c6d commit 191f9fc

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

Mono.Cecil/AssemblyReader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void ReadMethodsSymbols (TypeDefinition type, ISymbolReader symbol_reader)
419419
for (int i = 0; i < methods.Count; i++) {
420420
var method = methods [i];
421421

422-
if (method.HasBody && method.token.RID != 0 && method.debug_info == null)
422+
if (method.HasBody && method.token.RID != 0 && (method.debug_info == null || !method.debug_info.HasSequencePoints))
423423
method.debug_info = symbol_reader.Read (method);
424424
}
425425
}

Test/Mono.Cecil.Tests/PortablePdbTests.cs

+22
Original file line numberDiff line numberDiff line change
@@ -748,5 +748,27 @@ public void DoubleWriteAndReadAgainModuleWithDeterministicMvid ()
748748
Assert.AreNotEqual (mvid1_in, mvid2_in);
749749
Assert.AreNotEqual (mvid1_out, mvid2_out);
750750
}
751+
752+
[Test]
753+
public void LoadPdbOnDemand ()
754+
{
755+
var assembly = File.ReadAllBytes (GetAssemblyResourcePath ("Microsoft.AspNetCore.Components.dll"));
756+
var pdb = File.ReadAllBytes (GetAssemblyResourcePath ("Microsoft.AspNetCore.Components.pdb"));
757+
758+
var module = ModuleDefinition.ReadModule (new MemoryStream (assembly), new ReaderParameters (ReadingMode.Immediate));
759+
760+
var type = module.GetType ("Microsoft.AspNetCore.Components.Rendering.ComponentState");
761+
var main = type.GetMethod ("RenderIntoBatch");
762+
var debug_info = main.DebugInformation;
763+
764+
var pdbReaderProvider = new PdbReaderProvider ();
765+
var symbolReader = pdbReaderProvider.GetSymbolReader (module, new MemoryStream (pdb));
766+
module.ReadSymbols (symbolReader);
767+
type = module.GetType ("Microsoft.AspNetCore.Components.Rendering.ComponentState");
768+
main = type.GetMethod ("RenderIntoBatch");
769+
debug_info = main.DebugInformation;
770+
Assert.AreEqual (9, debug_info.SequencePoints.Count);
771+
}
772+
751773
}
752774
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)