blob: 6803636068613ba720b6f38536e8669caebbc06a [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
Zachary Turnerce386e32019-01-11 18:35:58 +000049 lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {
Pavel Labath1cf23e12019-01-11 11:17:51 +000050 return lldb::eLanguageTypeUnknown;
51 }
52
Zachary Turnerce386e32019-01-11 18:35:58 +000053 size_t ParseFunctions(CompileUnit &comp_unit) override;
Pavel Labath1cf23e12019-01-11 11:17:51 +000054
Zachary Turnerce386e32019-01-11 18:35:58 +000055 bool ParseLineTable(CompileUnit &comp_unit) override;
Pavel Labath1cf23e12019-01-11 11:17:51 +000056
Zachary Turnerce386e32019-01-11 18:35:58 +000057 bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
58
59 bool ParseSupportFiles(CompileUnit &comp_unit,
Pavel Labath3f35ab82019-02-07 13:42:32 +000060 FileSpecList &support_files) override;
Zachary Turnerce386e32019-01-11 18:35:58 +000061 size_t ParseTypes(CompileUnit &cu) override { return 0; }
Pavel Labath1cf23e12019-01-11 11:17:51 +000062
Adrian Prantl0f30a3b2019-02-13 18:10:41 +000063 bool ParseImportedModules(
64 const SymbolContext &sc,
65 std::vector<lldb_private::SourceModule> &imported_modules) override {
Pavel Labath1cf23e12019-01-11 11:17:51 +000066 return false;
67 }
68
Zachary Turnerffc1b8f2019-01-14 22:40:41 +000069 size_t ParseBlocksRecursive(Function &func) override { return 0; }
Pavel Labath1cf23e12019-01-11 11:17:51 +000070
Adrian Prantl0e4c4822019-03-06 21:22:25 +000071 uint32_t FindGlobalVariables(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +000072 const CompilerDeclContext *parent_decl_ctx,
73 uint32_t max_matches,
74 VariableList &variables) override {
75 return 0;
76 }
77
Pavel Labath1cf23e12019-01-11 11:17:51 +000078 size_t ParseVariablesForContext(const SymbolContext &sc) override {
79 return 0;
80 }
81 Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; }
82 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
83 lldb::user_id_t type_uid,
84 const lldb_private::ExecutionContext *exe_ctx) override {
85 return llvm::None;
86 }
87
88 bool CompleteType(CompilerType &compiler_type) override { return false; }
89 uint32_t ResolveSymbolContext(const Address &so_addr,
90 lldb::SymbolContextItem resolve_scope,
91 SymbolContext &sc) override;
92
Pavel Labath3f35ab82019-02-07 13:42:32 +000093 uint32_t ResolveSymbolContext(const FileSpec &file_spec, uint32_t line,
94 bool check_inlines,
95 lldb::SymbolContextItem resolve_scope,
96 SymbolContextList &sc_list) override;
97
Pavel Labath1cf23e12019-01-11 11:17:51 +000098 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
99 TypeList &type_list) override {
100 return 0;
101 }
102
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000103 uint32_t FindFunctions(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000104 const CompilerDeclContext *parent_decl_ctx,
105 lldb::FunctionNameType name_type_mask,
106 bool include_inlines, bool append,
107 SymbolContextList &sc_list) override;
108
109 uint32_t FindFunctions(const RegularExpression &regex, bool include_inlines,
110 bool append, SymbolContextList &sc_list) override;
111
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000112 uint32_t FindTypes(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000113 const CompilerDeclContext *parent_decl_ctx, bool append,
114 uint32_t max_matches,
115 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
116 TypeMap &types) override;
117
118 size_t FindTypes(const std::vector<CompilerContext> &context, bool append,
119 TypeMap &types) override;
120
121 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override {
122 return nullptr;
123 }
124
125 CompilerDeclContext
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000126 FindNamespace(ConstString name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000127 const CompilerDeclContext *parent_decl_ctx) override {
128 return CompilerDeclContext();
129 }
130
131 void AddSymbols(Symtab &symtab) override;
132
Pavel Labath1211baa2019-05-13 11:25:35 +0000133 lldb::UnwindPlanSP
134 GetUnwindPlan(const Address &address,
135 const RegisterInfoResolver &resolver) override;
136
Pavel Labath1cf23e12019-01-11 11:17:51 +0000137 ConstString GetPluginName() override { return GetPluginNameStatic(); }
138 uint32_t GetPluginVersion() override { return 1; }
139
140private:
Pavel Labath3f35ab82019-02-07 13:42:32 +0000141 // A class representing a position in the breakpad file. Useful for
142 // remembering the position so we can go back to it later and parse more data.
143 // Can be converted to/from a LineIterator, but it has a much smaller memory
144 // footprint.
145 struct Bookmark {
146 uint32_t section;
147 size_t offset;
Pavel Labath1211baa2019-05-13 11:25:35 +0000148
149 friend bool operator<(const Bookmark &lhs, const Bookmark &rhs) {
150 return std::tie(lhs.section, lhs.offset) <
151 std::tie(rhs.section, rhs.offset);
152 }
Pavel Labath3f35ab82019-02-07 13:42:32 +0000153 };
154
155 // At iterator class for simplifying algorithms reading data from the breakpad
156 // file. It iterates over all records (lines) in the sections of a given type.
157 // It also supports saving a specific position (via the GetBookmark() method)
158 // and then resuming from it afterwards.
159 class LineIterator;
160
161 // Return an iterator range for all records in the given object file of the
162 // given type.
163 llvm::iterator_range<LineIterator> lines(Record::Kind section_type);
164
165 // Breakpad files do not contain sufficient information to correctly
166 // reconstruct compile units. The approach chosen here is to treat each
167 // function as a compile unit. The compile unit name is the name if the first
168 // line entry belonging to this function.
169 // This class is our internal representation of a compile unit. It stores the
170 // CompileUnit object and a bookmark pointing to the FUNC record of the
171 // compile unit function. It also lazily construct the list of support files
172 // and line table entries for the compile unit, when these are needed.
173 class CompUnitData {
174 public:
175 CompUnitData(Bookmark bookmark) : bookmark(bookmark) {}
176
177 CompUnitData() = default;
178 CompUnitData(const CompUnitData &rhs) : bookmark(rhs.bookmark) {}
179 CompUnitData &operator=(const CompUnitData &rhs) {
180 bookmark = rhs.bookmark;
181 support_files.reset();
182 line_table_up.reset();
183 return *this;
184 }
185 friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs) {
Pavel Labath1211baa2019-05-13 11:25:35 +0000186 return lhs.bookmark < rhs.bookmark;
Pavel Labath3f35ab82019-02-07 13:42:32 +0000187 }
188
189 Bookmark bookmark;
190 llvm::Optional<FileSpecList> support_files;
191 std::unique_ptr<LineTable> line_table_up;
192
193 };
194
Pavel Labathe0119902019-07-23 09:24:02 +0000195 uint32_t CalculateNumCompileUnits() override;
196 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
197
Pavel Labath3f35ab82019-02-07 13:42:32 +0000198 lldb::addr_t GetBaseFileAddress();
199 void ParseFileRecords();
200 void ParseCUData();
201 void ParseLineTableAndSupportFiles(CompileUnit &cu, CompUnitData &data);
Pavel Labath1211baa2019-05-13 11:25:35 +0000202 void ParseUnwindData();
203 bool ParseUnwindRow(llvm::StringRef unwind_rules,
204 const RegisterInfoResolver &resolver,
205 UnwindPlan::Row &row);
Pavel Labath3f35ab82019-02-07 13:42:32 +0000206
207 using CompUnitMap = RangeDataVector<lldb::addr_t, lldb::addr_t, CompUnitData>;
208
209 llvm::Optional<std::vector<FileSpec>> m_files;
210 llvm::Optional<CompUnitMap> m_cu_data;
Pavel Labath1211baa2019-05-13 11:25:35 +0000211
212 using UnwindMap = RangeDataVector<lldb::addr_t, lldb::addr_t, Bookmark>;
213 llvm::Optional<UnwindMap> m_unwind_data;
214 llvm::BumpPtrAllocator m_allocator;
Pavel Labath1cf23e12019-01-11 11:17:51 +0000215};
216
217} // namespace breakpad
218} // namespace lldb_private
219
220#endif