1 //===-- sanitizer_stacktrace_libcdep.cc -----------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is shared between AddressSanitizer and ThreadSanitizer
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_common.h"
13 #include "sanitizer_placement_new.h"
14 #include "sanitizer_stacktrace.h"
15 #include "sanitizer_stacktrace_printer.h"
16 #include "sanitizer_symbolizer.h"
18 namespace __sanitizer
{
20 void StackTrace::Print() const {
21 if (trace
== nullptr || size
== 0) {
22 Printf(" <empty stack>\n\n");
25 InternalScopedString
frame_desc(GetPageSizeCached() * 2);
27 for (uptr i
= 0; i
< size
&& trace
[i
]; i
++) {
28 // PCs in stack traces are actually the return addresses, that is,
29 // addresses of the next instructions after the call.
30 uptr pc
= GetPreviousInstructionPc(trace
[i
]);
31 SymbolizedStack
*frames
= Symbolizer::GetOrInit()->SymbolizePC(pc
);
33 for (SymbolizedStack
*cur
= frames
; cur
; cur
= cur
->next
) {
35 RenderFrame(&frame_desc
, common_flags()->stack_trace_format
, frame_num
++,
36 cur
->info
, common_flags()->symbolize_vs_style
,
37 common_flags()->strip_path_prefix
);
38 Printf("%s\n", frame_desc
.data());
42 // Always print a trailing empty line after stack trace.
46 void BufferedStackTrace::Unwind(u32 max_depth
, uptr pc
, uptr bp
, void *context
,
47 uptr stack_top
, uptr stack_bottom
,
48 bool request_fast_unwind
) {
49 top_frame_bp
= (max_depth
> 0) ? bp
: 0;
50 // Avoid doing any work for small max_depth.
60 if (!WillUseFastUnwind(request_fast_unwind
)) {
61 #if SANITIZER_CAN_SLOW_UNWIND
63 SlowUnwindStackWithContext(pc
, context
, max_depth
);
65 SlowUnwindStack(pc
, max_depth
);
67 UNREACHABLE("slow unwind requested but not available");
70 FastUnwindStack(pc
, bp
, stack_top
, stack_bottom
, max_depth
);
74 } // namespace __sanitizer