1 //===-- sanitizer_symbolizer_fuchsia.cc -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is shared between various sanitizers' runtime libraries.
12 // Implementation of Fuchsia-specific symbolizer.
13 //===----------------------------------------------------------------------===//
15 #include "sanitizer_platform.h"
18 #include "sanitizer_fuchsia.h"
19 #include "sanitizer_symbolizer.h"
21 namespace __sanitizer {
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
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.
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.
39 // Global variable name or equivalent from data memory address.
40 constexpr const char *kFormatData = "{{{data:%p}}}";
42 // One frame in a backtrace (printed on a line by itself).
43 constexpr const char *kFormatFrame = "{{{bt:%u:%p}}}";
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);
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) {
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
68 // TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
69 // to render stack frames, but that should be changed to use
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);
79 // Always claim we succeeded, so that RenderDataInfo will be called.
80 bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
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);
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);
99 Symbolizer *Symbolizer::PlatformInit() {
100 return new (symbolizer_allocator_) Symbolizer({});
103 void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
105 } // namespace __sanitizer
107 #endif // SANITIZER_FUCHSIA