master
 1//===-- sanitizer_symbolizer_markup_fuchsia.cpp ---------------------------===//
 2//
 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
 6//
 7//===----------------------------------------------------------------------===//
 8//
 9// This file is shared between various sanitizers' runtime libraries.
10//
11// Fuchsia specific implementation of offline markup symbolizer.
12//===----------------------------------------------------------------------===//
13#include "sanitizer_platform.h"
14
15#if SANITIZER_SYMBOLIZER_MARKUP
16
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"
22
23namespace __sanitizer {
24
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.
27const char *Symbolizer::Demangle(const char *name) {
28  static char buffer[kFormatDemangleMax];
29  internal_snprintf(buffer, sizeof(buffer), kFormatDemangle, name);
30  return buffer;
31}
32
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.
38bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc, const char **module_name,
39                                             uptr *module_address) {
40  return false;
41}
42
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.
45bool Symbolizer::SymbolizeFrame(uptr addr, FrameInfo *info) { return false; }
46
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
51// value.
52// TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
53// to render stack frames, but that should be changed to use
54// RenderStackFrame.
55SymbolizedStack *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);
60  return s;
61}
62
63// Always claim we succeeded, so that RenderDataInfo will be called.
64bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
65  info->Clear();
66  info->start = addr;
67  return true;
68}
69
70// Fuchsia only uses MarkupStackTracePrinter
71StackTracePrinter *StackTracePrinter::NewStackTracePrinter() {
72  return new (GetGlobalLowLevelAllocator()) MarkupStackTracePrinter();
73}
74
75void MarkupStackTracePrinter::RenderContext(InternalScopedString *) {}
76
77Symbolizer *Symbolizer::PlatformInit() {
78  return new (symbolizer_allocator_) Symbolizer({});
79}
80
81void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
82
83}  // namespace __sanitizer
84
85#endif  // SANITIZER_SYMBOLIZER_MARKUP