[PATCH] [MSan] Implement __sanitizer_print_stack_trace().

Sergey Matveev earthdok at google.com
Fri May 23 10:17:35 PDT 2014


Hi eugenis,

http://reviews.llvm.org/D3899

Files:
  lib/msan/msan.cc
  lib/msan/msan.h
  test/msan/print-stack-trace.cc

Index: lib/msan/msan.cc
===================================================================
--- lib/msan/msan.cc
+++ lib/msan/msan.cc
@@ -211,9 +211,7 @@
 
   ++msan_report_count;
 
-  StackTrace stack;
-  GetStackTrace(&stack, kStackTraceMax, pc, bp,
-                common_flags()->fast_unwind_on_fatal);
+  GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
 
   u32 report_origin =
     (__msan_get_track_origins() && OriginIsValid(origin)) ? origin : 0;
@@ -422,9 +420,7 @@
   } else if (!msan_expected_umr_found) {
     GET_CALLER_PC_BP_SP;
     (void)sp;
-    StackTrace stack;
-    GetStackTrace(&stack, kStackTraceMax, pc, bp,
-                  common_flags()->fast_unwind_on_fatal);
+    GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
     ReportExpectedUMRNotFound(&stack);
     Die();
   }
@@ -662,3 +658,11 @@
 const char* __msan_default_options() { return ""; }
 }  // extern "C"
 #endif
+
+extern "C" {
+SANITIZER_INTERFACE_ATTRIBUTE
+void __sanitizer_print_stack_trace() {
+  GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME());
+  stack.Print();
+}
+}  // extern "C"
Index: lib/msan/msan.h
===================================================================
--- lib/msan/msan.h
+++ lib/msan/msan.h
@@ -111,6 +111,13 @@
     GetStackTrace(&stack, common_flags()->malloc_context_size, pc, bp, \
                   common_flags()->fast_unwind_on_malloc)
 
+#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp)       \
+  StackTrace stack;                               \
+  stack.size = 0;                                 \
+  if (msan_inited)                                \
+    GetStackTrace(&stack, kStackTraceMax, pc, bp, \
+                  common_flags()->fast_unwind_on_fatal)
+
 #define GET_STORE_STACK_TRACE \
   GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
 
Index: test/msan/print-stack-trace.cc
===================================================================
--- /dev/null
+++ test/msan/print-stack-trace.cc
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_msan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <sanitizer/msan_interface.h>
+
+void FooBarBaz() {
+  __sanitizer_print_stack_trace();
+}
+
+int main() {
+  FooBarBaz();
+  return 0;
+}
+// CHECK: {{    #0 0x.* in __sanitizer_print_stack_trace}}
+// CHECK: {{    #1 0x.* in FooBarBaz\(\) .*print-stack-trace.cc:7}}
+// CHECK: {{    #2 0x.* in main .*print-stack-trace.cc:11}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3899.9766.patch
Type: text/x-patch
Size: 2458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140523/c8e9c028/attachment.bin>


More information about the llvm-commits mailing list