blob: 373a633403a39361c2cb4884f377bd7cbadedfd9 [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"
16
17namespace lldb_private {
18
19namespace breakpad {
20
21class SymbolFileBreakpad : public SymbolFile {
22public:
23 //------------------------------------------------------------------
24 // Static Functions
25 //------------------------------------------------------------------
26 static void Initialize();
27 static void Terminate();
28 static void DebuggerInitialize(Debugger &debugger) {}
29 static ConstString GetPluginNameStatic();
30
31 static const char *GetPluginDescriptionStatic() {
32 return "Breakpad debug symbol file reader.";
33 }
34
35 static SymbolFile *CreateInstance(ObjectFile *obj_file) {
36 return new SymbolFileBreakpad(obj_file);
37 }
38
39 //------------------------------------------------------------------
40 // Constructors and Destructors
41 //------------------------------------------------------------------
42 SymbolFileBreakpad(ObjectFile *object_file) : SymbolFile(object_file) {}
43
44 ~SymbolFileBreakpad() override {}
45
46 uint32_t CalculateAbilities() override;
47
48 void InitializeObject() override {}
49
50 //------------------------------------------------------------------
51 // Compile Unit function calls
52 //------------------------------------------------------------------
53
54 uint32_t GetNumCompileUnits() override;
55
56 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
57
Zachary Turnerce386e32019-01-11 18:35:58 +000058 lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {
Pavel Labath1cf23e12019-01-11 11:17:51 +000059 return lldb::eLanguageTypeUnknown;
60 }
61
Zachary Turnerce386e32019-01-11 18:35:58 +000062 size_t ParseFunctions(CompileUnit &comp_unit) override;
Pavel Labath1cf23e12019-01-11 11:17:51 +000063
Zachary Turnerce386e32019-01-11 18:35:58 +000064 bool ParseLineTable(CompileUnit &comp_unit) override;
Pavel Labath1cf23e12019-01-11 11:17:51 +000065
Zachary Turnerce386e32019-01-11 18:35:58 +000066 bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
67
68 bool ParseSupportFiles(CompileUnit &comp_unit,
Pavel Labath3f35ab82019-02-07 13:42:32 +000069 FileSpecList &support_files) override;
Zachary Turnerce386e32019-01-11 18:35:58 +000070 size_t ParseTypes(CompileUnit &cu) override { return 0; }
Pavel Labath1cf23e12019-01-11 11:17:51 +000071
72 bool
73 ParseImportedModules(const SymbolContext &sc,
74 std::vector<ConstString> &imported_modules) override {
75 return false;
76 }
77
Zachary Turnerffc1b8f2019-01-14 22:40:41 +000078 size_t ParseBlocksRecursive(Function &func) override { return 0; }
Pavel Labath1cf23e12019-01-11 11:17:51 +000079
80 uint32_t FindGlobalVariables(const ConstString &name,
81 const CompilerDeclContext *parent_decl_ctx,
82 uint32_t max_matches,
83 VariableList &variables) override {
84 return 0;
85 }
86
Pavel Labath1cf23e12019-01-11 11:17:51 +000087 size_t ParseVariablesForContext(const SymbolContext &sc) override {
88 return 0;
89 }
90 Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; }
91 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
92 lldb::user_id_t type_uid,
93 const lldb_private::ExecutionContext *exe_ctx) override {
94 return llvm::None;
95 }
96
97 bool CompleteType(CompilerType &compiler_type) override { return false; }
98 uint32_t ResolveSymbolContext(const Address &so_addr,
99 lldb::SymbolContextItem resolve_scope,
100 SymbolContext &sc) override;
101
Pavel Labath3f35ab82019-02-07 13:42:32 +0000102 uint32_t ResolveSymbolContext(const FileSpec &file_spec, uint32_t line,
103 bool check_inlines,
104 lldb::SymbolContextItem resolve_scope,
105 SymbolContextList &sc_list) override;
106
Pavel Labath1cf23e12019-01-11 11:17:51 +0000107 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
108 TypeList &type_list) override {
109 return 0;
110 }
111
112 uint32_t FindFunctions(const ConstString &name,
113 const CompilerDeclContext *parent_decl_ctx,
114 lldb::FunctionNameType name_type_mask,
115 bool include_inlines, bool append,
116 SymbolContextList &sc_list) override;
117
118 uint32_t FindFunctions(const RegularExpression &regex, bool include_inlines,
119 bool append, SymbolContextList &sc_list) override;
120
Zachary Turner576495e2019-01-14 22:41:21 +0000121 uint32_t FindTypes(const ConstString &name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000122 const CompilerDeclContext *parent_decl_ctx, bool append,
123 uint32_t max_matches,
124 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
125 TypeMap &types) override;
126
127 size_t FindTypes(const std::vector<CompilerContext> &context, bool append,
128 TypeMap &types) override;
129
130 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override {
131 return nullptr;
132 }
133
134 CompilerDeclContext
Zachary Turnerc0a246a2019-01-14 22:41:00 +0000135 FindNamespace(const ConstString &name,
Pavel Labath1cf23e12019-01-11 11:17:51 +0000136 const CompilerDeclContext *parent_decl_ctx) override {
137 return CompilerDeclContext();
138 }
139
140 void AddSymbols(Symtab &symtab) override;
141
142 ConstString GetPluginName() override { return GetPluginNameStatic(); }
143 uint32_t GetPluginVersion() override { return 1; }
144
145private:
Pavel Labath3f35ab82019-02-07 13:42:32 +0000146 // A class representing a position in the breakpad file. Useful for
147 // remembering the position so we can go back to it later and parse more data.
148 // Can be converted to/from a LineIterator, but it has a much smaller memory
149 // footprint.
150 struct Bookmark {
151 uint32_t section;
152 size_t offset;
153 };
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) {
186 return std::tie(lhs.bookmark.section, lhs.bookmark.offset) <
187 std::tie(rhs.bookmark.section, rhs.bookmark.offset);
188 }
189
190 Bookmark bookmark;
191 llvm::Optional<FileSpecList> support_files;
192 std::unique_ptr<LineTable> line_table_up;
193
194 };
195
196 SymbolVendor &GetSymbolVendor();
197 lldb::addr_t GetBaseFileAddress();
198 void ParseFileRecords();
199 void ParseCUData();
200 void ParseLineTableAndSupportFiles(CompileUnit &cu, CompUnitData &data);
201
202 using CompUnitMap = RangeDataVector<lldb::addr_t, lldb::addr_t, CompUnitData>;
203
204 llvm::Optional<std::vector<FileSpec>> m_files;
205 llvm::Optional<CompUnitMap> m_cu_data;
Pavel Labath1cf23e12019-01-11 11:17:51 +0000206};
207
208} // namespace breakpad
209} // namespace lldb_private
210
211#endif