sanitizer_stacktrace.h revision ef578990fe3c9afecfcab1044d739371f4d4b459
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 FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom, 43 uptr max_depth); 44 void SlowUnwindStack(uptr pc, uptr max_depth); 45 46 void PopStackFrames(uptr count); 47 48 static uptr GetCurrentPc(); 49 static uptr GetPreviousInstructionPc(uptr pc); 50 51 SANITIZER_INTERFACE_ATTRIBUTE 52 static uptr CompressStack(StackTrace *stack, 53 u32 *compressed, uptr size); 54 SANITIZER_INTERFACE_ATTRIBUTE 55 static void UncompressStack(StackTrace *stack, 56 u32 *compressed, uptr size); 57}; 58 59void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, 60 uptr stack_top, uptr stack_bottom, bool fast); 61 62} // namespace __sanitizer 63 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(); \ 69 uptr local_stack; \ 70 uptr sp = (uptr)&local_stack 71 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(); \ 77 uptr local_stack; \ 78 uptr sp = (uptr)&local_stack 79 80 81#endif // SANITIZER_STACKTRACE_H 82