gdb 最常用的是在线程挂掉的时候查看现场

kernel space的deadlock 一般有debug config lock_up hard_lock  soft_lock帮助debug,userspace 发生deadlock的时候可以从现场的call stack 找到mutex 的owner帮助debug

Linux gdb debug deadlock

两个线程会互相等待对方的mutex

gcc -g deadlock.c -lpthread

./a.out  &

发生死锁后 sudo gdb attach  [pid]

通过thread 命令可以切换当前的线程,bt打印当前线程的backtrace

Linux gdb debug deadlock

可以看到 thread 2 的call stack dead.c  31行是在信号量的lock

Linux gdb debug deadlock

p mut1 查看信号量的owner

thread 1/2/3  分别是3031 3033 3032

可以看出mut1的owner 是thread 3

thread 3 然后bt 就可以查看到相互死锁的位置

相关文章:

  • 2021-09-11
  • 2021-06-16
  • 2021-10-26
  • 2022-12-23
  • 2021-12-18
  • 2021-07-27
  • 2019-10-28
  • 2022-12-23
猜你喜欢
  • 2021-11-03
  • 2021-06-29
  • 2021-07-08
  • 2021-06-06
  • 2022-12-23
  • 2021-10-04
  • 2021-11-11
相关资源
相似解决方案