blob: cbc151cc1bab723d4be0da6a04307f122caa75eb [file] [log] [blame]
Alexey Samsonove5f58952012-06-04 13:50:10 +00001//===-- asan_stack.cc -----------------------------------------------------===//
Kostya Serebryany1e172b42011-11-30 01:07:02 +00002//
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 Samsonovc70fa282013-01-31 13:46:14 +000014#include "asan_internal.h"
Kostya Serebryany1b5ea8f2012-08-28 14:11:57 +000015#include "asan_flags.h"
Kostya Serebryany1e172b42011-11-30 01:07:02 +000016#include "asan_stack.h"
Sergey Matveeved20ebe2013-05-06 11:27:58 +000017#include "sanitizer_common/sanitizer_flags.h"
Alexey Samsonov5f2fe372012-06-04 11:20:17 +000018
Kostya Serebryany1e172b42011-11-30 01:07:02 +000019namespace __asan {
20
Alexey Samsonov6a08d292012-12-07 22:01:28 +000021static 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 Serebryany6d958692013-10-18 14:50:44 +000027void PrintStack(const uptr *trace, uptr size) {
Kostya Serebryany547f9dd2013-10-18 17:46:43 +000028 if (!trace) {
29 Printf("<empty stack>\n");
30 return;
31 }
Kostya Serebryany6d958692013-10-18 14:50:44 +000032 StackTrace::PrintStack(trace, size, common_flags()->symbolize,
Alexey Samsonov90b0f1e2013-10-04 08:55:03 +000033 MaybeCallAsanSymbolize);
Kostya Serebryanycc347222012-08-28 13:49:49 +000034}
Kostya Serebryany6d958692013-10-18 14:50:44 +000035void PrintStack(StackTrace *stack) {
36 PrintStack(stack->trace, stack->size);
37}
Kostya Serebryanycc347222012-08-28 13:49:49 +000038
Kostya Serebryany1e172b42011-11-30 01:07:02 +000039} // namespace __asan
Alexey Samsonovc93d3e22012-08-22 13:31:37 +000040
41// ------------------ Interface -------------- {{{1
Alexey Samsonovc93d3e22012-08-22 13:31:37 +000042
Alexey Samsonov1ca53572012-10-02 12:11:17 +000043// 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 Stepanov24e13722013-03-19 14:33:38 +000046#if !SANITIZER_WINDOWS && !SANITIZER_SUPPORTS_WEAK_HOOKS
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000047SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE
Alexey Samsonov1ca53572012-10-02 12:11:17 +000048bool __asan_symbolize(const void *pc, char *out_buffer, int out_size) {
49 return false;
Alexey Samsonovc93d3e22012-08-22 13:31:37 +000050}
Alexey Samsonov1ca53572012-10-02 12:11:17 +000051#endif