揮発性のメモ2

http://d.hatena.ne.jp/iww/

コアを使ったデバッグ

コアのファイル名を指定する

# echo "/tmp/%e.core" > /proc/sys/kernel/core_pattern

http://www.linux.or.jp/JM/html/LDP_man-pages/man5/core.5.html

コアを吐くよう設定する

$ ulimit -c unlimited

【 ulimit 】 コマンドに割り当てる資源を制限する | 日経 xTECH(クロステック)
interest of mia: linux coreを吐かない設定
コアを吐かせたいプログラムがデーモン経由の実行ファイル(CGIとか)のときは、起動スクリプトstart-stop-daemonとか)の中に書く

コアを吐くプログラムを書く

 1: void hoge(int *a,int b)
 2: {
 3:     printf("a=%x,b=%d\n",a,b);
 4:     *a=b;
 5: }
 6: 
 7: int main()
 8: {
 9:     int *a;
10:     hoge(a,123);
11: }

コアを吐かせる

$ gcc -g test4.c
$ ulimit -c unlimited
$ ./a.out
a=8048470,b=123
セグメンテーション違反です (core dumped)

コアを眺める

$ gdb a.out /tmp/a.out.core
〜
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
〜
#0  0x080483a6 in hoge (a=0x8048470, b=123) at test4.c:4
4               *a=b;
(gdb) bt
#0  0x080483a6 in hoge (a=0x8048470, b=123) at test4.c:4
#1  0x080483e9 in main () at test4.c:13

ニコニコ動画(RC2)‐グラディウス ビッグコアの曲only いろいろな機種版メドレー