public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug dap/30680] [gdb/dap] ThreadSanitizer: data race gdbsupport/event-pipe.h:44 in event_pipe::is_open() const
Date: Wed, 26 Jul 2023 16:23:55 +0000	[thread overview]
Message-ID: <bug-30680-4717-QgW8BMwGh8@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30680-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=30680

--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom Tromey from comment #4)
> >     #2 sigchld_handler /data/vries/gdb/src/gdb/linux-nat.c:4238 (gdb+0x92f381)
> 
> This is odd because all the DAP-related threads should be started
> with SIGCHLD blocked.

I've written an assert to try to catch this situation without tsan:
...
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 250a8f43282..d6d0ba0f415 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -69,6 +69,7 @@
 #include "gdbsupport/scope-exit.h"
 #include "gdbsupport/gdb-sigmask.h"
 #include "gdbsupport/common-debug.h"
+#include "run-on-main-thread.h"
 #include <unordered_map>

 /* This comment documents high-level logic of this file.
@@ -4227,6 +4228,7 @@ linux_nat_target::supports_disable_randomization ()
 static void
 sigchld_handler (int signo)
 {
+  gdb_assert (is_main_thread ());
   int old_errno = errno;

   if (debug_linux_nat)
diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c
index c7d9de0afc8..f9388e33633 100644
--- a/gdb/run-on-main-thread.c
+++ b/gdb/run-on-main-thread.c
@@ -94,12 +94,27 @@ run_on_main_thread (std::function<void ()> &&func)
   serial_event_set (runnable_event);
 }

+#if CXX_STD_THREAD
+static void
+initialize_main_thread_var (void)
+{
+  static bool initialized = false;
+
+  if (initialized)
+    return;
+  initialized = true;
+
+  main_thread = std::this_thread::get_id ();
+}
+#endif
+
 /* See run-on-main-thread.h.  */

 bool
 is_main_thread ()
 {
 #if CXX_STD_THREAD
+  initialize_main_thread_var ();
   return std::this_thread::get_id () == main_thread;
 #else--
   return true;
@@ -111,7 +126,7 @@ void
 _initialize_run_on_main_thread ()
 {
 #if CXX_STD_THREAD
-  main_thread = std::this_thread::get_id ();
+  initialize_main_thread_var ();
 #endif
   runnable_event = make_serial_event ();
   add_file_handler (serial_event_fd (runnable_event), run_events, nullptr,
...
and it does trigger.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-07-26 16:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 10:33 [Bug dap/30680] New: " vries at gcc dot gnu.org
2023-07-25 10:46 ` [Bug dap/30680] " vries at gcc dot gnu.org
2023-07-25 11:10 ` vries at gcc dot gnu.org
2023-07-25 11:51 ` vries at gcc dot gnu.org
2023-07-25 12:36 ` tromey at sourceware dot org
2023-07-26 12:12 ` vries at gcc dot gnu.org
2023-07-26 16:23 ` vries at gcc dot gnu.org [this message]
2023-07-26 16:57 ` vries at gcc dot gnu.org
2023-07-26 16:59 ` vries at gcc dot gnu.org
2023-07-28 11:01 ` vries at gcc dot gnu.org
2023-07-28 16:04 ` tromey at sourceware dot org
2023-07-28 16:20 ` vries at gcc dot gnu.org
2023-07-28 17:58 ` tromey at sourceware dot org
2023-07-28 18:10 ` tromey at sourceware dot org
2023-07-31 12:37 ` cvs-commit at gcc dot gnu.org
2023-07-31 12:38 ` tromey at sourceware dot org

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=bug-30680-4717-QgW8BMwGh8@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).