diff options
author | Steve Gilham <SteveGilham@users.noreply.github.com> | 2021-08-13 02:27:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-13 02:27:19 +0300 |
commit | a0a6ce41c0e5292413ca33dcb76d514e608d21e5 (patch) | |
tree | 74daca4cf9f8a4164f628a9eb58f6d8bf4e3659e /Test | |
parent | 2f1077d7bb3527c3d821cb726a6d762abaea101a (diff) |
Addressing issue #781 (#782)
* Pose the problem
* Quick and v dirty fix
* A better and more targeted fix (to fix the previous fix)
Diffstat (limited to 'Test')
-rw-r--r-- | Test/Mono.Cecil.Tests/ILProcessorTests.cs | 39 |
1 files changed, 39 insertions, 0 deletions
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 @@ -64,6 +64,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 () { var method = CreateTestMethod (OpCodes.Ldloc_0, OpCodes.Ldloc_2, OpCodes.Ldloc_3); |