LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Thread names in GDB (https://www.linuxquestions.org/questions/programming-9/thread-names-in-gdb-4175510099/)

sree_ec 07-04-2014 08:10 AM

Thread names in GDB
 
Hi,

I was trying to set names to specific threads in a multi threaded application. This is to make sure that the debugging becomes easy when we debug the app. I tried using the function prctl(2) for the same purpose. Stil thread name doesnt appear when I try
(gdb) thread apply all bt


Currently the o/p of the above command is something like what I have pasted below
Quote:

Thread 2 (process 980):
#0 0x2aabd524 in ?? ()
I would like to see it as

Quote:

Name (process 980):
#0 0x2aabd524 in ?? ()

or
Quote:

Thread 2 (process Name):
#0 0x2aabd524 in ?? ()

is this possible?

this is how I used the function
Quote:

prctl(PR_SET_NAME, (unsigned long) "Name", 0, 0, 0);
Thanks

smallpond 07-08-2014 12:17 PM

You won't see thread names unless you compile with debug symbols. For gcc that's the "-g" switch.

sree_ec 07-09-2014 01:29 AM

Quote:

Originally Posted by smallpond (Post 5200590)
You won't see thread names unless you compile with debug symbols. For gcc that's the "-g" switch.


I clearly see debug symbols in my program as I have compiled it with -g option as you said.
But still I dont see a name.
My requirement is I should be able to set a name and then the name should appear on GDB for each thread.

if you are referring to ?? in my first post, I edited the actual function names which was appearing on gdb to ??

rtmistler 07-10-2014 07:33 AM

Haven't spent much time worrying over thread NAMES in GDB. Your attempt appeared to be a fair one; however it didn't work. I've always seen it in the "Thread # (Process #)" form. I would think that you'd have better success modifying GDB source and recompiling it so that it would do what you want; however you'd have to determine if the PR_SET_NAME gave symbol information sufficient enough for GDB's use. That is the core problem IMHO. The process name is dynamic, not sure that it is available to the symbol table.


All times are GMT -5. The time now is 09:30 AM.