> For the complete documentation index, see [llms.txt](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/basics/6.-foundry/forge/forge-less-than-subcommend-greater-than-debug.md).

# forge \<subcommend> --debug

foundry 에서는 옵션으로 특정 트랜잭션의 실행 흐름을 디버깅하는 기능을 제공한다.\
트랜잭션 해시를 기반으로 EVM에서 어떤 명령어들이 실행되었는지 상세하게 추적할 수 있다.

```
forge script script/Counter.s.sol:CounterScript --rpc-url --private-key <개인키> --broadcast --debug
```

이와 같이 --debug 옵션을 추가하여 디버깅을 할 수 있다.

### 디버거 UI 구성

<figure><img src="https://2462457462-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLf9vwRuaws92ULgGvzTi%2Fuploads%2FkKt2S1DARAyniHwA7W4A%2Fimage.png?alt=media&amp;token=dab13df9-f88b-486e-960b-960487a71ce3" alt=""><figcaption></figcaption></figure>

#### 🔹 1사분면: Opcode 실행 흐름

* 현재 실행 중인 EVM opcode를 표시
* 현재 계정 주소, 프로그램 카운터, 누적 가스 사용량도 확인 가능
* 실행 중인 opcode는 하이라이트로 표시됨

#### 🔹 2사분면: 스택 정보

* 현재 EVM 스택 상태와 스택 크기를 확인
* 연산 처리 흐름을 이해하는 데 중요

#### 🔹 3사분면: 소스 코드 뷰

* 디버깅 중인 Solidity 코드가 표시됨
* 현재 실행 중인 라인이 강조됨

#### 🔹 4사분면: 메모리 상태

* 현재 시점의 EVM 메모리 내용 표시
* `MLOAD`, `MSTORE`와 같은 연산 확인 가능
