16
16

More than 5 years have passed since last update.

VSCode に Go のデバッグ環境を整備する(Mac編)

Posted at

今日は、Go のしょーもないデバッグに一日を費やした。まさになんの成果もありませんでしたとはこのことだ。この過程でデバッグが辛かったので、デバッガなしでは無理や!と思い立って、Visual Studio Code に デバッグ環境を構築しようとしたら、意外と苦労したので、その内容をメモしておきたい。

環境

  • macOS Sierra version 10.12.6
  • XCode Version 8.3.3
  • 1.15.1

lldb-server がないと怒られる

could not launch process: exec: "lldb-server": executable file not found in $PATH

どうやらdelve で使ってるっぽい。LLDB次世代のハイパフォーマンスデバッガとこのこと。

Need documentation for lldb-server

上記のIssueを参考に、実際はあったので、リンクを貼ってパスを通す。

ln -s /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/lldb-server /usr/local/bin/lldb-server

delve

delve は go のデバッガで、こいつを、VSCode は使っているので、インストールする必要がある。

GitHub のサイトによると、brew でインストールできるらしい。と言うわけでインストール

$ brew install go-delve/delve/delve
==> Installing delve from go-delve/delve
==> Downloading https://github.com/derekparker/delve/archive/v1.0.0-rc.1.tar.gz
Already downloaded: /Users/ushio/Library/Caches/Homebrew/delve-1.0.0-rc.1.tar.gz
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.c
==> [SUDO] Installing dlv-cert as root
==> sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.
Last 15 lines from /Users/ushio/Library/Logs/Homebrew/delve/02.sudo:
2017-08-29 16:27:23 +0900

sudo
security
add-trusted-cert
-d
-r
trustRoot
-k
/Library/Keychains/System.keychain
dlv-cert.cer


If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
https://github.com/go-delve/homebrew-delve/issues

なんか落ちとるがな、、、探しているものがキーチェーンに無いと。Google 先生に聞くと、女神のポストが

この通りでうまくいって、無事インストール終了。

$ cd /Users/ushio/Library/Caches/Homebrew/delve-1.0.0-rc.1/scripts
$ ./gencert.sh
Password:
$ brew install go-delve/delve/delve 

ご想像の通り、このスクリプトは、証明書を作成して、キーチェーンに打ち込むもの。

これでどや!

Connection failed

Fail to connect to debugger

どうやら delve にバグがあるらしく、最新のでないとあかんぽい。

brew unlink delve && brew install go-delve/delve/delve --HEAD

segmentation fault

しかし、デバッグをしてみると、 Segmentation fault... なんでやねん。はよ、俺にデバッグさせて、、、

could not launch process: stub exited while attempting to connect: signal: segmentation fault
Process exiting with code: 1

ここで、おのおっさんは、みなさんに一蹴されます。そもそも、delve command 手で叩いて動く?と。

dlv debug main.go

もちろん同じエラーが出て、

VS Code じゃなくて、あんたの、delve の環境の問題よ。

とのこと。

could not launch process: dial tcp :50889: getsockopt: connection refused
Process exiting with code: 1

で、最終的にどうかと言うと、コマンドラインツールをダウンロードして入れると解決。ちゃんと、OS と、XCode のバージョンに合わせたものを入れる。

Download for Apple Developers

終わりに

新しい Mac だったので、環境構築すんでなかったけど、よくわかってないのに、delve 周りでたくさん問題出たのは辛かった、、、もしかすると、最初から Command Line Tools が入っていれば問題が出なかったのだろうか。知らんけど、メモしておく。

16
16
1

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
16
16