yoongrammer

gdlv - Go언어 디버거 본문

언어/Go 언어

gdlv - Go언어 디버거

yoongrammer 2020. 11. 22. 21:48
728x90

목차

gdlv - Go언어 디버거


gdlv는 go 언어 디버깅을 gui로 할 수 있는 tool입니다.

 

디버깅 중에 코드 , 변수, 스택, 고루틴 등 여러 정보를 한눈에 볼 수 있어 delve보다 디버깅이 편합니다.

gdlv 설치


1. delve 를 설치합니다.

gdlv를 사용하려면 delve가 있어야 합니다.

go get -u github.com/go-delve/delve/cmd/dlv

2. gdlv를 설치합니다.

go get -u github.com/aarzilli/gdlv

3. 설치 확인을 합니다.

$ gdlv version
Gdlv Debugger
Version: 1.4

version 정보가 출력된다면 설치가 완료된 것입니다.

gdlv 사용방법


gdlv run 명령어는 프로그램 파일을 가지고 디버깅하는 명령어입니다.

gdlv run <program file> <program's arguments...>

 

gdlv exec 명령어는 실행파일을 가지고 디버깅하는 명령어입니다.

gdlv exec <executable> <program's argumenrts...>

 

gdlv attach 명령어는 실행 중인 프로세스에 접근하여 디버깅하는 명령어입니다.

gdlv attach <pid> [path to executable]

 

이 밖에 여러 명령어가 있으니 확인해 보시기 바랍니다.

Usage:
	gdlv [options] connect <address>
	gdlv [options] debug <program's arguments...>
	gdlv [options] run <program file> <program's arguments...>
	gdlv [options] exec <executable> <program's arguments...>
	gdlv [options] test <testflags...>
	gdlv [options] attach <pid> [path to executable]
	gdlv [options] core <executable> <core file>
	gdlv [options] replay <trace directory>

All commands except "core" and "replay" can be prefixed with the name of a backend, for example:

	gdlv rr:run <program file> <program's arguments...>

Executes "gdlv run" using mozilla rr has a backend.

Options must appear before the command and include:

	-d <dir>	builds inside the specified directory instead of the current directory (for debug and test)
	-tags <taglist>	list of tags to pass to 'go build'

 

아래 파일을 가지고 디버깅을 해보겠습니다.

$ ls
hello.go
package main

import (
  "fmt"
  "os"
)

const (
  defaultName="yoon"
)

func disPlayHello(str string) {
  fmt.Println("Hello", str)
}

func main() {
  name := defaultName
  
  if len(os.Args) > 1 {
    name = os.Args[1]
  } 

  
  displayHello(name) 
}

위 코드는 인자 값이 없다면 "Hello yoon"을 출력하고 인자값이 있다면 "Hello 인자 값"을 출력하는 코드입니다.

728x90

 

yoongrammer라는 인자 값을 추가하여 gdlv를 실행해 보겠습니다.

$ gdlv run ./hello.go yoongrammer

위와 같은 화면이 실행되고 command창에 command를 입력하여 디버깅을 할 수 있습니다.

default로 4개의 창이 뜹니다.(Listing, Command, Stacktrace, Variables)

 

command 종류를 보고 싶다면 help를 입력하시면 사용할 수 있는 command 목록이 출력되니 확인해 보시기 바랍니다. (n : next , q : 종료...)

Command 창 우측 상단에 NEW WINDOW를 이용하면 여러 가지 정보(global 변숫값, 고루틴 등)를 새로운 창을 열어서 확인할 수 있습니다.

Command 창에 config 명령어를 입력하면 스킨 및 화면 크기 등을 조절할 수도 있습니다.

728x90

'언어 > Go 언어' 카테고리의 다른 글

[Go] Handle, Handler , HandleFunc 이해  (0) 2020.11.26
[Go] HTTP Server 만들기  (0) 2020.11.24
Delve - Go언어 디버거  (0) 2020.11.13
[Go] 채널 방향, 채널 버퍼링, Select  (0) 2020.11.06
[Go] 채널(Channel) 이란?  (0) 2020.11.05
Comments