Skip to content

Instantly share code, notes, and snippets.

@guangxuanliu
Last active November 6, 2022 13:05
Show Gist options
  • Save guangxuanliu/0416c38ea7a71d7675420994c3be66c9 to your computer and use it in GitHub Desktop.
Save guangxuanliu/0416c38ea7a71d7675420994c3be66c9 to your computer and use it in GitHub Desktop.
gdb调试死锁技巧

死锁问题调试技巧:

自动方式

  1. 下载deadlock.py

https://github.com/facebook/folly/blob/main/folly/experimental/gdb/deadlock.py

  1. 用gdb附加到死锁的程序

    gdb attach pid

  2. 加载deadlock.py

    source -v /xxx/deadlock.py

  3. 调用脚本,输出死锁位置

    deadlock

手动方式

上述deadlock.py要求安装python3,对gcc好像也有要求,在CentOS7上试了不行,所以需要用手动的方式打印

  1. 用gdb附加到死锁的程序

    gdb attach pid

  2. 查看死锁的线程

    最后一帧显示__lll_lock_wait

  3. 查看代码,找出mutex变量的名字,如g_mutex

  4. 打印g_mutex

    p g_mutex,会显示出来持有线程id:__owner = xxx

    即发生死锁线程

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment