]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_fuchsia.cc
Merge compiler-rt trunk r321017 to contrib/compiler-rt.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_symbolizer_fuchsia.cc
1 //===-- sanitizer_symbolizer_fuchsia.cc -----------------------------------===//
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 various sanitizers' runtime libraries.
11 //
12 // Implementation of Fuchsia-specific symbolizer.
13 //===----------------------------------------------------------------------===//
14
15 #include "sanitizer_platform.h"
16 #if SANITIZER_FUCHSIA
17
18 #include "sanitizer_fuchsia.h"
19 #include "sanitizer_symbolizer.h"
20
21 namespace __sanitizer {
22
23 // For Fuchsia we don't do any actual symbolization per se.
24 // Instead, we emit text containing raw addresses and raw linkage
25 // symbol names, embedded in Fuchsia's symbolization markup format.
26 // Fuchsia's logging infrastructure emits enough information about
27 // process memory layout that a post-processing filter can do the
28 // symbolization and pretty-print the markup.  See the spec at:
29 // https://fuchsia.googlesource.com/zircon/+/master/docs/symbolizer_markup.md
30
31 // This is used by UBSan for type names, and by ASan for global variable names.
32 constexpr const char *kFormatDemangle = "{{{symbol:%s}}}";
33 constexpr uptr kFormatDemangleMax = 1024;  // Arbitrary.
34
35 // Function name or equivalent from PC location.
36 constexpr const char *kFormatFunction = "{{{pc:%p}}}";
37 constexpr uptr kFormatFunctionMax = 64;  // More than big enough for 64-bit hex.
38
39 // Global variable name or equivalent from data memory address.
40 constexpr const char *kFormatData = "{{{data:%p}}}";
41
42 // One frame in a backtrace (printed on a line by itself).
43 constexpr const char *kFormatFrame = "{{{bt:%u:%p}}}";
44
45 // This is used by UBSan for type names, and by ASan for global variable names.
46 // It's expected to return a static buffer that will be reused on each call.
47 const char *Symbolizer::Demangle(const char *name) {
48   static char buffer[kFormatDemangleMax];
49   internal_snprintf(buffer, sizeof(buffer), kFormatDemangle, name);
50   return buffer;
51 }
52
53 // This is used mostly for suppression matching.  Making it work
54 // would enable "interceptor_via_lib" suppressions.  It's also used
55 // once in UBSan to say "in module ..." in a message that also
56 // includes an address in the module, so post-processing can already
57 // pretty-print that so as to indicate the module.
58 bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc, const char **module_name,
59                                              uptr *module_address) {
60   return false;
61 }
62
63 // This is used in some places for suppression checking, which we
64 // don't really support for Fuchsia.  It's also used in UBSan to
65 // identify a PC location to a function name, so we always fill in
66 // the function member with a string containing markup around the PC
67 // value.
68 // TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
69 // to render stack frames, but that should be changed to use
70 // RenderStackFrame.
71 SymbolizedStack *Symbolizer::SymbolizePC(uptr addr) {
72   SymbolizedStack *s = SymbolizedStack::New(addr);
73   char buffer[kFormatFunctionMax];
74   internal_snprintf(buffer, sizeof(buffer), kFormatFunction, addr);
75   s->info.function = internal_strdup(buffer);
76   return s;
77 }
78
79 // Always claim we succeeded, so that RenderDataInfo will be called.
80 bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
81   info->Clear();
82   info->start = addr;
83   return true;
84 }
85
86 // We ignore the format argument to __sanitizer_symbolize_global.
87 void RenderData(InternalScopedString *buffer, const char *format,
88                 const DataInfo *DI, const char *strip_path_prefix) {
89   buffer->append(kFormatData, DI->start);
90 }
91
92 // We don't support the stack_trace_format flag at all.
93 void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
94                  const AddressInfo &info, bool vs_style,
95                  const char *strip_path_prefix, const char *strip_func_prefix) {
96   buffer->append(kFormatFrame, frame_no, info.address);
97 }
98
99 Symbolizer *Symbolizer::PlatformInit() {
100   return new (symbolizer_allocator_) Symbolizer({});
101 }
102
103 void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
104
105 }  // namespace __sanitizer
106
107 #endif  // SANITIZER_FUCHSIA