How to programmatically identify the thread ID printed in GDB
Asked Answered
A

3

6

I am trying to debug an application written in c++, compiled for an ARM based processor running linux.

When the application intermittently crashes, it stops at a certain thread and I assume that thread is where is the fault is (segmentation fault).

My problem is, I am having trouble identifying WHAT this thread is. I see that the following printed in eclipse when GDB is running.

What are the numbers underlined in blue and is there a way for me to access them programmatically, so that I know where to look in the code ?

enter image description here

Aeromechanics answered 20/4, 2015 at 14:31 Comment(3)
Why not give your threads a name when spawning them?Thisbe
@SelçukCihan will this then show in GDB as well ?Aeromechanics
Gdb can display thread names, check link for more infoThisbe
E
4

In addition to @Heshan Perera answer.

You can also access the thread id which is the bigger number, inside your program

UNIX:

#include <sys/syscall.h>
syscall(SYS_gettid);

WINDOWS: (Not tested)

#include <windows.h>
GetCurrentThreadId();
Ecotone answered 20/4, 2015 at 16:22 Comment(0)
A
0

Based on this link posted by @Selcuk Cihan in the comment above, the first number within square brackets is an integer identifier assigned by GDB itself and the other is the SysTag assigned to the thread.

Aeromechanics answered 20/4, 2015 at 15:5 Comment(0)
H
0

A better solution, if you're on Linux/gcc, is to actually give a descriptive name to the thread with pthread_setname_np. gdb will then use this name when hitting breakpoints, and so on. Note that this is a GNU extension to pthreads.

Hathaway answered 20/1, 2017 at 9:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.