File indexing completed on 2026-05-10 08:43:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_MARKUPFILTER_H
0016 #define LLVM_DEBUGINFO_SYMBOLIZE_MARKUPFILTER_H
0017
0018 #include "llvm/ADT/DenseMap.h"
0019 #include "llvm/DebugInfo/Symbolize/Markup.h"
0020 #include "llvm/Object/BuildID.h"
0021 #include "llvm/Support/WithColor.h"
0022 #include "llvm/Support/raw_ostream.h"
0023 #include <map>
0024
0025 namespace llvm {
0026 namespace symbolize {
0027
0028 class LLVMSymbolizer;
0029
0030
0031
0032 class MarkupFilter {
0033 public:
0034 MarkupFilter(raw_ostream &OS, LLVMSymbolizer &Symbolizer,
0035 std::optional<bool> ColorsEnabled = std::nullopt);
0036
0037
0038
0039
0040
0041
0042 void filter(std::string &&InputLine);
0043
0044
0045 void finish();
0046
0047 private:
0048 struct Module {
0049 uint64_t ID;
0050 std::string Name;
0051 SmallVector<uint8_t> BuildID;
0052 };
0053
0054 struct MMap {
0055 uint64_t Addr;
0056 uint64_t Size;
0057 const Module *Mod;
0058 std::string Mode;
0059 uint64_t ModuleRelativeAddr;
0060
0061 bool contains(uint64_t Addr) const;
0062 uint64_t getModuleRelativeAddr(uint64_t Addr) const;
0063 };
0064
0065
0066
0067 struct ModuleInfoLine {
0068 const Module *Mod;
0069
0070 SmallVector<const MMap *> MMaps = {};
0071 };
0072
0073
0074 enum class PCType {
0075
0076
0077 ReturnAddress,
0078
0079 PreciseCode,
0080 };
0081
0082 bool tryContextualElement(const MarkupNode &Node,
0083 const SmallVector<MarkupNode> &DeferredNodes);
0084 bool tryMMap(const MarkupNode &Element,
0085 const SmallVector<MarkupNode> &DeferredNodes);
0086 bool tryReset(const MarkupNode &Element,
0087 const SmallVector<MarkupNode> &DeferredNodes);
0088 bool tryModule(const MarkupNode &Element,
0089 const SmallVector<MarkupNode> &DeferredNodes);
0090
0091 void beginModuleInfoLine(const Module *M);
0092 void endAnyModuleInfoLine();
0093
0094 void filterNode(const MarkupNode &Node);
0095
0096 bool tryPresentation(const MarkupNode &Node);
0097 bool trySymbol(const MarkupNode &Node);
0098 bool tryPC(const MarkupNode &Node);
0099 bool tryBackTrace(const MarkupNode &Node);
0100 bool tryData(const MarkupNode &Node);
0101
0102 bool trySGR(const MarkupNode &Node);
0103
0104 void highlight();
0105 void highlightValue();
0106 void restoreColor();
0107 void resetColor();
0108
0109 void printRawElement(const MarkupNode &Element);
0110 void printValue(Twine Value);
0111
0112 std::optional<Module> parseModule(const MarkupNode &Element) const;
0113 std::optional<MMap> parseMMap(const MarkupNode &Element) const;
0114
0115 std::optional<uint64_t> parseAddr(StringRef Str) const;
0116 std::optional<uint64_t> parseModuleID(StringRef Str) const;
0117 std::optional<uint64_t> parseSize(StringRef Str) const;
0118 object::BuildID parseBuildID(StringRef Str) const;
0119 std::optional<std::string> parseMode(StringRef Str) const;
0120 std::optional<PCType> parsePCType(StringRef Str) const;
0121 std::optional<uint64_t> parseFrameNumber(StringRef Str) const;
0122
0123 bool checkTag(const MarkupNode &Node) const;
0124 bool checkNumFields(const MarkupNode &Element, size_t Size) const;
0125 bool checkNumFieldsAtLeast(const MarkupNode &Element, size_t Size) const;
0126 void warnNumFieldsAtMost(const MarkupNode &Element, size_t Size) const;
0127
0128 void reportTypeError(StringRef Str, StringRef TypeName) const;
0129 void reportLocation(StringRef::iterator Loc) const;
0130
0131 const MMap *getOverlappingMMap(const MMap &Map) const;
0132 const MMap *getContainingMMap(uint64_t Addr) const;
0133
0134 uint64_t adjustAddr(uint64_t Addr, PCType Type) const;
0135
0136 StringRef lineEnding() const;
0137
0138 raw_ostream &OS;
0139 LLVMSymbolizer &Symbolizer;
0140 const bool ColorsEnabled;
0141
0142 MarkupParser Parser;
0143
0144
0145 std::string Line;
0146
0147
0148
0149 std::optional<ModuleInfoLine> MIL;
0150
0151
0152 std::optional<raw_ostream::Colors> Color;
0153 bool Bold = false;
0154
0155
0156 DenseMap<uint64_t, std::unique_ptr<Module>> Modules;
0157
0158
0159 std::map<uint64_t, MMap> MMaps;
0160 };
0161
0162 }
0163 }
0164
0165 #endif