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