diff options
author | Sergey Matveev <earthdok@google.com> | 2013-12-03 18:24:28 +0000 |
---|---|---|
committer | Sergey Matveev <earthdok@google.com> | 2013-12-03 18:24:28 +0000 |
commit | 82c016a473f9bbfa7bbe2618a4cf96838b113b82 (patch) | |
tree | 017170429828b20cfeed8af751772ded3f3f259a /lib | |
parent | 4621fc91a3e0ca9f337813fa2ba4cfd9849c21f7 (diff) |
[sanitizer] Expose __sanitizer_print_stack_trace().
Expose a new interface function for debugging code built with sanitizer tools.
Add an ASan implementation.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@196302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asan/asan_stack.cc | 6 | ||||
-rw-r--r-- | lib/asan/asan_stack.h | 9 | ||||
-rw-r--r-- | lib/asan/lit_tests/TestCases/print-stack-trace.cc | 16 |
3 files changed, 26 insertions, 5 deletions
diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc index 0bc5a5f2d..f5fba4b2d 100644 --- a/lib/asan/asan_stack.cc +++ b/lib/asan/asan_stack.cc @@ -45,3 +45,9 @@ bool __asan_symbolize(const void *pc, char *out_buffer, int out_size) { return false; } #endif + +SANITIZER_INTERFACE_ATTRIBUTE +extern "C" void __sanitizer_print_stack_trace() { + using namespace __asan; + PRINT_CURRENT_STACK(); +} diff --git a/lib/asan/asan_stack.h b/lib/asan/asan_stack.h index dedc59302..6a6ffe44e 100644 --- a/lib/asan/asan_stack.h +++ b/lib/asan/asan_stack.h @@ -77,11 +77,10 @@ void PrintStack(const uptr *trace, uptr size); #define GET_STACK_TRACE_FREE GET_STACK_TRACE_MALLOC -#define PRINT_CURRENT_STACK() \ - { \ - GET_STACK_TRACE(kStackTraceMax, \ - common_flags()->fast_unwind_on_fatal); \ - PrintStack(&stack); \ +#define PRINT_CURRENT_STACK() \ + { \ + GET_STACK_TRACE_FATAL_HERE; \ + PrintStack(&stack); \ } #endif // ASAN_STACK_H diff --git a/lib/asan/lit_tests/TestCases/print-stack-trace.cc b/lib/asan/lit_tests/TestCases/print-stack-trace.cc new file mode 100644 index 000000000..923fa6580 --- /dev/null +++ b/lib/asan/lit_tests/TestCases/print-stack-trace.cc @@ -0,0 +1,16 @@ +// RUN: %clangxx_asan -O0 %s -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -o %t && %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}} |