1 //===-- sanitizer_symbolizer_markup_fuchsia.cpp ---------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is shared between various sanitizers' runtime libraries.
11 // Fuchsia specific implementation of offline markup symbolizer.
12 //===----------------------------------------------------------------------===//
13 #include "sanitizer_platform.h"
15 #if SANITIZER_SYMBOLIZER_MARKUP
17 # include "sanitizer_common.h"
18 # include "sanitizer_stacktrace_printer.h"
19 # include "sanitizer_symbolizer.h"
20 # include "sanitizer_symbolizer_markup.h"
21 # include "sanitizer_symbolizer_markup_constants.h"
23 namespace __sanitizer
{
25 // This is used by UBSan for type names, and by ASan for global variable names.
26 // It's expected to return a static buffer that will be reused on each call.
27 const char *Symbolizer::Demangle(const char *name
) {
28 static char buffer
[kFormatDemangleMax
];
29 internal_snprintf(buffer
, sizeof(buffer
), kFormatDemangle
, name
);
33 // This is used mostly for suppression matching. Making it work
34 // would enable "interceptor_via_lib" suppressions. It's also used
35 // once in UBSan to say "in module ..." in a message that also
36 // includes an address in the module, so post-processing can already
37 // pretty-print that so as to indicate the module.
38 bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc
, const char **module_name
,
39 uptr
*module_address
) {
43 // This is mainly used by hwasan for online symbolization. This isn't needed
44 // since hwasan can always just dump stack frames for offline symbolization.
45 bool Symbolizer::SymbolizeFrame(uptr addr
, FrameInfo
*info
) { return false; }
47 // This is used in some places for suppression checking, which we
48 // don't really support for Fuchsia. It's also used in UBSan to
49 // identify a PC location to a function name, so we always fill in
50 // the function member with a string containing markup around the PC
52 // TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
53 // to render stack frames, but that should be changed to use
55 SymbolizedStack
*Symbolizer::SymbolizePC(uptr addr
) {
56 SymbolizedStack
*s
= SymbolizedStack::New(addr
);
57 char buffer
[kFormatFunctionMax
];
58 internal_snprintf(buffer
, sizeof(buffer
), kFormatFunction
, addr
);
59 s
->info
.function
= internal_strdup(buffer
);
63 // Always claim we succeeded, so that RenderDataInfo will be called.
64 bool Symbolizer::SymbolizeData(uptr addr
, DataInfo
*info
) {
70 // Fuchsia only uses MarkupStackTracePrinter
71 StackTracePrinter
*StackTracePrinter::NewStackTracePrinter() {
72 return new (GetGlobalLowLevelAllocator()) MarkupStackTracePrinter();
75 void MarkupStackTracePrinter::RenderContext(InternalScopedString
*) {}
77 Symbolizer
*Symbolizer::PlatformInit() {
78 return new (symbolizer_allocator_
) Symbolizer({});
81 void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
83 } // namespace __sanitizer
85 #endif // SANITIZER_SYMBOLIZER_MARKUP