sanitizer_symbolizer_markup.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===-- sanitizer_symbolizer_markup.h -----------------------------------===//
  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. // Header for the offline markup symbolizer.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef SANITIZER_SYMBOLIZER_MARKUP_H
  14. #define SANITIZER_SYMBOLIZER_MARKUP_H
  15. #include "sanitizer_common.h"
  16. #include "sanitizer_stacktrace_printer.h"
  17. #include "sanitizer_symbolizer.h"
  18. #include "sanitizer_symbolizer_internal.h"
  19. namespace __sanitizer {
  20. // Simplier view of a LoadedModule. It only holds information necessary to
  21. // identify unique modules.
  22. struct RenderedModule {
  23. char *full_name;
  24. uptr base_address;
  25. u8 uuid[kModuleUUIDSize]; // BuildId
  26. };
  27. class MarkupStackTracePrinter : public StackTracePrinter {
  28. public:
  29. // We don't support the stack_trace_format flag at all.
  30. void RenderFrame(InternalScopedString *buffer, const char *format,
  31. int frame_no, uptr address, const AddressInfo *info,
  32. bool vs_style, const char *strip_path_prefix = "") override;
  33. bool RenderNeedsSymbolization(const char *format) override;
  34. // We ignore the format argument to __sanitizer_symbolize_global.
  35. void RenderData(InternalScopedString *buffer, const char *format,
  36. const DataInfo *DI,
  37. const char *strip_path_prefix = "") override;
  38. private:
  39. // Keeps track of the modules that have been rendered to avoid re-rendering
  40. // them
  41. InternalMmapVector<RenderedModule> renderedModules_;
  42. void RenderContext(InternalScopedString *buffer);
  43. protected:
  44. ~MarkupStackTracePrinter() {}
  45. };
  46. class MarkupSymbolizerTool final : public SymbolizerTool {
  47. public:
  48. // This is used in some places for suppression checking, which we
  49. // don't really support for Fuchsia. It's also used in UBSan to
  50. // identify a PC location to a function name, so we always fill in
  51. // the function member with a string containing markup around the PC
  52. // value.
  53. // TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
  54. // to render stack frames, but that should be changed to use
  55. // RenderStackFrame.
  56. bool SymbolizePC(uptr addr, SymbolizedStack *stack) override;
  57. // Always claim we succeeded, so that RenderDataInfo will be called.
  58. bool SymbolizeData(uptr addr, DataInfo *info) override;
  59. // May return NULL if demangling failed.
  60. // This is used by UBSan for type names, and by ASan for global variable
  61. // names. It's expected to return a static buffer that will be reused on each
  62. // call.
  63. const char *Demangle(const char *name) override;
  64. };
  65. } // namespace __sanitizer
  66. #endif // SANITIZER_SYMBOLIZER_MARKUP_H