summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h
blob: f10c8c41b793a13e2d5062ddbe8bb7e8eb136474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//===-- BreakpadRecords.h ------------------------------------- -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_BREAKPAD_BREAKPADRECORDS_H
#define LLDB_SOURCE_PLUGINS_OBJECTFILE_BREAKPAD_BREAKPADRECORDS_H

#include "lldb/Utility/UUID.h"
#include "lldb/lldb-types.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FormatProviders.h"
#include "llvm/TargetParser/Triple.h"
#include <optional>

namespace lldb_private {
namespace breakpad {

class Record {
public:
  enum Kind {
    Module,
    Info,
    File,
    Func,
    Inline,
    InlineOrigin,
    Line,
    Public,
    StackCFI,
    StackWin
  };

  /// Attempt to guess the kind of the record present in the argument without
  /// doing a full parse. The returned kind will always be correct for valid
  /// records, but the full parse can still fail in case of corrupted input.
  static std::optional<Kind> classify(llvm::StringRef Line);

protected:
  Record(Kind K) : TheKind(K) {}

  ~Record() = default;

public:
  Kind getKind() { return TheKind; }

private:
  Kind TheKind;
};

llvm::StringRef toString(Record::Kind K);
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Record::Kind K) {
  OS << toString(K);
  return OS;
}

class ModuleRecord : public Record {
public:
  static std::optional<ModuleRecord> parse(llvm::StringRef Line);
  ModuleRecord(llvm::Triple::OSType OS, llvm::Triple::ArchType Arch, UUID ID)
      : Record(Module), OS(OS), Arch(Arch), ID(std::move(ID)) {}

  llvm::Triple::OSType OS;
  llvm::Triple::ArchType Arch;
  UUID ID;
};

inline bool operator==(const ModuleRecord &L, const ModuleRecord &R) {
  return L.OS == R.OS && L.Arch == R.Arch && L.ID == R.ID;
}
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const ModuleRecord &R);

class InfoRecord : public Record {
public:
  static std::optional<InfoRecord> parse(llvm::StringRef Line);
  InfoRecord(UUID ID) : Record(Info), ID(std::move(ID)) {}

  UUID ID;
};

inline bool operator==(const InfoRecord &L, const InfoRecord &R) {
  return L.ID == R.ID;
}
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const InfoRecord &R);

class FileRecord : public Record {
public:
  static std::optional<FileRecord> parse(llvm::StringRef Line);
  FileRecord(size_t Number, llvm::StringRef Name)
      : Record(File), Number(Number), Name(Name) {}

  size_t Number;
  llvm::StringRef Name;
};

inline bool operator==(const FileRecord &L, const FileRecord &R) {
  return L.Number == R.Number && L.Name == R.Name;
}
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FileRecord &R);

class InlineOriginRecord : public Record {
public:
  static std::optional<InlineOriginRecord> parse(llvm::StringRef Line);
  InlineOriginRecord(size_t Number, llvm::StringRef Name)
      : Record(InlineOrigin), Number(Number), Name(Name) {}

  size_t Number;
  llvm::StringRef Name;
};

inline bool operator==(const InlineOriginRecord &L,
                       const InlineOriginRecord &R) {
  return L.Number == R.Number && L.Name == R.Name;
}
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
                              const InlineOriginRecord &R);

class FuncRecord : public Record {
public:
  static std::optional<FuncRecord> parse(llvm::StringRef Line);
  FuncRecord(bool Multiple, lldb::addr_t Address, lldb::addr_t Size,
             lldb::addr_t ParamSize, llvm::StringRef Name)
      : Record(Module), Multiple(Multiple), Address(Address), Size(Size),
        ParamSize(ParamSize), Name(Name) {}

  bool Multiple;
  lldb::addr_t Address;
  lldb::addr_t Size;
  lldb::addr_t ParamSize;
  llvm::StringRef Name;
};

bool operator==(const FuncRecord &L, const FuncRecord &R);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FuncRecord &R);

class InlineRecord : public Record {
public:
  static std::optional<InlineRecord> parse(llvm::StringRef Line);
  InlineRecord(size_t InlineNestLevel, uint32_t CallSiteLineNum,
               size_t CallSiteFileNum, size_t OriginNum)
      : Record(Inline), InlineNestLevel(InlineNestLevel),
        CallSiteLineNum(CallSiteLineNum), CallSiteFileNum(CallSiteFileNum),
        OriginNum(OriginNum) {}

  size_t InlineNestLevel;
  uint32_t CallSiteLineNum;
  size_t CallSiteFileNum;
  size_t OriginNum;
  // A vector of address range covered by this inline
  std::vector<std::pair<lldb::addr_t, lldb::addr_t>> Ranges;
};

bool operator==(const InlineRecord &L, const InlineRecord &R);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const InlineRecord &R);

class LineRecord : public Record {
public:
  static std::optional<LineRecord> parse(llvm::StringRef Line);
  LineRecord(lldb::addr_t Address, lldb::addr_t Size, uint32_t LineNum,
             size_t FileNum)
      : Record(Line), Address(Address), Size(Size), LineNum(LineNum),
        FileNum(FileNum) {}

  lldb::addr_t Address;
  lldb::addr_t Size;
  uint32_t LineNum;
  size_t FileNum;
};

bool operator==(const LineRecord &L, const LineRecord &R);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const LineRecord &R);

class PublicRecord : public Record {
public:
  static std::optional<PublicRecord> parse(llvm::StringRef Line);
  PublicRecord(bool Multiple, lldb::addr_t Address, lldb::addr_t ParamSize,
               llvm::StringRef Name)
      : Record(Module), Multiple(Multiple), Address(Address),
        ParamSize(ParamSize), Name(Name) {}

  bool Multiple;
  lldb::addr_t Address;
  lldb::addr_t ParamSize;
  llvm::StringRef Name;
};

bool operator==(const PublicRecord &L, const PublicRecord &R);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const PublicRecord &R);

class StackCFIRecord : public Record {
public:
  static std::optional<StackCFIRecord> parse(llvm::StringRef Line);
  StackCFIRecord(lldb::addr_t Address, std::optional<lldb::addr_t> Size,
                 llvm::StringRef UnwindRules)
      : Record(StackCFI), Address(Address), Size(Size),
        UnwindRules(UnwindRules) {}

  lldb::addr_t Address;
  std::optional<lldb::addr_t> Size;
  llvm::StringRef UnwindRules;
};

bool operator==(const StackCFIRecord &L, const StackCFIRecord &R);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const StackCFIRecord &R);

class StackWinRecord : public Record {
public:
  static std::optional<StackWinRecord> parse(llvm::StringRef Line);

  StackWinRecord(lldb::addr_t RVA, lldb::addr_t CodeSize,
                 lldb::addr_t ParameterSize, lldb::addr_t SavedRegisterSize,
                 lldb::addr_t LocalSize, llvm::StringRef ProgramString)
      : Record(StackWin), RVA(RVA), CodeSize(CodeSize),
        ParameterSize(ParameterSize), SavedRegisterSize(SavedRegisterSize),
        LocalSize(LocalSize), ProgramString(ProgramString) {}

  enum class FrameType : uint8_t { FPO = 0, FrameData = 4 };
  lldb::addr_t RVA;
  lldb::addr_t CodeSize;
  lldb::addr_t ParameterSize;
  lldb::addr_t SavedRegisterSize;
  lldb::addr_t LocalSize;
  llvm::StringRef ProgramString;
};

bool operator==(const StackWinRecord &L, const StackWinRecord &R);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const StackWinRecord &R);

} // namespace breakpad
} // namespace lldb_private

#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_BREAKPAD_BREAKPADRECORDS_H