How to debug a rare deadlock?

后端 未结 2 2061
心在旅途
心在旅途 2021-02-13 01:10

I\'m trying to debug a custom thread pool implementation that has rarely deadlocks. So I cannot use a debugger like gdb because I have click like 100 times \"launch\"

2条回答
  •  耶瑟儿~
    2021-02-13 01:39

    There are 2 basic ways:

    1. Automate the running of program under debugger. Using gdb program -ex 'run ' -ex 'quit' should run the program under debugger and then quit. If the program is still alive in one form or another (segfault, or you broke it manually) you will be asked for confirmation.
    2. Attach the debugger after reproducing the deadlock. For example gdb can be run as gdb to attach to running program - just wait for deadlock and attach then. This is especially useful when attached debugger causes timing to be changed and you can no longer repro the bug.

    In this way you can just run it in loop and wait for result while you drink coffee. BTW - I find the second option easier.

提交回复
热议问题