Skip to content

Commit a449fd0

Browse files
committed
feat: Add debugging support
1 parent 48ab151 commit a449fd0

File tree

11 files changed

+188
-5
lines changed

11 files changed

+188
-5
lines changed

.agents/codebase-insights.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# Critical Architecture Notes
2+
3+
## Ruby Debugging Setup
4+
- VS Code debugging is configured with rdbg (Ruby Debug) support
5+
- Use the rdbg-wrapper script in scripts/ to avoid hardcoded paths
6+
- Debug configurations available:
7+
- "Debug Current Ruby File" - Debug the currently open Ruby file
8+
- "Debug Current Test File" - Debug test files with proper load paths
9+
- "Debug All Tests" - Debug the main test runner
10+
- For interactive debugging with Pry, use the "Debug Current Test with Pry" task
11+
- The Ruby LSP is configured for full language support features
12+
13+
## Debugging Gem Installation
14+
- To use debugging features, install: `gem install debug pry`
15+
- The debug gem is required for VS Code rdbg debugging
16+
- Pry is used for interactive debugging tasks
17+
- Native compilation may fail in nix environment due to missing headers
18+
- Alternative: Use system Ruby for gem installation if nix environment has issues
19+
20+
## Codetracer Architecture
121
When the pure Ruby recorder traces a script that holds a reference to the
222
`PureRubyRecorder` instance in a local variable, the variable inspection code
323
would recursively serialise the tracer's internal state. This results in an

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ pkg/
1414
# Offline dependency sources
1515
.codex/deps_src/
1616
.codex/internet_resources/
17+
18+
# JetBrains IDES
19+
.idea/

.vscode/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Ruby Debugging Setup for VS Code
2+
3+
This repository includes a comprehensive Ruby debugging setup for Visual Studio Code, similar to the one in the agents-workflow repository.
4+
5+
## Files Created
6+
7+
### VS Code Configuration (`.vscode/`)
8+
9+
- **`tasks.json`** - VS Code tasks for running and debugging Ruby code
10+
- **`launch.json`** - Debug configurations for rdbg debugger
11+
- **`settings.json`** - Ruby LSP settings and debugging preferences
12+
13+
### Scripts
14+
15+
- **`scripts/rdbg-wrapper`** - Wrapper script to locate and run rdbg without hardcoded paths
16+
17+
## Available Tasks
18+
19+
Use `Cmd+Shift+P` (macOS) or `Ctrl+Shift+P` (Windows/Linux) and search for "Tasks: Run Task":
20+
21+
1. **Run Current Test File** - Execute the currently open test file
22+
2. **Run All Tests** - Execute all tests using the main test runner
23+
3. **Debug Current Test with Pry** - Run current test with Pry for interactive debugging
24+
4. **Simple Test Run (No Debug)** - Basic test execution without debug features
25+
26+
## Debug Configurations
27+
28+
Use the Debug panel (F5 or Run → Start Debugging):
29+
30+
1. **Debug Current Ruby File** - Debug any Ruby file with rdbg
31+
2. **Debug Current Test File** - Debug test files with proper load paths
32+
3. **Debug All Tests** - Debug the complete test suite
33+
34+
## Required Gems
35+
36+
To use the debugging features, install these gems:
37+
38+
```bash
39+
gem install debug pry
40+
```
41+
42+
### For Nix Users
43+
44+
If you're using the nix development environment and encounter compilation issues:
45+
46+
1. Use system Ruby for gem installation:
47+
48+
```bash
49+
# Exit nix shell first
50+
gem install debug pry
51+
```
52+
53+
2. Or install globally and ensure they're available in PATH
54+
55+
## Usage
56+
57+
1. **Setting Breakpoints**: Click in the gutter next to line numbers or use `F9`
58+
2. **Interactive Debugging**: Use the "Debug Current Test with Pry" task for REPL-style debugging
59+
3. **Variable Inspection**: Hover over variables or use the Variables panel during debugging
60+
4. **Step Through Code**: Use F10 (step over), F11 (step into), Shift+F11 (step out)
61+
62+
## Ruby LSP Features
63+
64+
The setup includes full Ruby Language Server Protocol support:
65+
66+
- Code completion and IntelliSense
67+
- Go to definition/implementation
68+
- Syntax highlighting and error detection
69+
- Code formatting and refactoring
70+
- Document symbols and workspace search
71+
72+
## Troubleshooting
73+
74+
- **"debug gem not found"**: Install the debug gem with `gem install debug`
75+
- **Compilation errors in nix**: Try using system Ruby for gem installation
76+
- **rdbg not found**: The rdbg-wrapper script should handle this automatically
77+
- **Breakpoints not working**: Ensure the debug gem is installed and accessible
78+
79+
## Integration with Editor
80+
81+
The configuration integrates seamlessly with VS Code's built-in features:
82+
83+
- Debug console for evaluating expressions
84+
- Call stack navigation
85+
- Automatic variable inspection
86+
- Terminal integration for task execution

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

GEMINI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ source "https://rubygems.org"
44

55
gem "codetracer-ruby-recorder", path: "gems/codetracer-ruby-recorder"
66
gem "codetracer-pure-ruby-recorder", path: "gems/codetracer-pure-ruby-recorder"
7+
8+
# Development and debugging gems (optional - install separately if needed)
9+
# gem "debug", "~> 1.7" # Ruby debugging with rdbg
10+
# gem "pry", "~> 0.14" # Interactive debugging and REPL

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,40 @@ however you probably want to use it in combination with CodeTracer, which would
5858
* if you pass `CODETRACER_RUBY_RECORDER_DEBUG=1`, you enable some additional debug-related logging
5959
* `CODETRACER_RUBY_RECORDER_OUT_DIR` can be used to specify the directory for trace files
6060

61+
## Development Setup
62+
63+
This repository includes a comprehensive Ruby debugging setup for Visual Studio Code. See [`.vscode/README.md`](.vscode/README.md) for detailed information about:
64+
65+
* VS Code tasks for running and debugging Ruby code
66+
* Debug configurations for rdbg debugger
67+
* Ruby LSP integration for full language support
68+
* Interactive debugging with Pry
69+
70+
### Quick Start for Contributors
71+
72+
1. **Install debugging gems** (if not using nix):
73+
74+
```bash
75+
gem install debug pry
76+
```
77+
78+
2. **Use VS Code tasks**: Open Command Palette (`Cmd+Shift+P` / `Ctrl+Shift+P`) and search for "Tasks: Run Task"
79+
80+
3. **Debug with F5**: Use the debug panel to set breakpoints and step through code
81+
82+
4. **Run tests**: Use the provided tasks or run manually:
83+
84+
```bash
85+
ruby -I lib -I test test/test_tracer.rb
86+
```
87+
6188
## Future directions
6289

6390
The current Ruby support is a prototype. In the future, it may be expanded to function in a way similar to the more complete implementations, e.g. [Noir](https://github.com/blocksense-network/noir/tree/blocksense/tooling/tracer).
6491

6592
### Current approach: TracePoint API
6693

67-
Currently we're using the TracePoint API: https://rubyapi.org/3.4/o/tracepoint .
94+
Currently we're using the [TracePoint API](https://rubyapi.org/3.4/o/tracepoint).
6895
This is very flexible and can function with probably multiple Ruby versions out of the box.
6996
However, this is limited:
7097

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
# C standard library headers required for Ruby C extension compilation on Linux
3838
# Without this, build fails with "stdarg.h file not found" error
3939
glibc.dev
40+
] ++ pkgs.lib.optionals isDarwin [
41+
# Required for Ruby C extension compilation on macOS
42+
darwin.apple_sdk.frameworks.CoreFoundation
43+
darwin.apple_sdk.frameworks.Security
4044
];
4145

4246
# Environment variables required to fix build issues with rb-sys/bindgen

gems/codetracer-pure-ruby-recorder/lib/recorder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def to_value(v, depth=10)
394394
end)
395395
end
396396
when Hash
397-
if true or v.count > MAX_COUNT
397+
if v.count > MAX_COUNT
398398
not_supported_value
399399
else
400400
pairs = v.map do |k, val|

scripts/rdbg-wrapper

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# Wrapper script to launch rdbg without hardcoded paths
5+
# On Windows, rdbg doesn't place any executable binaries in the system
6+
# PATH for some reason, so this script discovers the debug gem path and
7+
# executes the main rdbg script directly
8+
9+
begin
10+
require 'debug'
11+
12+
# Find the rdbg executable in the debug gem
13+
debug_gem_spec = Gem.loaded_specs['debug']
14+
if debug_gem_spec.nil?
15+
puts 'Error: debug gem not found. Install with: gem install debug'
16+
exit 1
17+
end
18+
19+
rdbg_path = File.join(debug_gem_spec.full_gem_path, 'exe', 'rdbg')
20+
21+
unless File.exist?(rdbg_path)
22+
puts "Error: rdbg executable not found at #{rdbg_path}"
23+
exit 1
24+
end
25+
26+
# Set up ARGV to match what rdbg expects
27+
# The rdbg script reads from ARGV directly
28+
original_argv = ARGV.dup
29+
ARGV.replace(original_argv)
30+
31+
# Load and execute the rdbg script
32+
load rdbg_path
33+
rescue LoadError => e
34+
puts "Error loading debug gem: #{e.message}"
35+
puts 'Install with: gem install debug'
36+
exit 1
37+
rescue StandardError => e
38+
puts "Error: #{e.message}"
39+
exit 1
40+
end

0 commit comments

Comments
 (0)