From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wYldEhS2BGrptDYAWB0awg (envelope-from ) for ; Wed, 13 May 2026 13:34:12 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=RoPzDGtm; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 45F371E0BA; Wed, 13 May 2026 13:34:12 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 831B31E067 for ; Wed, 13 May 2026 13:34:11 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 521D14BBC0A3 for ; Wed, 13 May 2026 17:34:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 521D14BBC0A3 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=RoPzDGtm Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by sourceware.org (Postfix) with ESMTPS id A4A3A4BBC0A4 for ; Wed, 13 May 2026 17:33:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4A3A4BBC0A4 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A4A3A4BBC0A4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778693582; cv=none; b=Msaxe4iF2UiQnSYYqpZ/DSdOxycRx2nyTbFZUHEAkIcJoAo503eYRg7NKItn1s9NDMODhKKGtSTfJQgWDYIsxn/z1Z7+VEShd6g5vyt44bkorub748JFT632qWX5wOjt+YA43ccnvtYYMKoIBjWs7ZIQmNULKBcO8cUyIMGtDtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778693582; c=relaxed/simple; bh=hHYaed8yP8wakhm7sXR4Vi1AeS9hF0XbyQ38BhRloNM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=aV3MflVwGh957MuU9i8J3EpQRNyp/l8HmsJilcJ6zjwDBHg/UnDklWZasczKyrJ1CXSmUvydsr8wRhEnpFkx9QIvJUxXhfpB8UCNQVnbZcuTcSwqz5TaVtXocVKqKBvTavV/V7wqdoQo95zjN6wNRwruI27clYIec7mqhIIszXg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=RoPzDGtm DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4A3A4BBC0A4 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-679f6ee3fb0so2899539eaf.2 for ; Wed, 13 May 2026 10:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1778693582; x=1779298382; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5YgzpFPzwRKwcKGyaJgMubXXXj+tX5dfx2MdEC7cHQM=; b=RoPzDGtmrDCpV4HPXltQ/UUDxpo8kHh/0mPiuQ7Jw1t+PVfj6ZExS2mNXUkHisDUJo W32MsVQ6eN2pDLZHAiiMF3nB85fKPfSCKARkZrgxlJqvSK8FRJN5+QwvnVY8Hr/KfAXD 7r9fHgD/xt6eQm2jXuqrh0bsCsx35niXMQGp4+L+Mj5FtM1/iRGtuJfgv6q5+iaj/B94 mHDdAX9rjEXzxuUUBbZOZ4GAniE11Fi5tYwD8h3acXahw8V2gF/pLvbsKfhYWmPQqkmK gNERml9X2M82+bi0T3vSonohW6mD2MiUVx4f55Jr9A1EjPsTjNyxNSJZyZePY4E6H8aO MmfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778693582; x=1779298382; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=5YgzpFPzwRKwcKGyaJgMubXXXj+tX5dfx2MdEC7cHQM=; b=rfl/Kfdu9YpDEPUSBQSaEK32JQgPNnAMIx5UU9p6oRY3/sDO7zWh4S+iDm4vctjqMV Xj1sU807OcwMQv6UNHuJLftc8ueJfJbIFNqonobBwwivZa8m20A+D+nMDfy8bjl6MOrP tK+fD/MDSFQnkw1rK4/zi9Ys/syJo2evPrIo8SPAbAewHDa/oUdDlFPQRLOz2XSP4Col 9Zv8xoBDlccJmsFvz0PgkFoBsIPwIeOSuQ4QQCsgXKVDf5RS65kM97CDHHySd20nwZ6c qwqNcbfYDV5cRRA+YwVw8QosX7VjtIMlm9ixeqS/rfc5QUhMKug0/7OkOq+hdwxgstKS PHuw== X-Gm-Message-State: AOJu0Yw2+wHfttQB8A4J0QWNexXFu7HDyR5aGwL5qBBjm1U80nXGQqOg 8jPffJgHSaOoVSGCrVX5qvs2SfW9VmmM4SHJ/mpmlfVyuh+zYxYHDDYG/9utL7sIeRuJOFJ2MiL ZIMA= X-Gm-Gg: Acq92OGrnGHoYoyS6Jg8Nn64oGtKV7GAoFLwPwDHzSxkZgbRhSjA3xb+CvO9IF1SBSy PEV0qHgd1sRF1GVAWVPVNZZ+pYzK6WgvrPaaoZInG/6RrSxQpRKyQswRXOeelHqoQpH9tB+SqbT zutd1m9BYDHoWTNXUyi+toW7GKBIhE5pxhvegH72hiFD+REq//w96jXi8m1fTUZ+b9C6UI5sLEu RtWjUrcNa6sXExPeGs9m/Ia5TVpoPr4quGZmkv5qIS9o0nimXFXmb2ZP3BgGIH2D7h4Gnyh8ueJ bo2aTaJn6fWIko751F+8NkzrC0fbcfKMI8o4MeCWX4bITNiXBZOzbnCijDlODdh2voReWhMjE3Z HaJ1pN0smsoUxdqf5g/PH94T/gm5GFbhoF6wkBWMqG++np9XGDLXtQpAoKslzIK9GvMkd9Q+LsB pVaKSMnwOyvF8Kp6eehH0+VEn1HCSJbl1R9wV9THaHqJyRU7c6vT01NA== X-Received: by 2002:a05:6820:a05:b0:696:233b:20ef with SMTP id 006d021491bc7-69b78d11525mr2389131eaf.1.1778693581820; Wed, 13 May 2026 10:33:01 -0700 (PDT) Received: from [192.168.0.26] (75-166-225-82.hlrn.qwest.net. [75.166.225.82]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-439fc1d7be5sm47734fac.5.2026.05.13.10.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 10:33:01 -0700 (PDT) From: Tom Tromey Date: Wed, 13 May 2026 11:32:59 -0600 Subject: [PATCH 2/2] Remove for_each_thread MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260513-remove-for-each-v1-2-8793bd79f781@adacore.com> References: <20260513-remove-for-each-v1-0-8793bd79f781@adacore.com> In-Reply-To: <20260513-remove-for-each-v1-0-8793bd79f781@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This patch removes the for_each_thread function, changing the callers to use 'foreach' loops instead. In general I think loops with iterators should be preferred over callback-based approaches -- they are easier to read and often result in less source code as well. For example, in this patch a helper function is inlined into its sole caller. --- gdb/breakpoint.c | 6 ++---- gdb/gdbthread.h | 9 --------- gdb/infcmd.c | 55 ++++++++++++++++++++++++++----------------------------- gdb/mi/mi-main.c | 28 +++++++++++++--------------- gdb/thread.c | 9 --------- 5 files changed, 41 insertions(+), 66 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 101dc57ee6b..bf35d14b1d2 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -12694,10 +12694,8 @@ delete_breakpoint (struct breakpoint *bpt) event-top.c won't do anything, and temporary breakpoints with commands won't work. */ - for_each_thread ([&] (struct thread_info *th) - { - bpstat_remove_bp_location (th->control.stop_bpstat, bpt); - }); + for (auto &th : all_threads ()) + bpstat_remove_bp_location (th.control.stop_bpstat, bpt); /* Now that breakpoint is removed from breakpoint list, update the global location list. This will remove locations that used to diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index b3052b28d1a..224f1cc8621 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -791,15 +791,6 @@ extern struct thread_info *any_live_thread_of_inferior (inferior *inf); void thread_change_ptid (process_stratum_target *targ, ptid_t old_ptid, ptid_t new_ptid); -/* Callback function type for function for_each_thread. */ - -using for_each_thread_callback_ftype - = gdb::function_view; - -/* Call CALLBACK once for each known thread. */ - -extern void for_each_thread (for_each_thread_callback_ftype callback); - /* Callback function type for function find_thread. */ using find_thread_callback_ftype = gdb::function_view; diff --git a/gdb/infcmd.c b/gdb/infcmd.c index d4cd2c7d5cd..dc067879b9d 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -685,29 +685,6 @@ starti_command (const char *args, int from_tty) run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN); } -static void -proceed_thread_callback (struct thread_info *thread) -{ - /* We go through all threads individually instead of compressing - into a single target `resume_all' request, because some threads - may be stopped in internal breakpoints/events, or stopped waiting - for its turn in the displaced stepping queue (that is, they are - running from the user's perspective but internally stopped). The - target side has no idea about why the thread is stopped, so a - `resume_all' command would resume too much. If/when GDB gains a - way to tell the target `hold this thread stopped until I say - otherwise', then we can optimize this. */ - if (thread->state () != THREAD_STOPPED) - return; - - if (!thread->inf->has_execution ()) - return; - - switch_to_thread (thread); - clear_proceed_status (0); - proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); -} - static void ensure_valid_thread (void) { @@ -762,15 +739,35 @@ continue_1 (bool all_threads_p) scoped_disable_commit_resumed disable_commit_resumed ("continue all threads in non-stop"); - for_each_thread (proceed_thread_callback); + for (auto &thread : all_threads ()) + { + /* We go through all threads individually instead of compressing + into a single target `resume_all' request, because some threads + may be stopped in internal breakpoints/events, or stopped waiting + for its turn in the displaced stepping queue (that is, they are + running from the user's perspective but internally stopped). The + target side has no idea about why the thread is stopped, so a + `resume_all' command would resume too much. If/when GDB gains a + way to tell the target `hold this thread stopped until I say + otherwise', then we can optimize this. */ + if (thread.state () != THREAD_STOPPED) + continue; + + if (!thread.inf->has_execution ()) + continue; + + switch_to_thread (&thread); + clear_proceed_status (0); + proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); + } if (current_ui->prompt_state == PROMPT_BLOCKED) { - /* If all threads in the target were already running, - proceed_thread_callback ends up never calling proceed, - and so nothing calls this to put the inferior's terminal - settings in effect and remove stdin from the event loop, - which we must when running a foreground command. E.g.: + /* If all threads in the target were already running, the + above ends up never calling proceed, and so nothing calls + this to put the inferior's terminal settings in effect + and remove stdin from the event loop, which we must when + running a foreground command. E.g.: (gdb) c -a& Continuing. diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 53821e69042..8aee563bc03 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -278,10 +278,8 @@ exec_continue (const char *const *argv, int argc) pid = inf->pid; } - for_each_thread ([&] (struct thread_info *thread) - { - proceed_thread (thread, pid); - }); + for (auto &thread : all_threads ()) + proceed_thread (&thread, pid); disable_commit_resumed.reset_and_commit (); } else @@ -363,16 +361,16 @@ mi_cmd_exec_interrupt (const char *command, const char *const *argv, int argc) scoped_disable_commit_resumed disable_commit_resumed ("interrupting all threads of thread group"); - for_each_thread ([&] (struct thread_info *thread) + for (auto &thread : all_threads ()) { - if (thread->state () != THREAD_RUNNING) - return; + if (thread.state () != THREAD_RUNNING) + continue; - if (thread->ptid.pid () != inf->pid) - return; + if (thread.ptid.pid () != inf->pid) + continue; - target_stop (thread->ptid); - }); + target_stop (thread.ptid); + } } else { @@ -607,16 +605,16 @@ print_one_inferior (struct inferior *inferior, bool recurse, if (inferior->pid != 0) { - for_each_thread ([&] (struct thread_info *ti) + for (auto &ti : all_threads ()) { - if (ti->ptid.pid () == inferior->pid) + if (ti.ptid.pid () == inferior->pid) { - int core = target_core_of_thread (ti->ptid); + int core = target_core_of_thread (ti.ptid); if (core != -1) cores.insert (core); } - }); + } } if (!cores.empty ()) diff --git a/gdb/thread.c b/gdb/thread.c index 4f62ca280cd..197facf3214 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -602,15 +602,6 @@ find_thread_by_handle (gdb::array_view handle, /* See gdbthread.h. */ -void -for_each_thread (for_each_thread_callback_ftype callback) -{ - for (thread_info &tp : all_threads_safe ()) - callback (&tp); -} - -/* See gdbthread.h. */ - struct thread_info * find_thread (find_thread_callback_ftype callback) { -- 2.54.0