[PATCH] D91765: [sanitizer_common] Add facility to get the full report path

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 21:58:09 PST 2020


tejohnson created this revision.
tejohnson added a reviewer: vitalybuka.
Herald added subscribers: Sanitizers, phosek.
Herald added a project: Sanitizers.
tejohnson requested review of this revision.

Add a new interface __sanitizer_get_report_path which will return the
full path to the report file if __sanitizer_set_report_path was
previously called (otherwise it returns null). This is useful in
particular for memory profiling handlers to access the path which
was specified at compile time (and passed down via
__memprof_profile_filename), including the pid added to the path when
the file is opened.

There wasn't a test for __sanitizer_set_report_path, so I added one
which additionally tests the new interface.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91765

Files:
  compiler-rt/include/sanitizer/common_interface_defs.h
  compiler-rt/lib/sanitizer_common/sanitizer_common_interface.inc
  compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_file.h
  compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h


Index: compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h
@@ -28,6 +28,10 @@
   // (casted to void *).
   SANITIZER_INTERFACE_ATTRIBUTE
   void __sanitizer_set_report_fd(void *fd);
+  // Get the current full report file path, if a path was specified by
+  // an earlier call to __sanitizer_set_report_path. Returns null otherwise.
+  SANITIZER_INTERFACE_ATTRIBUTE
+  const char *__sanitizer_get_report_path();
 
   typedef struct {
       int coverage_sandboxed;
Index: compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
@@ -529,6 +529,10 @@
 void __sanitizer_set_report_fd(void *fd) {
   UNREACHABLE("not available on Fuchsia");
 }
+
+const char *__sanitizer_get_report_path() {
+  UNREACHABLE("not available on Fuchsia");
+}
 }  // extern "C"
 
 #endif  // SANITIZER_FUCHSIA
Index: compiler-rt/lib/sanitizer_common/sanitizer_file.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_file.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_file.h
@@ -26,6 +26,7 @@
   void Write(const char *buffer, uptr length);
   bool SupportsColors();
   void SetReportPath(const char *path);
+  const char *GetReportPath();
 
   // Don't use fields directly. They are only declared public to allow
   // aggregate initialization.
Index: compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
@@ -95,6 +95,12 @@
   }
 }
 
+const char *ReportFile::GetReportPath() {
+  SpinMutexLock l(mu);
+  ReopenIfNecessary();
+  return full_path;
+}
+
 bool ReadFileToBuffer(const char *file_name, char **buff, uptr *buff_size,
                       uptr *read_len, uptr max_len, error_t *errno_p) {
   *buff = nullptr;
@@ -213,6 +219,10 @@
   report_file.fd = (fd_t)reinterpret_cast<uptr>(fd);
   report_file.fd_pid = internal_getpid();
 }
+
+const char *__sanitizer_get_report_path() {
+  return report_file.GetReportPath();
+}
 } // extern "C"
 
 #endif  // !SANITIZER_FUCHSIA
Index: compiler-rt/lib/sanitizer_common/sanitizer_common_interface.inc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_common_interface.inc
+++ compiler-rt/lib/sanitizer_common/sanitizer_common_interface.inc
@@ -13,6 +13,7 @@
 INTERFACE_FUNCTION(__sanitizer_set_death_callback)
 INTERFACE_FUNCTION(__sanitizer_set_report_path)
 INTERFACE_FUNCTION(__sanitizer_set_report_fd)
+INTERFACE_FUNCTION(__sanitizer_get_report_path)
 INTERFACE_FUNCTION(__sanitizer_verify_contiguous_container)
 INTERFACE_WEAK_FUNCTION(__sanitizer_on_print)
 INTERFACE_WEAK_FUNCTION(__sanitizer_report_error_summary)
Index: compiler-rt/include/sanitizer/common_interface_defs.h
===================================================================
--- compiler-rt/include/sanitizer/common_interface_defs.h
+++ compiler-rt/include/sanitizer/common_interface_defs.h
@@ -43,6 +43,9 @@
 // Tell the tools to write their reports to the provided file descriptor
 // (casted to void *).
 void __sanitizer_set_report_fd(void *fd);
+// Get the current full report file path, if a path was specified by
+// an earlier call to __sanitizer_set_report_path. Returns null otherwise.
+const char *__sanitizer_get_report_path();
 
 // Notify the tools that the sandbox is going to be turned on. The reserved
 // parameter will be used in the future to hold a structure with functions


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91765.306311.patch
Type: text/x-patch
Size: 3908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201119/523163d7/attachment.bin>


More information about the llvm-commits mailing list