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 | d8fb4d8f91dcfcf5fa59c09a2484e6498694e89d (patch) | |
tree | 593ba79bbc076d590fb226db2798867c3da7fe82 /compiler-rt | |
parent | 8e5283ad1d9fd8ad029d524c1c70df5e8d0b9eb3 (diff) | |
download | bcm5719-llvm-d8fb4d8f91dcfcf5fa59c09a2484e6498694e89d.tar.gz bcm5719-llvm-d8fb4d8f91dcfcf5fa59c09a2484e6498694e89d.zip |
[sanitizer] Expose __sanitizer_print_stack_trace().
Expose a new interface function for debugging code built with sanitizer tools.
Add an ASan implementation.
llvm-svn: 196302
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/include/sanitizer/common_interface_defs.h | 3 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_stack.cc | 6 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_stack.h | 9 | ||||
-rw-r--r-- | compiler-rt/lib/asan/lit_tests/TestCases/print-stack-trace.cc | 16 |
4 files changed, 29 insertions, 5 deletions
diff --git a/compiler-rt/include/sanitizer/common_interface_defs.h b/compiler-rt/include/sanitizer/common_interface_defs.h index 801fe48a93b..ce4f75ad5c8 100644 --- a/compiler-rt/include/sanitizer/common_interface_defs.h +++ b/compiler-rt/include/sanitizer/common_interface_defs.h @@ -85,6 +85,9 @@ extern "C" { const void *old_mid, const void *new_mid); + // Print the stack trace leading to this call. Useful for debugging user code. + void __sanitizer_print_stack_trace(); + #ifdef __cplusplus } // extern "C" #endif diff --git a/compiler-rt/lib/asan/asan_stack.cc b/compiler-rt/lib/asan/asan_stack.cc index 0bc5a5f2d03..f5fba4b2d6b 100644 --- a/compiler-rt/lib/asan/asan_stack.cc +++ b/compiler-rt/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/compiler-rt/lib/asan/asan_stack.h b/compiler-rt/lib/asan/asan_stack.h index dedc5930219..6a6ffe44e96 100644 --- a/compiler-rt/lib/asan/asan_stack.h +++ b/compiler-rt/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/compiler-rt/lib/asan/lit_tests/TestCases/print-stack-trace.cc b/compiler-rt/lib/asan/lit_tests/TestCases/print-stack-trace.cc new file mode 100644 index 00000000000..923fa6580e5 --- /dev/null +++ b/compiler-rt/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}} |