1 //===-- sanitizer_stacktrace.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is shared between AddressSanitizer and ThreadSanitizer
11 // run-time libraries.
12 //===----------------------------------------------------------------------===//
13 #ifndef SANITIZER_STACKTRACE_H
14 #define SANITIZER_STACKTRACE_H
16 #include "sanitizer_internal_defs.h"
18 namespace __sanitizer
{
20 static const uptr kStackTraceMax
= 256;
23 typedef bool (*SymbolizeCallback
)(const void *pc
, char *out_buffer
,
27 uptr trace
[kStackTraceMax
];
28 static void PrintStack(const uptr
*addr
, uptr size
,
29 bool symbolize
, const char *strip_file_prefix
,
30 SymbolizeCallback symbolize_callback
);
31 void CopyTo(uptr
*dst
, uptr dst_size
) {
32 for (uptr i
= 0; i
< size
&& i
< dst_size
; i
++)
34 for (uptr i
= size
; i
< dst_size
; i
++)
38 void CopyFrom(uptr
*src
, uptr src_size
) {
40 if (size
> kStackTraceMax
) size
= kStackTraceMax
;
41 for (uptr i
= 0; i
< size
; i
++) {
46 void FastUnwindStack(uptr pc
, uptr bp
, uptr stack_top
, uptr stack_bottom
);
47 void SlowUnwindStack(uptr pc
, uptr max_depth
);
49 void PopStackFrames(uptr count
);
51 static uptr
GetCurrentPc();
52 static uptr
GetPreviousInstructionPc(uptr pc
);
54 static uptr
CompressStack(StackTrace
*stack
,
55 u32
*compressed
, uptr size
);
56 static void UncompressStack(StackTrace
*stack
,
57 u32
*compressed
, uptr size
);
60 } // namespace __sanitizer
62 // Use this macro if you want to print stack trace with the caller
63 // of the current function in the top frame.
64 #define GET_CALLER_PC_BP_SP \
65 uptr bp = GET_CURRENT_FRAME(); \
66 uptr pc = GET_CALLER_PC(); \
68 uptr sp = (uptr)&local_stack
70 // Use this macro if you want to print stack trace with the current
71 // function in the top frame.
72 #define GET_CURRENT_PC_BP_SP \
73 uptr bp = GET_CURRENT_FRAME(); \
74 uptr pc = StackTrace::GetCurrentPc(); \
76 uptr sp = (uptr)&local_stack
79 #endif // SANITIZER_STACKTRACE_H