summaryrefslogtreecommitdiff
path: root/lib/ubsan/ubsan_diag_standalone.cc
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2017-05-05 09:02:28 +0000
committerAlexander Potapenko <glider@google.com>2017-05-05 09:02:28 +0000
commit4ff00356cf47a180215cf673c33228b79c5a777a (patch)
tree96e1eacc6975555fcb1b26ed6dd3d34625d7bdbb /lib/ubsan/ubsan_diag_standalone.cc
parentf8e7a418d567bfbabafbff41c9e52a8386dd1160 (diff)
[ubsan] Implement __sanitizer_print_stack_trace for standalone UBSan runtime.
Patch by Max Moroz, reviewed at https://reviews.llvm.org/D32542 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302218 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ubsan/ubsan_diag_standalone.cc')
-rw-r--r--lib/ubsan/ubsan_diag_standalone.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/ubsan/ubsan_diag_standalone.cc b/lib/ubsan/ubsan_diag_standalone.cc
new file mode 100644
index 000000000..df8ed5fcd
--- /dev/null
+++ b/lib/ubsan/ubsan_diag_standalone.cc
@@ -0,0 +1,37 @@
+//===-- ubsan_diag_standalone.cc ------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Diagnostic reporting for the standalone UBSan runtime.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ubsan_platform.h"
+#if CAN_SANITIZE_UB
+#include "ubsan_diag.h"
+
+using namespace __ubsan;
+
+extern "C" {
+SANITIZER_INTERFACE_ATTRIBUTE
+void __sanitizer_print_stack_trace() {
+ uptr top = 0;
+ uptr bottom = 0;
+ bool request_fast_unwind = common_flags()->fast_unwind_on_fatal;
+ if (request_fast_unwind)
+ __sanitizer::GetThreadStackTopAndBottom(false, &top, &bottom);
+
+ GET_REPORT_OPTIONS(false);
+ BufferedStackTrace stack;
+ stack.Unwind(kStackTraceMax, Opts.pc, Opts.bp, nullptr, top, bottom,
+ request_fast_unwind);
+ stack.Print();
+}
+} // extern "C"
+
+#endif // CAN_SANITIZE_UB