none
Exact meaning of IL offset within a stack trace. RRS feed

  • Question

  • I understand that when an exception is thrown (and there's no PDB around) the stack trace exposes the IL offset of where the exception arose (in the lowest frame).

    I'm not very clear though on what this means, is it the IL offset of IL operation that thew the exception or is it the IL Offset of the previously executed IL operation or what?

    I'm examining ILDASM dumps of assemblies and the IL offset sometimes doesn't quite make sense.

    e.g. one null reference exception reports an offset IL_0063 in the stack frame, but that is just an operation br.s

    Any help on exactly how the system determines the IL offset when it reports the stack trace, greatly appreciated.

    Thx



    Monday, January 19, 2015 6:49 PM

Answers

  • There is managed code added to every "function" call to handle exceptions.  The offset is where the execution stack is located when a function starts executing.

    jdweng

    Monday, January 19, 2015 6:57 PM
  • Regardless of whether or not there is a PDB, managed code is able to provide a full trace with method names for the managed portion of the stack due to the metadata within the assembly. Where are you getting the offset? The offset that visual studio provides is the native offset within the jitted native method rather than the IL offset within its managed counterpart (or at least it was in VS2010, I haven't verified it since then).

    My understanding is that, when provided, the IL offset is simply mapped from the native offset using a table generated at JIT time (which may be an approximation due to optimizations). For the leaf native-frame, the native offset is where the exception was thrown while non-leaf native frames use the return address from the stack which may make it look like the exception was thrown by the instruction following the one where the exception actually happened.

    Monday, January 19, 2015 9:05 PM

All replies

  • There is managed code added to every "function" call to handle exceptions.  The offset is where the execution stack is located when a function starts executing.

    jdweng

    Monday, January 19, 2015 6:57 PM
  • Regardless of whether or not there is a PDB, managed code is able to provide a full trace with method names for the managed portion of the stack due to the metadata within the assembly. Where are you getting the offset? The offset that visual studio provides is the native offset within the jitted native method rather than the IL offset within its managed counterpart (or at least it was in VS2010, I haven't verified it since then).

    My understanding is that, when provided, the IL offset is simply mapped from the native offset using a table generated at JIT time (which may be an approximation due to optimizations). For the leaf native-frame, the native offset is where the exception was thrown while non-leaf native frames use the return address from the stack which may make it look like the exception was thrown by the instruction following the one where the exception actually happened.

    Monday, January 19, 2015 9:05 PM