[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
This commit is contained in:
Sergey Matveev 2013-12-03 18:24:28 +00:00
parent 8e5283ad1d
commit d8fb4d8f91
4 changed files with 29 additions and 5 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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

View File

@ -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}}