[PATCH] [sanitizer] Expose __sanitizer_print_stack_trace().

Sergey Matveev earthdok at google.com
Mon Dec 2 09:05:31 PST 2013


    - leave only the ASan implementation for now
    - add a test

Hi samsonov,

http://llvm-reviews.chandlerc.com/D2221

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2221?vs=5814&id=5852#toc

Files:
  include/sanitizer/common_interface_defs.h
  lib/asan/asan_stack.cc
  lib/asan/lit_tests/TestCases/print-stack-trace.cc

Index: include/sanitizer/common_interface_defs.h
===================================================================
--- include/sanitizer/common_interface_defs.h
+++ include/sanitizer/common_interface_defs.h
@@ -85,6 +85,9 @@
                                                  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
Index: lib/asan/asan_stack.cc
===================================================================
--- lib/asan/asan_stack.cc
+++ lib/asan/asan_stack.cc
@@ -45,3 +45,11 @@
   return false;
 }
 #endif
+
+using namespace __asan;  // NOLINT
+
+SANITIZER_INTERFACE_ATTRIBUTE
+extern "C" void __sanitizer_print_stack_trace() {
+  GET_STACK_TRACE_FATAL_HERE;
+  PrintStack(&stack);
+}
Index: lib/asan/lit_tests/TestCases/print-stack-trace.cc
===================================================================
--- /dev/null
+++ lib/asan/lit_tests/TestCases/print-stack-trace.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx_asan -O0 %s -o %t && %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 %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:9}}
+// CHECK: {{    #2 0x.* in main .*print-stack-trace.cc:13}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2221.3.patch
Type: text/x-patch
Size: 1722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131202/e9b735d8/attachment.bin>


More information about the llvm-commits mailing list