From patchwork Mon Feb 17 22:30:21 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: 38193 Received: (qmail 63829 invoked by alias); 17 Feb 2020 22:31:02 -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 63768 invoked by uid 89); 17 Feb 2020 22:30:57 -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=HContent-Transfer-Encoding:8bit X-HELO: mail-qt1-f194.google.com Received: from mail-qt1-f194.google.com (HELO mail-qt1-f194.google.com) (209.85.160.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Feb 2020 22:30:39 +0000 Received: by mail-qt1-f194.google.com with SMTP id w47so13167215qtk.4 for ; Mon, 17 Feb 2020 14:30:29 -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 u2sm919005qtd.72.2020.02.17.14.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 14:30:27 -0800 (PST) From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Galarneau?= To: gdb-patches@sourceware.org Cc: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Subject: [PATCH] gdb: print thread names in thread apply command output Date: Mon, 17 Feb 2020 17:30:21 -0500 Message-Id: <20200217223021.38030-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..0c1611bdc1 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