blob: 8a0b7645fd0a159a484d19c2b33e11c26bc0a707 [file] [log] [blame]
Pavel Labath1cf23e12019-01-11 11:17:51 +00001//===-- SymbolFileBreakpad.h ------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Pavel Labath1cf23e12019-01-11 11:17:51 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H
10#define LLDB_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H
11
Pavel Labath3f35ab82019-02-07 13:42:32 +000012#include "Plugins/ObjectFile/Breakpad/BreakpadRecords.h"
13#include "lldb/Core/FileSpecList.h"
14#include "lldb/Symbol/LineTable.h"
Pavel Labath1cf23e12019-01-11 11:17:51 +000015#include "lldb/Symbol/SymbolFile.h"
Pavel Labath1211baa2019-05-13 11:25:35 +000016#include "lldb/Symbol/UnwindPlan.h"
Pavel Labath1cf23e12019-01-11 11:17:51 +000017
18namespace lldb_private {
19
20namespace breakpad {
21
22class SymbolFileBreakpad : public SymbolFile {
23public:
Pavel Labath1cf23e12019-01-11 11:17:51 +000024 // Static Functions
Pavel Labath1cf23e12019-01-11 11:17:51 +000025 static void Initialize();
26 static void Terminate();
27 static void DebuggerInitialize(Debugger &debugger) {}
28 static ConstString GetPluginNameStatic();
29
30 static const char *GetPluginDescriptionStatic() {
31 return "Breakpad debug symbol file reader.";
32 }
33
34 static SymbolFile *CreateInstance(ObjectFile *obj_file) {
35 return new SymbolFileBreakpad(obj_file);
36 }
37
Pavel Labath1cf23e12019-01-11 11:17:51 +000038 // Constructors and Destructors
Pavel Labath1cf23e12019-01-11 11:17:51 +000039 SymbolFileBreakpad(ObjectFile *object_file) : SymbolFile(object_file) {}
40
41 ~SymbolFileBreakpad() override {}
42
43 uint32_t CalculateAbilities() override;
44
45 void InitializeObject() override {}
46
Pavel Labath1cf23e12019-01-11 11:17:51 +000047 // Compile Unit function calls
Pavel Labath1cf23e12019-01-11 11:17:51 +000048
49 uint32_t GetNumCompileUnits() override;
50
51 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
52
Zachary Turnerce386e32019-01-11 18:35:58 +000053 lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {
Pavel Labath1cf23e12019-01-11 11:17:51 +000054 return lldb::eLanguageTypeUnknown;
55 }
56
Zachary Turnerce386e32019-01-11 18:35:58 +000057 size_t ParseFunctions(CompileUnit &comp_unit) override;
Pavel Labath1cf23e12019-01-11 11:17:51 +000058
Zachary Turnerce386e32019-01-11 18:35:58 +000059 bool ParseLineTable(CompileUnit &comp_unit) override;
Pavel Labath1cf23e12019-01-11 11:17:51 +000060
Zachary Turnerce386e32019-01-11 18:35:58 +000061 bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
62
63 bool ParseSupportFiles(CompileUnit &comp_unit,
Pavel Labath3f35ab82019-02-07 13:42:32 +000064 FileSpecList &support_files) override;
Zachary Turnerce386e32019-01-11 18:35:58 +000065 size_t ParseTypes(CompileUnit &cu) override { return 0; }
Pavel Labath1cf23e12019-01-11 11:17:51 +000066
Adrian Prantl0f30a3b2019-02-13 18:10:41 +000067 bool ParseImportedModules(
68 const SymbolContext &sc,
69 std::vector<lldb_private::SourceModule> &imported_modules) override {
Pavel Labath1cf23e12019-01-11 11:17:51 +000070 return false;
71 }
72
Zachary Turnerffc1b8f2019-01-14 22:40:41 +000073 size_t ParseBlocksRecursive(Function &func) override { return 0; }
Pavel Labath1cf23e12019-01-11 11:17:51 +000074
Adrian Prantl0e4c4822019-03-06 21:22:25 +000075 uint32_t FindGlobalVariables(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +000076 const CompilerDeclContext *parent_decl_ctx,
77 uint32_t max_matches,
78 VariableList &variables) override {
79 return 0;
80 }
81
Pavel Labath1cf23e12019-01-11 11:17:51 +000082 size_t ParseVariablesForContext(const SymbolContext &sc) override {
83 return 0;
84 }
85 Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; }
86 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
87 lldb::user_id_t type_uid,
88 const lldb_private::ExecutionContext *exe_ctx) override {
89 return llvm::None;
90 }
91
92 bool CompleteType(CompilerType &compiler_type) override { return false; }
93 uint32_t ResolveSymbolContext(const Address &so_addr,
94 lldb::SymbolContextItem resolve_scope,
95 SymbolContext &sc) override;
96
Pavel Labath3f35ab82019-02-07 13:42:32 +000097 uint32_t ResolveSymbolContext(const FileSpec &file_spec, uint32_t line,
98 bool check_inlines,
99 lldb::SymbolContextItem resolve_scope,
100 SymbolContextList &sc_list) override;
101
Pavel Labath1cf23e12019-01-11 11:17:51 +0000102 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
103 TypeList &type_list) override {
104 return 0;
105 }
106
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000107 uint32_t FindFunctions(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000108 const CompilerDeclContext *parent_decl_ctx,
109 lldb::FunctionNameType name_type_mask,
110 bool include_inlines, bool append,
111 SymbolContextList &sc_list) override;
112
113 uint32_t FindFunctions(const RegularExpression &regex, bool include_inlines,
114 bool append, SymbolContextList &sc_list) override;
115
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000116 uint32_t FindTypes(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000117 const CompilerDeclContext *parent_decl_ctx, bool append,
118 uint32_t max_matches,
119 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
120 TypeMap &types) override;
121
122 size_t FindTypes(const std::vector<CompilerContext> &context, bool append,
123 TypeMap &types) override;
124
125 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override {
126 return nullptr;
127 }
128
129 CompilerDeclContext
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000130 FindNamespace(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000131 const CompilerDeclContext *parent_decl_ctx) override {
132 return CompilerDeclContext();
133 }
134
135 void AddSymbols(Symtab &symtab) override;
136
Pavel Labath1211baa2019-05-13 11:25:35 +0000137 lldb::UnwindPlanSP
138 GetUnwindPlan(const Address &address,
139 const RegisterInfoResolver &resolver) override;
140
Pavel Labath1cf23e12019-01-11 11:17:51 +0000141 ConstString GetPluginName() override { return GetPluginNameStatic(); }
142 uint32_t GetPluginVersion() override { return 1; }
143
144private:
Pavel Labath3f35ab82019-02-07 13:42:32 +0000145 // A class representing a position in the breakpad file. Useful for
146 // remembering the position so we can go back to it later and parse more data.
147 // Can be converted to/from a LineIterator, but it has a much smaller memory
148 // footprint.
149 struct Bookmark {
150 uint32_t section;
151 size_t offset;
Pavel Labath1211baa2019-05-13 11:25:35 +0000152
153 friend bool operator<(const Bookmark &lhs, const Bookmark &rhs) {
154 return std::tie(lhs.section, lhs.offset) <
155 std::tie(rhs.section, rhs.offset);
156 }
Pavel Labath3f35ab82019-02-07 13:42:32 +0000157 };
158
159 // At iterator class for simplifying algorithms reading data from the breakpad
160 // file. It iterates over all records (lines) in the sections of a given type.
161 // It also supports saving a specific position (via the GetBookmark() method)
162 // and then resuming from it afterwards.
163 class LineIterator;
164
165 // Return an iterator range for all records in the given object file of the
166 // given type.
167 llvm::iterator_range<LineIterator> lines(Record::Kind section_type);
168
169 // Breakpad files do not contain sufficient information to correctly
170 // reconstruct compile units. The approach chosen here is to treat each
171 // function as a compile unit. The compile unit name is the name if the first
172 // line entry belonging to this function.
173 // This class is our internal representation of a compile unit. It stores the
174 // CompileUnit object and a bookmark pointing to the FUNC record of the
175 // compile unit function. It also lazily construct the list of support files
176 // and line table entries for the compile unit, when these are needed.
177 class CompUnitData {
178 public:
179 CompUnitData(Bookmark bookmark) : bookmark(bookmark) {}
180
181 CompUnitData() = default;
182 CompUnitData(const CompUnitData &rhs) : bookmark(rhs.bookmark) {}
183 CompUnitData &operator=(const CompUnitData &rhs) {
184 bookmark = rhs.bookmark;
185 support_files.reset();
186 line_table_up.reset();
187 return *this;
188 }
189 friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs) {
Pavel Labath1211baa2019-05-13 11:25:35 +0000190 return lhs.bookmark < rhs.bookmark;
Pavel Labath3f35ab82019-02-07 13:42:32 +0000191 }
192
193 Bookmark bookmark;
194 llvm::Optional<FileSpecList> support_files;
195 std::unique_ptr<LineTable> line_table_up;
196
197 };
198
199 SymbolVendor &GetSymbolVendor();
200 lldb::addr_t GetBaseFileAddress();
201 void ParseFileRecords();
202 void ParseCUData();
203 void ParseLineTableAndSupportFiles(CompileUnit &cu, CompUnitData &data);
Pavel Labath1211baa2019-05-13 11:25:35 +0000204 void ParseUnwindData();
205 bool ParseUnwindRow(llvm::StringRef unwind_rules,
206 const RegisterInfoResolver &resolver,
207 UnwindPlan::Row &row);
Pavel Labath3f35ab82019-02-07 13:42:32 +0000208
209 using CompUnitMap = RangeDataVector<lldb::addr_t, lldb::addr_t, CompUnitData>;
210
211 llvm::Optional<std::vector<FileSpec>> m_files;
212 llvm::Optional<CompUnitMap> m_cu_data;
Pavel Labath1211baa2019-05-13 11:25:35 +0000213
214 using UnwindMap = RangeDataVector<lldb::addr_t, lldb::addr_t, Bookmark>;
215 llvm::Optional<UnwindMap> m_unwind_data;
216 llvm::BumpPtrAllocator m_allocator;
Pavel Labath1cf23e12019-01-11 11:17:51 +0000217};
218
219} // namespace breakpad
220} // namespace lldb_private
221
222#endif