From a8e4beca721a9fb25fc3050bac2a44360f83f743 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 24 Apr 2025 19:36:12 +0100 Subject: [PATCH 2/2] No threads matched Change-Id: I12ea3d283319c8249807e70de890b40ad3a00f7d --- .../gdb.threads/info-threads-stopped.exp | 2 +- gdb/thread.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/gdb/testsuite/gdb.threads/info-threads-stopped.exp b/gdb/testsuite/gdb.threads/info-threads-stopped.exp index d554bd7ef2c..660ed4aa197 100644 --- a/gdb/testsuite/gdb.threads/info-threads-stopped.exp +++ b/gdb/testsuite/gdb.threads/info-threads-stopped.exp @@ -91,7 +91,7 @@ if {$flag eq ""} { # Test specifying thread ids. gdb_test "info threads -stopped $running_tid" \ - "No stopped threads match '$running_tid'\." \ + "No threads matched\\." \ "info thread -stopped for a running thread" set fill "\[^\r\n\]+" diff --git a/gdb/thread.c b/gdb/thread.c index 7057fa1d641..7485dcce8d6 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -1267,13 +1267,15 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, list_emitter.emplace (uiout, "threads"); else { - int n_threads = 0; + int n_matching_threads = 0; /* The width of the "Target Id" column. Grown below to accommodate the largest entry. */ size_t target_id_col_width = 17; for (thread_info *tp : all_threads ()) { + any_thread = true; + /* In case REQUESTED_THREADS contains $_thread. */ if (current_thread != nullptr) switch_to_thread (current_thread); @@ -1290,22 +1292,20 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, = std::max (target_id_col_width, thread_target_id_str (tp).size ()); - ++n_threads; + ++n_matching_threads; } - if (n_threads == 0) + if (n_matching_threads == 0) { - if (requested_threads == NULL || *requested_threads == '\0') + if (!any_thread) uiout->message (_("No threads.\n")); else - uiout->message (_("No %sthreads match '%s'.\n"), - (opts.show_stopped_threads ? "stopped " : ""), - requested_threads); + uiout->message (_("No threads matched.\n")); return; } table_emitter.emplace (uiout, opts.show_global_ids ? 5 : 4, - n_threads, "threads"); + n_matching_threads, "threads"); uiout->table_header (1, ui_left, "current", ""); uiout->table_header (4, ui_left, "id-in-tg", "Id"); @@ -1320,8 +1320,6 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, for (inferior *inf : all_inferiors ()) for (thread_info *tp : inf->threads ()) { - any_thread = true; - if (tp == current_thread && tp->state == THREAD_EXITED) current_exited = true; -- 2.49.0