[Sanitizer] extend internal libc with stat/fstat/lstat functions
[blocksruntime.git] / lib / sanitizer_common / sanitizer_stacktrace.h
blob597d24fd067f7cb7b09216d179adef6f03ffe17c
1 //===-- sanitizer_stacktrace.h ----------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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;
22 struct StackTrace {
23 typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
24 int out_size);
25 uptr size;
26 uptr max_size;
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++)
33 dst[i] = trace[i];
34 for (uptr i = size; i < dst_size; i++)
35 dst[i] = 0;
38 void CopyFrom(uptr *src, uptr src_size) {
39 size = src_size;
40 if (size > kStackTraceMax) size = kStackTraceMax;
41 for (uptr i = 0; i < size; i++) {
42 trace[i] = src[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(); \
67 uptr local_stack; \
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(); \
75 uptr local_stack; \
76 uptr sp = (uptr)&local_stack
79 #endif // SANITIZER_STACKTRACE_H