sanitizer_stacktrace.h revision 80175018541984bdcfe6a304bb189bd30592fa8a
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 15 16#include "sanitizer_internal_defs.h" 17 18namespace __sanitizer { 19 20static const uptr kStackTraceMax = 256; 21 22#if SANITIZER_LINUX && (defined(__arm__) || \ 23 defined(__powerpc__) || defined(__powerpc64__) || \ 24 defined(__sparc__) || \ 25 defined(__mips__)) 26#define SANITIZER_CAN_FAST_UNWIND 0 27#else 28#define SANITIZER_CAN_FAST_UNWIND 1 29#endif 30 31struct StackTrace { 32 typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer, 33 int out_size); 34 uptr size; 35 uptr max_size; 36 uptr trace[kStackTraceMax]; 37 static void PrintStack(const uptr *addr, uptr size, bool symbolize, 38 SymbolizeCallback symbolize_callback); 39 40 void CopyFrom(const uptr *src, uptr src_size); 41 42 void Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top, 43 uptr stack_bottom, bool fast); 44 // FIXME: Make FastUnwindStack and SlowUnwindStack private methods. 45 void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom, 46 uptr max_depth); 47 void SlowUnwindStack(uptr pc, uptr max_depth); 48 49 void PopStackFrames(uptr count); 50 51 static uptr GetCurrentPc(); 52 static uptr GetPreviousInstructionPc(uptr pc); 53 54 static uptr CompressStack(StackTrace *stack, 55 u32 *compressed, uptr size); 56 static void UncompressStack(StackTrace *stack, 57 u32 *compressed, uptr size); 58}; 59 60} // namespace __sanitizer 61 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 69 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 77 78 79#endif // SANITIZER_STACKTRACE_H 80