LoginSignup
4
2

More than 5 years have passed since last update.

gvm+delveなVisualStudioCodeでのデバッグ環境構築

Last updated at Posted at 2016-12-07

golangの環境構築時なかなかめんどくさかったのでメモ

対象者: golangをVisualStudioCodeで実行する環境を欲する人
前提: gvmを使っている人

VisualStudioCodeの設定

<ワークスペース>/.setting/setting.json$GOPATH,$GOROOTなどを設定する
gvm で適切に設定した後に go env で出力した値を設定する

VisualStudioCodeのUIに沿って関連プラグインをインストールしようとしても失敗する
ため setting.json に設定したら手元で go get -u -v して引っ張ってくる必要がある

go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-find-references
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols

delveのインストール

Macでインストールする場合

ググると証明書を用意してビルドしている手順があるがこれは鬼門なのであまりやらない方が良い
gvm で環境を切り替えている場合は各環境にdelveをインストールする必要が
あるのでその手順を示す

公式ドキュメント にある通り、brew install を用いてインストールする
しかし、これでは各環境にはdelveはインストールされないため、各環境でdelveを
インストールする必要がある

下記のように、brew installすると dlv-cert という名称の証明書が生成されるので
その生成された証明書を用いて各環境のビルド&インストールを行うと楽
(めんどくさい証明書作成をbrew installに任せる)

$ git clone https://github.com/derekparker/delve 【まずはビルドするためのソースを引っ張る】
Cloning into 'delve'...
remote: Counting objects: 7964, done.
remote: Total 7964 (delta 0), reused 0 (delta 0), pack-reused 7964
Receiving objects: 100% (7964/7964), 10.85 MiB | 525.00 KiB/s, done.
Resolving deltas: 100% (4749/4749), done.
Checking connectivity... done.
$ brew install go-delve/delve/delve 【brewでインストールする(証明書のインストールをbrewに任す)】
〜〜略〜〜
==> Tapping go-delve/delve
Cloning into '/usr/local/Homebrew/Library/Taps/go-delve/homebrew-delve'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
Checking connectivity... done.
Tapped 1 formula (32 files, 40.8K)
==> Installing delve from go-delve/delve
==> Installing dependencies for go-delve/delve/delve: go
==> Installing go-delve/delve/delve dependency: go
==> Downloading https://homebrew.bintray.com/bottles/go-1.7.4.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring go-1.7.4.el_capitan.bottle.tar.gz
==> Caveats
As of go 1.2, a valid GOPATH is required to use the `go get` command:
  https://golang.org/doc/code.html#GOPATH

You may wish to add the GOROOT-based install location to your PATH:
  export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
🍺  /usr/local/Cellar/go/1.7.4: 6,438 files, 250.7M
==> Installing go-delve/delve/delve
==> Downloading https://github.com/derekparker/delve/archive/v0.11.0-alpha.tar.gz
==> Downloading from https://codeload.github.com/derekparker/delve/tar.gz/v0.11.0-alpha
######################################################################## 100.0%
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
==> Generating dlv-cert
==> openssl req -new -newkey rsa:2048 -x509 -days 3650 -nodes -config dlv-cert.cfg -extensions codesign_reqext -batch -out dlv-cert.cer -keyout dlv-cert.key
==> [SUDO] Installing dlv-cert as root
==> sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain dlv-cert.cer
Password: 【ここで端末のパスワードを入力する】
==> sudo security import dlv-cert.key -A -k /Library/Keychains/System.keychain
==> [SUDO] Killing taskgated
==> sudo pkill -f /usr/libexec/taskgated
==> make build BUILD_SHA=v0.11.0
==> Caveats
If you get "could not launch process: could not fork/exec", you need to try
in a new terminal.

When uninstalling, to remove the dlv-cert certificate, run this command:

    $ sudo security delete-certificate -t -c dlv-cert /Library/Keychains/System.keychain

Alternatively, you may want to delete from the Keychain (with the Imported private key).

==> Summary
🍺  /usr/local/Cellar/delve/0.11.0: 6 files, 7.4M, built in 29 seconds
$ gvm list

gvm gos (installed)

   go1.4
   go1.5
   go1.5.4
   go1.6.3
   go1.7.3
   system
$ gvm use go1.6.3 【各環境に切り替えてインストールしていく】
$ go get github.com/derekparker/delve/cmd/dlv
$ CERT=dlv-cert make install
go install -ldflags="-s -X main.Build=6bff4d19706b46b7bd350212048e4a140caad271" github.com/derekparker/delve/cmd/dlv
codesign -s "dlv-cert"  /Users/okayayohei/.gvm/pkgsets/go1.6.3/global/bin/dlv
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2