Skip to content

Write interpreter inputs to files for debuggers (experimental) - #1156

Open
conrade-ctc wants to merge 1 commit into
compiler-research:mainfrom
chicagotrading:upstreaming/jit-debugging
Open

conrade-ctc wants to merge 1 commit into
compiler-research:mainfrom
chicagotrading:upstreaming/jit-debugging

Conversation

@conrade-ctc

@conrade-ctc conrade-ctc commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

clang-repl registers JIT code with gdb, but the debug info names in-memory buffers such as input_line_5. Thus a debugger cannot show the source or set a breakpoint by file and line.

This adds experimental support. If CPPINTEROP_JIT_SOURCE_DIR is set, the interpreter writes each input to a file in that directory. It then parses the input after a #line directive that names the file. The file name is a hash of the input, so the path stays the same between runs and breakpoints stay valid. Without the variable, the cost is one getenv when the interpreter starts and one check for each input.

cppjit uses this for its experimental debugger support (compiler-research/cppjit#167).

Type of change

  • Bug fix
  • New feature
  • Requires documentation updates

Testing

Interpreter_JitSourceDir checks that the input goes to a file and that __FILE__ names that file. Interpreter_JitSourceDirGdb runs gdb in batch mode, if gdb is on the PATH, and stops at a line of the file. Both tests run with clang-repl on Linux and macOS. Locally (Linux, gdb 16.3) both pass.

Checklist

  • I have read the contribution guide recently

🤖 Done with the help of Claude Code (Opus 5.5, human in the loop)

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.77%. Comparing base (d3c8cf7) to head (0c1c68a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1156      +/-   ##
==========================================
+ Coverage   88.70%   88.77%   +0.06%     
==========================================
  Files          24       24              
  Lines        6978     7020      +42     
==========================================
+ Hits         6190     6232      +42     
  Misses        788      788              
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOpInterpreter.h 91.30% <100.00%> (+1.30%) ⬆️
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOpInterpreter.h 91.30% <100.00%> (+1.30%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread lib/CppInterOp/CppInterOpInterpreter.h
Comment thread unittests/CppInterOp/InterpreterTest.cpp
Comment thread unittests/CppInterOp/InterpreterTest.cpp
Comment thread unittests/CppInterOp/InterpreterTest.cpp
Comment thread unittests/CppInterOp/InterpreterTest.cpp

@Vipul-Cariappa Vipul-Cariappa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should condition this on a macro CPPINTEROP_ENABLE_JIT_SOURCE_DIR. We are already conditioning this feature on an environmental variable CPPINTEROP_JIT_SOURCE_DIR.
Think about shipping CppInterOp. We will need to ship two different versions, one that supports debugging and another that does not support it.
I did not go through the PR in detail, but from what I can see, if we enable debugging support by default, it will not cost us much, as we still enable it only when the env var is defined.

@conrade-ctc
conrade-ctc force-pushed the upstreaming/jit-debugging branch from 856b44d to a367f97 Compare October 23, 2026 12:47
@conrade-ctc

Copy link
Copy Markdown
Collaborator Author

Not sure if we should condition this on a macro CPPINTEROP_ENABLE_JIT_SOURCE_DIR. We are already conditioning this feature on an environmental variable CPPINTEROP_JIT_SOURCE_DIR. Think about shipping CppInterOp. We will need to ship two different versions, one that supports debugging and another that does not support it. I did not go through the PR in detail, but from what I can see, if we enable debugging support by default, it will not cost us much, as we still enable it only when the env var is defined.

Agreed, I had thought to make it completely opt-in... not actually ship this, but treat it as experimental. But the cost should be small, so maybe not work treating that way. I'll remove for now, and if anyone else has an objection and prefers to keep it experimental, we can reintroduce it.

@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@conrade-ctc
conrade-ctc force-pushed the upstreaming/jit-debugging branch from a367f97 to 1c9675a Compare October 23, 2026 13:09
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@conrade-ctc
conrade-ctc force-pushed the upstreaming/jit-debugging branch from 1c9675a to 475ca79 Compare October 23, 2026 13:32
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@conrade-ctc
conrade-ctc force-pushed the upstreaming/jit-debugging branch from 475ca79 to e40772a Compare October 23, 2026 19:18
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

clang-repl registers jitted code with GDB, but the debug info names
in-memory buffers such as input_line_5. Thus a debugger cannot show
the source or set a breakpoint by file and line.

The support is experimental. If CPPINTEROP_JIT_SOURCE_DIR is set,
write each input to a file in that directory. Parse the input after a
#line directive that names the file. The file name is a hash of the
input, so the path stays the same between runs. A new test runs gdb in
batch mode if gdb is on the PATH.

Co-developed-with-the-help-of: Claude Code (Opus 5.5, human in the loop)
@conrade-ctc
conrade-ctc force-pushed the upstreaming/jit-debugging branch from e40772a to 0c1c68a Compare October 28, 2026 14:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants