[Lldb-commits] [PATCH] D37926: Fix the SIGINT handlers

Leonard Mosescu via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 15 13:28:41 PDT 2017


lemo created this revision.
Herald added a subscriber: ki.stfu.

1. Fix a data race (g_interrupt_sent flag usage was not thread safe, signals can be handled on arbitrary threads)
2. exit() is not signal-safe, replaced it with the signal-safe equivalent _exit()


https://reviews.llvm.org/D37926

Files:
  driver/Driver.cpp
  lldb-mi/MIDriverMain.cpp


Index: lldb-mi/MIDriverMain.cpp
===================================================================
--- lldb-mi/MIDriverMain.cpp
+++ lldb-mi/MIDriverMain.cpp
@@ -72,14 +72,13 @@
 #ifdef _WIN32 // Restore handler as it is not persistent on Windows
   signal(SIGINT, sigint_handler);
 #endif
-  static bool g_interrupt_sent = false;
+  static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
   CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
   lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger();
   if (pDebugger != nullptr) {
-    if (!g_interrupt_sent) {
-      g_interrupt_sent = true;
+    if (!g_interrupt_sent.test_and_set()) {
       pDebugger->DispatchInputInterrupt();
-      g_interrupt_sent = false;
+      g_interrupt_sent.clear();
     }
   }
 
Index: driver/Driver.cpp
===================================================================
--- driver/Driver.cpp
+++ driver/Driver.cpp
@@ -1177,17 +1177,16 @@
 }
 
 void sigint_handler(int signo) {
-  static bool g_interrupt_sent = false;
+  static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
   if (g_driver) {
-    if (!g_interrupt_sent) {
-      g_interrupt_sent = true;
+    if (!g_interrupt_sent.test_and_set()) {
       g_driver->GetDebugger().DispatchInputInterrupt();
-      g_interrupt_sent = false;
+      g_interrupt_sent.clear();
       return;
     }
   }
 
-  exit(signo);
+  _exit(signo);
 }
 
 void sigtstp_handler(int signo) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37926.115473.patch
Type: text/x-patch
Size: 1437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170915/e0ff472b/attachment.bin>


More information about the lldb-commits mailing list