LLDB mainline
SymbolFileCTF.h
Go to the documentation of this file.
1//===-- SymbolFileCTF.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_CTF_SYMBOLFILECTF_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H
11
12#include <map>
13#include <optional>
14#include <vector>
15
16#include "CTFTypes.h"
19
20namespace lldb_private {
21
23 /// LLVM RTTI support.
24 static char ID;
25
26public:
27 /// LLVM RTTI support.
28 /// \{
29 bool isA(const void *ClassID) const override {
30 return ClassID == &ID || SymbolFileCommon::isA(ClassID);
31 }
32 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
33 /// \}
34
36
37 static void Initialize();
38
39 static void Terminate();
40
41 static llvm::StringRef GetPluginNameStatic() { return "CTF"; }
42
43 static llvm::StringRef GetPluginDescriptionStatic();
44
47
48 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
49
50 uint32_t CalculateAbilities() override;
51
52 void InitializeObject() override;
53
56 }
57
58 bool ParseHeader();
59
60 size_t ParseFunctions(CompileUnit &comp_unit) override;
61
62 size_t ParseObjects(CompileUnit &comp_unit);
63
64 bool ParseLineTable(CompileUnit &comp_unit) override { return false; }
65
66 bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
67
69 SupportFileList &support_files) override {
70 return false;
71 }
72
73 size_t ParseTypes(CompileUnit &cu) override;
74
76 const SymbolContext &sc,
77 std::vector<lldb_private::SourceModule> &imported_modules) override {
78 return false;
79 }
80
81 size_t ParseBlocksRecursive(Function &func) override { return 0; }
82
83 size_t ParseVariablesForContext(const SymbolContext &sc) override;
84
85 uint32_t CalculateNumCompileUnits() override { return 0; }
86
87 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
88
89 Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
90 std::optional<ArrayInfo> GetDynamicArrayInfoForUID(
91 lldb::user_id_t type_uid,
92 const lldb_private::ExecutionContext *exe_ctx) override {
93 return std::nullopt;
94 }
95
96 bool CompleteType(CompilerType &compiler_type) override;
97
98 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
99 lldb::SymbolContextItem resolve_scope,
100 lldb_private::SymbolContext &sc) override;
101
102 void AddSymbols(Symtab &symtab) override;
103
105 lldb::TypeClass type_mask,
106 lldb_private::TypeList &type_list) override {}
107
108 void FindTypes(const lldb_private::TypeQuery &match,
109 lldb_private::TypeResults &results) override;
110
112 uint32_t max_matches, lldb_private::TypeMap &types);
113
114 void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info,
115 const lldb_private::CompilerDeclContext &parent_decl_ctx,
116 bool include_inlines,
117 lldb_private::SymbolContextList &sc_list) override;
118
120 bool include_inlines,
121 lldb_private::SymbolContextList &sc_list) override;
122
123 void
125 const lldb_private::CompilerDeclContext &parent_decl_ctx,
126 uint32_t max_matches,
127 lldb_private::VariableList &variables) override;
128
130 uint32_t max_matches,
131 lldb_private::VariableList &variables) override;
132
133 enum TypeKind : uint32_t {
142 eEnum = 8,
146 eConst = 12,
148 eSlice = 14,
149 };
150
151private:
152 enum Flags : uint32_t {
153 eFlagCompress = (1u << 0),
154 eFlagNewFuncInfo = (1u << 1),
155 eFlagIdxSorted = (1u << 2),
156 eFlagDynStr = (1u << 3),
157 };
158
159 enum IntEncoding : uint32_t {
160 eSigned = 0x1,
161 eChar = 0x2,
162 eBool = 0x4,
163 eVarArgs = 0x8,
164 };
165
167 uint16_t magic;
168 uint8_t version;
169 uint8_t flags;
170 };
171
174 uint32_t parlabel;
175 uint32_t parname;
176 uint32_t lbloff;
177 uint32_t objtoff;
178 uint32_t funcoff;
179 uint32_t typeoff;
180 uint32_t stroff;
181 uint32_t strlen;
182 };
183
184 struct ctf_type_t {
185 uint32_t name;
186 uint32_t info;
187 union {
188 uint32_t size;
189 uint32_t type;
190 };
191 uint32_t lsizehi;
192 uint32_t lsizelo;
193 };
194
195 struct ctf_stype_t {
196 uint32_t name;
197 uint32_t info;
198 union {
199 uint32_t size;
200 uint32_t type;
201 };
202
203 bool IsLargeType() const { return size == 0xffff; }
204 uint32_t GetStructSize() const {
205 if (IsLargeType())
206 return sizeof(ctf_type_t);
207 return sizeof(ctf_stype_t);
208 }
209 uint32_t GetType() const { return type; }
210 uint32_t GetSize() const { return size; }
211 };
212
213 llvm::Expected<std::unique_ptr<CTFType>> ParseType(lldb::offset_t &offset,
214 lldb::user_id_t uid);
215
216 llvm::Expected<lldb::TypeSP> CreateType(CTFType *ctf_type);
217 llvm::Expected<lldb::TypeSP> CreateInteger(const CTFInteger &ctf_integer);
218 llvm::Expected<lldb::TypeSP> CreateModifier(const CTFModifier &ctf_modifier);
219 llvm::Expected<lldb::TypeSP> CreateTypedef(const CTFTypedef &ctf_typedef);
220 llvm::Expected<lldb::TypeSP> CreateArray(const CTFArray &ctf_array);
221 llvm::Expected<lldb::TypeSP> CreateEnum(const CTFEnum &ctf_enum);
222 llvm::Expected<lldb::TypeSP> CreateFunction(const CTFFunction &ctf_function);
223 llvm::Expected<lldb::TypeSP> CreateRecord(const CTFRecord &ctf_record);
224 llvm::Expected<lldb::TypeSP> CreateForward(const CTFForward &ctf_forward);
225
226 llvm::StringRef ReadString(lldb::offset_t offset) const;
227
228 std::vector<uint16_t> GetFieldSizes(lldb::offset_t field_offset,
229 uint32_t fields, uint32_t struct_size);
230
232
233 /// The start offset of the CTF body into m_data. If the body is uncompressed,
234 /// m_data contains the header and the body and the body starts after the
235 /// header. If the body is compressed, m_data only contains the body and the
236 /// offset is zero.
238
241
242 std::optional<ctf_header_t> m_header;
243
244 /// Parsed CTF types.
245 llvm::DenseMap<lldb::user_id_t, std::unique_ptr<CTFType>> m_ctf_types;
246
247 /// Parsed LLDB types.
248 llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types;
249
250 /// To complete types, we need a way to map (imcomplete) compiler types back
251 /// to parsed CTF types.
252 llvm::DenseMap<lldb::opaque_compiler_type_t, const CTFType *>
254
255 std::vector<lldb::FunctionSP> m_functions;
256 std::vector<lldb::VariableSP> m_variables;
257
258 static constexpr uint16_t g_ctf_magic = 0xcff1;
259 static constexpr uint8_t g_ctf_version = 4;
260 static constexpr uint16_t g_ctf_field_threshold = 0x2000;
261};
262} // namespace lldb_private
263
264#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H
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
An data extractor class.
Definition: DataExtractor.h:48
"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
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
void FindTypesByRegex(const lldb_private::RegularExpression &regex, uint32_t max_matches, lldb_private::TypeMap &types)
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override
Definition: SymbolFileCTF.h:54
static constexpr uint16_t g_ctf_magic
llvm::Expected< lldb::TypeSP > CreateFunction(const CTFFunction &ctf_function)
void AddSymbols(Symtab &symtab) override
bool ParseSupportFiles(CompileUnit &comp_unit, SupportFileList &support_files) override
Definition: SymbolFileCTF.h:68
bool CompleteType(CompilerType &compiler_type) override
lldb::CompUnitSP m_comp_unit_sp
std::vector< lldb::FunctionSP > m_functions
static char ID
LLVM RTTI support.
Definition: SymbolFileCTF.h:24
llvm::Expected< lldb::TypeSP > CreateTypedef(const CTFTypedef &ctf_typedef)
bool ParseDebugMacros(CompileUnit &comp_unit) override
Definition: SymbolFileCTF.h:66
size_t ParseFunctions(CompileUnit &comp_unit) override
static llvm::StringRef GetPluginDescriptionStatic()
llvm::DenseMap< lldb::opaque_compiler_type_t, const CTFType * > m_compiler_types
To complete types, we need a way to map (imcomplete) compiler types back to parsed CTF types.
static bool classof(const SymbolFile *obj)
Definition: SymbolFileCTF.h:32
void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool include_inlines, lldb_private::SymbolContextList &sc_list) override
llvm::Expected< lldb::TypeSP > CreateArray(const CTFArray &ctf_array)
llvm::StringRef GetPluginName() override
Definition: SymbolFileCTF.h:48
uint32_t CalculateAbilities() override
size_t ParseVariablesForContext(const SymbolContext &sc) override
void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list) override
static lldb_private::SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
bool isA(const void *ClassID) const override
LLVM RTTI support.
Definition: SymbolFileCTF.h:29
lldb::offset_t m_body_offset
The start offset of the CTF body into m_data.
static constexpr uint16_t g_ctf_field_threshold
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
static llvm::StringRef GetPluginNameStatic()
Definition: SymbolFileCTF.h:41
size_t ParseObjects(CompileUnit &comp_unit)
llvm::Expected< lldb::TypeSP > CreateForward(const CTFForward &ctf_forward)
llvm::Expected< lldb::TypeSP > CreateEnum(const CTFEnum &ctf_enum)
size_t ParseBlocksRecursive(Function &func) override
Definition: SymbolFileCTF.h:81
void InitializeObject() override
Initialize the SymbolFile object.
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
llvm::StringRef ReadString(lldb::offset_t offset) const
llvm::Expected< lldb::TypeSP > CreateRecord(const CTFRecord &ctf_record)
void FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override
bool ParseImportedModules(const SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
Definition: SymbolFileCTF.h:75
llvm::Expected< lldb::TypeSP > CreateInteger(const CTFInteger &ctf_integer)
static constexpr uint8_t g_ctf_version
llvm::DenseMap< lldb::user_id_t, lldb::TypeSP > m_types
Parsed LLDB types.
uint32_t CalculateNumCompileUnits() override
Definition: SymbolFileCTF.h:85
std::vector< lldb::VariableSP > m_variables
llvm::DenseMap< lldb::user_id_t, std::unique_ptr< CTFType > > m_ctf_types
Parsed CTF types.
llvm::Expected< lldb::TypeSP > CreateModifier(const CTFModifier &ctf_modifier)
llvm::Expected< lldb::TypeSP > CreateType(CTFType *ctf_type)
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.
Definition: SymbolFileCTF.h:90
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) override
llvm::Expected< std::unique_ptr< CTFType > > ParseType(lldb::offset_t &offset, lldb::user_id_t uid)
std::optional< ctf_header_t > m_header
bool ParseLineTable(CompileUnit &comp_unit) override
Definition: SymbolFileCTF.h:64
size_t ParseTypes(CompileUnit &cu) override
std::vector< uint16_t > GetFieldSizes(lldb::offset_t field_offset, uint32_t fields, uint32_t struct_size)
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
A class that contains all state required for type lookups.
Definition: Type.h:98
This class tracks the state and results of a TypeQuery.
Definition: Type.h:306
A TypeSystem implementation based on Clang.
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:367
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
uint64_t user_id_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:327