To debug multithreaded programs to in case of conditions such as deadlock or livelock, what are the useful utilities? I was wondering if gcore gives the stack dump of all running threds in the process or just the main thread. Also, does gcore suspend/kill the running process? Any information on debugging multithreaded programs will be very useful.
gdb
supports switching between threads to investigate the state of everything going on. Here is some more information.
As Carl stated, gdb supports threads. Using a UI (such as one provided by Eclipse) for GDB makes this easier, but you can get thread information when running via the command line by typing "info threads". This will list the threads and allow you to switch by typing "thread 3" etc. Once you switch to a thread, you can do backtraces in order to see the current threads stack and other commands that you're used to using with a single threaded process.
gdb has some nice features for working with threads. One of my favorites is thread apply
. This allows you to run the same command for multiple threads.
For example, if you wanted to get a backtrace of all threads, you can use this:
thread apply all where
To break this down, the command starts with thread apply
.
Next is the list of threads. Here I used the keyword all
to apply this to every thread in the process. You can also use a space separated list of the gdb thread ids (thread apply 1 2 3 command
).
And finally comes the command to perform. I used where
which shows you the call stack but you can use any command you want.