[PATCH] D24781: [ubsan] Respect log_to_syslog=1 on Darwin
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 20 13:32:39 PDT 2016
vsk created this revision.
vsk added reviewers: samsonov, eugenis, zaks.anna.
vsk added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.
This patch adds support for logging ubsan errors to syslog on Darwin.
I turned off color encoding in this patch because the macOS log viewer doesn't know what to do with the color codes, and just displays a mess.
https://reviews.llvm.org/D24781
Files:
lib/sanitizer_common/sanitizer_common_libcdep.cc
lib/ubsan/ubsan_diag.cc
test/ubsan/TestCases/Misc/log-path_test.cc
Index: test/ubsan/TestCases/Misc/log-path_test.cc
===================================================================
--- test/ubsan/TestCases/Misc/log-path_test.cc
+++ test/ubsan/TestCases/Misc/log-path_test.cc
@@ -20,6 +20,10 @@
// RUN: %env_ubsan_opts=log_path='"%t.log"' %run %t 4
// RUN: not cat %t.log.*
+// We should print out a report even if we're logging to syslog.
+// RUN: %env_ubsan_opts=log_to_syslog=1 %run %t -4 2> %t.out
+// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out
+
// FIXME: log_path is not supported on Windows yet.
// XFAIL: win32
Index: lib/ubsan/ubsan_diag.cc
===================================================================
--- lib/ubsan/ubsan_diag.cc
+++ lib/ubsan/ubsan_diag.cc
@@ -100,8 +100,14 @@
const char *Note() const { return Black(); }
const char *EndNote() const { return Default(); }
};
+
+void PrintToLog(const char *S) {
+ Printf("%s", S);
+ LogFullErrorReport(S);
}
+} // end anonymous namespace
+
SymbolizedStack *__ubsan::getSymbolizedLocation(uptr PC) {
InitAsStandaloneIfNecessary();
return Symbolizer::GetOrInit()->SymbolizePC(PC);
@@ -263,7 +269,7 @@
Max = addNoOverflow(Min, BytesToShow);
if (!IsAccessibleMemoryRange(Min, Max - Min)) {
- Printf("<memory cannot be printed>\n");
+ PrintToLog("<memory cannot be printed>\n");
return;
}
@@ -319,7 +325,8 @@
Spaces += 2;
}
- Printf("%s", Buffer.data());
+ PrintToLog(Buffer.data());
+
// FIXME: Print names for anything we can identify within the line:
//
// * If we can identify the memory itself as belonging to a particular
@@ -356,7 +363,7 @@
RenderText(&Buffer, Message, Args);
Buffer.append("%s\n", Decor.Default());
- Printf("%s", Buffer.data());
+ PrintToLog(Buffer.data());
if (Loc.isMemoryLocation())
PrintMemorySnippet(Decor, Loc.getMemoryLocation(), Ranges, NumRanges, Args);
Index: lib/sanitizer_common/sanitizer_common_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_common_libcdep.cc
+++ lib/sanitizer_common/sanitizer_common_libcdep.cc
@@ -37,6 +37,10 @@
if (SANITIZER_WINDOWS)
return false;
+ // The macOS syslog viewer doesn't know what to do with color codes.
+ if (common_flags()->log_to_syslog)
+ return false;
+
const char *flag = common_flags()->color;
return internal_strcmp(flag, "always") == 0 ||
(internal_strcmp(flag, "auto") == 0 && report_file.SupportsColors());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24781.71975.patch
Type: text/x-patch
Size: 2494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160920/82924894/attachment.bin>
More information about the llvm-commits
mailing list