Bug 8618 - Extract the thread name
Summary: Extract the thread name
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: mi (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: 7.3
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-01-14 18:58 UTC by alain
Modified: 2011-01-19 17:26 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description alain 2004-01-14 18:58:00 UTC
[Converted from Gnats 1513]

From a discussion on the CDT Debug mailing list,
It would be nice to be able to retrieve the Thread name
part of mi, for now -thread-list-ids does not give the
information nor it gives the current thread.

> >
> > The way we determine native thread names in GDB is by using the "info threads" GDB
> > command implemented in a custom GDB remote target connection. I believe that this
> > approach is quite common in the embedded world. On Solaris, the "info threads" GDB
> > command reports the Solaris LWP id. I don't remember what OS information "info
> > threads" reports on Linux and Windows.
> >
> 
> The problem, how do you get, in a portable way, the name of a thread in gdb.
> 
> 1) GDB/MI:
> 
>      -thread-list-ids
>      ^done,thread-ids={thread-id="3",thread-id="2",thread-id="1"}, number-of-threads="3"
> 
> If this command could be enhance to provide, current selected thread and thread names,
> that would be perfect.

Release:
GDB-6.x

Environment:
Any environment
Comment 1 Mark Wielaard 2010-05-11 09:23:08 UTC
This idea was also mentioned here:
http://0pointer.de/blog/projects/name-your-threads.html

"So, now go, if you have a project which involves a lot of threads, name them
all individually, and make it easier to debug them. What's missing now, of
course, is that gdb learns this and shows the comm name when doing info threads."
Comment 2 Mark Wielaard 2010-05-11 09:31:42 UTC
Also note that glibc recently got support for getting/setting thread names for
Linux threads:
http://sourceware.org/git/?p=glibc.git;a=commit;h=86a4c67fb91b82c7b47c115b88ab01b1a696f10f

pthread_getname_np () and pthread_setname_np ()
Comment 3 Jan Kratochvil 2010-07-31 16:03:47 UTC
Related patch by Karen Osmond + former mail thread:
http://sourceware.org/ml/gdb-patches/2009-06/msg00073.html
http://sourceware.org/ml/archer/2008-q4/msg00534.html
Comment 4 Tom Tromey 2011-01-11 18:28:10 UTC
(In reply to comment #0)

[ -thread-list-ids ]
> > If this command could be enhance to provide, current selected thread and thread names,
> > that would be perfect.

-thread-list-ids is deprecated, you should use -thread-info instead.

I am working on a patch to enable thread names.
Comment 5 cvs-commit@gcc.gnu.org 2011-01-19 17:21:43 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	tromey@sourceware.org	2011-01-19 17:21:39

Modified files:
	gdb            : ChangeLog NEWS gdbthread.h linux-nat.c target.c 
	                 target.h thread.c 
	gdb/doc        : ChangeLog gdb.texinfo 
	gdb/python     : py-infthread.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.python: py-infthread.exp 
	gdb/testsuite/gdb.threads: manythreads.exp 

Log message:
	gdb
	PR mi/8618:
	* thread.c (free_thread): Free 'name'.
	(print_thread_info): Emit thread name.  Change CLI output.
	(thread_name_command): New function.
	(do_captured_thread_select): Emit newline.
	(_initialize_thread): Register 'thread name' command.
	* target.h (struct target_ops) <to_thread_name>: New field.
	(target_thread_name): New macro.
	* target.c (update_current_target): Handle to_thread_name.
	* python/py-infthread.c (thpy_get_name): New function.
	(thpy_set_name): Likewise.
	(thread_object_getset): Add "name".
	* linux-nat.c (linux_nat_thread_name): New function.
	(linux_nat_add_target): Set to_thread_name.
	* gdbthread.h (struct thread_info) <name>: New field.
	gdb/doc
	* gdb.texinfo (Threads): Document thread name output and `thread
	name' command.
	(Threads In Python): Document Thread.name attribute.
	(GDB/MI Thread Commands): Document thread attributes.
	gdb/testsuite
	* gdb.python/py-infthread.exp: Add thread tests.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12489&r2=1.12490
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/NEWS.diff?cvsroot=src&r1=1.420&r2=1.421
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbthread.h.diff?cvsroot=src&r1=1.61&r2=1.62
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/linux-nat.c.diff?cvsroot=src&r1=1.192&r2=1.193
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/target.c.diff?cvsroot=src&r1=1.270&r2=1.271
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/target.h.diff?cvsroot=src&r1=1.198&r2=1.199
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/thread.c.diff?cvsroot=src&r1=1.130&r2=1.131
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/ChangeLog.diff?cvsroot=src&r1=1.1142&r2=1.1143
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/gdb.texinfo.diff?cvsroot=src&r1=1.792&r2=1.793
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/python/py-infthread.c.diff?cvsroot=src&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2554&r2=1.2555
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.python/py-infthread.exp.diff?cvsroot=src&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.threads/manythreads.exp.diff?cvsroot=src&r1=1.21&r2=1.22
Comment 6 Tom Tromey 2011-01-19 17:26:27 UTC
Fixed.