Debugging multithreaded program using gdb
You may find this useful in writing breakpoint conditional expressions, command scripts, and so forth. See Convenience Variables , for general information on convenience variables. If GDB detects the program is multi-threaded, it augments the usual message about stopping at a breakpoint with the ID and name of the thread that hit the breakpoint. Display information about one or more threads. With no arguments displays information about all threads.
You can specify the list of threads that you want to display using the thread ID list syntax see thread ID lists. Otherwise, only thread-num is shown. Make thread ID thread-id the current thread. GDB responds by displaying the system identifier of the thread you selected, and its current stack frame summary:. The thread apply command allows you to apply the named command to one or more threads. Specify the threads that you want affected using the thread ID list syntax see thread ID lists , or specify all to apply to all threads.
To apply a command to all threads in descending order, type thread apply all command. To apply a command to all threads in ascending order, type thread apply all -ascending command.
The flag arguments control what output to produce and how to handle errors raised when applying command to a thread. If several flags are provided, they must be given individually, such as -c -q.
By default, GDB displays some thread information before the output produced by command , and an error raised during the execution of a command will abort thread apply. The following flags can be used to fine-tune this behavior:. That is, the execution continues, but the thread information and errors are not printed. This could mean changing the order of resource acquisition as someone has pointed out but really there isn't a general method it will need extra information about the design of the application to understand how to remove the cyclic dependency in the wait graph.
There are circumstances where a cycle may not be the cause of the problem for example your system maybe waiting for user input that will never come hands up anyone who has seen a call to MessageBox for a process running as a service. Some platforms support pstack. I have not done this, but I think you can use gdb to generate core of your application at the moment it is hung. You can try debugging this core using the gdb itself and see for yourself what threads are blocked where?
The above is possible in linux platforms. Not sure, if cygwin on windows can be used for the same purpose. Of course, strategically placed cout statements or other output alternatives are always an option but often far from ideal. You can attach to a running process and the source code or simply run the program in the debugger to start with.
Then look at the stack. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 12 years, 3 months ago. Active 2 years, 7 months ago. Viewed 13k times. Improve this question. What in environment are you developing? It would be really great if you can talk about both the environments.
Debuggging is fun and a challenge in both the environments. As you don't get cores automatically on Windows, it is more challenging in Windows. People may have other opinions — pankajt. Add a comment. I'm looking for one that includes simple examples. In supplement to the various gdb tutorials out there I would really advise using "watch" alot in multi-threaded debugging. You can find it here. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 12 years, 2 months ago. Active 1 year, 8 months ago. Viewed 46k times.
Improve this question.
0コメント