Alexey Samsonov | e5f5895 | 2012-06-04 13:50:10 +0000 | [diff] [blame] | 1 | //===-- asan_stack.cc -----------------------------------------------------===// |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of AddressSanitizer, an address sanity checker. |
| 11 | // |
| 12 | // Code for ASan stack trace. |
| 13 | //===----------------------------------------------------------------------===// |
Alexey Samsonov | c70fa28 | 2013-01-31 13:46:14 +0000 | [diff] [blame] | 14 | #include "asan_internal.h" |
Kostya Serebryany | 1b5ea8f | 2012-08-28 14:11:57 +0000 | [diff] [blame] | 15 | #include "asan_flags.h" |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 16 | #include "asan_stack.h" |
Sergey Matveev | ed20ebe | 2013-05-06 11:27:58 +0000 | [diff] [blame] | 17 | #include "sanitizer_common/sanitizer_flags.h" |
Alexey Samsonov | 5f2fe37 | 2012-06-04 11:20:17 +0000 | [diff] [blame] | 18 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 19 | namespace __asan { |
| 20 | |
Alexey Samsonov | 6a08d29 | 2012-12-07 22:01:28 +0000 | [diff] [blame] | 21 | static bool MaybeCallAsanSymbolize(const void *pc, char *out_buffer, |
| 22 | int out_size) { |
| 23 | return (&__asan_symbolize) ? __asan_symbolize(pc, out_buffer, out_size) |
| 24 | : false; |
| 25 | } |
| 26 | |
Kostya Serebryany | 6d95869 | 2013-10-18 14:50:44 +0000 | [diff] [blame] | 27 | void PrintStack(const uptr *trace, uptr size) { |
Kostya Serebryany | 547f9dd | 2013-10-18 17:46:43 +0000 | [diff] [blame^] | 28 | if (!trace) { |
| 29 | Printf("<empty stack>\n"); |
| 30 | return; |
| 31 | } |
Kostya Serebryany | 6d95869 | 2013-10-18 14:50:44 +0000 | [diff] [blame] | 32 | StackTrace::PrintStack(trace, size, common_flags()->symbolize, |
Alexey Samsonov | 90b0f1e | 2013-10-04 08:55:03 +0000 | [diff] [blame] | 33 | MaybeCallAsanSymbolize); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 34 | } |
Kostya Serebryany | 6d95869 | 2013-10-18 14:50:44 +0000 | [diff] [blame] | 35 | void PrintStack(StackTrace *stack) { |
| 36 | PrintStack(stack->trace, stack->size); |
| 37 | } |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 38 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 39 | } // namespace __asan |
Alexey Samsonov | c93d3e2 | 2012-08-22 13:31:37 +0000 | [diff] [blame] | 40 | |
| 41 | // ------------------ Interface -------------- {{{1 |
Alexey Samsonov | c93d3e2 | 2012-08-22 13:31:37 +0000 | [diff] [blame] | 42 | |
Alexey Samsonov | 1ca5357 | 2012-10-02 12:11:17 +0000 | [diff] [blame] | 43 | // Provide default implementation of __asan_symbolize that does nothing |
| 44 | // and may be overriden by user if he wants to use his own symbolization. |
| 45 | // ASan on Windows has its own implementation of this. |
Evgeniy Stepanov | 24e1372 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 46 | #if !SANITIZER_WINDOWS && !SANITIZER_SUPPORTS_WEAK_HOOKS |
Timur Iskhodzhanov | 3c80c6c | 2013-08-13 11:42:45 +0000 | [diff] [blame] | 47 | SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE |
Alexey Samsonov | 1ca5357 | 2012-10-02 12:11:17 +0000 | [diff] [blame] | 48 | bool __asan_symbolize(const void *pc, char *out_buffer, int out_size) { |
| 49 | return false; |
Alexey Samsonov | c93d3e2 | 2012-08-22 13:31:37 +0000 | [diff] [blame] | 50 | } |
Alexey Samsonov | 1ca5357 | 2012-10-02 12:11:17 +0000 | [diff] [blame] | 51 | #endif |