1 //===-- BreakpadRecords.h ------------------------------------- -*- C++ -*-===//
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
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"
19 namespace lldb_private
{
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
);
43 Record(Kind K
) : TheKind(K
) {}
48 Kind
getKind() { return TheKind
; }
54 llvm::StringRef
toString(Record::Kind K
);
55 inline llvm::raw_ostream
&operator<<(llvm::raw_ostream
&OS
, Record::Kind K
) {
60 class ModuleRecord
: public Record
{
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
;
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
{
78 static std::optional
<InfoRecord
> parse(llvm::StringRef Line
);
79 InfoRecord(UUID ID
) : Record(Info
), ID(std::move(ID
)) {}
84 inline bool operator==(const InfoRecord
&L
, const InfoRecord
&R
) {
87 llvm::raw_ostream
&operator<<(llvm::raw_ostream
&OS
, const InfoRecord
&R
);
89 class FileRecord
: public Record
{
91 static std::optional
<FileRecord
> parse(llvm::StringRef Line
);
92 FileRecord(size_t Number
, llvm::StringRef Name
)
93 : Record(File
), Number(Number
), Name(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
{
106 static std::optional
<InlineOriginRecord
> parse(llvm::StringRef Line
);
107 InlineOriginRecord(size_t Number
, llvm::StringRef Name
)
108 : Record(InlineOrigin
), Number(Number
), Name(Name
) {}
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
{
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
) {}
130 lldb::addr_t Address
;
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
{
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
;
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
{
161 static std::optional
<LineRecord
> parse(llvm::StringRef Line
);
162 LineRecord(lldb::addr_t Address
, lldb::addr_t Size
, uint32_t LineNum
,
164 : Record(Line
), Address(Address
), Size(Size
), LineNum(LineNum
),
167 lldb::addr_t Address
;
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
{
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
) {}
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
{
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
{
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 };
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