Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically identify the thread ID printed in GDB

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

like image 842
Heshan Perera Avatar asked Sep 29 '22 05:09

Heshan Perera


People also ask

How to check 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.

How do I find the process thread ID?

In the GNU C Library implementation running on Linux, the process ID is the thread group ID of all threads in the process. You can get the process ID of a process by calling getpid . The function getppid returns the process ID of the parent of the current process (this is also known as the parent process ID).

Does a thread have an ID?

In some threads implementations, the thread ID is a 4-byte integer that starts at 1 and increases by 1 every time a thread is created. This integer can be used in a non-portable fashion by an application.

What is the thread ID?

Thread Id is a long positive integer that is created when the thread was created. During the entire lifecycle of a thread, the thread ID is unique and remains unchanged. It can be reused when the thread is terminated.


1 Answers

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();
like image 152
WaeCo Avatar answered Oct 06 '22 18:10

WaeCo