sanitizer_stacktrace.h revision d09c91ac4e2f544651921b7cb307e8aaae8948d1
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 trace[kStackTraceMax]; 36 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 size = src_size; 42 if (size > kStackTraceMax) size = kStackTraceMax; 43 for (uptr i = 0; i < size; i++) 44 trace[i] = src[i]; 45 } 46 47 void Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top, 48 uptr stack_bottom, bool fast); 49 // FIXME: Make FastUnwindStack and SlowUnwindStack private methods. 50 void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom, 51 uptr max_depth); 52 void SlowUnwindStack(uptr pc, uptr max_depth); 53 54 void PopStackFrames(uptr count); 55 56 static uptr GetCurrentPc(); 57 static uptr GetPreviousInstructionPc(uptr pc); 58 59 static uptr CompressStack(StackTrace *stack, 60 u32 *compressed, uptr size); 61 static void UncompressStack(StackTrace *stack, 62 u32 *compressed, uptr size); 63}; 64 65} // namespace __sanitizer 66 67// Use this macro if you want to print stack trace with the caller 68// of the current function in the top frame. 69#define GET_CALLER_PC_BP_SP \ 70 uptr bp = GET_CURRENT_FRAME(); \ 71 uptr pc = GET_CALLER_PC(); \ 72 uptr local_stack; \ 73 uptr sp = (uptr)&local_stack 74 75// Use this macro if you want to print stack trace with the current 76// function in the top frame. 77#define GET_CURRENT_PC_BP_SP \ 78 uptr bp = GET_CURRENT_FRAME(); \ 79 uptr pc = StackTrace::GetCurrentPc(); \ 80 uptr local_stack; \ 81 uptr sp = (uptr)&local_stack 82 83 84#endif // SANITIZER_STACKTRACE_H 85