[llvm-commits] [compiler-rt] r167290 - in /compiler-rt/trunk: include/sanitizer/common_interface_defs.h lib/sanitizer_common/sanitizer_common.cc

Alexey Samsonov samsonov at google.com
Fri Nov 2 02:23:36 PDT 2012


Author: samsonov
Date: Fri Nov  2 04:23:36 2012
New Revision: 167290

URL: http://llvm.org/viewvc/llvm-project?rev=167290&view=rev
Log:
[Sanitizer]: add __sanitizer_set_report_fd function to alter file descriptor for error reports

Modified:
    compiler-rt/trunk/include/sanitizer/common_interface_defs.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc

Modified: compiler-rt/trunk/include/sanitizer/common_interface_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/common_interface_defs.h?rev=167290&r1=167289&r2=167290&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/common_interface_defs.h (original)
+++ compiler-rt/trunk/include/sanitizer/common_interface_defs.h Fri Nov  2 04:23:36 2012
@@ -63,6 +63,11 @@
   // Tell the tools to write their reports to "path.<pid>" instead of stderr.
   void __sanitizer_set_report_path(const char *path)
       SANITIZER_INTERFACE_ATTRIBUTE;
+
+  // Tell the tools to write their reports to given file descriptor instead of
+  // stderr.
+  void __sanitizer_set_report_fd(int fd)
+      SANITIZER_INTERFACE_ATTRIBUTE;
 }  // extern "C"
 
 #endif  // SANITIZER_COMMON_INTERFACE_DEFS_H

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=167290&r1=167289&r2=167290&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri Nov  2 04:23:36 2012
@@ -16,7 +16,9 @@
 
 namespace __sanitizer {
 
-static fd_t report_fd = 2;  // By default, dump to stderr.
+// By default, dump to stderr. If report_fd is kInvalidFd, try to obtain file
+// descriptor by opening file in report_path.
+static fd_t report_fd = 2;
 static char report_path[4096];  // Set via __sanitizer_set_report_path.
 
 static void (*DieCallback)(void);
@@ -138,6 +140,10 @@
 
 }  // namespace __sanitizer
 
+using namespace __sanitizer;  // NOLINT
+
+extern "C" {
+
 void __sanitizer_set_report_path(const char *path) {
   if (!path) return;
   uptr len = internal_strlen(path);
@@ -151,3 +157,11 @@
                     sizeof(__sanitizer::report_path), "%s.%d", path, GetPid());
   __sanitizer::report_fd = kInvalidFd;
 }
+
+void __sanitizer_set_report_fd(int fd) {
+  if (__sanitizer::report_fd > 2 && __sanitizer::report_fd != kInvalidFd)
+    internal_close(__sanitizer::report_fd);
+  __sanitizer::report_fd = fd;
+}
+
+}  // extern "C"





More information about the llvm-commits mailing list