From a531058d2b6572e1502bf129a5b1fe973c350976 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 26 May 2014 13:08:08 +0000 Subject: [PATCH] [MSan] Implement __sanitizer_print_stack_trace(). llvm-svn: 209625 --- compiler-rt/lib/msan/msan.cc | 16 ++++++++++------ compiler-rt/lib/msan/msan.h | 7 +++++++ compiler-rt/test/asan/TestCases/print-stack-trace.cc | 16 ---------------- .../sanitizer_common/TestCases/print-stack-trace.cc | 20 ++++++++++++++++++++ compiler-rt/test/sanitizer_common/lit.common.cfg | 2 ++ 5 files changed, 39 insertions(+), 22 deletions(-) delete mode 100644 compiler-rt/test/asan/TestCases/print-stack-trace.cc create mode 100644 compiler-rt/test/sanitizer_common/TestCases/print-stack-trace.cc diff --git a/compiler-rt/lib/msan/msan.cc b/compiler-rt/lib/msan/msan.cc index 058ef7e..5ee92bf 100644 --- a/compiler-rt/lib/msan/msan.cc +++ b/compiler-rt/lib/msan/msan.cc @@ -211,9 +211,7 @@ void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin) { ++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_umr) { } 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_WEAK_ATTRIBUTE 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" diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h index e8b25e3..2105791 100644 --- a/compiler-rt/lib/msan/msan.h +++ b/compiler-rt/lib/msan/msan.h @@ -111,6 +111,13 @@ u32 ChainOrigin(u32 id, StackTrace *stack); 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()) diff --git a/compiler-rt/test/asan/TestCases/print-stack-trace.cc b/compiler-rt/test/asan/TestCases/print-stack-trace.cc deleted file mode 100644 index d6fc654..0000000 --- a/compiler-rt/test/asan/TestCases/print-stack-trace.cc +++ /dev/null @@ -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 - -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}} diff --git a/compiler-rt/test/sanitizer_common/TestCases/print-stack-trace.cc b/compiler-rt/test/sanitizer_common/TestCases/print-stack-trace.cc new file mode 100644 index 0000000..98d9ddf --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/print-stack-trace.cc @@ -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 + +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}} diff --git a/compiler-rt/test/sanitizer_common/lit.common.cfg b/compiler-rt/test/sanitizer_common/lit.common.cfg index b4a2f3c..6e2d772 100644 --- a/compiler-rt/test/sanitizer_common/lit.common.cfg +++ b/compiler-rt/test/sanitizer_common/lit.common.cfg @@ -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 -- 2.7.4