Is the stack trace of a function that was inline saved on an exception?

When compiling an executable file in Release mode — with code optimization turned on — the compiler can select built-in functions that meet certain criteria to improve performance.

My question is this: when an exception is thrown into the body of the inline function, will the stack information be saved, regardless of the inline extension? . In other words, will it display the original function as the source of the error, or will it display the calling function instead?

+6
source share
2 answers

It depends on how the exception was thrown. If you use the throw statement, you have no problem, jitter will not have inline methods containing the throw. Something you need to know about when you need a property setting device to be fast.

However, if the exception is caused by normal execution, for example, NullReferenceException or IndexOutOfRangeException, etc., then yes, you do not see the method name in the stack trace if it was included. This may be a little confusing, but you usually understand this from the source code of the calling method and the type of exception. I hope it is relatively small. The [MethodImpl(MethodImplOptions.NoInlining)] is available to suppress insertion. By the time you find it would be helpful, usually too late;)

+5
source

This is not the final answer, but I tried to decorate a simple method that only divides by zero with the [MethodImpl(MethodImplOptions.AggressiveInlining)] attribute, which in .NET 4.5 gives a JIT hint (which actually does inlining) to embed a specific method, and when I I ran the program in release mode, an exception was reported from the calling method, and not with division. On the other hand, as Hans said, emission reporting techniques and complex flow logic are not included. This MSDN blog article (although since 2004) gives you an overview of how embedding is performed by JIT.

+6
source

Source: https://habr.com/ru/post/947789/


All Articles