gdb を使ったデバッグ

macOS での方法の忘備録。


brew なり MacPorts で入れてコード署名をする必要がある。
OS XでGDBを使う(ためにコード署名をする)


taskgated を再起動するの忘れててしばらく使えなくて混乱した。
普通に pkill すれば良い。


Vimデバッグオプション付きでビルドする。

CFLAGS="-g -O0 -ggdb" LDFLAGS=-L/opt/local/lib ./configure --with-features=huge \
--enable-multibyte \
--enable-netbeans \
--with-tlib=ncurses \
--enable-cscope \
--enable-python3interp \
--enable-rubyinterp

終わったら make してビルドする。

src/vim にバイナリが出来上がってるので、gdb 経由で起動する。
(MacPorts を使ったので gddb になってる)

$ ggdb src/vim
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 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-darwin15.6.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"...
Reading symbols from src/vim...done.
(gdb) 

起動できた。

ブレークポイントを SEGV してるところの前らへんに適当にはる。

b channel.c:4153

デバッグするため Vim を起動する。

run -u NONE -U NONE ~/sample.txt

Vim を -u NONE -U NONE オプションで ~/sample.txt を開く。
Vim を操作しブレークポイントを張った箇所を通る操作をする。
あとは n とか step とか p とかで適当にデバッグしていく。