From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: Simon Marchi <simark@simark.ca>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH] gdb: fix an issue with thread list corruption
Date: Mon, 11 May 2026 10:05:05 +0000 [thread overview]
Message-ID: <DM8PR11MB57490D8D474DBC8E933D8F5CDE382@DM8PR11MB5749.namprd11.prod.outlook.com> (raw)
In-Reply-To: <DM8PR11MB5749F5F59F32C7BD65EDAF48DE382@DM8PR11MB5749.namprd11.prod.outlook.com>
Hello Simon,
>The general issue is that safe-iterations should not be nested. They should
>only
>be used with the intent of deleting the current item. A comment may be more
>effective at preventing mis-use.
>
>Both for_each_thread() and find_thread() use all_threads_safe(). They
>probably
>shouldn't. So, instead of fixing this one case by not using for_each_thread(),
>we
>should probably change for_each_thread() to use all_threads() and find those
>few
>cases, if any, that do use for_each_thread() to delete threads and change
>them
>to explicitly use all_threads_safe().
It turns out that there are only few calls to for_each_thread() and it looks like
one such call in mi/mi-main.c would run into a similar issue that this patch
fixes for infcmd.c. I have not found a call that deletes the thread in the callback.
I'm testing a patch [1] that changes for_each_thread().
Regards,
markus.
[1]:
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index b3052b28d1a..1bdbf621982 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -796,7 +796,14 @@ void thread_change_ptid (process_stratum_target *targ,
using for_each_thread_callback_ftype
= gdb::function_view<void (thread_info *)>;
-/* Call CALLBACK once for each known thread. */
+/* Call CALLBACK once for each known thread.
+
+ CALLBACK must not delete the thread. To delete threads, use:
+
+ for (thread_info &t : all_threads_safe ())
+ if (some_condition ())
+ delete &t;
+*/
extern void for_each_thread (for_each_thread_callback_ftype callback);
diff --git a/gdb/thread.c b/gdb/thread.c
index 4f62ca280cd..110e58a70aa 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -605,7 +605,7 @@ find_thread_by_handle (gdb::array_view<const gdb_byte> handle,
void
for_each_thread (for_each_thread_callback_ftype callback)
{
- for (thread_info &tp : all_threads_safe ())
+ for (thread_info &tp : all_threads ())
callback (&tp);
}
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2026-05-11 10:05 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 7:16 [PATCH] gdb, btrace: fix wrong #endif comments Markus Metzger
2026-05-04 7:16 ` [PATCH] gdb: fix an issue with thread list corruption Markus Metzger
2026-05-04 15:30 ` Simon Marchi
2026-05-05 5:04 ` Metzger, Markus T
2026-05-05 15:51 ` Simon Marchi
2026-05-06 5:43 ` Metzger, Markus T
2026-05-06 18:36 ` Simon Marchi
2026-05-07 7:36 ` Metzger, Markus T
2026-05-07 15:11 ` Simon Marchi
2026-05-11 7:25 ` Metzger, Markus T
2026-05-11 10:05 ` Metzger, Markus T [this message]
2026-05-12 6:36 ` Metzger, Markus T
2026-05-13 14:33 ` Tom Tromey
2026-05-13 17:05 ` Tom Tromey
2026-05-14 22:07 ` Thiago Jung Bauermann
2026-05-04 7:16 ` [PATCH] gdb, remote: fix notify debug nullptr dereference Markus Metzger
2026-05-04 15:40 ` Simon Marchi
2026-05-04 7:16 ` [PATCH] gdb, testsuite: increase timeout in gdb.threads/attach-non-stop.exp Markus Metzger
2026-05-04 15:49 ` Simon Marchi
2026-05-05 6:15 ` Metzger, Markus T
2026-05-05 15:54 ` Simon Marchi
2026-05-06 6:33 ` Metzger, Markus T
2026-05-04 7:16 ` [PATCH] gdb: update store_integer's comment Markus Metzger
2026-05-04 15:52 ` Simon Marchi
2026-05-04 7:16 ` [PATCH] gdb: use correct target in notify_thread_exited() Markus Metzger
2026-05-04 16:06 ` Simon Marchi
2026-05-05 7:56 ` Metzger, Markus T
2026-05-05 16:10 ` Simon Marchi
2026-05-06 6:56 ` Metzger, Markus T
2026-05-04 7:16 ` [PATCH v2] gdb, btrace: support libipt v2.2 events Markus Metzger
2026-05-04 12:08 ` Eli Zaretskii
2026-05-04 14:00 ` Metzger, Markus T
2026-05-04 15:04 ` Eli Zaretskii
2026-05-05 4:32 ` Metzger, Markus T
2026-05-05 5:12 ` Eli Zaretskii
2026-05-04 14:44 ` [PATCH] gdb, btrace: fix wrong #endif comments Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM8PR11MB57490D8D474DBC8E933D8F5CDE382@DM8PR11MB5749.namprd11.prod.outlook.com \
--to=markus.t.metzger@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox