[Lldb-commits] [PATCH] D69403: [Driver] Force llvm to install its handlers before lldb's

Vedant Kumar via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 24 13:25:34 PDT 2019


vsk created this revision.
vsk added reviewers: labath, JDevlieghere.
Herald added a reviewer: jfb.

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.


https://reviews.llvm.org/D69403

Files:
  lldb/tools/driver/Driver.cpp


Index: lldb/tools/driver/Driver.cpp
===================================================================
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -845,6 +845,25 @@
   }
   SBHostOS::ThreadCreated("<lldb.driver.main-thread>");
 
+  // 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.
+  llvm::sys::AddSignalHandler([](void *) -> void {}, nullptr);
+
   signal(SIGINT, sigint_handler);
 #if !defined(_MSC_VER)
   signal(SIGPIPE, SIG_IGN);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69403.226318.patch
Type: text/x-patch
Size: 1451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191024/ae8d1a06/attachment.bin>


More information about the lldb-commits mailing list