Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch to thread using GDB

I debug a multi thread process using GDB.

When I pause the debug to run some commands in GDB termial, how can I switch to another thread context?

When I stop debugging GDB is always on the main thread, but I want to switch for example to thread 1234

like image 831
Kokomelom Avatar asked Feb 20 '26 09:02

Kokomelom


1 Answers

you can get thread_id from this command, such as "helloworld" thread

ps -o comm,tid -T `pgrep your_process_name` | grep helloworld
helloworld 12345

and lookup for thread number of it in gdb

gdb attach `pgrep your_process_name`
thread find 12345
Thread 3 has target id 'LWP 12345'

then switch to it

thread 3
like image 95
Nroskill Avatar answered Feb 23 '26 10:02

Nroskill