Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb breakpoint on pthread_create

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?

like image 660
Juan Avatar asked Sep 17 '09 18:09

Juan


People also ask

How to put breakpoint in thread GDB?

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.

Does GDB breakpoint stop all threads?

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.

How do I get thread info in GDB?

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.

What is LWP in GDB?

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.


2 Answers

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"

like image 197
Employed Russian Avatar answered Sep 28 '22 20:09

Employed Russian


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.

like image 45
Michael Snyder Avatar answered Sep 28 '22 20:09

Michael Snyder