Repository navigation
Add experimental debugger support for JIT-compiled C++ - #167
Open
conrade-ctc wants to merge 1 commit into
Open
conrade-ctc wants to merge 1 commit into
conrade-ctc wants to merge 1 commit into
Conversation
The support is off by default. Build with -DCPPJIT_ENABLE_DEBUGGER_SUPPORT=ON to get it. Without the option, the build has no new code, symbols or files. In a build with the support, CPPJIT_DEBUGGER_SUPPORT=1 starts a debug session: - The JIT compiles with -g -O0. CppInterOp writes each C++ input to a file in CPPINTEROP_JIT_SOURCE_DIR, so gdb shows the source and binds FILE:LINE breakpoints. - cppjit.debugger copies in-memory Python source to files, and adds Python line breakpoints and steps through sys.monitoring. - A gdb extension shows the Python frames between the C++ frames, with the variables of both. It reads CPython's _Py_DebugOffsets, so CPython needs no debug information. - examples/vscode-gdb uses it from VS Code through gdb's DAP server. A DAP proxy adds Python breakpoints and steps between Python and C++. Co-developed-with-the-help-of: Claude Code (Opus 5.5, human in the loop)
Open
2 of 4 tasks
Collaborator
|
Nice! So that your changes are tested on the CI, can you add a commit like cc7edf7 pointing to your CppInterOp remote and branch? That would stack your changes and any iterations on compiler-research/CppInterOp#1156 will automatically reflect here |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds experimental support to debug JIT-compiled C++ at the source level with gdb, from Python and from VS Code. It is off by default: only a build with
-DCPPJIT_ENABLE_DEBUGGER_SUPPORT=ONhas it. Without the option, the build has no new code, exported symbols or package files, andpython/cppjitdoes not change.In a build with the support,
CPPJIT_DEBUGGER_SUPPORT=1starts a debug session:-g -O0. With Write interpreter inputs to files for debuggers (experimental) CppInterOp#1156, each C++ input goes to a file, so gdb shows the source and bindsfile:linebreakpoints, also in headers thatcppjit.includeloads.cppjit.debuggeradds Python line breakpoints and steps throughsys.monitoring.cppjit/debugger/gdb) shows the Python frames between the C++ frames, with the variables of both. It reads CPython's_Py_DebugOffsets, so CPython needs no debug information (3.13 or later).examples/vscode-gdbuses it from VS Code through gdb's DAP server (gdb 14 or later). A small DAP proxy adds Python breakpoints, and steps between Python and C++.Notes for review:
CPPJIT_WITH_DEBUGGER_SUPPORT: a hook pair around each JIT call inWrapperCall, a few exported variables for the debugger, and the import ofcppjit.debuggerin the module init.CPPInstancefields. I think that is acceptable for an experimental feature, but a change of these layouts needs an update here.test/test_debugging.pyskip there. The two decoder tests run in CI from the source tree. Locally (Linux, gdb 16.3, CPython 3.13), all 21 tests pass with the option. I can add a CI cell with the option if you want one.file:linebreakpoints need the CppInterOp change and a pin that has it. Breakpoints by function name work without it.🤖 Done with the help of Claude Code (Opus 5.5, human in the loop)