summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew G McGovern <matthew.mcgovern@microsoft.com>2019-02-27 23:43:50 +0000
committerMatthew G McGovern <matthew.mcgovern@microsoft.com>2019-02-27 23:43:50 +0000
commite69521b84da34751c2e71d672ad598d7250047c8 (patch)
treec31ffc65863e8442a1e4b7b86a285d3363184cde
parent2081e3e82022d96dba0b548da788450081a2ab87 (diff)
downloadcompiler-rt-e69521b84da34751c2e71d672ad598d7250047c8.tar.gz
[compiler-rt] Windows Trace Logging for error reports.
Adds option for collecting sanitixer dumps via trace logging. - Set log_to_syslog=1 to enable this output. - Consult https://aka.ms/windowstracelogging for details on use. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355045 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/sanitizer_common/sanitizer_common.h4
-rw-r--r--lib/sanitizer_common/sanitizer_win.cc34
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h
index b42139724..d0e982fba 100644
--- a/lib/sanitizer_common/sanitizer_common.h
+++ b/lib/sanitizer_common/sanitizer_common.h
@@ -804,7 +804,7 @@ enum AndroidApiLevel {
void WriteToSyslog(const char *buffer);
-#if SANITIZER_MAC
+#if SANITIZER_MAC || SANITIZER_WINDOWS
void LogFullErrorReport(const char *buffer);
#else
INLINE void LogFullErrorReport(const char *buffer) {}
@@ -818,7 +818,7 @@ INLINE void WriteOneLineToSyslog(const char *s) {}
INLINE void LogMessageOnPrintf(const char *str) {}
#endif
-#if SANITIZER_LINUX
+#if SANITIZER_LINUX || SANITIZER_WINDOWS
// Initialize Android logging. Any writes before this are silently lost.
void AndroidLogInit();
void SetAbortMessage(const char *);
diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc
index 68e882fba..75b8b46c8 100644
--- a/lib/sanitizer_common/sanitizer_win.cc
+++ b/lib/sanitizer_common/sanitizer_win.cc
@@ -20,6 +20,7 @@
#include <io.h>
#include <psapi.h>
#include <stdlib.h>
+#include <TraceLoggingProvider.h>
#include "sanitizer_common.h"
#include "sanitizer_file.h"
@@ -31,6 +32,13 @@
#if defined(PSAPI_VERSION) && PSAPI_VERSION == 1
#pragma comment(lib, "psapi")
#endif
+// Windows trace logging provider init
+#pragma comment(lib, "advapi32.lib")
+TRACELOGGING_DECLARE_PROVIDER(g_asan_provider);
+// GUID must be the same in utils/AddressSanitizerLoggingProvider.wprp
+TRACELOGGING_DEFINE_PROVIDER(g_asan_provider, "AddressSanitizerLoggingProvider",
+ (0x6c6c766d, 0x3846, 0x4e6a, 0xa4, 0xfb, 0x5b,
+ 0x53, 0x0b, 0xd0, 0xf3, 0xfa));
// A macro to tell the compiler that this part of the code cannot be reached,
// if the compiler supports this feature. Since we're using this in
@@ -652,6 +660,7 @@ int Atexit(void (*function)(void)) {
}
static int RunAtexit() {
+ TraceLoggingUnregister(g_asan_provider);
int ret = 0;
for (uptr i = 0; i < atexit_functions.size(); ++i) {
ret |= atexit(atexit_functions[i]);
@@ -749,6 +758,7 @@ uptr internal_sched_yield() {
}
void internal__exit(int exitcode) {
+ TraceLoggingUnregister(g_asan_provider);
// ExitProcess runs some finalizers, so use TerminateProcess to avoid that.
// The debugger doesn't stop on TerminateProcess like it does on ExitProcess,
// so add our own breakpoint here.
@@ -1070,6 +1080,30 @@ u32 GetNumberOfCPUs() {
return sysinfo.dwNumberOfProcessors;
}
+// TODO: Rename this project-wide to PlatformLogInit
+void AndroidLogInit(void) {
+ HRESULT hr = TraceLoggingRegister(g_asan_provider);
+ if (!SUCCEEDED(hr))
+ return;
+}
+
+void SetAbortMessage(const char *) {}
+
+void LogFullErrorReport(const char *buffer) {
+ if (common_flags()->log_to_syslog) {
+ InternalMmapVector<wchar_t> filename;
+ DWORD filename_length = 0;
+ do {
+ filename.resize(filename.size() + 0x100);
+ filename_length =
+ GetModuleFileName(NULL, filename.begin(), filename.size());
+ } while (filename_length >= filename.size());
+ TraceLoggingWrite(g_asan_provider, "AsanReportEvent",
+ TraceLoggingValue(filename.begin(), "ExecutableName"),
+ TraceLoggingValue(buffer, "AsanReportContents"));
+ }
+}
+
} // namespace __sanitizer
#endif // _WIN32