GDB Multi-threaded debugging http://hi.baidu.com/hcq11/blog/item/9f5bfc6e696209d680cb4a25.html
Http://hi.baidu.com/litto/blog/item/759389dd198111375882dd1e.html
Http://blogold.chinaunix.net/u3/94700/showart_2389432.html < recommended reading >
First, we introduce the basic command of GDB multi-threaded debugging.
Info Threads shows all threads currently available for debugging, each with a GDB-assigned ID, which is used when the thread is being manipulated. Previous * is the thread that is currently being debugged.
The thread ID Toggles the currently debugged thread for the specified ID.
Break thread_test.c:123 Thread all sets a breakpoint on the corresponding line in all threads
thread apply ID1 ID2 command to have one or more threads execute GDB commands.
The thread apply all command lets all the debugged threads execute GDB command commands.
The set scheduler-locking off|on|step estimate is that anyone who has actually used multithreaded debugging can find that other threads are executing at the same time using the step or Continue command to debug the currently debugged thread. How do you just let the debugger execute it? This requirement can be achieved with this command. Off does not lock any threads, that is, all threads are executed, which is the default value. On only the currently debugged program will execute. Step in a single step, in addition to the case of next over a function (the person familiar with the situation may know that this is actually a set breakpoint and then continue behavior), only when the front-thread will execute.
GDB has the following support for debugging multi-threaded threads:
- Thread Generation Notification: GDB gives a hint when a new thread is generated
(GDB) R
Starting program:/root/thread
[New Thread 1073951360 (LWP 12900)]
[New Thread 1082342592 (LWP 12907)]---The following three new threads are created
[New Thread 1090731072 (LWP 12908)]
[New Thread 1099119552 (LWP 12909)]
- View Threads: Use info threads to view the threads that are running.
(GDB) Info threads
4 Thread 1099119552 (LWP 12940) 0xffffe002 in?? ()
3 Thread 1090731072 (LWP 12939) 0xffffe002 in?? ()
2 Thread 1082342592 (LWP 12938) 0xffffe002 in?? ()
* 1 Thread 1073951360 (LWP 12931) Main (argc=1, argv=0xbfffda04) at thread.c:21
(GDB)
Note that the blue text at the beginning of the line is the thread number assigned by GDB, which is used when switching threads, instead of the green number indicated above.
In addition, the red asterisk at the beginning of the line identifies the currently active thread
- Toggle Thread: Use thread threadnumber to switch threadnumber to the thread number mentioned above. The following example shows switching the active thread from 1 to 4.
(GDB) Info threads
4 Thread 1099119552 (LWP 12940) 0xffffe002 in?? ()
3 Thread 1090731072 (LWP 12939) 0xffffe002 in?? ()
2 Thread 1082342592 (LWP 12938) 0xffffe002 in?? ()
* 1 Thread 1073951360 (LWP 12931) Main (argc=1, argv=0xbfffda04) at thread.c:21
(GDB) Thread 4
[Switching to thread 4 (thread 1099119552 (LWP 12940)]) #0 0xffffe002 in?? ()
(GDB) Info threads
* 4 Thread 1099119552 (LWP 12940) 0xffffe002 in?? ()
3 Thread 1090731072 (LWP 12939) 0xffffe002 in?? ()
2 Thread 1082342592 (LWP 12938) 0xffffe002 in?? ()
1 Thread 1073951360 (LWP 12931) Main (argc=1, argv=0xbfffda04) at thread.c:21
(GDB)
The following is directly in your thread function to set a breakpoint, and then continue to that breakpoint, generally multi-threaded, because it is running at the same time, it is best to set scheduler-locking on
In this case, only the current thread is debugged
GDB multithreaded debugging