Account for prologue spills in reg_pressure scheduling
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_stacktrace.h
blob0e0f17022282150d749fcfe70d7278d80ecd632e
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(__aarch64__) || defined(__powerpc__) || \
21 defined(__powerpc64__) || defined(__sparc__) || \
22 defined(__mips__))
23 # define SANITIZER_CAN_FAST_UNWIND 0
24 #elif SANITIZER_WINDOWS
25 # define SANITIZER_CAN_FAST_UNWIND 0
26 #else
27 # define SANITIZER_CAN_FAST_UNWIND 1
28 #endif
30 struct StackTrace {
31 typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
32 int out_size);
33 uptr top_frame_bp;
34 uptr size;
35 uptr trace[kStackTraceMax];
37 // Prints a symbolized stacktrace, followed by an empty line.
38 static void PrintStack(const uptr *addr, uptr size);
39 void Print() const {
40 PrintStack(trace, size);
43 void CopyFrom(const uptr *src, uptr src_size) {
44 top_frame_bp = 0;
45 size = src_size;
46 if (size > kStackTraceMax) size = kStackTraceMax;
47 for (uptr i = 0; i < size; i++)
48 trace[i] = src[i];
51 static bool WillUseFastUnwind(bool request_fast_unwind) {
52 // Check if fast unwind is available. Fast unwind is the only option on Mac.
53 // It is also the only option on FreeBSD as the slow unwinding that
54 // leverages _Unwind_Backtrace() yields the call stack of the signal's
55 // handler and not of the code that raised the signal (as it does on Linux).
56 if (!SANITIZER_CAN_FAST_UNWIND)
57 return false;
58 else if (SANITIZER_MAC != 0 || SANITIZER_FREEBSD != 0)
59 return true;
60 return request_fast_unwind;
63 void Unwind(uptr max_depth, uptr pc, uptr bp, void *context, uptr stack_top,
64 uptr stack_bottom, bool request_fast_unwind);
66 static uptr GetCurrentPc();
67 static uptr GetPreviousInstructionPc(uptr pc);
69 private:
70 void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom,
71 uptr max_depth);
72 void SlowUnwindStack(uptr pc, uptr max_depth);
73 void SlowUnwindStackWithContext(uptr pc, void *context,
74 uptr max_depth);
75 void PopStackFrames(uptr count);
76 uptr LocatePcInTrace(uptr pc);
79 } // namespace __sanitizer
81 // Use this macro if you want to print stack trace with the caller
82 // of the current function in the top frame.
83 #define GET_CALLER_PC_BP_SP \
84 uptr bp = GET_CURRENT_FRAME(); \
85 uptr pc = GET_CALLER_PC(); \
86 uptr local_stack; \
87 uptr sp = (uptr)&local_stack
89 #define GET_CALLER_PC_BP \
90 uptr bp = GET_CURRENT_FRAME(); \
91 uptr pc = GET_CALLER_PC();
93 // Use this macro if you want to print stack trace with the current
94 // function in the top frame.
95 #define GET_CURRENT_PC_BP_SP \
96 uptr bp = GET_CURRENT_FRAME(); \
97 uptr pc = StackTrace::GetCurrentPc(); \
98 uptr local_stack; \
99 uptr sp = (uptr)&local_stack
102 #endif // SANITIZER_STACKTRACE_H