Debugging in JetBrains IDEs
This guide covers setting up debugging for Run programs in IntelliJ IDEA, CLion, GoLand, and other JetBrains IDEs.
Prerequisites
Section titled “Prerequisites”- A JetBrains IDE with the Debug Adapter Protocol support (2023.1+)
- The
runcompiler installed and on yourPATH - GDB or LLDB installed on your system
Option 1: External Tool + DAP (Recommended)
Section titled “Option 1: External Tool + DAP (Recommended)”-
Open Settings > Tools > External Tools
-
Click + to add a new tool:
- Name:
Run Debug - Program:
run - Arguments:
debug --dap $FilePath$ - Working directory:
$ProjectFileDir$
- Name:
-
Open Run > Edit Configurations
-
Click + > Debug Adapter Protocol
-
Configure:
- Name:
Debug Run Program - Debug adapter: Executable
- Path: path to
runbinary (e.g.,/usr/local/bin/run) - Arguments:
debug --dap - Configuration: Set
programto the file path:{"request": "launch","program": "$FilePath$"}
- Name:
Option 2: Shell Script Wrapper
Section titled “Option 2: Shell Script Wrapper”Create a wrapper script run-debug-adapter.sh:
#!/bin/bashexec run debug --dap "$@"Make it executable: chmod +x run-debug-adapter.sh
Then configure the DAP adapter to use this script.
Using the Debugger
Section titled “Using the Debugger”- Open a
.runfile in the editor - Click in the gutter to set breakpoints
- Run your debug configuration (
Shift+F9) - Use the Debug tool window to:
- Step over (
F8), step into (F7), step out (Shift+F8) - Inspect variables in the Variables pane
- Evaluate expressions in the Debug Console
- View the call stack with demangled Run function names
- Step over (
Conditional Breakpoints
Section titled “Conditional Breakpoints”Right-click a breakpoint and select More to set:
- Condition: A Run expression (e.g.,
i > 10) - Hit count: Break after N hits
Troubleshooting
Section titled “Troubleshooting””Failed to start debugger”
Section titled “”Failed to start debugger””- Verify
runis on your PATH:which run - Verify GDB or LLDB is installed:
gdb --versionorlldb --version - Check the Debug Console output for error messages
Breakpoints not hitting
Section titled “Breakpoints not hitting”- Ensure the file path matches exactly (no symlinks)
- Check that
#linedirectives in generated C code point to the correct.runsource - Try setting a breakpoint on a line with a statement (not a blank line or comment)
Variables showing C types
Section titled “Variables showing C types”- The DAP server maps C types to Run types automatically
- If you see
int64_tinstead ofint, the type mapping may not cover that type - SSA temporaries (
_t0,_t1, etc.) are automatically filtered out