[compiler-rt] dd5c2b8 - [sanitizer] Add suffix to report file name

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 13:50:27 PST 2021


Author: Bill Torpey
Date: 2021-02-04T13:50:11-08:00
New Revision: dd5c2b8de92d109c78b6b0961a496d328aa25854

URL: https://github.com/llvm/llvm-project/commit/dd5c2b8de92d109c78b6b0961a496d328aa25854
DIFF: https://github.com/llvm/llvm-project/commit/dd5c2b8de92d109c78b6b0961a496d328aa25854.diff

LOG: [sanitizer] Add suffix to report file name

For those using a GUI, it can be very helpful to have a
particular suffix appended to the report file name, so
it can be opened with a double-click.

(see also: https://github.com/google/sanitizers/issues/951)

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D46546

Added: 
    compiler-rt/test/sanitizer_common/TestCases/suffix-log-path_test.c

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_flags.inc

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
index 7c64b53e9b11..0b92dccde4a1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
@@ -58,6 +58,9 @@ void ReportFile::ReopenIfNecessary() {
   } else {
     internal_snprintf(full_path, kMaxPathLength, "%s.%zu", path_prefix, pid);
   }
+  if (common_flags()->log_suffix) {
+    internal_strlcat(full_path, common_flags()->log_suffix, kMaxPathLength);
+  }
   error_t err;
   fd = OpenFile(full_path, WrOnly, &err);
   if (fd == kInvalidFd) {

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
index cfb5822645f1..3bc44c6b1eb1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
@@ -59,6 +59,8 @@ COMMON_FLAG(
     bool, log_exe_name, false,
     "Mention name of executable when reporting error and "
     "append executable name to logs (as in \"log_path.exe_name.pid\").")
+COMMON_FLAG(const char *, log_suffix, nullptr,
+            "String to append to log file name, e.g. \".txt\".")
 COMMON_FLAG(
     bool, log_to_syslog, (bool)SANITIZER_ANDROID || (bool)SANITIZER_MAC,
     "Write all sanitizer output to syslog in addition to other means of "

diff  --git a/compiler-rt/test/sanitizer_common/TestCases/suffix-log-path_test.c b/compiler-rt/test/sanitizer_common/TestCases/suffix-log-path_test.c
new file mode 100644
index 000000000000..8e131054c2d4
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/suffix-log-path_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang %s -o %T/suffix-log-path_test-binary
+
+// The glob below requires bash.
+// REQUIRES: shell
+
+// Good log_path with suffix.
+// RUN: rm -f %T/sanitizer.log.*.txt
+// RUN: %env_tool_opts=log_path=%T/sanitizer.log:log_exe_name=1:log_suffix=.txt %run %T/suffix-log-path_test-binary 2> %t.out
+// RUN: FileCheck %s < %T/sanitizer.log.suffix-log-path_test-binary.*.txt
+
+// UNSUPPORTED: ios, android
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <sanitizer/common_interface_defs.h>
+
+int main(int argc, char **argv) {
+  __sanitizer_print_stack_trace();
+  return 0;
+}
+// CHECK: #{{.*}} main


        


More information about the llvm-commits mailing list