From a0a6ce41c0e5292413ca33dcb76d514e608d21e5 Mon Sep 17 00:00:00 2001 From: Steve Gilham Date: Fri, 13 Aug 2021 00:27:19 +0100 Subject: Addressing issue #781 (#782) * Pose the problem * Quick and v dirty fix * A better and more targeted fix (to fix the previous fix) --- Test/Mono.Cecil.Tests/ILProcessorTests.cs | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Test/Mono.Cecil.Tests') diff --git a/Test/Mono.Cecil.Tests/ILProcessorTests.cs b/Test/Mono.Cecil.Tests/ILProcessorTests.cs index 4eecfe3..c585403 100644 --- a/Test/Mono.Cecil.Tests/ILProcessorTests.cs +++ b/Test/Mono.Cecil.Tests/ILProcessorTests.cs @@ -63,6 +63,45 @@ namespace Mono.Cecil.Tests { } } + [Test] + public void InsertBeforeIssue697bis () + { + var parameters = new ReaderParameters { SymbolReaderProvider = new MdbReaderProvider () }; + using (var module = GetResourceModule ("Issue697.dll", parameters)) { + var pathGetterDef = module.GetTypes () + .SelectMany (t => t.Methods) + .First (m => m.Name.Equals ("get_Defer")); + + var body = pathGetterDef.Body; + var worker = body.GetILProcessor (); + var initialBody = body.Instructions.ToList (); + Console.WriteLine (initialBody.Sum (i => i.GetSize ())); + + var head = initialBody.First (); + var opcode = worker.Create (OpCodes.Ldc_I4_1); + worker.InsertBefore (head, opcode); + + Assert.That (pathGetterDef.DebugInformation.Scope.Start.IsEndOfMethod, Is.False); + foreach (var subscope in pathGetterDef.DebugInformation.Scope.Scopes) + Assert.That (subscope.Start.IsEndOfMethod, Is.False); + + // big test -- we can write w/o crashing + var unique = Guid.NewGuid ().ToString (); + var output = Path.GetTempFileName (); + var outputdll = output + ".dll"; + + var writer = new WriterParameters () { + SymbolWriterProvider = new MdbWriterProvider (), + WriteSymbols = true + }; + using (var sink = File.Open (outputdll, FileMode.Create, FileAccess.ReadWrite)) { + module.Write (sink, writer); + } + + Assert.Pass (); + } + } + [Test] public void InsertAfter () { -- cgit v1.2.3