Daily bump.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_stacktrace.h
blobd06db5ffa7a9dc70da4da1d855cf39c6bc951ec1
1 //===-- sanitizer_stacktrace.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 shared between AddressSanitizer and ThreadSanitizer
9 // run-time libraries.
10 //===----------------------------------------------------------------------===//
11 #ifndef SANITIZER_STACKTRACE_H
12 #define SANITIZER_STACKTRACE_H
14 #include "sanitizer_internal_defs.h"
16 namespace __sanitizer {
18 static const uptr kStackTraceMax = 256;
20 #if SANITIZER_LINUX && (defined(__arm__) || \
21 defined(__powerpc__) || defined(__powerpc64__) || \
22 defined(__sparc__) || \
23 defined(__mips__))
24 # define SANITIZER_CAN_FAST_UNWIND 0
25 #elif SANITIZER_WINDOWS
26 # define SANITIZER_CAN_FAST_UNWIND 0
27 #else
28 # define SANITIZER_CAN_FAST_UNWIND 1
29 #endif
31 struct StackTrace {
32 typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
33 int out_size);
34 uptr top_frame_bp;
35 uptr size;
36 uptr trace[kStackTraceMax];
38 // Prints a symbolized stacktrace, followed by an empty line.
39 static void PrintStack(const uptr *addr, uptr size,
40 SymbolizeCallback symbolize_callback = 0);
42 void CopyFrom(const uptr *src, uptr src_size) {
43 top_frame_bp = 0;
44 size = src_size;
45 if (size > kStackTraceMax) size = kStackTraceMax;
46 for (uptr i = 0; i < size; i++)
47 trace[i] = src[i];
50 static bool WillUseFastUnwind(bool request_fast_unwind) {
51 // Check if fast unwind is available. Fast unwind is the only option on Mac.
52 if (!SANITIZER_CAN_FAST_UNWIND)
53 return false;
54 else if (SANITIZER_MAC)
55 return true;
56 return request_fast_unwind;
59 void Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top,
60 uptr stack_bottom, bool request_fast_unwind);
62 static uptr GetCurrentPc();
63 static uptr GetPreviousInstructionPc(uptr pc);
65 private:
66 void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom,
67 uptr max_depth);
68 void SlowUnwindStack(uptr pc, uptr max_depth);
69 void PopStackFrames(uptr count);
70 uptr LocatePcInTrace(uptr pc);
73 } // namespace __sanitizer
75 // Use this macro if you want to print stack trace with the caller
76 // of the current function in the top frame.
77 #define GET_CALLER_PC_BP_SP \
78 uptr bp = GET_CURRENT_FRAME(); \
79 uptr pc = GET_CALLER_PC(); \
80 uptr local_stack; \
81 uptr sp = (uptr)&local_stack
83 // Use this macro if you want to print stack trace with the current
84 // function in the top frame.
85 #define GET_CURRENT_PC_BP_SP \
86 uptr bp = GET_CURRENT_FRAME(); \
87 uptr pc = StackTrace::GetCurrentPc(); \
88 uptr local_stack; \
89 uptr sp = (uptr)&local_stack
92 #endif // SANITIZER_STACKTRACE_H