LoginSignup
30
31

More than 5 years have passed since last update.

MacのIntelliJ IDEA でGO言語を使う③ ~GDBを使ってみる~

Last updated at Posted at 2015-01-07

MacのIntelliJ IDEA でGO言語を使う①
MacのIntelliJ IDEA でGO言語を使う②

で、とりあえず、コードが実行できるように開発環境は整った。
次は、GDBでデバックし、ブレークポインタや変数の中身を覗きたいなーと思ったので、
設定してみた。

gdbのインストール

まずは入っているか確認してみた。

$ gdb
zsh: command not found: gdb

ないじゃん。
brewであったりするのかなーと探してみた。

$brew search gdb
cgdb   gdbm   pgdbf
homebrew/dupes/gdb    Caskroom/cask/macgdbp

homebrew/dupes/gdbあるじゃん。
早速インストール。

$ brew install homebrew/dupes/gdb
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-dupes'...
remote: Counting objects: 1510, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 1510 (delta 5), reused 1 (delta 1)
Receiving objects: 100% (1510/1510), 301.52 KiB | 199.00 KiB/s, done.
Resolving deltas: 100% (830/830), done.
Checking connectivity... done.
Tapped 36 formulae
==> Installing gdb from homebrew/homebrew-dupes
==> Installing gdb dependency: xz
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/xz-5.0.7.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xz-5.0.7.yosemite.bottle.tar.gz
?  /usr/local/Cellar/xz/5.0.7: 58 files, 1.5M
==> Installing gdb
==> Downloading http://ftpmirror.gnu.org/gdb/gdb-7.8.1.tar.xz
######################################################################## 100.0%
==> Patching
patching file gdb/darwin-nat.c
==> ./configure --prefix=/usr/local/Cellar/gdb/7.8.1 --with-system-readline --with-lzma --with-python=/usr
==> make
^@^@^@==> make install
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  http://sourceware.org/gdb/wiki/BuildingOnDarwin
==> Summary
?  /usr/local/Cellar/gdb/7.8.1: 42 files, 5.7M, built in 3.1 minutes

できた。確認。

$which gdb
/usr/local/bin/gdb

$gdb --version
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin14.0.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

ただし、このままだと、ゲートキーパーというMacOSのセキュリティ設定によって、
gdbがデバックしたいプロセスにアタッチすることができません。

インストール時にも、こんなメッセージがでてきましたね。

gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  http://sourceware.org/gdb/wiki/BuildingOnDarwin

よって、証明書を作成してあげる必要があります。

証明書を作成して、適用する

1.ご存知、キーチェーンアプリを立ち上げてください。
2.証明書作成を選択

スクリーンショット 2015-01-07 15.39.18.png

3.名前を、「gdb-cert]とかにして次へ。

スクリーンショット 2015-01-07 15.40.03.png

4.その他は適当で大丈夫なので、以下の画面がでるまで、次へで進んでください。
 でたら、システムを選択。

スクリーンショット 2015-01-07 15.41.20.png

5.できた証明書をダブルクリックして、コード署名のところを「常に信頼」に変更。

スクリーンショット 2015-01-07 15.42.30.png

6.最後に以下のコマンドを打って、署名してあげてくださいな。

codesign -s gdb-cert /usr/local/Cellar/gdb/7.8.1/bin/gdb

IntelliJにgdbの設定をする。

1.Edit Configurations...を選択。

2.「debug」のタブを開いて、gdb executable

/usr/local/bin/gdb

と入力する。

スクリーンショット 2015-01-07 16.12.54.png

3.デバックモードを有効にする

runタブを選んで、Enable debuggingを有効してしてください。
グレーアウトで選べない時は、一つ上のBuild before runのチェックボッスクを付け外しすると
選べるようになります。(バグだね、これ。)

設定完了。お疲れさん。

ブレークポイント貼ってみる。

ソースコードにブレークポイントを貼って、
右上の昆虫のマークをクリック。

おーーーーー、とまった。

スクリーンショット 2015-01-07 16.17.02.png

やっぽい。

まとめ

これで、IntelliJを使って、GO言語のコーディングおよび、デバックができるようになった。
次はフレームワークでも試すかなー。

30
31
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
30
31