@@ -858,6 +858,25 @@ main(int argc, char const *argv[])
858
858
}
859
859
SBHostOS::ThreadCreated (" <lldb.driver.main-thread>" );
860
860
861
+ // Install llvm's signal handlers up front to prevent lldb's handlers from
862
+ // being ignored. This is (hopefully) a stopgap workaround.
863
+ //
864
+ // When lldb invokes an llvm API that installs signal handlers (e.g.
865
+ // llvm::sys::RemoveFileOnSignal, possibly via a compiler embedded within
866
+ // lldb), lldb's signal handlers are overriden if llvm is installing its
867
+ // handlers for the first time.
868
+ //
869
+ // To work around llvm's behavior, force it to install its handlers up front,
870
+ // and *then* install lldb's handlers. In practice this is used to prevent
871
+ // lldb test processes from exiting due to IO_ERR when SIGPIPE is received.
872
+ //
873
+ // Note that when llvm installs its handlers, it 1) records the old handlers
874
+ // it replaces and 2) re-installs the old handlers when its new handler is
875
+ // invoked. That means that a signal not explicitly handled by lldb can fall
876
+ // back to being handled by llvm's handler the first time it is received,
877
+ // and then by the default handler the second time it is received.
878
+ llvm::sys::AddSignalHandler ([](void *) -> void {}, nullptr );
879
+
861
880
signal (SIGINT, sigint_handler);
862
881
#if !defined(_MSC_VER)
863
882
signal (SIGPIPE, SIG_IGN);
0 commit comments