How to debug a rare deadlock?

后端 未结 2 2019
心在旅途
心在旅途 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:34

    If this is some kind of homework - restarting again and again with more debug will be a reasonable approach.

    If somebody pays money for every hour you wait, they might prefer to invest in a software that supports replay-based debugging, that is, a software that records everything a program does, every instruction, and allows you to replay it again and again, debugging back and forth. Thus instead of adding more debug, you record a session during which a deadlock happens, and then start debugging just before the deadlock happened. You can step back and forth as often as you want, until you finally found the culprit.

    The software mentioned in the link actually supports Linux and multithreading.

    0 讨论(0)
  • 2021-02-13 01:39

    There are 2 basic ways:

    1. Automate the running of program under debugger. Using gdb program -ex 'run <args>' -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 <program> <pid> 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.

    0 讨论(0)
提交回复
热议问题