From 81f7b96ed0a2295e0b82ca185019370ac8e1895e Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Sat, 24 Oct 2020 22:32:03 -0700 Subject: [PATCH] [sanitizer] Print errno for report file open failure To help debug failures, specifically the llvm-avr-linux bot failure from 5c20d7db9f2791367b9311130eb44afecb16829c: http://lab.llvm.org:8011/#/builders/112/builds/407/steps/5/logs/FAIL__MemProfiler-x86_64-linux-dynamic__log_path_t Also re-enable the failing test which I temporarily disabled, to see if this change will help identify why that particular log file can't be opened for write on that bot (when another log file in the same directory could earlier in the test). Differential Revision: https://reviews.llvm.org/D90120 --- compiler-rt/lib/sanitizer_common/sanitizer_file.cpp | 6 +++++- compiler-rt/test/memprof/TestCases/log_path_test.cpp | 9 ++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp index 6a79967..7cce609 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp @@ -58,11 +58,15 @@ void ReportFile::ReopenIfNecessary() { } else { internal_snprintf(full_path, kMaxPathLength, "%s.%zu", path_prefix, pid); } - fd = OpenFile(full_path, WrOnly); + error_t err; + fd = OpenFile(full_path, WrOnly, &err); if (fd == kInvalidFd) { const char *ErrorMsgPrefix = "ERROR: Can't open file: "; WriteToFile(kStderrFd, ErrorMsgPrefix, internal_strlen(ErrorMsgPrefix)); WriteToFile(kStderrFd, full_path, internal_strlen(full_path)); + char errmsg[100]; + internal_snprintf(errmsg, sizeof(errmsg), " (reason: %d)", err); + WriteToFile(kStderrFd, errmsg, internal_strlen(errmsg)); Die(); } fd_pid = pid; diff --git a/compiler-rt/test/memprof/TestCases/log_path_test.cpp b/compiler-rt/test/memprof/TestCases/log_path_test.cpp index 7952c61..b3bc432 100644 --- a/compiler-rt/test/memprof/TestCases/log_path_test.cpp +++ b/compiler-rt/test/memprof/TestCases/log_path_test.cpp @@ -19,11 +19,10 @@ // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-LONG --dump-input=always // Specifying the log name via the __memprof_profile_filename variable. -// TODO: Temporarily disabled due to llvm-avr-linux bot failure -// %clangxx_memprof %s -o %t -DPROFILE_NAME_VAR="%t.log2" -// rm -f %t.log2.* -// %run %t -// FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always < %t.log2.* +// RUN: %clangxx_memprof %s -o %t -DPROFILE_NAME_VAR="%t.log2" +// RUN: rm -f %t.log2.* +// RUN: %run %t +// RUN: FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always < %t.log2.* #ifdef PROFILE_NAME_VAR #define xstr(s) str(s) -- 2.7.4