Skip to content

Commit 6c84ffb

Browse files
committedSep 20, 2017
Fix the SIGINT handlers
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() (This differs from the patch on Phabrictor because I had to add `#include <atomic>` to get the definition of `std::atomic_flag`.) patch by lemo Differential Revision: https://reviews.llvm.org/D37926 llvm-svn: 313785
1 parent b9be536 commit 6c84ffb

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed
 

‎lldb/tools/driver/Driver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "Driver.h"
1111

12+
#include <atomic>
1213
#include <csignal>
1314
#include <fcntl.h>
1415
#include <limits.h>
@@ -1177,17 +1178,16 @@ void sigwinch_handler(int signo) {
11771178
}
11781179

11791180
void sigint_handler(int signo) {
1180-
static bool g_interrupt_sent = false;
1181+
static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
11811182
if (g_driver) {
1182-
if (!g_interrupt_sent) {
1183-
g_interrupt_sent = true;
1183+
if (!g_interrupt_sent.test_and_set()) {
11841184
g_driver->GetDebugger().DispatchInputInterrupt();
1185-
g_interrupt_sent = false;
1185+
g_interrupt_sent.clear();
11861186
return;
11871187
}
11881188
}
11891189

1190-
exit(signo);
1190+
_exit(signo);
11911191
}
11921192

11931193
void sigtstp_handler(int signo) {

‎lldb/tools/lldb-mi/MIDriverMain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
// Third party headers:
3535
#include "lldb/API/SBHostOS.h"
36+
#include <atomic>
3637
#include <csignal>
3738
#include <stdio.h>
3839

@@ -72,14 +73,13 @@ void sigint_handler(int vSigno) {
7273
#ifdef _WIN32 // Restore handler as it is not persistent on Windows
7374
signal(SIGINT, sigint_handler);
7475
#endif
75-
static bool g_interrupt_sent = false;
76+
static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
7677
CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
7778
lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger();
7879
if (pDebugger != nullptr) {
79-
if (!g_interrupt_sent) {
80-
g_interrupt_sent = true;
80+
if (!g_interrupt_sent.test_and_set()) {
8181
pDebugger->DispatchInputInterrupt();
82-
g_interrupt_sent = false;
82+
g_interrupt_sent.clear();
8383
}
8484
}
8585

0 commit comments

Comments
 (0)
Please sign in to comment.