Skip to content

Add Phase 3 debugger features: p/x commands, %DB::sub, @DB::args#287

Merged
fglock merged 6 commits intomasterfrom
debugger-phase3
Mar 9, 2026
Merged

Add Phase 3 debugger features: p/x commands, %DB::sub, @DB::args#287
fglock merged 6 commits intomasterfrom
debugger-phase3

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Mar 9, 2026

Summary

This PR adds Phase 3 features to the Perl debugger:

  • p expr command: Evaluate and print expressions in the debugger
  • x expr command: Dump expressions with Data::Dumper formatting
  • %DB::sub hash: Track subroutine locations (file:startline-endline)
  • @DB::args array: Capture subroutine arguments on each call

Bug Fixes

  • Step-into subroutines: Fixed by tracking callDepth with enterSubroutine()/exitSubroutine() calls
  • DEBUG opcode line numbers: Fixed incorrect line numbers for lazily compiled subroutines by using getLineNumberAccurate() which counts from the beginning of the file
  • Disassembler: Added DEBUG opcode support for better debugging

Testing

$ ./jperl -d script.pl
main::(script.pl:5):
5:  foo(10, 20);
  DB<1> s
main::(script.pl:2):
2:  my ($x, $y) = @_;
  DB<2> p "@DB::args"
10 20
  DB<2> x \@DB::args
$VAR1 = [
          10,
          20
        ];

Test plan

  • All existing tests pass
  • Step into subroutines works correctly
  • Breakpoints inside subroutines work
  • @DB::args shows correct arguments
  • %DB::sub tracks subroutine locations

Generated with Devin

fglock and others added 6 commits March 9, 2026 10:21
- Add `p expr` command to evaluate and print expressions
- Add `x expr` command to dump data structures (uses Data::Dumper)
- Pass code and registers context to DebugHooks.debug()
- Temporarily disable debug mode during eval to prevent recursion
- Fix EvalStringHandler to pass errorUtil to BytecodeCompiler

Note: Lexical variable access not yet working due to scope limitations.
Expressions like `p 1+2` and `p "hello"` work correctly.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
- Add 'p expr' command to evaluate and print expressions in debugger
- Add 'x expr' command to dump expressions with Data::Dumper formatting
- Implement %DB::sub hash to track subroutine locations (file:start-end)
- Implement @db::args to capture subroutine arguments on each call
- Fix step-into subroutines by tracking callDepth with enterSubroutine/exitSubroutine
- Fix DEBUG opcode line numbers for lazily compiled subroutines using getLineNumberAccurate()
- Add DEBUG opcode support to bytecode disassembler

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
- Create docs/reference/debugger.md with full command reference
- Update cli-options.md to document -d flag
- Update feature-matrix.md with Phase 3 debugger features

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
- Add `r` command to step out of current subroutine
- Add `T` command to display stack trace
- Implement one-time breakpoints for `c line` command
- Add stepOutDepth tracking in DebugState
- Update documentation with new commands

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Move debugger features from bullet points under "Compiler Usability"
to a standalone section with organized tables for:
- Execution commands
- Breakpoints
- Source and stack commands
- Expression evaluation
- Debug variables

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit a408ff3 into master Mar 9, 2026
2 checks passed
@fglock fglock deleted the debugger-phase3 branch March 9, 2026 10:34
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.

1 participant