ashmind / SharpLab

.NET language playground
https://sharplab.io
BSD 2-Clause "Simplified" License
2.72k stars 199 forks source link

[Proposal] Show method name in addition to address for calls and jumps in JIT disasm mode #890

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

On this we currently get

A.Do1(Single)
    L0000: vzeroupper
    L0003: vaddss xmm0, xmm0, xmm0
    L0007: ret

A.Heavy(Single)
    L0000: sub rsp, 0x28
    L0004: vzeroupper
    L0007: call 0x00007ffcbc210420
    L000c: vmovss [rsp+0x24], xmm0
    L0012: call 0x00007ffcbc210420
    L0017: vaddss xmm0, xmm0, [rsp+0x24]
    L001d: add rsp, 0x28
    L0021: ret

Instead it's desired to get

A.Do1(Single)
    L0000: vzeroupper
    L0003: vaddss xmm0, xmm0, xmm0
    L0007: ret

A.Heavy(Single)
    L0000: sub rsp, 0x28
    L0004: vzeroupper
-   L0007: call 0x00007ffcbc210420
+   L0007: call A.Do1(Single) (0x00007ffcbc210420)
    L000c: vmovss [rsp+0x24], xmm0
-   L0007: call 0x00007ffcbc210420
+   L0007: call A.Do1(Single) (0x00007ffcbc210420)
    L0017: vaddss xmm0, xmm0, [rsp+0x24]
    L001d: add rsp, 0x28
    L0021: ret

If you approve this, I can try to implement it

ashmind commented 2 years ago

Thanks for the suggestion! Method name resolution is intentionally disabled for x64 due to stability issues: https://github.com/ashmind/SharpLab/issues/814#issuecomment-934094242 I would be very happy to reenable it any time once that's resolved.

Attaching ClrMD to the current process is not a supported scenario, which might be one reason for the crashes, but then it works mostly well in other cases (and not on x64), so likely there is a more specific reason I still need to diagnose.

Here is the error:

Your app, sl-a-core-x64, crashed because of System.ExecutionEngineException and aborted the requests it was processing when the overflow occurred. As a result, your app’s users may have experienced HTTP 502 errors. This call stack caused the exception:

InlinedCallFrame
InlinedCallFrame
ILStubClass.IL_STUB_PInvoke
Microsoft.Diagnostics.Runtime.DacInterface.MetadataImport.GetMethodAttributes
Microsoft.Diagnostics.Runtime.Implementation.ClrmdMethod..ctor
Microsoft.Diagnostics.Runtime.Builders.RuntimeBuilder.Microsoft.Diagnostics.Runtime.Implementation.ITypeFactory.CreateMethodsForType
Microsoft.Diagnostics.Runtime.Implementation.ClrmdType.get_Methods
Microsoft.Diagnostics.Runtime.Builders.RuntimeBuilder.CreateMethodFromHandle
Microsoft.Diagnostics.Runtime.Implementation.ClrmdRuntime.GetMethodByHandle
Microsoft.Diagnostics.Runtime.Implementation.ClrmdRuntime.GetMethodByInstructionPointer
SharpLab.Server.Decompilation.Internal.JitAsmSymbolResolver.TryGetSymbol
SharpLab.Server.Decompilation.Internal.JitAsmSymbolResolver.Iced.Intel.ISymbolResolver.TryGetSymbol
Iced.Intel.IntelFormatter.FormatOperand
Iced.Intel.IntelFormatter.FormatOperands
Iced.Intel.IntelFormatter.Format
SharpLab.Server.Decompilation.JitAsmDecompiler.DisassembleAndWriteSimpleMethod
SharpLab.Server.Decompilation.JitAsmDecompiler.DisassembleAndWriteMethod
SharpLab.Server.Decompilation.JitAsmDecompiler.DisassembleAndWriteMembers
SharpLab.Server.Decompilation.JitAsmDecompiler.Decompile
SharpLab.Server.MirrorSharp.SlowUpdate.WriteResult
MirrorSharp.Internal.Handlers.SlowUpdateHandler+d__5.MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MirrorSharp.Internal.Handlers.SlowUpdateHandler+d__5 MirrorSharp.Common]]
System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[MirrorSharp.Internal.Handlers.SlowUpdateHandler+d__5 MirrorSharp.Common]]
MirrorSharp.Internal.Handlers.SlowUpdateHandler.SendSlowUpdateAsync
MirrorSharp.Internal.Handlers.SlowUpdateHandler+d__4.MoveNext
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult System.Private.CoreLib][MirrorSharp.Internal.Handlers.SlowUpdateHandler+d__4 MirrorSharp.Common]].ExecutionContextCallback
System.Threading.ExecutionContext.RunInternal
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult System.Private.CoreLib][MirrorSharp.Internal.Handlers.SlowUpdateHandler+d__4 MirrorSharp.Common]].MoveNext
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult System.Private.CoreLib][MirrorSharp.Internal.Handlers.SlowUpdateHandler+d__4 MirrorSharp.Common]].MoveNext
System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction
System.Threading.Tasks.Task.RunContinuations
System.Threading.Tasks.Task.FinishContinuations
System.Threading.Tasks.Task`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].TrySetResult
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].SetExistingTaskResult
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].SetResult
MirrorSharp.Internal.Roslyn.RoslynSession+d__15.MoveNext
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable][MirrorSharp.Internal.Roslyn.RoslynSession+d__15 MirrorSharp.Common]].ExecutionContextCallback
System.Threading.ExecutionContext.RunInternal
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable][MirrorSharp.Internal.Roslyn.RoslynSession+d__15 MirrorSharp.Common]].MoveNext
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable][MirrorSharp.Internal.Roslyn.RoslynSession+d__15 MirrorSharp.Common]].MoveNext
System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction
System.Threading.Tasks.Task.RunContinuations
System.Threading.Tasks.Task.FinishContinuations
System.Threading.Tasks.Task`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].TrySetResult
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].SetExistingTaskResult
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].SetResult
Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers+d__42.MoveNext
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable][Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers+d__42 Microsoft.CodeAnalysis]].ExecutionContextCallback
System.Threading.ExecutionContext.RunInternal
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable][Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers+d__42 Microsoft.CodeAnalysis]].MoveNext
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable][Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers+d__42 Microsoft.CodeAnalysis]].MoveNext
System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction
System.Threading.Tasks.Task.RunContinuations
System.Threading.Tasks.Task.FinishContinuations
System.Threading.Tasks.Task`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].TrySetResult
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].SetExistingTaskResult
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable]].SetResult
Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers+d__50.MoveNext
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Collections.Immutable.ImmutableArray`1[[System.__Canon System.Private.CoreLib]] System.Collections.Immutable][Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers+d__50 Microsoft.CodeAnalysis]].ExecutionContextCallback
System.Threading.ExecutionContext.RunInternal
WhiteBlackGoose commented 2 years ago

Interesting. But is this necessary for the name resolution? I've asked Jakob from the runtime team, who said that there's a workaround to use runtime handle by the ID of a method, I used it like this from here. My library is based on ETW, so it reads MethodID here and then finds the MethodBase.

What do you think of this way? I'm not posing it as a super-stable documented one, because again, according to folks from the runtime, it's an implementation detail. But it at least works XD

UPD: proof that it actually works: image

ashmind commented 2 years ago

@WhiteBlackGoose Thanks, I can give it a try (when I have time) -- just to note that some of your sample links seems to have broken since.

WhiteBlackGoose commented 2 years ago

Thanks, here's a permalink to that file, though you probably know it all better than I do anyway XD