Go 언어용 디버거, dlv

in #golang6 years ago (edited)

개요

  • dlv 는 go 언어용 공식 디버거
  • go 언어로 개발한 어플리케이션을 소스코드 레벨에서 디버깅할 수 있음

설치 및 사용 방법

  • 설치방법: https://github.com/derekparker/delve 문서 참조
  • 사용방법
    • $ dlv debug : main 패키지가 존재하는 디렉토리에서 어플리케이션에 대한 디버깅 시작
    • $ dlv test <package-name> : <package-name>_test.go 테스트 케이스에 대한 디버깅 시작
    • (dlv) break <package-name>.<func-name>: break-point 설정
    • (dlv) next: 다음 줄 실행
    • (dlv) continue: 다음 break-point 까지 계속 실행
    • (dlv) print <variable-name>: 변수 값 조회

사용예

PS D:\git\go\src\hello> dlv debug
Type 'help' for list of commands.
(dlv) break main.main
Breakpoint 1 set at 0x4aa216 for main.main() D:/git/go/src/hello/hello.go:5
(dlv) continue
> main.main() D:/git/go/src/hello/hello.go:5 (hits goroutine(1):1 total:1) (PC: 0x4aa216)
     1: package main
     2:
     3: import "fmt"
     4:
=>   5: func main() {
     6:   fmt.Printf("Hello, world\n")
     7: }
(dlv) next
> main.main() D:/git/go/src/hello/hello.go:6 (PC: 0x4aa224)
     1: package main
     2:
     3: import "fmt"
     4:
     5: func main() {
=>   6:   fmt.Printf("Hello, world\n")
     7: }
(dlv) next
Hello, world
> main.main() D:/git/go/src/hello/hello.go:7 (PC: 0x4aa24e)
     2:
     3: import "fmt"
     4:
     5: func main() {
     6:   fmt.Printf("Hello, world\n")
=>   7: }
(dlv) continue
Process 11340 has exited with status 0
(dlv)

특이사항

  • WSL (Windows Subsystem for Linux) 에서는 dlv 가 정상 실행되지 않음
    • dlv debug 명령을 실행시키면 아무 응답 없다가, CTRL+C 를 누르면 한꺼번에 실행되고 종료됨 (디버깅 못함)
    • WSL 팀에서 관련 이슈를 인지하고 해결 중 (dlv 문제가 아니라 WSL 의 문제인 듯 보임)
Sort:  

Congratulations @ingee! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Do not miss the last announcement from @steemitboard!