Wednesday, October 7, 2009

Threads in GDB

I was recently facing some issue with a multi threaded program. The program was getting terminated because one thread was dying and it was causing a broken pipe in other threads. Now, there were multiple threads that are opening a pipe. The program had quite a few number of threads. Hence I could not find out which thread was misbehaving and causing the entire application to fail. However, this made me to look into threads support in GDB.

I found the following interesting articles on the net on debugging threads using gdb.

Here is a summary of commands

1. info threads
Shows information on threads

2. thread
Allows you to switch to that thread. Then you can do a bt or something similar

3. break file.c:lineno thread if condition
Allows to set a break point conditionally for a specific thread

4. set print thread-events on
Turns on printing entry and exit of a thread

5. thread apply args
Applies a command to a thread/all threads

I still don't know how to tackle my issue of dying thread. However, I expect a combo of 3,4 might shed some light. I will post the details tomorrow after trying.

No comments: