From patchwork Tue Feb 18 00:08:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=C3=A9r=C3=A9mie_Galarneau?= X-Patchwork-Id: 38195 Received: (qmail 24118 invoked by alias); 18 Feb 2020 00:08:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24110 invoked by uid 89); 18 Feb 2020 00:08:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f193.google.com Received: from mail-qk1-f193.google.com (HELO mail-qk1-f193.google.com) (209.85.222.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Feb 2020 00:08:10 +0000 Received: by mail-qk1-f193.google.com with SMTP id c188so17912867qkg.4 for ; Mon, 17 Feb 2020 16:08:10 -0800 (PST) Return-Path: Received: from localhost (192-222-181-218.qc.cable.ebox.net. [192.222.181.218]) by smtp.gmail.com with ESMTPSA id h14sm1075114qke.99.2020.02.17.16.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 16:08:07 -0800 (PST) From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Galarneau?= To: gdb-patches@sourceware.org Cc: luis.machado@linaro.org, =?UTF-8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Subject: [PATCH v2] gdb: print thread names in thread apply command output Date: Mon, 17 Feb 2020 19:08:03 -0500 Message-Id: <20200218000803.132171-1-jeremie.galarneau@efficios.com> MIME-Version: 1.0 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. --- gdb/ChangeLog | 4 ++++ gdb/thread.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dafd90ec37..4fce196187 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2020-02-17 Jérémie Galarneau + + * thread.c (thr_try_catch_cmd): Print thread name. + 2020-02-14 Simon Marchi * aarch64-tdep.c (aarch64_displaced_step_copy_insn): Use diff --git a/gdb/thread.c b/gdb/thread.c index 54b59e2244..e581cb83b5 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