gdb調試kernel的時候, 如果設定通用函數斷點, 比如vfs_read, 就會遇到一堆撞到斷點的地方, 比如tty輸入一個字元, 就是vfs_read, 沒辦法調試具體的某一個程序
一種辦法就是條件斷點, 其實不是很好用, 比如用pid, 但是有時候這個程序還沒啟動, 比如task的comm來判定, 但是kernel中是不支援strcmp來判斷字元串是否相等, 因為需要跑函數
gdb 7.5對此問題做了增強, gdb自己去比較字元串, 而不需要機器去跑代碼
https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Funs.html#Convenience-Funsb do_fault if $_streq($lx_current()->comm, "a.out")
還可以對調用者來做條件斷點, 比如a->c, b->c, 斷點隻停在b調用c的地方
$_caller_is(name[, number_of_frames])
Returns one if the calling function’s name is equal to name. Otherwise it returns zero.
If the optional argument number_of_frames is provided, it is the number of frames up in the stack to look. The default is 1.
Example:
(gdb) backtrace
#0 bottom_func ()
at testsuite/gdb.python/py-caller-is.c:21
#1 0x00000000004005a0 in middle_func ()
at testsuite/gdb.python/py-caller-is.c:27
#2 0x00000000004005ab in top_func ()
at testsuite/gdb.python/py-caller-is.c:33
#3 0x00000000004005b6 in main ()
at testsuite/gdb.python/py-caller-is.c:39
(gdb) print $_caller_is ("middle_func")
$1 = 1
(gdb) print $_caller_is ("top_func", 2)
$1 = 1