Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting info about threads in gdb/ddd

I am debugging a multi threaded application using ddd.

At the same time each second I can see on DDD console out that a new thread is created

 [NewThread 0x455fc940 (LWP 27373)]

and destroyed immediately after it.

 [Thread 0x455fc940  (LWP 27373) exited]

After few minutes I have this text out

 [NewThread 0x455fc940 (LWP 27363)]
 [Thread 0x455fc940  (LWP 27363) exited]
 [NewThread 0x455fc940 (LWP 27367)]
 [Thread 0x455fc940  (LWP 27367) exited]
 [NewThread 0x455fc940 (LWP 27373)]
 [Thread 0x455fc940  (LWP 27373) exited]
 ...and so on..

with this LWP increasing.

The threas comes and go too fast to be displayed using the window I got clicking on Status->Thread. Can you address me a bit about how to get information about that thread?

Do you know why this LWP is increasing all the time? More important how to get the function that is lunched into that thread?

Thank you all AFG

like image 699
Abruzzo Forte e Gentile Avatar asked Jan 14 '11 12:01

Abruzzo Forte e Gentile


People also ask

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.

Is GDB multithreaded?

GDB provides these facilities for debugging multithreaded programs: thread threadno , a command to switch between threads. info threads, a command to inquire about existing threads. thread apply [ threadno ] [ all ] args , a command to apply a command to a list of threads.

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.

How do I list breakpoints in GDB?

You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.


2 Answers

LWP is an acronym and stands for Light Weight Process. It is in effect the thread ID of each newly spawned thread.

On what to do about those spawning and dying threads: you could try set a break point at clone, which is he system call (? am I correct?) which starts a new thread at a given function.

Note: When breaking at clone you know from where the thread will be started, but don't actually have a thread, you can then however set break points at the functions given as argument to clone...

That is, start your program from gdb or ddd with the start command, which sets a temporary break point at the program entry point (i.e. main), than set a break point at clone, continue and see what happens ;).

Update: setting a break point at clone works for me... at least in my test. I should add that this is linux specific - and is actually what pthread_create uses.

like image 115
Marcus Borkenhagen Avatar answered Sep 29 '22 11:09

Marcus Borkenhagen


Set a breakpoint at pthread_create.

(gdb) break pthread_create
Breakpoint 1 at 0x20c49ba5cabf44

Now when you run it, it will stop execution when the next call to create a thread happens, and you can type where to see who the caller was.

like image 27
EmeryBerger Avatar answered Sep 29 '22 10:09

EmeryBerger