スタックトレース

D言語/スタックトレース(http://tinyurl.com/5ougv) via http://d.hatena.ne.jp/ABA/20041102#p1

このへんの与太話が生きているようなのが嬉しい。

なるほどメソッドの行さえ見えればそれなりに使えるのか。 mlpp で各行ごとに行番号をインクリメントして…なんていうことをやろうかと思ってた。この手のことをやる気が起きないのは Linux ではスタックトレース位余裕で見えてるからなんだよねぇ…

i@u ~/wrk/sino> cat raise.d
void f() {
  throw new Error("hoge");
}

int main() {
  f();
  return 0;
}
i@u ~/wrk/sino> dmd -g raise
gcc raise.o -o raise -g -lphobos -lpthread -lm
i@u ~/wrk/sino> gdb raise
GNU gdb Red Hat Linux (6.0post-0.20040223.19rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) b '_d_throw@4'
Breakpoint 1 at 0x804a389
(gdb) run
Starting program: /home/i/wrk/sino/raise
Error while mapping shared library sections:
: 成功です.
Error while reading shared library symbols:
: そのようなファイルやディレクトリはありません.
[Thread debugging using libthread_db enabled]
[New Thread -1208033152 (LWP 1380)]
Error while reading shared library symbols:
: そのようなファイルやディレクトリはありません.
Error while reading shared library symbols:
: そのようなファイルやディレクトリはありません.
[Switching to Thread -1208033152 (LWP 1380)]

Breakpoint 1, 0x0804a389 in _d_throw@4 ()
(gdb) where
#0  0x0804a389 in _d_throw@4 ()
#1  0x0804a20c in _D5raise1fFZv ()
#2  0x0804a218 in _Dmain () at raise.d:6
#3  0x0804a928 in main ()

f() の中の行数は見えないようだ。ちなみに gdc なら、

(gdb) where
#0  _d_throw () at ../../gcc/d/phobos/gcc/deh.d:105
#1  0x080492d8 in _D5raise1fFZv () at raise.d:2
#2  0x080492e5 in _Dmain () at raise.d:6
#3  0x08049a5a in true_main () at ../../gcc/d/phobos/internal/dmain2.d:102
#4  0x080499ce in main () at ../../gcc/d/phobos/internal/dmain2.d:49

という程度は出ますし、一行実行とかもだいたいできてしまう。

ただまぁ、できるにも関わらず、めったにこんなことしないんだよね…だって自分のコードの落ちる位置とかだいたいわかるし…

なにかあれば下記メールアドレスへ。
shinichiro.hamaji _at_ gmail.com
shinichiro.h