Getting line number from pdb in release mode

前端 未结 4 1564
走了就别回头了
走了就别回头了 2021-01-18 07:25

Is it possible for the debugger (or the CLR exception handler) to show the line where the exception happened in Release mode using the pdb?

The code, in release mode

4条回答
  •  醉酒成梦
    2021-01-18 08:29

    [@Not Sure] has it almost right. The compiler makes a best effort at identifying an appropriate line number that closely matches the current machine code instruction.

    The PDB and the debugger don't know anything about optimizations; the PDB file essentially maps address locations in the machine code to source code line numbers. In optimized code, it's not always possible to match exactly an assembly instruction to a specific line of source code, so the compiler will write to the PDB the closest thing it has at hand. This might be "the source code line before", or "the source code line of the enclosing context (loop, etc)" or something else.

    Regardless, the debugger essentially finds the entry in the PDB map closest (as in "before or equal") to the current IP (Instruction Pointer) and highlights that line.

    Sometimes the match is not very good, and that's when you see the highlighted area jumping all over the place.

提交回复
热议问题