[compiler-rt] r209625 - [MSan] Implement __sanitizer_print_stack_trace().

Sergey Matveev earthdok at google.com
Mon May 26 06:08:08 PDT 2014


Author: smatveev
Date: Mon May 26 08:08:08 2014
New Revision: 209625

URL: http://llvm.org/viewvc/llvm-project?rev=209625&view=rev
Log:
[MSan] Implement __sanitizer_print_stack_trace().

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc
Removed:
    compiler-rt/trunk/test/asan/TestCases/print-stack-trace.cc
Modified:
    compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan.h
    compiler-rt/trunk/test/sanitizer_common/lit.common.cfg

Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=209625&r1=209624&r2=209625&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Mon May 26 08:08:08 2014
@@ -211,9 +211,7 @@ void PrintWarningWithOrigin(uptr pc, upt
 
   ++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 @@ void __msan_set_expect_umr(int expect_um
   } 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 @@ SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_
 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"

Modified: compiler-rt/trunk/lib/msan/msan.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=209625&r1=209624&r2=209625&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.h (original)
+++ compiler-rt/trunk/lib/msan/msan.h Mon May 26 08:08:08 2014
@@ -111,6 +111,13 @@ u32 ChainOrigin(u32 id, StackTrace *stac
     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())
 

Removed: compiler-rt/trunk/test/asan/TestCases/print-stack-trace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/print-stack-trace.cc?rev=209624&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/print-stack-trace.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/print-stack-trace.cc (removed)
@@ -1,16 +0,0 @@
-// RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s
-
-#include <sanitizer/asan_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}}

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc?rev=209625&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc Mon May 26 08:08:08 2014
@@ -0,0 +1,20 @@
+// RUN: %clangxx -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx -O3 %s -o %t && %run %t 2>&1 | FileCheck %s
+//
+// Not yet implemented for TSan.
+// https://code.google.com/p/address-sanitizer/issues/detail?id=243
+// XFAIL: tsan
+
+#include <sanitizer/common_interface_defs.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:11}}
+// CHECK: {{    #2 0x.* in main.*print-stack-trace.cc:15}}

Modified: compiler-rt/trunk/test/sanitizer_common/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/lit.common.cfg?rev=209625&r1=209624&r2=209625&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/lit.common.cfg (original)
+++ compiler-rt/trunk/test/sanitizer_common/lit.common.cfg Mon May 26 08:08:08 2014
@@ -14,6 +14,8 @@ elif config.tool_name == "msan":
 else:
   lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)
 
+config.available_features.add(config.tool_name)
+
 clang_cflags = ["-g"] + tool_cflags + [config.target_cflags]
 clang_cxxflags = config.cxx_mode_flags + clang_cflags
 





More information about the llvm-commits mailing list