Forge ships with an interactive debugger.
Currently, the debugger is only accessible on forge run
. To run the debugger, run:
$ forge run --debug $FILE --sig $FUNC
Where $FILE
is the path to the contract you want to debug, and $FUNC
is the signature of the function you want to debug. For example:
$ forge run --debug src/MyContract.sol --sig "someFunction()"
If your source file contains more than one contract, specify the contract you want to debug using the --target-contract
flag.
When the debugger is run, you are presented with a terminal divided into four quadrants:
- Quadrant 1: The opcodes in the debugging session, with the current opcode highlighted. Additionally, the address of the current account, the program counter and the accumulated gas usage is also displayed
- Quadrant 2: The current stack, as well as the size of the stack
- Quadrant 3: The source view
- Quadrant 4: The current memory of the EVM
- q: Quit the debugger
- n + k: Step
n
times backwards (alternatively scroll up with your mouse) - n + j: Step
n
times forwards (alternatively scroll down with your mouse) - g: Move to the beginning of the transaction
- G: Move to the end of the transaction
- c: Move to the previous call-type instruction (i.e.
CALL
,STATICCALL
,DELEGATECALL
, andCALLCODE
). - C: Move to the next call-type instruction
- a: Move to the previous
JUMP
orJUMPI
instruction - s: Move to the next
JUMPDEST
instruction