From: Pat Pannuto <pat.pannuto@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Print thread name when executing thread commands
Date: Wed, 18 Sep 2013 06:50:00 -0000 [thread overview]
Message-ID: <CA+Yp1NUTX7fQ4eq_LyGfR3JwRzOoEsT8dAFwX+WwFA9gaA22KQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 870 bytes --]
Currently the thread family of commands only prints the thread ID and
PID. GDB also has access to the thread's name, which is often an easier
way of quickly identifying a thread. This simple patch uses the same
mechanism as `info threads' to get the name of a thread and add it to
the thread identifier line when it's printed.
I wrapped the name in []'s to offset it and make it visually distinct
from the ()'s that wrap the other thread information. I'm not at all
attached to this look, just looked best to me.
Diff should be from current cvs. This is my first patch to GDB, if I
messed something up don't hesitate to yell at me.
Bonus: solves my old SO question:
http://stackoverflow.com/questions/12679339/make-gdb-show-thread-names-on-apply-all-operations
-Pat
--
Pat Pannuto
NSF/NDSEG/Qualcomm Fellow
Computer Engineering
University of Michigan
248.990.4548
[-- Attachment #2: print_thread_names.ChangeLog --]
[-- Type: application/octet-stream, Size: 156 bytes --]
2013-09-18 Pat Pannuto <pat.pannuto@gmail.com>
* thread.c: Print thread name as well as ID number and PID when
executing the thread family of commands
[-- Attachment #3: print_thread_names.diff --]
[-- Type: application/octet-stream, Size: 1513 bytes --]
Index: gdb/thread.c
===================================================================
RCS file: /cvs/src/src/gdb/thread.c,v
retrieving revision 1.157
diff -u -p -r1.157 thread.c
--- gdb/thread.c 17 Sep 2013 18:26:39 -0000 1.157
+++ gdb/thread.c 18 Sep 2013 06:33:29 -0000
@@ -1255,10 +1255,14 @@ thread_apply_all_command (char *cmd, int
for (k = 0; k != i; k++)
if (thread_alive (tp_array[k]))
{
+ char* name;
switch_to_thread (tp_array[k]->ptid);
- printf_filtered (_("\nThread %d (%s):\n"),
+ name = tp_array[k]->name ? tp_array[k]->name
+ : target_thread_name (tp_array[k]);
+ printf_filtered (_("\nThread %d (%s) [%s]:\n"),
tp_array[k]->num,
- target_pid_to_str (inferior_ptid));
+ target_pid_to_str (inferior_ptid),
+ name);
execute_command (cmd, from_tty);
/* Restore exact command used previously. */
@@ -1308,10 +1312,12 @@ thread_apply_command (char *tidlist, int
warning (_("Thread %d has terminated."), start);
else
{
+ char *name;
switch_to_thread (tp->ptid);
- printf_filtered (_("\nThread %d (%s):\n"), tp->num,
- target_pid_to_str (inferior_ptid));
+ name = tp->name ? tp->name : target_thread_name (tp);
+ printf_filtered (_("\nThread %d (%s) [%s]:\n"), tp->num,
+ target_pid_to_str (inferior_ptid), name);
execute_command (cmd, from_tty);
/* Restore exact command used previously. */
next reply other threads:[~2013-09-18 6:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-18 6:50 Pat Pannuto [this message]
2013-09-18 7:04 ` Ricard Wanderlof
2013-09-18 18:37 ` Pat Pannuto
2013-09-23 12:18 ` Agovic, Sanimir
2013-09-23 16:33 ` Pat Pannuto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+Yp1NUTX7fQ4eq_LyGfR3JwRzOoEsT8dAFwX+WwFA9gaA22KQ@mail.gmail.com \
--to=pat.pannuto@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox