From fd67c83e7e494498f8ab37a4f7160673d719d55b Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 2 Nov 2012 09:23:36 +0000 Subject: [PATCH] [Sanitizer]: add __sanitizer_set_report_fd function to alter file descriptor for error reports llvm-svn: 167290 --- compiler-rt/include/sanitizer/common_interface_defs.h | 5 +++++ compiler-rt/lib/sanitizer_common/sanitizer_common.cc | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler-rt/include/sanitizer/common_interface_defs.h b/compiler-rt/include/sanitizer/common_interface_defs.h index cbce63f..4666318 100644 --- a/compiler-rt/include/sanitizer/common_interface_defs.h +++ b/compiler-rt/include/sanitizer/common_interface_defs.h @@ -63,6 +63,11 @@ extern "C" { // Tell the tools to write their reports to "path." 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 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 614b7b9..e6526f5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -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 @@ void SortArray(uptr *array, uptr size) { } // 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 @@ void __sanitizer_set_report_path(const char *path) { 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" -- 2.7.4