re PR target/69667 (ppc64le -mlra: ICE: Max. number of generated reload insns per...
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_stacktrace_libcdep.cc
blobaddf44f73279f1c1248336dbe5caba0ecc364c59
1 //===-- sanitizer_stacktrace_libcdep.cc -----------------------------------===//
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 //===----------------------------------------------------------------------===//
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");
23 return;
25 InternalScopedString frame_desc(GetPageSizeCached() * 2);
26 uptr frame_num = 0;
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);
32 CHECK(frames);
33 for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
34 frame_desc.clear();
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());
40 frames->ClearAll();
42 // Always print a trailing empty line after stack trace.
43 Printf("\n");
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.
51 if (max_depth == 0) {
52 size = 0;
53 return;
55 if (max_depth == 1) {
56 size = 1;
57 trace_buffer[0] = pc;
58 return;
60 if (!WillUseFastUnwind(request_fast_unwind)) {
61 #if SANITIZER_CAN_SLOW_UNWIND
62 if (context)
63 SlowUnwindStackWithContext(pc, context, max_depth);
64 else
65 SlowUnwindStack(pc, max_depth);
66 #else
67 UNREACHABLE("slow unwind requested but not available");
68 #endif
69 } else {
70 FastUnwindStack(pc, bp, stack_top, stack_bottom, max_depth);
74 } // namespace __sanitizer