Sequence points can no longer be cleared when using deferred reading mode #694

Closed
opened 2020-10-02 13:34:19 -05:00 by ltrzesniewski · 4 comments
ltrzesniewski commented 2020-10-02 13:34:19 -05:00 (Migrated from github.com)

This is a regression introduced by #686. When using the deferred reading mode, if you clear the sequence points of a method, those will be read again from the source file on writing.

Here's a repro:

using System;
using System.Linq;
using Mono.Cecil;

namespace ConsoleApp
{
    internal static class Program
    {
        public static void Main()
        {
            using var assembly = AssemblyDefinition.ReadAssembly(typeof(Program).Assembly.Location, new ReaderParameters { ReadSymbols = true });
            var method = assembly.MainModule.GetType(typeof(Program).FullName).Methods.Single(m => m.Name == nameof(SomeMethod));

            Console.WriteLine($"Sequence points A: {method.DebugInformation.SequencePoints.Count}");

            method.DebugInformation.SequencePoints.Clear();

            Console.WriteLine($"Sequence points B: {method.DebugInformation.SequencePoints.Count}");

            assembly.Write("Processed.dll", new WriterParameters { WriteSymbols = true });

            Console.WriteLine($"Sequence points C: {method.DebugInformation.SequencePoints.Count}");
        }

        private static void SomeMethod()
        {
            Console.WriteLine("Hello!");
        }
    }
}

This prints the following on v0.11.3:

Sequence points A: 3
Sequence points B: 0
Sequence points C: 3

It prints the expected result on v0.11.2, or if you set ReadingMode = ReadingMode.Immediate in ReaderParameters:

Sequence points A: 3
Sequence points B: 0
Sequence points C: 0

I'm not entirely sure what the proper fix would be here. Maybe an additional flag is needed to tell if debug information has been read, so the status does not depend on sequence points.

/cc @thaystg FYI

This is a regression introduced by #686. When using the deferred reading mode, if you clear the sequence points of a method, those will be read again from the source file on writing. Here's a repro: ```C# using System; using System.Linq; using Mono.Cecil; namespace ConsoleApp { internal static class Program { public static void Main() { using var assembly = AssemblyDefinition.ReadAssembly(typeof(Program).Assembly.Location, new ReaderParameters { ReadSymbols = true }); var method = assembly.MainModule.GetType(typeof(Program).FullName).Methods.Single(m => m.Name == nameof(SomeMethod)); Console.WriteLine($"Sequence points A: {method.DebugInformation.SequencePoints.Count}"); method.DebugInformation.SequencePoints.Clear(); Console.WriteLine($"Sequence points B: {method.DebugInformation.SequencePoints.Count}"); assembly.Write("Processed.dll", new WriterParameters { WriteSymbols = true }); Console.WriteLine($"Sequence points C: {method.DebugInformation.SequencePoints.Count}"); } private static void SomeMethod() { Console.WriteLine("Hello!"); } } } ``` This prints the following on v0.11.3: ``` Sequence points A: 3 Sequence points B: 0 Sequence points C: 3 ``` It prints the expected result on v0.11.2, or if you set `ReadingMode = ReadingMode.Immediate` in `ReaderParameters`: ``` Sequence points A: 3 Sequence points B: 0 Sequence points C: 0 ``` I'm not entirely sure what the proper fix would be here. Maybe an additional flag is needed to tell if debug information has been read, so the status does not depend on sequence points. /cc @thaystg FYI
jbevain commented 2020-10-02 14:13:17 -05:00 (Migrated from github.com)

@ltrzesniewski good catch. Could you submit a failing test? Thank you!

@ltrzesniewski good catch. Could you submit a failing test? Thank you!
thaystg commented 2020-10-02 15:37:23 -05:00 (Migrated from github.com)

If you need to revert it's okay for me I did a workaround on wasm debugger side.

If you need to revert it's okay for me I did a workaround on wasm debugger side.
jbevain commented 2020-10-05 12:17:36 -05:00 (Migrated from github.com)

Cool, let's do that then.

Cool, let's do that then.
jbevain commented 2020-10-15 12:02:29 -05:00 (Migrated from github.com)

Fixed in master. Thanks!

Fixed in master. Thanks!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#694
No description provided.