Debugger and JIT generated code on CPU

Though this issues is easy to reproduce, I didn’t find any discussion on it.
Also, I don’t know if this issue should be discussed here, or should it be raised e.g. on the llvmlite?

Using a debugger (e.g. GDB) to debug JIT compiled functions is challenging, due to issues in both the generated DWARF and the generated binary code.

Followings are detected, when optimization is disabled (NUMBA_OPT=0):

  • Generated DWARF contains line references, which make stepping to jump around. Typically the binary code initializing local variables at the function entry is set to refer multiple source lines, rather than referring the first source line only.
  • Generated binary clears local variables immediately after use. This makes difficult to follow variable values through a function.
  • Generated binary copies the function argument(s) into local(s) only when they are used. This makes difficult to see, what argument values were passed in.

Enabling optimization (NUMBA_OPT=1 or higher) often optimizes out most (if not all) local variables.
Though this is an expected behavior, it further increases difficulty to use a debugger with Numba JIT generated code on CPU.

Thanks for the discussion! Support for debugging Numba-compiled code with GDB does presently have some limitations, that are outlined in the docs: Troubleshooting and tips — Numba 0.52.0.dev0+274.g626b40e-py3.7-linux-x86_64.egg documentation

Also, I don’t know if this issue should be discussed here, or should it be raised e.g. on the llvmlite?

If you’re able to provide executable reproducers of specific issues using the debugger that aren’t listed in the documentation, then it would be good to open issues for each of them on the Numba issue tracker: Issues · numba/numba · GitHub - that way we can discuss potential fixes there and track progress. For issues that are known, you could open feature request issues for discussion if they don’t already exist (I did a quick search and couldn’t find any).

Thank you for your comments.
Yes, I was aware of the referred documentation.
The text there doesn’t go much into details, so in my message I was I was trying to be a little more specific on the possible root causes.
Please correct me, but they don’t seem to be specific for any particular debugger?

Are there best known practices, ways to bypass these “limitations”, planned improvements, or proposed methods for debugging Numba functions on CPU?