Biohazrd
Biohazrd copied to clipboard
Hide trampolines from the debugger/stack traces
C#-side trampolines can pollute stack traces. Consider adding DebuggerHiddenAttribute
, DebuggerStepThroughAttribute
, and StackTraceHiddenAttribute
(depends on https://github.com/dotnet/runtime/issues/29681) to these methods. (Similar example from the BCL: https://github.com/dotnet/runtime/pull/32353/files)
- [x]
DebuggerHiddenAttribute
- [x]
DebuggerStepThroughAttribute
- [ ]
StackTraceHiddenAttribute
This is blocked until .NET 6 is released since StackTraceHidden
didn't make it into .NET 5. (Although DebuggerStepThrough
and DebuggerHidden
would still be useful here.)
DebuggerHidden
is somewhat unfortunate because it also prevents placing breakpoints in a method. (Well, you can place them but they'll have a warning on them and won't be hit.) I almost removed it from the scope of this issue because I thought DebuggerStepThrough
was enough, but without it exceptions don't properly get attributed to the "important" call.
c55d7c5748be0152d4d91cd17d9b62640c5d4058 added DebuggerStepThrough
and DebuggerHidden
. I decided to make it a global setting rather than extensible metadata because I couldn't think of a reason someone would want to only use it on some trampolines but not others. (It is configurable in general due to the previously mentioned issue where DebuggerHidden
disables setting breakpoints in the trampolines, and both make it harder to debug issues in the actual trampolines in general.)
I am realizing that DebuggerNonUserCodeAttribute
may actually be slightly more appropriate for trampolines for people who use Just My Code. I don't use this feature of Visual Studio, so I'll have to hear feedback about this to know if DebuggerNonUserCodeAttribute
would be better as a default and whether people find DebuggerStepThrough
/DebuggerHidden
to be annoying. I considered making this feature disabled by default for that reason, but I feel like I'd enable it on any libraries I translate and I'd rather kinda force the feedback if I'm honest.
Feedback from me: This has been more annoying than helpful I think. It makes me second-guess myself when debugging and I'm pretty sure DebuggerStepThrough
is actually making it annoying to step into the native code. I'll keep the feature (and add StackTraceHiddenAttribute
when targeting .NET 6) but I don't think I'll be using it myself anymore.