使用 GDB 除錯內建函式

從 V8 v6.9 開始,可以在 GDB(以及其他除錯器)中建立中斷點,以除錯 CSA/ASM/Torque 內建函式。

(gdb) tb i::Isolate::Init
Temporary breakpoint 1 at 0x7ffff706742b: i::Isolate::Init. (2 locations)
(gdb) r
Thread 1 "d8" hit Temporary breakpoint 1, 0x00007ffff7c55bc0 in Isolate::Init
(gdb) br Builtins_RegExpPrototypeExec
Breakpoint 2 at 0x7ffff7ac8784
(gdb) c
Thread 1 "d8" hit Breakpoint 2, 0x00007ffff7ac8784 in Builtins_RegExpPrototypeExec ()

請注意,使用臨時中斷點(GDB 中的捷徑為 tb)會比使用一般中斷點(br)更適合這個情況,因為你只需要在程序啟動時使用它。

內建函式也會顯示在堆疊追蹤中

(gdb) bt
#0  0x00007ffff7ac8784 in Builtins_RegExpPrototypeExec ()
#1  0x00007ffff78f5066 in Builtins_ArgumentsAdaptorTrampoline ()
#2  0x000039751d2825b1 in ?? ()
#3  0x000037ef23a0fa59 in ?? ()
#4  0x0000000000000000 in ?? ()

注意事項