LLDB  mainline
SymbolFileBreakpad.h
Go to the documentation of this file.
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_SOURCE_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H
11 
13 #include "lldb/Core/FileSpecList.h"
14 #include "lldb/Symbol/LineTable.h"
16 #include "lldb/Symbol/SymbolFile.h"
17 #include "lldb/Symbol/UnwindPlan.h"
18 
19 namespace lldb_private {
20 
21 namespace breakpad {
22 
24  /// LLVM RTTI support.
25  static char ID;
26 
27 public:
28  /// LLVM RTTI support.
29  /// \{
30  bool isA(const void *ClassID) const override {
31  return ClassID == &ID || SymbolFile::isA(ClassID);
32  }
33  static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
34  /// \}
35 
36  // Static Functions
37  static void Initialize();
38  static void Terminate();
39  static void DebuggerInitialize(Debugger &debugger) {}
41 
42  static const char *GetPluginDescriptionStatic() {
43  return "Breakpad debug symbol file reader.";
44  }
45 
46  static SymbolFile *CreateInstance(lldb::ObjectFileSP objfile_sp) {
47  return new SymbolFileBreakpad(std::move(objfile_sp));
48  }
49 
50  // Constructors and Destructors
51  SymbolFileBreakpad(lldb::ObjectFileSP objfile_sp)
52  : SymbolFile(std::move(objfile_sp)) {}
53 
54  ~SymbolFileBreakpad() override = default;
55 
56  uint32_t CalculateAbilities() override;
57 
58  void InitializeObject() override {}
59 
60  // Compile Unit function calls
61 
64  }
65 
66  size_t ParseFunctions(CompileUnit &comp_unit) override;
67 
68  bool ParseLineTable(CompileUnit &comp_unit) override;
69 
70  bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
71 
72  bool ParseSupportFiles(CompileUnit &comp_unit,
73  FileSpecList &support_files) override;
74  size_t ParseTypes(CompileUnit &cu) override { return 0; }
75 
77  const SymbolContext &sc,
78  std::vector<lldb_private::SourceModule> &imported_modules) override {
79  return false;
80  }
81 
82  size_t ParseBlocksRecursive(Function &func) override { return 0; }
83 
85  const CompilerDeclContext &parent_decl_ctx,
86  uint32_t max_matches,
87  VariableList &variables) override {}
88 
89  size_t ParseVariablesForContext(const SymbolContext &sc) override {
90  return 0;
91  }
92  Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; }
93  llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
94  lldb::user_id_t type_uid,
95  const lldb_private::ExecutionContext *exe_ctx) override {
96  return llvm::None;
97  }
98 
99  bool CompleteType(CompilerType &compiler_type) override { return false; }
100  uint32_t ResolveSymbolContext(const Address &so_addr,
101  lldb::SymbolContextItem resolve_scope,
102  SymbolContext &sc) override;
103 
104  uint32_t ResolveSymbolContext(const SourceLocationSpec &src_location_spec,
105  lldb::SymbolContextItem resolve_scope,
106  SymbolContextList &sc_list) override;
107 
108  void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
109  TypeList &type_list) override {}
110 
111  void FindFunctions(ConstString name,
112  const CompilerDeclContext &parent_decl_ctx,
113  lldb::FunctionNameType name_type_mask,
114  bool include_inlines, SymbolContextList &sc_list) override;
115 
116  void FindFunctions(const RegularExpression &regex, bool include_inlines,
117  SymbolContextList &sc_list) override;
118 
119  void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx,
120  uint32_t max_matches,
121  llvm::DenseSet<SymbolFile *> &searched_symbol_files,
122  TypeMap &types) override;
123 
124  void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
125  llvm::DenseSet<SymbolFile *> &searched_symbol_files,
126  TypeMap &types) override;
127 
128  llvm::Expected<TypeSystem &>
130  return llvm::make_error<llvm::StringError>(
131  "SymbolFileBreakpad does not support GetTypeSystemForLanguage",
132  llvm::inconvertibleErrorCode());
133  }
134 
137  const CompilerDeclContext &parent_decl_ctx) override {
138  return CompilerDeclContext();
139  }
140 
141  void AddSymbols(Symtab &symtab) override;
142 
143  llvm::Expected<lldb::addr_t> GetParameterStackSize(Symbol &symbol) override;
144 
145  lldb::UnwindPlanSP
146  GetUnwindPlan(const Address &address,
147  const RegisterInfoResolver &resolver) override;
148 
149  llvm::StringRef GetPluginName() override {
151  }
152 
153 private:
154  // A class representing a position in the breakpad file. Useful for
155  // remembering the position so we can go back to it later and parse more data.
156  // Can be converted to/from a LineIterator, but it has a much smaller memory
157  // footprint.
158  struct Bookmark {
160  size_t offset;
161 
162  friend bool operator<(const Bookmark &lhs, const Bookmark &rhs) {
163  return std::tie(lhs.section, lhs.offset) <
164  std::tie(rhs.section, rhs.offset);
165  }
166  };
167 
168  // At iterator class for simplifying algorithms reading data from the breakpad
169  // file. It iterates over all records (lines) in the sections of a given type.
170  // It also supports saving a specific position (via the GetBookmark() method)
171  // and then resuming from it afterwards.
172  class LineIterator;
173 
174  // Return an iterator range for all records in the given object file of the
175  // given type.
176  llvm::iterator_range<LineIterator> lines(Record::Kind section_type);
177 
178  // Breakpad files do not contain sufficient information to correctly
179  // reconstruct compile units. The approach chosen here is to treat each
180  // function as a compile unit. The compile unit name is the name if the first
181  // line entry belonging to this function.
182  // This class is our internal representation of a compile unit. It stores the
183  // CompileUnit object and a bookmark pointing to the FUNC record of the
184  // compile unit function. It also lazily construct the list of support files
185  // and line table entries for the compile unit, when these are needed.
186  class CompUnitData {
187  public:
189 
190  CompUnitData() = default;
193  bookmark = rhs.bookmark;
194  support_files.reset();
195  line_table_up.reset();
196  return *this;
197  }
198  friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs) {
199  return lhs.bookmark < rhs.bookmark;
200  }
201 
203  llvm::Optional<FileSpecList> support_files;
204  std::unique_ptr<LineTable> line_table_up;
205 
206  };
207 
209  lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
210 
212  void ParseFileRecords();
213  void ParseCUData();
215  void ParseUnwindData();
216  llvm::ArrayRef<uint8_t> SaveAsDWARF(postfix::Node &node);
217  lldb::UnwindPlanSP ParseCFIUnwindPlan(const Bookmark &bookmark,
218  const RegisterInfoResolver &resolver);
219  bool ParseCFIUnwindRow(llvm::StringRef unwind_rules,
220  const RegisterInfoResolver &resolver,
221  UnwindPlan::Row &row);
222  lldb::UnwindPlanSP ParseWinUnwindPlan(const Bookmark &bookmark,
223  const RegisterInfoResolver &resolver);
224 
226 
227  llvm::Optional<std::vector<FileSpec>> m_files;
228  llvm::Optional<CompUnitMap> m_cu_data;
229 
231  struct UnwindData {
234  };
235  llvm::Optional<UnwindData> m_unwind_data;
236  llvm::BumpPtrAllocator m_allocator;
237 };
238 
239 } // namespace breakpad
240 } // namespace lldb_private
241 
242 #endif
lldb_private::breakpad::SymbolFileBreakpad::m_files
llvm::Optional< std::vector< FileSpec > > m_files
Definition: SymbolFileBreakpad.h:227
lldb_private::SymbolFile
Definition: SymbolFile.h:37
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::breakpad::SymbolFileBreakpad::m_unwind_data
llvm::Optional< UnwindData > m_unwind_data
Definition: SymbolFileBreakpad.h:235
lldb_private::RegularExpression
Definition: RegularExpression.h:18
lldb_private::breakpad::SymbolFileBreakpad::m_cu_data
llvm::Optional< CompUnitMap > m_cu_data
Definition: SymbolFileBreakpad.h:228
lldb_private::breakpad::SymbolFileBreakpad::lines
llvm::iterator_range< LineIterator > lines(Record::Kind section_type)
Definition: SymbolFileBreakpad.cpp:131
lldb_private::Symbol
Definition: Symbol.h:20
lldb_private::postfix::Node
The base class for all nodes in the parsed postfix tree.
Definition: PostfixExpression.h:29
lldb_private::SourceLocationSpec
Definition: SourceLocationSpec.h:27
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::line_table_up
std::unique_ptr< LineTable > line_table_up
Definition: SymbolFileBreakpad.h:204
lldb_private::breakpad::SymbolFileBreakpad::AddSymbols
void AddSymbols(Symtab &symtab) override
Definition: SymbolFileBreakpad.cpp:317
lldb_private::breakpad::SymbolFileBreakpad::CompleteType
bool CompleteType(CompilerType &compiler_type) override
Definition: SymbolFileBreakpad.h:99
lldb_private::breakpad::SymbolFileBreakpad::m_allocator
llvm::BumpPtrAllocator m_allocator
Definition: SymbolFileBreakpad.h:236
lldb_private::breakpad::SymbolFileBreakpad::UnwindData::win
UnwindMap win
Definition: SymbolFileBreakpad.h:233
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::operator<
friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs)
Definition: SymbolFileBreakpad.h:198
lldb_private::breakpad::SymbolFileBreakpad::classof
static bool classof(const SymbolFile *obj)
Definition: SymbolFileBreakpad.h:33
lldb_private::breakpad::SymbolFileBreakpad
Definition: SymbolFileBreakpad.h:23
lldb_private::breakpad::SymbolFileBreakpad::ParseLineTable
bool ParseLineTable(CompileUnit &comp_unit) override
Definition: SymbolFileBreakpad.cpp:232
lldb_private::breakpad::SymbolFileBreakpad::UnwindData
Definition: SymbolFileBreakpad.h:231
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::SymbolContextList
Definition: SymbolContext.h:379
lldb_private::breakpad::SymbolFileBreakpad::ParseCFIUnwindRow
bool ParseCFIUnwindRow(llvm::StringRef unwind_rules, const RegisterInfoResolver &resolver, UnwindPlan::Row &row)
Definition: SymbolFileBreakpad.cpp:446
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData
Definition: SymbolFileBreakpad.h:186
lldb_private::breakpad::SymbolFileBreakpad::ParseCUData
void ParseCUData()
Definition: SymbolFileBreakpad.cpp:678
lldb_private::breakpad::SymbolFileBreakpad::GetTypeSystemForLanguage
llvm::Expected< TypeSystem & > GetTypeSystemForLanguage(lldb::LanguageType language) override
Definition: SymbolFileBreakpad.h:129
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::breakpad::SymbolFileBreakpad::UnwindData::cfi
UnwindMap cfi
Definition: SymbolFileBreakpad.h:232
lldb_private::breakpad::SymbolFileBreakpad::ParseTypes
size_t ParseTypes(CompileUnit &cu) override
Definition: SymbolFileBreakpad.h:74
lldb_private::breakpad::SymbolFileBreakpad::ParseVariablesForContext
size_t ParseVariablesForContext(const SymbolContext &sc) override
Definition: SymbolFileBreakpad.h:89
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::breakpad::SymbolFileBreakpad::Terminate
static void Terminate()
Definition: SymbolFileBreakpad.cpp:175
lldb_private::breakpad::SymbolFileBreakpad::GetBaseFileAddress
lldb::addr_t GetBaseFileAddress()
Definition: SymbolFileBreakpad.cpp:648
lldb_private::VariableList
Definition: VariableList.h:18
lldb_private::breakpad::SymbolFileBreakpad::ParseSupportFiles
bool ParseSupportFiles(CompileUnit &comp_unit, FileSpecList &support_files) override
Definition: SymbolFileBreakpad.cpp:243
lldb_private::CompileUnit
Definition: CompileUnit.h:38
lldb_private::breakpad::SymbolFileBreakpad::GetPluginDescriptionStatic
static const char * GetPluginDescriptionStatic()
Definition: SymbolFileBreakpad.h:42
lldb_private::breakpad::SymbolFileBreakpad::ParseFileRecords
void ParseFileRecords()
Definition: SymbolFileBreakpad.cpp:657
lldb_private::Function
Definition: Function.h:413
lldb_private::breakpad::SymbolFileBreakpad::GetParameterStackSize
llvm::Expected< lldb::addr_t > GetParameterStackSize(Symbol &symbol) override
Return the number of stack bytes taken up by the parameters to this function.
Definition: SymbolFileBreakpad.cpp:372
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::breakpad::SymbolFileBreakpad::GetPluginNameStatic
static ConstString GetPluginNameStatic()
Definition: SymbolFileBreakpad.cpp:179
PostfixExpression.h
FileSpecList.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::SymbolFile::isA
virtual bool isA(const void *ClassID) const
LLVM RTTI support.
Definition: SymbolFile.h:44
lldb_private::breakpad::SymbolFileBreakpad::FindNamespace
CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx) override
Definition: SymbolFileBreakpad.h:136
lldb_private::breakpad::SymbolFileBreakpad::CalculateNumCompileUnits
uint32_t CalculateNumCompileUnits() override
Definition: SymbolFileBreakpad.cpp:191
lldb_private::breakpad::SymbolFileBreakpad::DebuggerInitialize
static void DebuggerInitialize(Debugger &debugger)
Definition: SymbolFileBreakpad.h:39
lldb_private::breakpad::SymbolFileBreakpad::ID
static char ID
LLVM RTTI support.
Definition: SymbolFileBreakpad.h:25
lldb_private::breakpad::SymbolFileBreakpad::FindGlobalVariables
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
Definition: SymbolFileBreakpad.h:84
lldb_private::Debugger
Definition: Debugger.h:70
lldb_private::SymbolFile::RegisterInfoResolver
Definition: SymbolFile.h:281
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::CompUnitData
CompUnitData(Bookmark bookmark)
Definition: SymbolFileBreakpad.h:188
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::CompUnitData
CompUnitData()=default
lldb_private::breakpad::SymbolFileBreakpad::Bookmark::offset
size_t offset
Definition: SymbolFileBreakpad.h:160
UnwindPlan.h
lldb_private::TypeMap
Definition: TypeMap.h:20
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
lldb_private::SymbolContextScope
Definition: SymbolContextScope.h:64
lldb_private::breakpad::SymbolFileBreakpad::GetDynamicArrayInfoForUID
llvm::Optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
Definition: SymbolFileBreakpad.h:93
lldb_private::breakpad::SymbolFileBreakpad::CalculateAbilities
uint32_t CalculateAbilities() override
Definition: SymbolFileBreakpad.cpp:184
lldb_private::breakpad::SymbolFileBreakpad::FindTypes
void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, llvm::DenseSet< SymbolFile * > &searched_symbol_files, TypeMap &types) override
Definition: SymbolFileBreakpad.cpp:308
lldb_private::breakpad::SymbolFileBreakpad::GetTypes
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
Definition: SymbolFileBreakpad.h:108
lldb_private::breakpad::SymbolFileBreakpad::Bookmark::operator<
friend bool operator<(const Bookmark &lhs, const Bookmark &rhs)
Definition: SymbolFileBreakpad.h:162
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
lldb_private::Symtab
Definition: Symtab.h:22
lldb_private::breakpad::SymbolFileBreakpad::Bookmark
Definition: SymbolFileBreakpad.h:158
lldb_private::UnwindPlan::Row
Definition: UnwindPlan.h:55
uint32_t
lldb_private::breakpad::SymbolFileBreakpad::ResolveTypeUID
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
Definition: SymbolFileBreakpad.h:92
lldb_private::Address
Definition: Address.h:59
lldb_private::breakpad::SymbolFileBreakpad::FindFunctions
void FindFunctions(ConstString name, const CompilerDeclContext &parent_decl_ctx, lldb::FunctionNameType name_type_mask, bool include_inlines, SymbolContextList &sc_list) override
lldb_private::breakpad::SymbolFileBreakpad::ParseUnwindData
void ParseUnwindData()
Definition: SymbolFileBreakpad.cpp:753
lldb_private::RangeDataVector
Definition: RangeMap.h:398
lldb_private::Type
Definition: Type.h:66
LineTable.h
lldb_private::breakpad::SymbolFileBreakpad::InitializeObject
void InitializeObject() override
Initialize the SymbolFile object.
Definition: SymbolFileBreakpad.h:58
lldb_private::breakpad::SymbolFileBreakpad::Initialize
static void Initialize()
Definition: SymbolFileBreakpad.cpp:169
lldb_private::breakpad::SymbolFileBreakpad::ParseLanguage
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override
Definition: SymbolFileBreakpad.h:62
lldb_private::breakpad::SymbolFileBreakpad::ParseCFIUnwindPlan
lldb::UnwindPlanSP ParseCFIUnwindPlan(const Bookmark &bookmark, const RegisterInfoResolver &resolver)
Definition: SymbolFileBreakpad.cpp:513
lldb_private::breakpad::SymbolFileBreakpad::ParseCompileUnitAtIndex
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
Definition: SymbolFileBreakpad.cpp:196
lldb_private::breakpad::SymbolFileBreakpad::isA
bool isA(const void *ClassID) const override
LLVM RTTI support.
Definition: SymbolFileBreakpad.h:30
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::support_files
llvm::Optional< FileSpecList > support_files
Definition: SymbolFileBreakpad.h:203
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::breakpad::Record::Kind
Kind
Definition: BreakpadRecords.h:23
lldb_private::breakpad::SymbolFileBreakpad::GetPluginName
llvm::StringRef GetPluginName() override
Definition: SymbolFileBreakpad.h:149
lldb_private::breakpad::SymbolFileBreakpad::Bookmark::section
uint32_t section
Definition: SymbolFileBreakpad.h:159
lldb_private::TypeList
Definition: TypeList.h:20
lldb_private::breakpad::SymbolFileBreakpad::ParseDebugMacros
bool ParseDebugMacros(CompileUnit &comp_unit) override
Definition: SymbolFileBreakpad.h:70
lldb_private::breakpad::SymbolFileBreakpad::GetUnwindPlan
lldb::UnwindPlanSP GetUnwindPlan(const Address &address, const RegisterInfoResolver &resolver) override
Definition: SymbolFileBreakpad.cpp:500
lldb_private::LanguageSet
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:40
lldb_private::breakpad::SymbolFileBreakpad::ResolveSymbolContext
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
lldb_private::breakpad::SymbolFileBreakpad::SaveAsDWARF
llvm::ArrayRef< uint8_t > SaveAsDWARF(postfix::Node &node)
Definition: SymbolFileBreakpad.cpp:436
lldb_private::breakpad::SymbolFileBreakpad::CreateInstance
static SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
Definition: SymbolFileBreakpad.h:46
lldb_private::breakpad::SymbolFileBreakpad::ParseWinUnwindPlan
lldb::UnwindPlanSP ParseWinUnwindPlan(const Bookmark &bookmark, const RegisterInfoResolver &resolver)
Definition: SymbolFileBreakpad.cpp:556
lldb_private::breakpad::SymbolFileBreakpad::ParseImportedModules
bool ParseImportedModules(const SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
Definition: SymbolFileBreakpad.h:76
BreakpadRecords.h
lldb_private::breakpad::SymbolFileBreakpad::ParseFunctions
size_t ParseFunctions(CompileUnit &comp_unit) override
Definition: SymbolFileBreakpad.cpp:227
lldb_private::breakpad::SymbolFileBreakpad::ParseBlocksRecursive
size_t ParseBlocksRecursive(Function &func) override
Definition: SymbolFileBreakpad.h:82
SymbolFile.h
lldb_private::breakpad::SymbolFileBreakpad::ParseLineTableAndSupportFiles
void ParseLineTableAndSupportFiles(CompileUnit &cu, CompUnitData &data)
Definition: SymbolFileBreakpad.cpp:705
lldb_private::breakpad::SymbolFileBreakpad::SymbolFileBreakpad
SymbolFileBreakpad(lldb::ObjectFileSP objfile_sp)
Definition: SymbolFileBreakpad.h:51
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::CompUnitData
CompUnitData(const CompUnitData &rhs)
Definition: SymbolFileBreakpad.h:191
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::operator=
CompUnitData & operator=(const CompUnitData &rhs)
Definition: SymbolFileBreakpad.h:192
lldb_private::breakpad::SymbolFileBreakpad::~SymbolFileBreakpad
~SymbolFileBreakpad() override=default
lldb_private::breakpad::SymbolFileBreakpad::CompUnitData::bookmark
Bookmark bookmark
Definition: SymbolFileBreakpad.h:202