gdb kernel debug的进程断点

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-Funs

b 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值