*iroi*

mechairoi の Blog

gdbでEmacs Lisp のスタックトレースを表示する

Emacs"で"デバッグする方法はいっぱい出てくるのに、Emacs"を"デバッグする方法が http://www.emacswiki.org/emacs/DebugEmacs くらいしかみつけられないです...

とりあえずgdbelispスタックトレースをみたいので GDBで実行中のスクリプト言語のスタックフレームをダンプしてみる試み - muddy brown thang を参考に 書いてみました。

関数(struct Lisp_Function)以外に対応してないとか, アーキテクチャ(OSX)にとても依存している気がします。

あとハッシュを計算するのが面倒なのでシンボルテーブルを引くのが欲しいです。

実行結果は以下

bt だと C の関数ばっかりでよくわからない! のが

(gdb) bt
#0  0x00007fff84a210b6 in __kill ()
#1  0x00007fff84ac19f6 in abort ()
#2  0x00000001001429d9 in die (msg=<value temporarily unavailable, due to optimizations>, file=<value temporarily unavailable, due to optimizations>, line=<value temporarily unavailable, due to optimizations>) at alloc.c:6279
#3  0x0000000100068541 in temp_output_buffer_show (buf=4762380197) at window.c:3787
#4  0x00000001001b764a in Fbyte_code (bytestr=<value temporarily unavailable, due to optimizations>, vector=<value temporarily unavailable, due to optimizations>, maxdepth=<value temporarily unavailable, due to optimizations>) at bytecode.c:888
#5  0x00000001001649b7 in funcall_lambda (fun=4737389829, nargs=1, arg_vector=0x7fff5fbfc8c8) at eval.c:3220
#6  0x0000000100164cef in Ffuncall (nargs=<value temporarily unavailable, due to optimizations>, args=<value temporarily unavailable, due to optimizations>) at eval.c:3088
#7  0x00000001001b8687 in Fbyte_code (bytestr=<value temporarily unavailable, due to optimizations>, vector=<value temporarily unavailable, due to optimizations>, maxdepth=<value temporarily unavailable, due to optimizations>) at bytecode.c:680
#8  0x00000001001649b7 in funcall_lambda (fun=4737395093, nargs=2, arg_vector=0x7fff5fbfcaa8) at eval.c:3220
#9  0x0000000100164cef in Ffuncall (nargs=<value temporarily unavailable, due to optimizations>, args=<value temporarily unavailable, due to optimizations>) at eval.c:3088
#10 0x00000001001b8687 in Fbyte_code (bytestr=<value temporarily unavailable, due to optimizations>, vector=<value temporarily unavailable, due to optimizations>, maxdepth=<value temporarily unavailable, due to optimizations>) at bytecode.c:680
#11 0x00000001001649b7 in funcall_lambda (fun=4737392117, nargs=2, arg_vector=0x7fff5fbfcc88) at eval.c:3220
#12 0x0000000100164cef in Ffuncall (nargs=<value temporarily unavailable, due to optimizations>, args=<value temporarily unavailable, due to optimizations>) at eval.c:3088
#13 0x00000001001b8687 in Fbyte_code (bytestr=<value temporarily unavailable, due to optimizations>, vector=<value temporarily unavailable, due to optimizations>, maxdepth=<value temporarily unavailable, due to optimizations>) at bytecode.c:680
#14 0x00000001001640fd in Feval (form=<value temporarily unavailable, due to optimizations>) at eval.c:2356
#15 0x0000000100163050 in internal_catch (tag=<value temporarily unavailable, due to optimizations>, func=0x100163940 <Feval>, arg=4748685078) at eval.c:1228
#16 0x00000001001b771d in Fbyte_code (bytestr=<value temporarily unavailable, due to optimizations>, vector=<value temporarily unavailable, due to optimizations>, maxdepth=<value temporarily unavailable, due to optimizations>) at bytecode.c:855
#17 0x00000001001649b7 in funcall_lambda (fun=4737350181, nargs=1, arg_vector=0x7fff5fbfd188) at eval.c:3220
#18 0x0000000100164cef in Ffuncall (nargs=<value temporarily unavailable, due to optimizations>, args=<value temporarily unavailable, due to optimizations>) at eval.c:3088
#19 0x00000001001611e1 in Fcall_interactively (function=4321459514, record_flag=4320133130, keys=4309662936) at callint.c:869
#20 0x0000000100165033 in Ffuncall (nargs=<value temporarily unavailable, due to optimizations>, args=<value temporarily unavailable, due to optimizations>) at eval.c:3037
#21 0x0000000100165386 in call3 (fn=<value temporarily unavailable, due to optimizations>, arg1=<value temporarily unavailable, due to optimizations>, arg2=<value temporarily unavailable, due to optimizations>, arg3=<value temporarily unavailable, due to optimizations>) at eval.c:2857
#22 0x00000001000e83d6 in command_loop_1 () at keyboard.c:1930
#23 0x0000000100162f47 in internal_condition_case (bfun=0x1000e7c60 <command_loop_1>, handlers=4320204266, hfun=0x1000dce90 <cmd_error>) at eval.c:1492
#24 0x00000001000dc18e in command_loop_2 () at keyboard.c:1379
#25 0x0000000100163050 in internal_catch (tag=<value temporarily unavailable, due to optimizations>, func=0x1000dc150 <command_loop_2>, arg=4320133130) at eval.c:1228
#26 0x00000001000dcc68 in command_loop () at keyboard.c:1354
#27 0x00000001000dd10f in recursive_edit_1 () at keyboard.c:963
#28 0x00000001000dd308 in Frecursive_edit () at keyboard.c:1025
#29 0x00000001000cf021 in main (argc=1, argv=0x7fff5fbfda18) at emacs.c:1858

これだとわかる!!1

(gdb) dump_emacs_bt
$7 = {
  size = 26,
  size_byte = 26,
  intervals = 0x0,
  data = 0x115a56870 "pcomplete-show-completions"
}
$8 = {
  size = 14,
  size_byte = 14,
  intervals = 0x0,
  data = 0x115a55668 "pcomplete-stub"
}
$9 = {
  size = 21,
  size_byte = 21,
  intervals = 0x0,
  data = 0x115a558b0 "pcomplete-do-complete"
}
$10 = {
  size = 9,
  size_byte = -1,
  intervals = 0x0,
  data = 0x1002c63e8 "byte-code"
}
$11 = {
  size = 9,
  size_byte = 9,
  intervals = 0x0,
  data = 0x100638d74 "pcomplete"
}
$12 = {
  size = 18,
  size_byte = -1,
  intervals = 0x0,
  data = 0x1002b6b15 "call-interactively"
}
(gdb)