1 //===-- SymbolFileBreakpad.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_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H
10 #define LLDB_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H
12 #include "Plugins/ObjectFile/Breakpad/BreakpadRecords.h"
13 #include "lldb/Core/FileSpecList.h"
14 #include "lldb/Symbol/LineTable.h"
15 #include "lldb/Symbol/SymbolFile.h"
16 #include "lldb/Symbol/UnwindPlan.h"
18 namespace lldb_private {
22 class SymbolFileBreakpad : public SymbolFile {
25 static void Initialize();
26 static void Terminate();
27 static void DebuggerInitialize(Debugger &debugger) {}
28 static ConstString GetPluginNameStatic();
30 static const char *GetPluginDescriptionStatic() {
31 return "Breakpad debug symbol file reader.";
34 static SymbolFile *CreateInstance(ObjectFile *obj_file) {
35 return new SymbolFileBreakpad(obj_file);
38 // Constructors and Destructors
39 SymbolFileBreakpad(ObjectFile *object_file) : SymbolFile(object_file) {}
41 ~SymbolFileBreakpad() override {}
43 uint32_t CalculateAbilities() override;
45 void InitializeObject() override {}
47 // Compile Unit function calls
49 uint32_t GetNumCompileUnits() override;
51 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
53 lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {
54 return lldb::eLanguageTypeUnknown;
57 size_t ParseFunctions(CompileUnit &comp_unit) override;
59 bool ParseLineTable(CompileUnit &comp_unit) override;
61 bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
63 bool ParseSupportFiles(CompileUnit &comp_unit,
64 FileSpecList &support_files) override;
65 size_t ParseTypes(CompileUnit &cu) override { return 0; }
67 bool ParseImportedModules(
68 const SymbolContext &sc,
69 std::vector<lldb_private::SourceModule> &imported_modules) override {
73 size_t ParseBlocksRecursive(Function &func) override { return 0; }
75 uint32_t FindGlobalVariables(ConstString name,
76 const CompilerDeclContext *parent_decl_ctx,
78 VariableList &variables) override {
82 size_t ParseVariablesForContext(const SymbolContext &sc) override {
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 {
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;
97 uint32_t ResolveSymbolContext(const FileSpec &file_spec, uint32_t line,
99 lldb::SymbolContextItem resolve_scope,
100 SymbolContextList &sc_list) override;
102 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
103 TypeList &type_list) override {
107 uint32_t FindFunctions(ConstString name,
108 const CompilerDeclContext *parent_decl_ctx,
109 lldb::FunctionNameType name_type_mask,
110 bool include_inlines, bool append,
111 SymbolContextList &sc_list) override;
113 uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines,
114 bool append, SymbolContextList &sc_list) override;
116 uint32_t FindTypes(ConstString name,
117 const CompilerDeclContext *parent_decl_ctx, bool append,
118 uint32_t max_matches,
119 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
120 TypeMap &types) override;
122 size_t FindTypes(const std::vector<CompilerContext> &context, bool append,
123 TypeMap &types) override;
125 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override {
130 FindNamespace(ConstString name,
131 const CompilerDeclContext *parent_decl_ctx) override {
132 return CompilerDeclContext();
135 void AddSymbols(Symtab &symtab) override;
138 GetUnwindPlan(const Address &address,
139 const RegisterInfoResolver &resolver) override;
141 ConstString GetPluginName() override { return GetPluginNameStatic(); }
142 uint32_t GetPluginVersion() override { return 1; }
145 // 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
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);
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.
165 // Return an iterator range for all records in the given object file of the
167 llvm::iterator_range<LineIterator> lines(Record::Kind section_type);
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.
179 CompUnitData(Bookmark bookmark) : bookmark(bookmark) {}
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();
189 friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs) {
190 return lhs.bookmark < rhs.bookmark;
194 llvm::Optional<FileSpecList> support_files;
195 std::unique_ptr<LineTable> line_table_up;
199 SymbolVendor &GetSymbolVendor();
200 lldb::addr_t GetBaseFileAddress();
201 void ParseFileRecords();
203 void ParseLineTableAndSupportFiles(CompileUnit &cu, CompUnitData &data);
204 void ParseUnwindData();
205 bool ParseUnwindRow(llvm::StringRef unwind_rules,
206 const RegisterInfoResolver &resolver,
207 UnwindPlan::Row &row);
209 using CompUnitMap = RangeDataVector<lldb::addr_t, lldb::addr_t, CompUnitData>;
211 llvm::Optional<std::vector<FileSpec>> m_files;
212 llvm::Optional<CompUnitMap> m_cu_data;
214 using UnwindMap = RangeDataVector<lldb::addr_t, lldb::addr_t, Bookmark>;
215 llvm::Optional<UnwindMap> m_unwind_data;
216 llvm::BumpPtrAllocator m_allocator;
219 } // namespace breakpad
220 } // namespace lldb_private