[PATCH] D43692: [MSan] Print current stack on CHECK violation

Aleksey Shlyapnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 13:17:08 PST 2018


alekseyshl created this revision.
alekseyshl added a reviewer: eugenis.
Herald added subscribers: Sanitizers, delcypher.

Print current stack on CHECK violation to aid debugging and
match other sanitizers functionality.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D43692

Files:
  lib/msan/msan.cc
  lib/msan/msan.h


Index: lib/msan/msan.h
===================================================================
--- lib/msan/msan.h
+++ lib/msan/msan.h
@@ -356,14 +356,23 @@
                     common_flags()->fast_unwind_on_malloc);               \
   }
 
+#define GET_STORE_STACK_TRACE \
+  GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
+
 #define GET_FATAL_STACK_TRACE_PC_BP(pc, bp)              \
   BufferedStackTrace stack;                              \
   if (msan_inited)                                       \
   GetStackTrace(&stack, kStackTraceMax, pc, bp, nullptr, \
                 common_flags()->fast_unwind_on_fatal)
 
-#define GET_STORE_STACK_TRACE \
-  GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
+#define GET_FATAL_STACK_TRACE_HERE \
+  GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
+
+#define PRINT_CURRENT_STACK_CHECK() \
+  {                                 \
+    GET_FATAL_STACK_TRACE_HERE;     \
+    stack.Print();                  \
+  }
 
 class ScopedThreadLocalStateBackup {
  public:
Index: lib/msan/msan.cc
===================================================================
--- lib/msan/msan.cc
+++ lib/msan/msan.cc
@@ -379,6 +379,14 @@
   HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
 }
 
+static void MsanCheckFailed(const char *file, int line, const char *cond,
+                            u64 v1, u64 v2) {
+  Report("MemorySanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file,
+         line, cond, (uptr)v1, (uptr)v2);
+  PRINT_CURRENT_STACK_CHECK();
+  Die();
+}
+
 void __msan_init() {
   CHECK(!msan_init_is_running);
   if (msan_inited) return;
@@ -391,6 +399,9 @@
   CacheBinaryName();
   InitializeFlags();
 
+  // Install tool-specific callbacks in sanitizer_common.
+  SetCheckFailedCallback(MsanCheckFailed);
+
   __sanitizer_set_report_path(common_flags()->log_path);
 
   InitializeInterceptors();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43692.135687.patch
Type: text/x-patch
Size: 1963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180223/bbdf0ce5/attachment.bin>


More information about the llvm-commits mailing list