Skip to content

Commit 8edffdb

Browse files
committed
[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. llvm-svn: 355045
1 parent 4fb3502 commit 8edffdb

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ enum AndroidApiLevel {
804804

805805
void WriteToSyslog(const char *buffer);
806806

807-
#if SANITIZER_MAC
807+
#if SANITIZER_MAC || SANITIZER_WINDOWS
808808
void LogFullErrorReport(const char *buffer);
809809
#else
810810
INLINE void LogFullErrorReport(const char *buffer) {}
@@ -818,7 +818,7 @@ INLINE void WriteOneLineToSyslog(const char *s) {}
818818
INLINE void LogMessageOnPrintf(const char *str) {}
819819
#endif
820820

821-
#if SANITIZER_LINUX
821+
#if SANITIZER_LINUX || SANITIZER_WINDOWS
822822
// Initialize Android logging. Any writes before this are silently lost.
823823
void AndroidLogInit();
824824
void SetAbortMessage(const char *);

compiler-rt/lib/sanitizer_common/sanitizer_win.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <io.h>
2121
#include <psapi.h>
2222
#include <stdlib.h>
23+
#include <TraceLoggingProvider.h>
2324

2425
#include "sanitizer_common.h"
2526
#include "sanitizer_file.h"
@@ -31,6 +32,13 @@
3132
#if defined(PSAPI_VERSION) && PSAPI_VERSION == 1
3233
#pragma comment(lib, "psapi")
3334
#endif
35+
// Windows trace logging provider init
36+
#pragma comment(lib, "advapi32.lib")
37+
TRACELOGGING_DECLARE_PROVIDER(g_asan_provider);
38+
// GUID must be the same in utils/AddressSanitizerLoggingProvider.wprp
39+
TRACELOGGING_DEFINE_PROVIDER(g_asan_provider, "AddressSanitizerLoggingProvider",
40+
(0x6c6c766d, 0x3846, 0x4e6a, 0xa4, 0xfb, 0x5b,
41+
0x53, 0x0b, 0xd0, 0xf3, 0xfa));
3442

3543
// A macro to tell the compiler that this part of the code cannot be reached,
3644
// if the compiler supports this feature. Since we're using this in
@@ -652,6 +660,7 @@ int Atexit(void (*function)(void)) {
652660
}
653661

654662
static int RunAtexit() {
663+
TraceLoggingUnregister(g_asan_provider);
655664
int ret = 0;
656665
for (uptr i = 0; i < atexit_functions.size(); ++i) {
657666
ret |= atexit(atexit_functions[i]);
@@ -749,6 +758,7 @@ uptr internal_sched_yield() {
749758
}
750759

751760
void internal__exit(int exitcode) {
761+
TraceLoggingUnregister(g_asan_provider);
752762
// ExitProcess runs some finalizers, so use TerminateProcess to avoid that.
753763
// The debugger doesn't stop on TerminateProcess like it does on ExitProcess,
754764
// so add our own breakpoint here.
@@ -1070,6 +1080,30 @@ u32 GetNumberOfCPUs() {
10701080
return sysinfo.dwNumberOfProcessors;
10711081
}
10721082

1083+
// TODO: Rename this project-wide to PlatformLogInit
1084+
void AndroidLogInit(void) {
1085+
HRESULT hr = TraceLoggingRegister(g_asan_provider);
1086+
if (!SUCCEEDED(hr))
1087+
return;
1088+
}
1089+
1090+
void SetAbortMessage(const char *) {}
1091+
1092+
void LogFullErrorReport(const char *buffer) {
1093+
if (common_flags()->log_to_syslog) {
1094+
InternalMmapVector<wchar_t> filename;
1095+
DWORD filename_length = 0;
1096+
do {
1097+
filename.resize(filename.size() + 0x100);
1098+
filename_length =
1099+
GetModuleFileName(NULL, filename.begin(), filename.size());
1100+
} while (filename_length >= filename.size());
1101+
TraceLoggingWrite(g_asan_provider, "AsanReportEvent",
1102+
TraceLoggingValue(filename.begin(), "ExecutableName"),
1103+
TraceLoggingValue(buffer, "AsanReportContents"));
1104+
}
1105+
}
1106+
10731107
} // namespace __sanitizer
10741108

10751109
#endif // _WIN32

0 commit comments

Comments
 (0)