asan_stack.cc revision db92faf488988543b18aaac537ac5ee4f4ee68a5
1//===-- asan_stack.cc -----------------------------------------------------===//
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//===----------------------------------------------------------------------===//
14#include "asan_internal.h"
15#include "asan_flags.h"
16#include "asan_stack.h"
17#include "sanitizer_common/sanitizer_flags.h"
18
19namespace __asan {
20
21static 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
27void PrintStack(const uptr *trace, uptr size) {
28  if (!trace) {
29    Printf("<empty stack>\n\n");
30    return;
31  }
32  StackTrace::PrintStack(trace, size, common_flags()->symbolize,
33                         MaybeCallAsanSymbolize);
34    Printf("\n");
35}
36
37void PrintStack(StackTrace *stack) {
38  PrintStack(stack->trace, stack->size);
39}
40
41}  // namespace __asan
42
43// ------------------ Interface -------------- {{{1
44
45// Provide default implementation of __asan_symbolize that does nothing
46// and may be overriden by user if he wants to use his own symbolization.
47// ASan on Windows has its own implementation of this.
48#if !SANITIZER_WINDOWS && !SANITIZER_SUPPORTS_WEAK_HOOKS
49SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE
50bool __asan_symbolize(const void *pc, char *out_buffer, int out_size) {
51  return false;
52}
53#endif
54