[PATCH] [sanitizer] Expose __sanitizer_print_stack_trace().

Sergey Matveev earthdok at google.com
Tue Nov 19 08:31:26 PST 2013


Hi samsonov,

Useful for debugging code built with sanitizer tools.

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

Files:
  include/sanitizer/common_interface_defs.h
  lib/sanitizer_common/sanitizer_common_libcdep.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.
+  void __sanitizer_print_stack_trace();
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif
Index: lib/sanitizer_common/sanitizer_common_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_common_libcdep.cc
+++ lib/sanitizer_common/sanitizer_common_libcdep.cc
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "sanitizer_common.h"
+#include "sanitizer_stacktrace.h"
 
 namespace __sanitizer {
 
@@ -35,3 +36,14 @@
   return prints_to_tty;
 }
 }  // namespace __sanitizer
+
+extern "C" {
+void __sanitizer_print_stack_trace() {
+  GET_CURRENT_PC_BP_SP;
+  (void) sp;
+  StackTrace stack;
+  stack.Unwind(kStackTraceMax, pc, bp, 0 /* stack_top */, 0 /* stack_bottom */,
+               false /* request_fast_unwind */);
+  StackTrace::PrintStack(stack.trace, stack.size);
+}
+}  // extern "C"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2221.1.patch
Type: text/x-patch
Size: 1334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131119/111427c4/attachment.bin>


More information about the llvm-commits mailing list