1 //===-- sanitizer_stacktrace.h ----------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is shared between AddressSanitizer and ThreadSanitizer
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;
21 typedef bool (*SymbolizeCallback
)(const void *pc
, char *out_buffer
,
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
++)
32 for (uptr i
= size
; i
< dst_size
; i
++)
36 void CopyFrom(uptr
*src
, uptr src_size
) {
38 if (size
> kStackTraceMax
) size
= kStackTraceMax
;
39 for (uptr i
= 0; i
< size
; 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
);
59 const char *StripPathPrefix(const char *filepath
,
60 const char *strip_file_prefix
);
62 } // namespace __sanitizer
64 // Use this macro if you want to print stack trace with the caller
65 // of the current function in the top frame.
66 #define GET_CALLER_PC_BP_SP \
67 uptr bp = GET_CURRENT_FRAME(); \
68 uptr pc = GET_CALLER_PC(); \
70 uptr sp = (uptr)&local_stack
72 // Use this macro if you want to print stack trace with the current
73 // function in the top frame.
74 #define GET_CURRENT_PC_BP_SP \
75 uptr bp = GET_CURRENT_FRAME(); \
76 uptr pc = StackTrace::GetCurrentPc(); \
78 uptr sp = (uptr)&local_stack
81 #endif // SANITIZER_STACKTRACE_H