abrahab
abrahab

Reputation: 2500

Debugging multithread server in GDB- Find state of every thread. cont and stop while execution

I attached to my multithread application with gdb and after that type cont to continue execution.

Upvotes: 2

Views: 1043

Answers (5)

raul
raul

Reputation: 55

Is it "pstack" because i don't think "pstask" is any command in linux, If it is please provide some more info

Upvotes: 0

Jay D
Jay D

Reputation: 3307

thread apply all bt

Or

info threads

t <threadid from above trace > Followed by

where or bt

Upvotes: 2

Viktor Latypov
Viktor Latypov

Reputation: 14467

To get the backtrace for all of the stopped threads type the

thread apply all bt

command (the output is exactly the same that one might see in the MacOSX crash report box).

Usually the threads are stopped simultaneously in gdb.

Reference: http://www.delorie.com/gnu/docs/gdb/gdb_40.html

And here's about "all-stop" mode, which is default: http://sourceware.org/gdb/onlinedocs/gdb/All_002dStop-Mode.html

Upvotes: 1

Michael Anderson
Michael Anderson

Reputation: 73440

Here's what I do, (taken from here )

Create a little gdb script stackdumper.gdb that dumps the stack trace of all threads:

thread apply all backtrace

Then repeatedly attach gdb and run the dumper:

for i in $(seq 1 10) ; do
  gdb -batch -x stackdumper.gdb ./a.out 123456 > stack.$i
  sleep 10
done

where ./a.out is the binary you are interested and 123456 is the PID.

Adjust the sleep to match your sampling needs.

Upvotes: 2

user184968
user184968

Reputation:

Is this any way to stop execution at any time on cont gdb state and check what every thread do

If you ask about ways to check what threads do without gdb the you can just run
pstask <pid-of-your application>

Upvotes: 0

Related Questions