Starting the debugger
Launch a program with the--debugger flag:
Debugger prompt
The(walrus-debug) prompt accepts commands to control execution and inspect state.
Execution control
Step (s)
Execute one instruction and pause (step into functions):Next (n)
Step over function calls:Continue (c)
Resume execution until the next breakpoint:Finish
Run until the current function returns:Breakpoints
Set breakpoint (b)
Set a breakpoint at a specific line number:List breakpoints
Show all breakpoints:Delete breakpoint
Remove a breakpoint by line number:Variable inspection
Print state (p)
Show current execution state:Print variable
Inspect a specific variable by name:--debugger).
Show locals
Display all local variables:Call stack inspection
Backtrace (bt)
Show the call stack:Source code viewing
List source (l)
Show source code context around the current line:-> marking the current line.
List at specific line
View source around a different line:Stack inspection
View operand stack
Show the VM’s operand stack:Help and quit
Help (h)
Show all available commands:Quit (q)
Exit the debugger and stop execution:Complete command reference
| Command | Alias | Description |
|---|---|---|
step | s | Execute one instruction (step into) |
next | n | Step over function calls |
continue | c | Resume until next breakpoint |
finish | - | Run until current function returns |
print | p | Show current state |
print <var> | p <var> | Print variable by name |
locals | - | Show all local variables |
backtrace | bt | Show call stack |
list | l | Show source context |
list <line> | l <line> | Show source at line |
b | - | List breakpoints |
b <line> | - | Set breakpoint at line |
delete <line> | - | Remove breakpoint |
stack | - | Show operand stack |
help | h | Show command help |
quit | q | Exit debugger |
Debugging workflow
Basic debugging session
Finding bugs
Tracing execution
Debug information
The debugger requires debug information, which is automatically built when using--debugger. Debug info includes:
- Line table: Maps bytecode IPs to source line numbers
- Local names: Variable names for each local slot
- Global names: Names of global variables and functions
Debugging with JIT
The debugger can be combined with JIT compilation:continue execution.
Performance impact
The debugger adds overhead:- Debug info generation during compilation
- Execution checks at every instruction
- State tracking for breakpoints and stepping
--debugger:
Tips
Combine with logging
Use debug flags for more context:Set strategic breakpoints
Place breakpoints at:- Function entry points
- Loop bodies
- Conditional branches
- Before suspected bugs