0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vim の debug をやるときのメモ

Last updated at Posted at 2020-05-29

Vim に限った話ではないけれど。

diff --git a/src/Makefile b/src/Makefile
index 9b50eca6d..340d60b1a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -593,7 +593,7 @@ CClink = $(CC)
 # When using -g with some older versions of Linux you might get a
 # statically linked executable.
 # When not defined, configure will try to use -O2 -g for gcc and -O for cc.
-#CFLAGS = -g
+CFLAGS = -ggdb3
 #CFLAGS = -O

 # Optimization limits - depends on the compiler.  Automatic check in configure
@@ -1162,7 +1162,7 @@ INSTALL_DATA_R    = cp -r

 ### Program to run on installed binary.  Use the second one to disable strip.
 #STRIP = strip
-#STRIP = /bin/true
+STRIP = /bin/true

 ### Permissions for binaries  {{{1
 BINMOD = 755

ggdb3

CFLAGS にこれのみを設定することによって、debug info を GDB 用に出力するようになり、かつ最適化もやらないようになる。最適化をやめるとアセンブリ言語の内容 (つまり CPU の動作) が変わってくる。最適化が行われて、変数処理がすべてレジスタ上で完結しているような場合には optimized out されて見えなくなってしまう。-ggdb3 だけを設定するようにしておけばすべて見えるはず。

strip

STRIP には $ make install するときに実行されるプログラムを定義する。/bin/true の行をアンコメントすると、つまり strip しなくなる。strip すると symbol や section の情報が取り除かれてしまうので debug は難しくなる。

普通に build した Vim で問題が起きた場合

再現手順が分かっていて上の patch 入りでも再現する場合にはいいけれども、そうでない場合や、何の準備もなく急に問題が起きた場合の対応: 上述の通り、build した binary そのものは strip されておらず、$ make install するときに、strip された binary を配置しているようだ。なので、急に問題が起きて core dump だけが残ったというような場合でも、落ちた時の (install した) binary ではなく build した binary そのものを使えば symbol などは見れる。

$ gdb repository/vim/src/vim core-file
    とか
$ gdb -p $(pgrep vim) repository/vim/src/vim

参考文書

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?