* config/pa/constraints.md: Adjust unused letters. Change "T"
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_stacktrace.h
blobc939644401cd0f6ed41717988c50fcd0441afff5
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 struct StackTrace {
21 typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
22 int out_size);
23 uptr size;
24 uptr max_size;
25 uptr trace[kStackTraceMax];
26 static void PrintStack(const uptr *addr, uptr size,
27 bool symbolize, const char *strip_file_prefix,
28 SymbolizeCallback symbolize_callback);
29 void CopyTo(uptr *dst, uptr dst_size) {
30 for (uptr i = 0; i < size && i < dst_size; i++)
31 dst[i] = trace[i];
32 for (uptr i = size; i < dst_size; i++)
33 dst[i] = 0;
36 void CopyFrom(uptr *src, uptr src_size) {
37 size = src_size;
38 if (size > kStackTraceMax) size = kStackTraceMax;
39 for (uptr i = 0; i < size; i++) {
40 trace[i] = src[i];
44 void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom);
45 void SlowUnwindStack(uptr pc, uptr max_depth);
47 void PopStackFrames(uptr count);
49 static uptr GetCurrentPc();
50 static uptr GetPreviousInstructionPc(uptr pc);
52 static uptr CompressStack(StackTrace *stack,
53 u32 *compressed, uptr size);
54 static void UncompressStack(StackTrace *stack,
55 u32 *compressed, uptr size);
58 } // namespace __sanitizer
60 // Use this macro if you want to print stack trace with the caller
61 // of the current function in the top frame.
62 #define GET_CALLER_PC_BP_SP \
63 uptr bp = GET_CURRENT_FRAME(); \
64 uptr pc = GET_CALLER_PC(); \
65 uptr local_stack; \
66 uptr sp = (uptr)&local_stack
68 // Use this macro if you want to print stack trace with the current
69 // function in the top frame.
70 #define GET_CURRENT_PC_BP_SP \
71 uptr bp = GET_CURRENT_FRAME(); \
72 uptr pc = StackTrace::GetCurrentPc(); \
73 uptr local_stack; \
74 uptr sp = (uptr)&local_stack
77 #endif // SANITIZER_STACKTRACE_H