Search code examples
multithreadinggdbparent-childcoredump

Find the main thread while debugging core file


I have a program, where main threads creates lots of threads. It crashed, and I'm debugging core file. Crash happened in one of child threads. In order to find the reason, I need to know whether the main thread is still alive. Is there any way to find out which thread was the initial one?


Solution

  • Is there any way to find out which thread was the initial one?

    When there are 100s of threads, I use the following technique to look through them:

    (gdb) shell rm gdb.txt
    (gdb) set logging on   # GDB output will go to gdb.txt
    (gdb) thread apply all where
    

    Now load gdb.txt into your editor or pager of choice, look for main, etc.