Skip to content

Commit c654d29

Browse files
committed
[Driver] Force llvm to install its handlers before lldb's
Install llvm's signal handlers up front to prevent lldb's handlers from being ignored. This is (hopefully) a stopgap workaround. When lldb invokes an llvm API that installs signal handlers (e.g. llvm::sys::RemoveFileOnSignal, possibly via a compiler embedded within lldb), lldb's signal handlers are overriden if llvm is installing its handlers for the first time. To work around llvm's behavior, force it to install its handlers up front, and *then* install lldb's handlers. In practice this is used to prevent lldb test processes from exiting due to IO_ERR when SIGPIPE is received. Note that when llvm installs its handlers, it 1) records the old handlers it replaces and 2) re-installs the old handlers when its new handler is invoked. That means that a signal not explicitly handled by lldb can fall back to being handled by llvm's handler the first time it is received, and then by the default handler the second time it is received. Differential Revision: https://reviews.llvm.org/D69403 (cherry picked from commit 0877dd1)
1 parent c1a1515 commit c654d29

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lldb/tools/driver/Driver.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,25 @@ main(int argc, char const *argv[])
862862
}
863863
SBHostOS::ThreadCreated("<lldb.driver.main-thread>");
864864

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

0 commit comments

Comments
 (0)