================
@@ -637,48 +641,50 @@ void Driver::UpdateWindowSize() {
}
void sigwinch_handler(int signo) {
- if (g_driver != nullptr)
- g_driver->UpdateWindowSize();
+ g_signal_loop.AddPendingCallback([](MainLoopBase &loop) {
+ if (g_driver != nullptr)
+ g_driver->UpdateWindowSize();
+ });
}
void sigint_handler(int signo) {
#ifdef _WIN32 // Restore handler as it is not persistent on Windows
signal(SIGINT, sigint_handler);
#endif
- static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
- if (g_driver != nullptr) {
- if (!g_interrupt_sent.test_and_set()) {
- g_driver->GetDebugger().DispatchInputInterrupt();
- g_interrupt_sent.clear();
- return;
+ g_signal_loop.AddPendingCallback([signo](MainLoopBase &loop) {
+ static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
+ if (g_driver != nullptr) {
+ if (!g_interrupt_sent.test_and_set()) {
+ g_driver->GetDebugger().DispatchInputInterrupt();
+ g_interrupt_sent.clear();
+ return;
+ }
}
- }
- _exit(signo);
+ loop.RequestTermination();
+ _exit(signo);
+ });
}
#ifndef _WIN32
static void sigtstp_handler(int signo) {
- if (g_driver != nullptr)
- g_driver->GetDebugger().SaveInputTerminalState();
-
- // Unblock the signal and remove our handler.
- sigset_t set;
- sigemptyset(&set);
- sigaddset(&set, signo);
- pthread_sigmask(SIG_UNBLOCK, &set, nullptr);
- signal(signo, SIG_DFL);
-
- // Now re-raise the signal. We will immediately suspend...
- raise(signo);
- // ... and resume after a SIGCONT.
-
- // Now undo the modifications.
- pthread_sigmask(SIG_BLOCK, &set, nullptr);
- signal(signo, sigtstp_handler);
-
- if (g_driver != nullptr)
- g_driver->GetDebugger().RestoreInputTerminalState();
+ g_signal_loop.AddPendingCallback([signo](MainLoopBase &loop) {
+ if (g_driver != nullptr)
+ g_driver->GetDebugger().SaveInputTerminalState();
+
+ // Remove our handler.
+ signal(signo, SIG_DFL);
----------------
labath wrote:
We should use `sigaction` here to make sure we restore the handler state
exactly as MainLoop has set it. Fiddling with the handlers installed by the
main loop slightly rude, but it should work if we properly restore them
afterwards. One possibility would be to add some sort of a flag to request that
the MainLoop runs our handler with the default signal handler, but I'm not sure
that would be much of an improvement. Another possibility would be to raise a
SIGSTOP instead of SIGTSTP, but I think that's also not how one is "supposed
to" handle a SIGTSTP.
https://github.com/llvm/llvm-project/pull/134956
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits