DELAEMON BLOG

Live as if you were to die tomorrow. Learn as if you were to live forever.

Apache Module Debug

作ったモジュールにClearSilverを使って表示を追加したら
コンパイルは通るがアクセスするとerror.log吐いてる

[notice] child pid 32713 exit signal Segmentation fault (11)

デバック情報が少ないのでどこで落ちているのか調べるためcoreを吐く

core file sizeが0だとcoreが吐かれない

$ ulimit -a
-t: cpu time (seconds)         unlimited
-f: file size (blocks)         unlimited
-d: data seg size (kbytes)     unlimited
-s: stack size (kbytes)        8192
-c: core file size (blocks)    0
-m: resident set size (kbytes) unlimited
-u: processes                  7826
-n: file descriptors           1024
-l: locked-in-memory size (kb) 64
-v: address space (kb)         unlimited
-x: file locks                 unlimited
-i: pending signals            7826
-q: bytes in POSIX msg queues  819200
-e: max nice                   0
-r: max rt priority            0
-N 15:                         unlimited

容量を無制限に変更

$ ulimit -c unlimited > /dev/null 2>&1
$ ulimit -a
-t: cpu time (seconds)         unlimited
-f: file size (blocks)         unlimited
-d: data seg size (kbytes)     unlimited
-s: stack size (kbytes)        8192
-c: core file size (blocks)    0
-m: resident set size (kbytes) unlimited
-u: processes                  7826
-n: file descriptors           1024
-l: locked-in-memory size (kb) 64
-v: address space (kb)         unlimited
-x: file locks                 unlimited
-i: pending signals            7826
-q: bytes in POSIX msg queues  819200
-e: max nice                   0
-r: max rt priority            0
-N 15:                         unlimited

設定追加

sudo vim /etc/apache2/apache2.conf
#適当なところに以下追記

CoreDumpDirectory /tmp

apache再起動する

アクセスするとエラーでcoreファイルができてる

$ ls -la /tmp/core
-rw------- 1 www-data www-data 230006784  426 03:20 /tmp/core

gdbで中身を見れる

$ sudo gdb /usr/sbin/apache2 -c /tmp/core
warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/usr/sbin/apache2 -k start'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007f2a7f0b7e55 in _set_value () from /usr/lib/apache2/modules/mod_hello_world.so