sanitizer_stacktrace.h revision a30c8f9eac981dcf137e84226810b760e35c7be1
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 22struct 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; 36 } 37 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]; 43 } 44 } 45 46 void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom); 47 void SlowUnwindStack(uptr pc, uptr max_depth, uptr frames_to_pop); 48 49 void PopStackFrames(uptr count); 50 51 static uptr GetCurrentPc(); 52 53 static uptr CompressStack(StackTrace *stack, 54 u32 *compressed, uptr size); 55 static void UncompressStack(StackTrace *stack, 56 u32 *compressed, uptr size); 57}; 58 59} // namespace __sanitizer 60 61// Use this macro if you want to print stack trace with the caller 62// of the current function in the top frame. 63#define GET_CALLER_PC_BP_SP \ 64 uptr bp = GET_CURRENT_FRAME(); \ 65 uptr pc = GET_CALLER_PC(); \ 66 uptr local_stack; \ 67 uptr sp = (uptr)&local_stack 68 69// Use this macro if you want to print stack trace with the current 70// function in the top frame. 71#define GET_CURRENT_PC_BP_SP \ 72 uptr bp = GET_CURRENT_FRAME(); \ 73 uptr pc = StackTrace::GetCurrentPc(); \ 74 uptr local_stack; \ 75 uptr sp = (uptr)&local_stack 76 77 78#endif // SANITIZER_STACKTRACE_H 79