[compiler-rt] r196302 - [sanitizer] Expose __sanitizer_print_stack_trace().
Sergey Matveev
earthdok at google.com
Tue Dec 3 10:24:29 PST 2013
Author: smatveev
Date: Tue Dec 3 12:24:28 2013
New Revision: 196302
URL: http://llvm.org/viewvc/llvm-project?rev=196302&view=rev
Log:
[sanitizer] Expose __sanitizer_print_stack_trace().
Expose a new interface function for debugging code built with sanitizer tools.
Add an ASan implementation.
Added:
compiler-rt/trunk/lib/asan/lit_tests/TestCases/print-stack-trace.cc
Modified:
compiler-rt/trunk/include/sanitizer/common_interface_defs.h
compiler-rt/trunk/lib/asan/asan_stack.cc
compiler-rt/trunk/lib/asan/asan_stack.h
Modified: compiler-rt/trunk/include/sanitizer/common_interface_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/common_interface_defs.h?rev=196302&r1=196301&r2=196302&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/common_interface_defs.h (original)
+++ compiler-rt/trunk/include/sanitizer/common_interface_defs.h Tue Dec 3 12:24:28 2013
@@ -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
Modified: compiler-rt/trunk/lib/asan/asan_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=196302&r1=196301&r2=196302&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.cc Tue Dec 3 12:24:28 2013
@@ -45,3 +45,9 @@ bool __asan_symbolize(const void *pc, ch
return false;
}
#endif
+
+SANITIZER_INTERFACE_ATTRIBUTE
+extern "C" void __sanitizer_print_stack_trace() {
+ using namespace __asan;
+ PRINT_CURRENT_STACK();
+}
Modified: compiler-rt/trunk/lib/asan/asan_stack.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.h?rev=196302&r1=196301&r2=196302&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.h Tue Dec 3 12:24:28 2013
@@ -77,11 +77,10 @@ void PrintStack(const uptr *trace, uptr
#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
Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/print-stack-trace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/print-stack-trace.cc?rev=196302&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/print-stack-trace.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/print-stack-trace.cc Tue Dec 3 12:24:28 2013
@@ -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}}
More information about the llvm-commits
mailing list