2012-10-29 Wei Mi <wmi@google.com>
[official-gcc.git] / libasan / sanitizer_common / sanitizer_stacktrace.h
bloba7934c65e1e0b35ca34c41abf82c862334b25cfe
1 //===-- sanitizer_stacktrace.h ----------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between AddressSanitizer and ThreadSanitizer
9 // run-time libraries.
10 //===----------------------------------------------------------------------===//
11 #ifndef SANITIZER_STACKTRACE_H
12 #define SANITIZER_STACKTRACE_H
14 #include "sanitizer_internal_defs.h"
16 namespace __sanitizer {
18 static const uptr kStackTraceMax = 256;
20 struct StackTrace {
21 typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
22 int out_size);
23 uptr size;
24 uptr max_size;
25 uptr trace[kStackTraceMax];
26 static void PrintStack(const uptr *addr, uptr size,
27 bool symbolize, const char *strip_file_prefix,
28 SymbolizeCallback symbolize_callback);
29 void CopyTo(uptr *dst, uptr dst_size) {
30 for (uptr i = 0; i < size && i < dst_size; i++)
31 dst[i] = trace[i];
32 for (uptr i = size; i < dst_size; i++)
33 dst[i] = 0;
36 void CopyFrom(uptr *src, uptr src_size) {
37 size = src_size;
38 if (size > kStackTraceMax) size = kStackTraceMax;
39 for (uptr i = 0; i < size; i++) {
40 trace[i] = src[i];
44 void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom);
46 static uptr GetCurrentPc();
48 static uptr CompressStack(StackTrace *stack,
49 u32 *compressed, uptr size);
50 static void UncompressStack(StackTrace *stack,
51 u32 *compressed, uptr size);
54 } // namespace __sanitizer
56 // Use this macro if you want to print stack trace with the caller
57 // of the current function in the top frame.
58 #define GET_CALLER_PC_BP_SP \
59 uptr bp = GET_CURRENT_FRAME(); \
60 uptr pc = GET_CALLER_PC(); \
61 uptr local_stack; \
62 uptr sp = (uptr)&local_stack
64 // Use this macro if you want to print stack trace with the current
65 // function in the top frame.
66 #define GET_CURRENT_PC_BP_SP \
67 uptr bp = GET_CURRENT_FRAME(); \
68 uptr pc = StackTrace::GetCurrentPc(); \
69 uptr local_stack; \
70 uptr sp = (uptr)&local_stack
73 #endif // SANITIZER_STACKTRACE_H