LLVM  16.0.0git
MarkupFilter.h
Go to the documentation of this file.
1 //===- MarkupFilter.h -------------------------------------------*- C++ -*-===//
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 /// \file
10 /// This file declares a filter that replaces symbolizer markup with
11 /// human-readable expressions.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_MARKUPFILTER_H
16 #define LLVM_DEBUGINFO_SYMBOLIZE_MARKUPFILTER_H
17 
18 #include "Markup.h"
19 
20 #include <map>
21 
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/Support/WithColor.h"
25 
26 namespace llvm {
27 namespace symbolize {
28 
29 class LLVMSymbolizer;
30 
31 /// Filter to convert parsed log symbolizer markup elements into human-readable
32 /// text.
33 class MarkupFilter {
34 public:
35  MarkupFilter(raw_ostream &OS, LLVMSymbolizer &Symbolizer,
36  Optional<bool> ColorsEnabled = llvm::None);
37 
38  /// Filters a line containing symbolizer markup and writes the human-readable
39  /// results to the output stream.
40  ///
41  /// Invalid or unimplemented markup elements are removed. Some output may be
42  /// deferred until future filter() or finish() call.
43  void filter(StringRef Line);
44 
45  /// Records that the input stream has ended and writes any deferred output.
46  void finish();
47 
48 private:
49  struct Module {
50  uint64_t ID;
51  std::string Name;
53  };
54 
55  struct MMap {
56  uint64_t Addr;
57  uint64_t Size;
58  const Module *Mod;
59  std::string Mode; // Lowercase
60  uint64_t ModuleRelativeAddr;
61 
62  bool contains(uint64_t Addr) const;
63  uint64_t getModuleRelativeAddr(uint64_t Addr) const;
64  };
65 
66  // An informational module line currently being constructed. As many mmap
67  // elements as possible are folded into one ModuleInfo line.
68  struct ModuleInfoLine {
69  const Module *Mod;
70 
71  SmallVector<const MMap *> MMaps = {};
72  };
73 
74  // The semantics of a possible program counter value.
75  enum class PCType {
76  // The address is a return address and must be adjusted to point to the call
77  // itself.
78  ReturnAddress,
79  // The address is the precise location in the code and needs no adjustment.
80  PreciseCode,
81  };
82 
83  bool tryContextualElement(const MarkupNode &Node,
84  const SmallVector<MarkupNode> &DeferredNodes);
85  bool tryMMap(const MarkupNode &Element,
86  const SmallVector<MarkupNode> &DeferredNodes);
87  bool tryReset(const MarkupNode &Element,
88  const SmallVector<MarkupNode> &DeferredNodes);
89  bool tryModule(const MarkupNode &Element,
90  const SmallVector<MarkupNode> &DeferredNodes);
91 
92  void beginModuleInfoLine(const Module *M);
93  void endAnyModuleInfoLine();
94 
95  void filterNode(const MarkupNode &Node);
96 
97  bool tryPresentation(const MarkupNode &Node);
98  bool trySymbol(const MarkupNode &Node);
99  bool tryPC(const MarkupNode &Node);
100  bool tryBackTrace(const MarkupNode &Node);
101  bool tryData(const MarkupNode &Node);
102 
103  bool trySGR(const MarkupNode &Node);
104 
105  void highlight();
106  void highlightValue();
107  void restoreColor();
108  void resetColor();
109 
110  void printRawElement(const MarkupNode &Element);
111  void printValue(Twine Value);
112 
113  Optional<Module> parseModule(const MarkupNode &Element) const;
114  Optional<MMap> parseMMap(const MarkupNode &Element) const;
115 
116  Optional<uint64_t> parseAddr(StringRef Str) const;
117  Optional<uint64_t> parseModuleID(StringRef Str) const;
118  Optional<uint64_t> parseSize(StringRef Str) const;
119  Optional<SmallVector<uint8_t>> parseBuildID(StringRef Str) const;
120  Optional<std::string> parseMode(StringRef Str) const;
121  Optional<PCType> parsePCType(StringRef Str) const;
122  Optional<uint64_t> parseFrameNumber(StringRef Str) const;
123 
124  bool checkTag(const MarkupNode &Node) const;
125  bool checkNumFields(const MarkupNode &Element, size_t Size) const;
126  bool checkNumFieldsAtLeast(const MarkupNode &Element, size_t Size) const;
127  bool checkNumFieldsAtMost(const MarkupNode &Element, size_t Size) const;
128 
129  void reportTypeError(StringRef Str, StringRef TypeName) const;
130  void reportLocation(StringRef::iterator Loc) const;
131 
132  const MMap *getOverlappingMMap(const MMap &Map) const;
133  const MMap *getContainingMMap(uint64_t Addr) const;
134 
135  uint64_t adjustAddr(uint64_t Addr, PCType Type) const;
136 
137  StringRef lineEnding() const;
138 
139  raw_ostream &OS;
140  LLVMSymbolizer &Symbolizer;
141  const bool ColorsEnabled;
142 
144 
145  // Current line being filtered.
146  StringRef Line;
147 
148  // A module info line currently being built. This incorporates as much mmap
149  // information as possible before being emitted.
151 
152  // SGR state.
154  bool Bold = false;
155 
156  // Map from Module ID to Module.
158 
159  // Ordered map from starting address to mmap.
160  std::map<uint64_t, MMap> MMaps;
161 };
162 
163 } // end namespace symbolize
164 } // end namespace llvm
165 
166 #endif // LLVM_DEBUGINFO_SYMBOLIZE_MARKUPFILTER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::symbolize::MarkupParser
Parses a log containing symbolizer markup into a sequence of nodes.
Definition: Markup.h:52
contains
return AArch64::GPR64RegClass contains(Reg)
llvm::SmallVector< uint8_t >
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
llvm::Optional< bool >
llvm::object::BuildID
SmallVector< uint8_t, 10 > BuildID
A build ID in binary form.
Definition: BuildID.h:25
llvm::object::Parser
Definition: COFFModuleDefinition.cpp:139
llvm::StringRef::iterator
const char * iterator
Definition: StringRef.h:54
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::symbolize::MarkupFilter::finish
void finish()
Records that the input stream has ended and writes any deferred output.
Definition: MarkupFilter.cpp:67
llvm::None
const NoneType None
Definition: None.h:24
Markup.h
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::DenseMap
Definition: DenseMap.h:714
llvm::symbolize::MarkupFilter
Filter to convert parsed log symbolizer markup elements into human-readable text.
Definition: MarkupFilter.h:33
llvm::symbolize::MarkupFilter::MarkupFilter
MarkupFilter(raw_ostream &OS, LLVMSymbolizer &Symbolizer, Optional< bool > ColorsEnabled=llvm::None)
Definition: MarkupFilter.cpp:38
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:262
llvm::symbolize::LLVMSymbolizer
Definition: Symbolize.h:50
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
Node
Definition: ItaniumDemangle.h:155
WithColor.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition: AMDGPUMetadata.h:175
llvm::symbolize::MarkupFilter::filter
void filter(StringRef Line)
Filters a line containing symbolizer markup and writes the human-readable results to the output strea...
Definition: MarkupFilter.cpp:44
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
raw_ostream.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::symbolize::MarkupNode
A node of symbolizer markup.
Definition: Markup.h:34
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38