2012-10-29 Wei Mi <wmi@google.com>
[official-gcc.git] / libasan / asan_stack.h
blobda622ed8eec0fb5e97a22679447909806c6a3196
1 //===-- asan_stack.h --------------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 // ASan-private header for asan_stack.cc.
11 //===----------------------------------------------------------------------===//
12 #ifndef ASAN_STACK_H
13 #define ASAN_STACK_H
15 #include "sanitizer_common/sanitizer_stacktrace.h"
17 namespace __asan {
19 void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp);
20 void PrintStack(StackTrace *stack);
22 } // namespace __asan
24 // Get the stack trace with the given pc and bp.
25 // The pc will be in the position 0 of the resulting stack trace.
26 // The bp may refer to the current frame or to the caller's frame.
27 // fast_unwind is currently unused.
28 #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp) \
29 StackTrace stack; \
30 GetStackTrace(&stack, max_s, pc, bp)
32 // NOTE: A Rule of thumb is to retrieve stack trace in the interceptors
33 // as early as possible (in functions exposed to the user), as we generally
34 // don't want stack trace to contain functions from ASan internals.
36 #define GET_STACK_TRACE_HERE(max_size) \
37 GET_STACK_TRACE_WITH_PC_AND_BP(max_size, \
38 StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
40 #define GET_STACK_TRACE_HERE_FOR_MALLOC \
41 GET_STACK_TRACE_HERE(flags()->malloc_context_size)
43 #define GET_STACK_TRACE_HERE_FOR_FREE(ptr) \
44 GET_STACK_TRACE_HERE(flags()->malloc_context_size)
46 #define PRINT_CURRENT_STACK() \
47 { \
48 GET_STACK_TRACE_HERE(kStackTraceMax); \
49 PrintStack(&stack); \
52 #endif // ASAN_STACK_H