csnemes / tracer

Tracing rewriter using Fody
Apache License 2.0
93 stars 26 forks source link

Attribute targets used on Async methods adds the local variable to the wrong method #100

Closed ndrwrbgs closed 2 years ago

ndrwrbgs commented 4 years ago

e.g.

[TraceOn(IncludeReturnValue = true)]
public async Task<List<SecretType>> SuperSecretMethod(...) {}

Resulted in, for me,


    .custom instance void [Tracer.OpenTracing]TracerAttributes.TraceOn::.ctor(valuetype [Tracer.OpenTracing]TracerAttributes.TraceTarget)
      = (
        01 00 03 00 00 00 01 00 54 02 12 49 6e 63 6c 75 // ........T..Inclu
        64 65 52 65 74 75 72 6e 56 61 6c 75 65 01       // deReturnValue.
      )
      // int32(3) // 0x00000003
      // property bool 'IncludeReturnValue' = bool(true)
    .maxstack 3
    .locals init (
      [0] class HighlySecretType/'<SuperSecretMethod>d__89' V_0,
      [1] valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<int64> V_1,
      // Others
      [5] class [mscorlib]System.Tuple`2<string, string>[] V_5

and


    .method private final hidebysig virtual newslot instance void
      MoveNext() cil managed
    {
      .override method instance void [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext()
      .maxstack 13
      .locals init (
        // Others
        [5] valuetype [mscorlib]System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1/ConfiguredTaskAwaiter<class [mscorlib]System.Collections.Generic.List`1<class [SecretAssembly]SecretType>> V_5,
      // Others
        [37] class [mscorlib]System.Tuple`2<string, string>[] $configParameters,
        [38] object $returnValue,
        [39] string[] $paramNames,
        [40] object[] $paramValues,
        [41] class [mscorlib]System.Exception $exception
      )

      IL_0000: ldarg.0      // this
      IL_0001: ldfld        int32 HighlySecretType/'<SuperSecretMethod>d__89'::'<>1__state'
      IL_0006: ldc.i4.m1
      IL_0007: bne.un.s     IL_0041
      IL_0009: ldc.i4.1
      IL_000a: newarr       class [mscorlib]System.Tuple`2<string, string>
      IL_000f: stloc.s      V_5
      IL_0011: ldloc.s      V_5

I believe this meant to use V_37, or otherwise meant to add another local to the MoveNext but instead added it to the async-entry-method and then tried to reference the same location in MoveNext which had been given to another variable.

csnemes commented 4 years ago

fixed

ndrwrbgs commented 2 years ago

Thanks!