sanitizer_symbolizer_markup_fuchsia.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #if SANITIZER_SYMBOLIZER_MARKUP
  15. # include "sanitizer_common.h"
  16. # include "sanitizer_stacktrace_printer.h"
  17. # include "sanitizer_symbolizer.h"
  18. # include "sanitizer_symbolizer_markup.h"
  19. # include "sanitizer_symbolizer_markup_constants.h"
  20. namespace __sanitizer {
  21. // This is used by UBSan for type names, and by ASan for global variable names.
  22. // It's expected to return a static buffer that will be reused on each call.
  23. const char *Symbolizer::Demangle(const char *name) {
  24. static char buffer[kFormatDemangleMax];
  25. internal_snprintf(buffer, sizeof(buffer), kFormatDemangle, name);
  26. return buffer;
  27. }
  28. // This is used mostly for suppression matching. Making it work
  29. // would enable "interceptor_via_lib" suppressions. It's also used
  30. // once in UBSan to say "in module ..." in a message that also
  31. // includes an address in the module, so post-processing can already
  32. // pretty-print that so as to indicate the module.
  33. bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc, const char **module_name,
  34. uptr *module_address) {
  35. return false;
  36. }
  37. // This is mainly used by hwasan for online symbolization. This isn't needed
  38. // since hwasan can always just dump stack frames for offline symbolization.
  39. bool Symbolizer::SymbolizeFrame(uptr addr, FrameInfo *info) { return false; }
  40. // This is used in some places for suppression checking, which we
  41. // don't really support for Fuchsia. It's also used in UBSan to
  42. // identify a PC location to a function name, so we always fill in
  43. // the function member with a string containing markup around the PC
  44. // value.
  45. // TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
  46. // to render stack frames, but that should be changed to use
  47. // RenderStackFrame.
  48. SymbolizedStack *Symbolizer::SymbolizePC(uptr addr) {
  49. SymbolizedStack *s = SymbolizedStack::New(addr);
  50. char buffer[kFormatFunctionMax];
  51. internal_snprintf(buffer, sizeof(buffer), kFormatFunction, addr);
  52. s->info.function = internal_strdup(buffer);
  53. return s;
  54. }
  55. // Always claim we succeeded, so that RenderDataInfo will be called.
  56. bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
  57. info->Clear();
  58. info->start = addr;
  59. return true;
  60. }
  61. // Fuchsia only uses MarkupStackTracePrinter
  62. StackTracePrinter *StackTracePrinter::NewStackTracePrinter() {
  63. return new (GetGlobalLowLevelAllocator()) MarkupStackTracePrinter();
  64. }
  65. void MarkupStackTracePrinter::RenderContext(InternalScopedString *) {}
  66. Symbolizer *Symbolizer::PlatformInit() {
  67. return new (symbolizer_allocator_) Symbolizer({});
  68. }
  69. void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
  70. } // namespace __sanitizer
  71. #endif // SANITIZER_SYMBOLIZER_MARKUP