I am trying to set a breakpoint in linux in gdb for a program creating threads. I would like to set a breakpoint on thread creation, but unfortunately pthread_create
is a versioned symbol, and I can't get its full name.
If I type:
catch thread_start
I get
Catch of thread_start not yet implemented
How is the best way to catch thread creation in gdb for this situation?
Use the qualifier ' thread thread-id ' with a breakpoint command to specify that you only want GDB to stop the program when a particular thread reaches this breakpoint. The thread-id specifier is one of the thread identifiers assigned by GDB, shown in the first column of the ' info threads ' display.
By default, GDB stops all threads when any breakpoint is hit, and resumes all threads when you issue any command (such as continue , next , step , finish , etc.) which requires that the inferior process (the one you are debugging) start to execute.
Use the "info threads" command to see the IDs of currently known threads. The GDB thread debugging facility allows you to observe all threads while your program runs--but whenever GDB takes control, one thread in particular is always the focus of debugging. This thread is called the current thread.
The operating system's lightweight process (LWP) ID value for the thread. This ID is used in part for the OS to keep track of this thread for scheduling purposes. The GDB ID for the thread. This is the ID to use when specifying a specific thread in GDB commands.
Try this:
(gdb) b __pthread_create_2_1
Or build your own GDB
with this patch applied.
Or try the latest pre-release GDB
here, which should allow you to do "catch syscall clone"
OK, so in case I didn't really understand you, or my first answer wasn't helpful, do this:
(gdb) info func pthread_create
All functions matching regular expression "pthread_create":
Non-debugging symbols:
0x080485e0 pthread_create
0x080485e0 pthread_create@plt
0x00786590 __pthread_create_2_1
0x00786590 pthread_create@@GLIBC_2.1
0x00786ee0 __pthread_create_2_0
0x00786ee0 pthread_create@GLIBC_2.0
Now pick the symbol that you think is the right one, and set a breakpoint there. Don't pick the ones that have "@" in them, but one of the ones that has digits and underscores, such as 1__pthread_create_2_1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With