public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: print thread names in thread apply command output
@ 2020-02-26 21:23 Simon Marchi
0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2020-02-26 21:23 UTC (permalink / raw)
To: gdb-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 3199 bytes --]
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b65ce565416b950d8730b34106c54779c48efd29
commit b65ce565416b950d8730b34106c54779c48efd29
Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Date: Mon Feb 17 19:08:03 2020 -0500
gdb: print thread names in thread apply command output
This makes the thread apply command print the thread's name. The use
of target_pid_to_str is replaced by thread_target_id_str, which
provides the same output as "info threads".
Before:
(gdb) thread apply 2 bt
Thread 2 (Thread 0x7fd245602700 (LWP 3837)):
[...]
After:
(gdb) thread apply 2 bt
Thread 2 (Thread 0x7fd245602700 (LWP 3837) "HT cleanup"):
[...]
The thread's description header is pre-computed before running the
command since the command may change the selected inferior. This is
not permitted by thread_target_id_str as target_thread_name asserts
that `info->inf == current_inferior ()`.
This situation arises in the `gdb.threads/threadapply.exp` test which
kills and removes the inferior as part of a "thread apply" command.
gdb/ChangeLog:
* thread.c (thr_try_catch_cmd): Print thread name.
Diff:
---
gdb/ChangeLog | 4 ++++
gdb/thread.c | 16 ++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 33f7bc8..385cd01 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2020-02-26 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+
+ * thread.c (thr_try_catch_cmd): Print thread name.
+
2020-02-26 Simon Marchi <simon.marchi@efficios.com>
* dwarf2/loc.h (dwarf2_fetch_die_loc_sect_off,
diff --git a/gdb/thread.c b/gdb/thread.c
index 54b59e2..c6e3d35 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1563,6 +1563,14 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
const qcs_flags &flags)
{
switch_to_thread (thr);
+
+ /* The thread header is computed before running the command since
+ the command can change the inferior, which is not permitted
+ by thread_target_id_str. */
+ std::string thr_header =
+ string_printf (_("\nThread %s (%s):\n"), print_thread_id (thr),
+ thread_target_id_str (thr).c_str ());
+
try
{
std::string cmd_result = execute_command_to_string
@@ -1570,9 +1578,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
if (!flags.silent || cmd_result.length () > 0)
{
if (!flags.quiet)
- printf_filtered (_("\nThread %s (%s):\n"),
- print_thread_id (thr),
- target_pid_to_str (inferior_ptid).c_str ());
+ printf_filtered ("%s", thr_header.c_str ());
printf_filtered ("%s", cmd_result.c_str ());
}
}
@@ -1581,9 +1587,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
if (!flags.silent)
{
if (!flags.quiet)
- printf_filtered (_("\nThread %s (%s):\n"),
- print_thread_id (thr),
- target_pid_to_str (inferior_ptid).c_str ());
+ printf_filtered ("%s", thr_header.c_str ());
if (flags.cont)
printf_filtered ("%s\n", ex.what ());
else
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-02-26 21:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 21:23 [binutils-gdb] gdb: print thread names in thread apply command output Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).