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