1 //===-- SymbolFileBreakpad.h ------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H 10 #define LLDB_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H 11 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" 17 18 namespace lldb_private { 19 20 namespace breakpad { 21 22 class SymbolFileBreakpad : public SymbolFile { 23 public: 24 // Static Functions 25 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 38 // Constructors and Destructors 39 SymbolFileBreakpad(ObjectFile *object_file) : SymbolFile(object_file) {} 40 41 ~SymbolFileBreakpad() override {} 42 43 uint32_t CalculateAbilities() override; 44 45 void InitializeObject() override {} 46 47 // Compile Unit function calls 48 49 uint32_t GetNumCompileUnits() override; 50 51 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; 52 53 lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override { 54 return lldb::eLanguageTypeUnknown; 55 } 56 57 size_t ParseFunctions(CompileUnit &comp_unit) override; 58 59 bool ParseLineTable(CompileUnit &comp_unit) override; 60 61 bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; } 62 63 bool ParseSupportFiles(CompileUnit &comp_unit, 64 FileSpecList &support_files) override; 65 size_t ParseTypes(CompileUnit &cu) override { return 0; } 66 67 bool ParseImportedModules( 68 const SymbolContext &sc, 69 std::vector<lldb_private::SourceModule> &imported_modules) override { 70 return false; 71 } 72 73 size_t ParseBlocksRecursive(Function &func) override { return 0; } 74 75 uint32_t FindGlobalVariables(ConstString name, 76 const CompilerDeclContext *parent_decl_ctx, 77 uint32_t max_matches, 78 VariableList &variables) override { 79 return 0; 80 } 81 82 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 97 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 102 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, 103 TypeList &type_list) override { 104 return 0; 105 } 106 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; 112 113 uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines, 114 bool append, SymbolContextList &sc_list) override; 115 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; 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 130 FindNamespace(ConstString name, 131 const CompilerDeclContext *parent_decl_ctx) override { 132 return CompilerDeclContext(); 133 } 134 135 void AddSymbols(Symtab &symtab) override; 136 137 lldb::UnwindPlanSP 138 GetUnwindPlan(const Address &address, 139 const RegisterInfoResolver &resolver) override; 140 141 ConstString GetPluginName() override { return GetPluginNameStatic(); } 142 uint32_t GetPluginVersion() override { return 1; } 143 144 private: 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 148 // footprint. 149 struct Bookmark { 150 uint32_t section; 151 size_t offset; 152 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 } 157 }; 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) { 190 return lhs.bookmark < rhs.bookmark; 191 } 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); 204 void ParseUnwindData(); 205 bool ParseUnwindRow(llvm::StringRef unwind_rules, 206 const RegisterInfoResolver &resolver, 207 UnwindPlan::Row &row); 208 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; 213 214 using UnwindMap = RangeDataVector<lldb::addr_t, lldb::addr_t, Bookmark>; 215 llvm::Optional<UnwindMap> m_unwind_data; 216 llvm::BumpPtrAllocator m_allocator; 217 }; 218 219 } // namespace breakpad 220 } // namespace lldb_private 221 222 #endif 223