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
18#include <optional>
19
20namespace lldb_private {
21
22namespace breakpad {
23
25 /// LLVM RTTI support.
26 static char ID;
27
28public:
29 /// LLVM RTTI support.
30 /// \{
31 bool isA(const void *ClassID) const override {
32 return ClassID == &ID || SymbolFileCommon::isA(ClassID);
33 }
34 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
35 /// \}
36
37 // Static Functions
38 static void Initialize();
39 static void Terminate();
40 static void DebuggerInitialize(Debugger &debugger) {}
41 static llvm::StringRef GetPluginNameStatic() { return "breakpad"; }
42
43 static llvm::StringRef GetPluginDescriptionStatic() {
44 return "Breakpad debug symbol file reader.";
45 }
46
48 return new SymbolFileBreakpad(std::move(objfile_sp));
49 }
50
51 // Constructors and Destructors
53 : SymbolFileCommon(std::move(objfile_sp)) {}
54
55 ~SymbolFileBreakpad() override = default;
56
57 uint32_t CalculateAbilities() override;
58
59 void InitializeObject() override {}
60
61 // Compile Unit function calls
62
65 }
66
68
69 size_t ParseFunctions(CompileUnit &comp_unit) override;
70
71 bool ParseLineTable(CompileUnit &comp_unit) override;
72
73 bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
74
75 bool ParseSupportFiles(CompileUnit &comp_unit,
76 SupportFileList &support_files) override;
77 size_t ParseTypes(CompileUnit &cu) override { return 0; }
78
80 const SymbolContext &sc,
81 std::vector<lldb_private::SourceModule> &imported_modules) override {
82 return false;
83 }
84
85 size_t ParseBlocksRecursive(Function &func) override;
86
88 const CompilerDeclContext &parent_decl_ctx,
89 uint32_t max_matches,
90 VariableList &variables) override {}
91
92 size_t ParseVariablesForContext(const SymbolContext &sc) override {
93 return 0;
94 }
95 Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; }
96 std::optional<ArrayInfo> GetDynamicArrayInfoForUID(
97 lldb::user_id_t type_uid,
98 const lldb_private::ExecutionContext *exe_ctx) override {
99 return std::nullopt;
100 }
101
102 bool CompleteType(CompilerType &compiler_type) override { return false; }
103 uint32_t ResolveSymbolContext(const Address &so_addr,
104 lldb::SymbolContextItem resolve_scope,
105 SymbolContext &sc) override;
106
107 uint32_t ResolveSymbolContext(const SourceLocationSpec &src_location_spec,
108 lldb::SymbolContextItem resolve_scope,
109 SymbolContextList &sc_list) override;
110
111 void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
112 TypeList &type_list) override {}
113
114 void FindFunctions(const Module::LookupInfo &lookup_info,
115 const CompilerDeclContext &parent_decl_ctx,
116 bool include_inlines, SymbolContextList &sc_list) override;
117
118 void FindFunctions(const RegularExpression &regex, bool include_inlines,
119 SymbolContextList &sc_list) override;
120
121 llvm::Expected<lldb::TypeSystemSP>
123 return llvm::make_error<llvm::StringError>(
124 "SymbolFileBreakpad does not support GetTypeSystemForLanguage",
125 llvm::inconvertibleErrorCode());
126 }
127
129 const CompilerDeclContext &parent_decl_ctx,
130 bool only_root_namespaces) override {
131 return CompilerDeclContext();
132 }
133
134 void AddSymbols(Symtab &symtab) override;
135
136 llvm::Expected<lldb::addr_t> GetParameterStackSize(Symbol &symbol) override;
137
139 GetUnwindPlan(const Address &address,
140 const RegisterInfoResolver &resolver) override;
141
142 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
143
144 uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;
145
146private:
147 // A class representing a position in the breakpad file. Useful for
148 // remembering the position so we can go back to it later and parse more data.
149 // Can be converted to/from a LineIterator, but it has a much smaller memory
150 // footprint.
151 struct Bookmark {
152 uint32_t section;
153 size_t offset;
154
155 friend bool operator<(const Bookmark &lhs, const Bookmark &rhs) {
156 return std::tie(lhs.section, lhs.offset) <
157 std::tie(rhs.section, rhs.offset);
158 }
159 };
160
161 // At iterator class for simplifying algorithms reading data from the breakpad
162 // file. It iterates over all records (lines) in the sections of a given type.
163 // It also supports saving a specific position (via the GetBookmark() method)
164 // and then resuming from it afterwards.
165 class LineIterator;
166
167 // Return an iterator range for all records in the given object file of the
168 // given type.
169 llvm::iterator_range<LineIterator> lines(Record::Kind section_type);
170
171 // Breakpad files do not contain sufficient information to correctly
172 // reconstruct compile units. The approach chosen here is to treat each
173 // function as a compile unit. The compile unit name is the name if the first
174 // line entry belonging to this function.
175 // This class is our internal representation of a compile unit. It stores the
176 // CompileUnit object and a bookmark pointing to the FUNC record of the
177 // compile unit function. It also lazily construct the list of support files
178 // and line table entries for the compile unit, when these are needed.
180 public:
182
183 CompUnitData() = default;
186 bookmark = rhs.bookmark;
187 support_files.reset();
188 line_table_up.reset();
189 return *this;
190 }
191 friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs) {
192 return lhs.bookmark < rhs.bookmark;
193 }
194
196 std::optional<FileSpecList> support_files;
197 std::unique_ptr<LineTable> line_table_up;
198 };
199
200 uint32_t CalculateNumCompileUnits() override;
201 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
202
204 void ParseFileRecords();
205 void ParseCUData();
207 void ParseUnwindData();
208 llvm::ArrayRef<uint8_t> SaveAsDWARF(postfix::Node &node);
210 const RegisterInfoResolver &resolver);
211 bool ParseCFIUnwindRow(llvm::StringRef unwind_rules,
212 const RegisterInfoResolver &resolver,
213 UnwindPlan::Row &row);
215 const RegisterInfoResolver &resolver);
217
219
220 std::optional<std::vector<FileSpec>> m_files;
221 std::optional<CompUnitMap> m_cu_data;
222 std::optional<std::vector<llvm::StringRef>> m_inline_origins;
223
225 struct UnwindData {
228 };
229 std::optional<UnwindData> m_unwind_data;
230 llvm::BumpPtrAllocator m_allocator;
231};
232
233} // namespace breakpad
234} // namespace lldb_private
235
236#endif
A section + offset based address class.
Definition: Address.h:62
A class that describes a compilation unit.
Definition: CompileUnit.h:41
Represents a generic declaration context in a program.
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
A class to manage flag bits.
Definition: Debugger.h:79
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A class that describes a function.
Definition: Function.h:399
A class that encapsulates name lookup information.
Definition: Module.h:904
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
A list of support files for a CompileUnit.
Definition: FileSpecList.h:23
Defines a list of symbol context objects.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Containing protected virtual methods for child classes to override.
Definition: SymbolFile.h:496
bool isA(const void *ClassID) const override
LLVM RTTI support.
Definition: SymbolFile.h:503
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:50
virtual bool isA(const void *ClassID) const
LLVM RTTI support.
Definition: SymbolFile.h:57
friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs)
CompUnitData & operator=(const CompUnitData &rhs)
size_t ParseBlocksRecursive(Function &func) override
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
size_t ParseFunctions(CompileUnit &comp_unit) override
bool ParseImportedModules(const SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
void InitializeObject() override
Initialize the SymbolFile object.
bool isA(const void *ClassID) const override
LLVM RTTI support.
static void DebuggerInitialize(Debugger &debugger)
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
lldb::UnwindPlanSP ParseCFIUnwindPlan(const Bookmark &bookmark, const RegisterInfoResolver &resolver)
lldb::UnwindPlanSP ParseWinUnwindPlan(const Bookmark &bookmark, const RegisterInfoResolver &resolver)
llvm::ArrayRef< uint8_t > SaveAsDWARF(postfix::Node &node)
size_t ParseTypes(CompileUnit &cu) override
bool ParseCFIUnwindRow(llvm::StringRef unwind_rules, const RegisterInfoResolver &resolver, UnwindPlan::Row &row)
lldb::UnwindPlanSP GetUnwindPlan(const Address &address, const RegisterInfoResolver &resolver) override
llvm::Expected< lldb::addr_t > GetParameterStackSize(Symbol &symbol) override
Return the number of stack bytes taken up by the parameters to this function.
std::optional< std::vector< llvm::StringRef > > m_inline_origins
static llvm::StringRef GetPluginDescriptionStatic()
bool CompleteType(CompilerType &compiler_type) override
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
std::optional< std::vector< FileSpec > > m_files
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
SymbolFileBreakpad(lldb::ObjectFileSP objfile_sp)
bool ParseLineTable(CompileUnit &comp_unit) override
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
static SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
bool ParseSupportFiles(CompileUnit &comp_unit, SupportFileList &support_files) override
std::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.
size_t ParseVariablesForContext(const SymbolContext &sc) override
void ParseLineTableAndSupportFiles(CompileUnit &cu, CompUnitData &data)
bool ParseDebugMacros(CompileUnit &comp_unit) override
CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
lldb::FunctionSP GetOrCreateFunction(CompileUnit &comp_unit)
static bool classof(const SymbolFile *obj)
llvm::iterator_range< LineIterator > lines(Record::Kind section_type)
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override
The base class for all nodes in the parsed postfix tree.
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::shared_ptr< lldb_private::Function > FunctionSP
Definition: lldb-forward.h:347
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:367
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
Definition: lldb-forward.h:471
uint64_t user_id_t
Definition: lldb-types.h:80
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:327
friend bool operator<(const Bookmark &lhs, const Bookmark &rhs)