LoginSignup
4
4

More than 5 years have passed since last update.

golang と gdb (macで)

Posted at

環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.9.5

$ go version
go version go1.4.2 darwin/amd64

参照

go1.4はdwarfが壊れていたのがなおったみたい。

gdb の install

mervericks は もうgdb入ってない

$ brew install homebrew/dupes/gdb
$ gdb -v
GNU gdb (GDB) 7.9
Copyright (C) 2015 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-darwin13.4.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".

ok

ビルドするときに オプション をつける

$ go build -o ./a -gcflags "-N -l" main.go

ok

ちらうら

https://golang.org/cmd/ld/
-ldflagsに-wつけるとdwarfが含まれなくなってバイナリがちょっと縮む

-w -s!

gdbで起動

$ gdb ./a

$GOROOT/src/runtime/runtime-gdb.py
が読み込まれるはずだが、go1.4.2だとうまく動かなかった。

自分の環境ではこれが原因でした。

実行しようとしておこられたら

(gdb) r
Starting program: /Users/a12508/workspace/madrid-deploy/madrid-web/app/t/a
Unable to find Mach task port for process-id 43426: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))

こちらを参照して自己証明書を作成する

権限問題などで[System]で作れないときは[Login]でも大丈夫だけれど

$ sudo gdb a

のようにgdbを起動しないといけなくなる

完了したら、brew install したgdbに署名する

$ codesign -s gdb-cert /usr/local/Cellar/gdb/7.9/bin/gdb

証明書が見つからない時は taskgated が証明書を認識するように再起動する

(killすると勝手に再起動する. hupはためしていない)

$ pgrep taskgated
13
$ sudo pkill -KILL taskgated
Password:
$ pgrep taskgated
44791

スゲーッ 爽やかな気分だぜ
新しいパンツをはいたばかりの 正月元旦の朝のよーによォ~ッ
(もうprintデバッグしなくていいかとおもうと)

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