Visual Studio 코드에서 디버깅

Blockchain App Builder에는 TypeScript 및 Go 프로젝트에 대한 Visual Studio Code의 라인별 디버그 지원이 포함되어 있습니다.

Microsoft Windows에서 명령 프롬프트를 PowerShell 대신 기본 터미널로 사용하도록 Visual Studio Code를 구성합니다. Visual Studio Code의 터미널 메뉴에서 기본 프로파일 선택, 명령 프롬프트 순으로 선택합니다.

Go 체인코드 프로젝트를 디버깅하려면 먼저 Visual Studio Code에 필요한 Go 도구를 설치해야 합니다. Visual Studio Code에서 명령 팔레트를 연 다음 Go: Install/Update Tools 명령을 실행합니다. 나열된 모든 Go 확장을 설치합니다.

Visual Studio Code는 Delve를 사용하여 Go를 디버그합니다. Go 체인코드를 처음 디버그하면 Delve를 설치하라는 메시지가 표시됩니다. 계속하기 전에 Delve 설치를 적용합니다. Visual Studio Code에는 TypeScript용 디버거가 내장되어 있습니다.

행별 디버깅을 실행하려면 다음과 같이 하십시오.
  1. Visual Studio Code Explorer에서 체인코드 프로젝트를 엽니다.Open your chaincode project in Visual Studio Code Explorer. Chaincodes(체인 코드) 창에서 체인 코드를 마우스 오른쪽 버튼으로 누르고 Open in Explorer(탐색기에서 열기)를 선택합니다.
  2. 필요한 경우 코드에 중단점을 첨부합니다.
  3. Run 메뉴로 이동하고 Start Debugging을 누릅니다. 그러면 디버거가 연결됩니다. 디버거가 체인코드에 연결하는 데 몇 초 정도 걸릴 수 있습니다.
  4. 터미널에서 코드를 실행할 명령을 호출합니다.

    Visual Studio Code 인터페이스를 사용하여 지금까지 체인코드를 테스트한 경우 Test Your Chaincode on a Local Hyperledger Fabric Network에 설명된 호출 구문을 따를 수 있습니다.

    디버거가 중단점에서 멈춥니다. 그런 다음 디버깅을 시작할 수 있습니다.

  5. 새로운 변경 내용이 반영되도록 디버깅을 다시 시작합니다.

체인코드는 디버그 모드에서 실행 중이므로 새 변경사항의 핫 배포가 자동으로 수행되지 않습니다. 최신 변경 사항을 적용하려면 Visual Studio Code의 디버그 컨트롤을 사용하여 디버깅 프로세스를 수동으로 다시 시작해야 합니다.You must manually restart the debugging process, using the debug controls in Visual Studio Code, to make the latest changes take effect.

문제 해결

Windows 11에서 다음과 유사한 오류가 발생할 수 있습니다.
dlv: failed to install dlv(github.com/go-delve/delve/cmd/dlv@latest): Error: Command failed:
C:\Program Files (x86)\Go\bin\go.exe get -x github.com/go-delve/delve/cmd/dlv@latest
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/dlv/@v/list
# get https://proxy.golang.org/github.com/@v/list
# get https://proxy.golang.org/github.com/go-delve/@v/list
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/@v/list
# get https://proxy.golang.org/github.com/go-delve/delve/@v/list
# get https://proxy.golang.org/github.com/@v/list: 410 Gone (0.420s)
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/@v/list: 410 Gone (1.040s)
# get https://proxy.golang.org/github.com/go-delve/@v/list: 410 Gone (1.062s)
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/dlv/@v/list: 410 Gone (1.066s)
# get https://proxy.golang.org/github.com/go-delve/delve/@v/list: 200 OK (1.448s)
go: found github.com/go-delve/delve/cmd/dlv in github.com/go-delve/delve v1.8.3C:\Users\<UserName>\go\pkg\mod\github.com\go-delve\delve@v1.8.3\service\debugger\debugger.go:28:2:found packages native (proc.go) and 
your_operating_system_and_architecture_combination_is_not_supported_by_delve(support_sentinel.go) in C:\Users\Asus\go\pkg\mod\github.com\go-delve\delve@v1.8.3\pkg\proc\native
현재는 이 오류에 대한 해결 방법이 없습니다.