Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / ObjectFile / Breakpad / BreakpadRecords.h
blobf10c8c41b793a13e2d5062ddbe8bb7e8eb136474
1 //===-- BreakpadRecords.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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_BREAKPAD_BREAKPADRECORDS_H
10 #define LLDB_SOURCE_PLUGINS_OBJECTFILE_BREAKPAD_BREAKPADRECORDS_H
12 #include "lldb/Utility/UUID.h"
13 #include "lldb/lldb-types.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/FormatProviders.h"
16 #include "llvm/TargetParser/Triple.h"
17 #include <optional>
19 namespace lldb_private {
20 namespace breakpad {
22 class Record {
23 public:
24 enum Kind {
25 Module,
26 Info,
27 File,
28 Func,
29 Inline,
30 InlineOrigin,
31 Line,
32 Public,
33 StackCFI,
34 StackWin
37 /// Attempt to guess the kind of the record present in the argument without
38 /// doing a full parse. The returned kind will always be correct for valid
39 /// records, but the full parse can still fail in case of corrupted input.
40 static std::optional<Kind> classify(llvm::StringRef Line);
42 protected:
43 Record(Kind K) : TheKind(K) {}
45 ~Record() = default;
47 public:
48 Kind getKind() { return TheKind; }
50 private:
51 Kind TheKind;
54 llvm::StringRef toString(Record::Kind K);
55 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Record::Kind K) {
56 OS << toString(K);
57 return OS;
60 class ModuleRecord : public Record {
61 public:
62 static std::optional<ModuleRecord> parse(llvm::StringRef Line);
63 ModuleRecord(llvm::Triple::OSType OS, llvm::Triple::ArchType Arch, UUID ID)
64 : Record(Module), OS(OS), Arch(Arch), ID(std::move(ID)) {}
66 llvm::Triple::OSType OS;
67 llvm::Triple::ArchType Arch;
68 UUID ID;
71 inline bool operator==(const ModuleRecord &L, const ModuleRecord &R) {
72 return L.OS == R.OS && L.Arch == R.Arch && L.ID == R.ID;
74 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const ModuleRecord &R);
76 class InfoRecord : public Record {
77 public:
78 static std::optional<InfoRecord> parse(llvm::StringRef Line);
79 InfoRecord(UUID ID) : Record(Info), ID(std::move(ID)) {}
81 UUID ID;
84 inline bool operator==(const InfoRecord &L, const InfoRecord &R) {
85 return L.ID == R.ID;
87 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const InfoRecord &R);
89 class FileRecord : public Record {
90 public:
91 static std::optional<FileRecord> parse(llvm::StringRef Line);
92 FileRecord(size_t Number, llvm::StringRef Name)
93 : Record(File), Number(Number), Name(Name) {}
95 size_t Number;
96 llvm::StringRef Name;
99 inline bool operator==(const FileRecord &L, const FileRecord &R) {
100 return L.Number == R.Number && L.Name == R.Name;
102 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FileRecord &R);
104 class InlineOriginRecord : public Record {
105 public:
106 static std::optional<InlineOriginRecord> parse(llvm::StringRef Line);
107 InlineOriginRecord(size_t Number, llvm::StringRef Name)
108 : Record(InlineOrigin), Number(Number), Name(Name) {}
110 size_t Number;
111 llvm::StringRef Name;
114 inline bool operator==(const InlineOriginRecord &L,
115 const InlineOriginRecord &R) {
116 return L.Number == R.Number && L.Name == R.Name;
118 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
119 const InlineOriginRecord &R);
121 class FuncRecord : public Record {
122 public:
123 static std::optional<FuncRecord> parse(llvm::StringRef Line);
124 FuncRecord(bool Multiple, lldb::addr_t Address, lldb::addr_t Size,
125 lldb::addr_t ParamSize, llvm::StringRef Name)
126 : Record(Module), Multiple(Multiple), Address(Address), Size(Size),
127 ParamSize(ParamSize), Name(Name) {}
129 bool Multiple;
130 lldb::addr_t Address;
131 lldb::addr_t Size;
132 lldb::addr_t ParamSize;
133 llvm::StringRef Name;
136 bool operator==(const FuncRecord &L, const FuncRecord &R);
137 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FuncRecord &R);
139 class InlineRecord : public Record {
140 public:
141 static std::optional<InlineRecord> parse(llvm::StringRef Line);
142 InlineRecord(size_t InlineNestLevel, uint32_t CallSiteLineNum,
143 size_t CallSiteFileNum, size_t OriginNum)
144 : Record(Inline), InlineNestLevel(InlineNestLevel),
145 CallSiteLineNum(CallSiteLineNum), CallSiteFileNum(CallSiteFileNum),
146 OriginNum(OriginNum) {}
148 size_t InlineNestLevel;
149 uint32_t CallSiteLineNum;
150 size_t CallSiteFileNum;
151 size_t OriginNum;
152 // A vector of address range covered by this inline
153 std::vector<std::pair<lldb::addr_t, lldb::addr_t>> Ranges;
156 bool operator==(const InlineRecord &L, const InlineRecord &R);
157 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const InlineRecord &R);
159 class LineRecord : public Record {
160 public:
161 static std::optional<LineRecord> parse(llvm::StringRef Line);
162 LineRecord(lldb::addr_t Address, lldb::addr_t Size, uint32_t LineNum,
163 size_t FileNum)
164 : Record(Line), Address(Address), Size(Size), LineNum(LineNum),
165 FileNum(FileNum) {}
167 lldb::addr_t Address;
168 lldb::addr_t Size;
169 uint32_t LineNum;
170 size_t FileNum;
173 bool operator==(const LineRecord &L, const LineRecord &R);
174 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const LineRecord &R);
176 class PublicRecord : public Record {
177 public:
178 static std::optional<PublicRecord> parse(llvm::StringRef Line);
179 PublicRecord(bool Multiple, lldb::addr_t Address, lldb::addr_t ParamSize,
180 llvm::StringRef Name)
181 : Record(Module), Multiple(Multiple), Address(Address),
182 ParamSize(ParamSize), Name(Name) {}
184 bool Multiple;
185 lldb::addr_t Address;
186 lldb::addr_t ParamSize;
187 llvm::StringRef Name;
190 bool operator==(const PublicRecord &L, const PublicRecord &R);
191 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const PublicRecord &R);
193 class StackCFIRecord : public Record {
194 public:
195 static std::optional<StackCFIRecord> parse(llvm::StringRef Line);
196 StackCFIRecord(lldb::addr_t Address, std::optional<lldb::addr_t> Size,
197 llvm::StringRef UnwindRules)
198 : Record(StackCFI), Address(Address), Size(Size),
199 UnwindRules(UnwindRules) {}
201 lldb::addr_t Address;
202 std::optional<lldb::addr_t> Size;
203 llvm::StringRef UnwindRules;
206 bool operator==(const StackCFIRecord &L, const StackCFIRecord &R);
207 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const StackCFIRecord &R);
209 class StackWinRecord : public Record {
210 public:
211 static std::optional<StackWinRecord> parse(llvm::StringRef Line);
213 StackWinRecord(lldb::addr_t RVA, lldb::addr_t CodeSize,
214 lldb::addr_t ParameterSize, lldb::addr_t SavedRegisterSize,
215 lldb::addr_t LocalSize, llvm::StringRef ProgramString)
216 : Record(StackWin), RVA(RVA), CodeSize(CodeSize),
217 ParameterSize(ParameterSize), SavedRegisterSize(SavedRegisterSize),
218 LocalSize(LocalSize), ProgramString(ProgramString) {}
220 enum class FrameType : uint8_t { FPO = 0, FrameData = 4 };
221 lldb::addr_t RVA;
222 lldb::addr_t CodeSize;
223 lldb::addr_t ParameterSize;
224 lldb::addr_t SavedRegisterSize;
225 lldb::addr_t LocalSize;
226 llvm::StringRef ProgramString;
229 bool operator==(const StackWinRecord &L, const StackWinRecord &R);
230 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const StackWinRecord &R);
232 } // namespace breakpad
233 } // namespace lldb_private
235 #endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_BREAKPAD_BREAKPADRECORDS_H