1 //===-- SymbolFileCTF.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_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H
17 #include "lldb/Symbol/CompileUnit.h"
18 #include "lldb/Symbol/SymbolFile.h"
20 namespace lldb_private
{
22 class SymbolFileCTF
: public lldb_private::SymbolFileCommon
{
23 /// LLVM RTTI support.
27 /// LLVM RTTI support.
29 bool isA(const void *ClassID
) const override
{
30 return ClassID
== &ID
|| SymbolFileCommon::isA(ClassID
);
32 static bool classof(const SymbolFile
*obj
) { return obj
->isA(&ID
); }
35 SymbolFileCTF(lldb::ObjectFileSP objfile_sp
);
37 static void Initialize();
39 static void Terminate();
41 static llvm::StringRef
GetPluginNameStatic() { return "CTF"; }
43 static llvm::StringRef
GetPluginDescriptionStatic();
45 static lldb_private::SymbolFile
*
46 CreateInstance(lldb::ObjectFileSP objfile_sp
);
48 llvm::StringRef
GetPluginName() override
{ return GetPluginNameStatic(); }
50 uint32_t CalculateAbilities() override
;
52 void InitializeObject() override
;
54 lldb::LanguageType
ParseLanguage(CompileUnit
&comp_unit
) override
{
55 return lldb::eLanguageTypeUnknown
;
60 size_t ParseFunctions(CompileUnit
&comp_unit
) override
;
62 size_t ParseObjects(CompileUnit
&comp_unit
);
64 bool ParseLineTable(CompileUnit
&comp_unit
) override
{ return false; }
66 bool ParseDebugMacros(CompileUnit
&comp_unit
) override
{ return false; }
68 bool ParseSupportFiles(CompileUnit
&comp_unit
,
69 FileSpecList
&support_files
) override
{
73 size_t ParseTypes(CompileUnit
&cu
) override
;
75 bool ParseImportedModules(
76 const SymbolContext
&sc
,
77 std::vector
<lldb_private::SourceModule
> &imported_modules
) override
{
81 size_t ParseBlocksRecursive(Function
&func
) override
{ return 0; }
83 size_t ParseVariablesForContext(const SymbolContext
&sc
) override
;
85 uint32_t CalculateNumCompileUnits() override
{ return 0; }
87 lldb::CompUnitSP
ParseCompileUnitAtIndex(uint32_t index
) override
;
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
{
96 bool CompleteType(CompilerType
&compiler_type
) override
;
98 uint32_t ResolveSymbolContext(const lldb_private::Address
&so_addr
,
99 lldb::SymbolContextItem resolve_scope
,
100 lldb_private::SymbolContext
&sc
) override
;
102 void AddSymbols(Symtab
&symtab
) override
;
104 void GetTypes(lldb_private::SymbolContextScope
*sc_scope
,
105 lldb::TypeClass type_mask
,
106 lldb_private::TypeList
&type_list
) override
{}
109 FindTypes(lldb_private::ConstString name
,
110 const lldb_private::CompilerDeclContext
&parent_decl_ctx
,
111 uint32_t max_matches
,
112 llvm::DenseSet
<lldb_private::SymbolFile
*> &searched_symbol_files
,
113 lldb_private::TypeMap
&types
) override
;
115 void FindTypesByRegex(const lldb_private::RegularExpression
®ex
,
116 uint32_t max_matches
, lldb_private::TypeMap
&types
);
118 void FindFunctions(const lldb_private::Module::LookupInfo
&lookup_info
,
119 const lldb_private::CompilerDeclContext
&parent_decl_ctx
,
120 bool include_inlines
,
121 lldb_private::SymbolContextList
&sc_list
) override
;
123 void FindFunctions(const lldb_private::RegularExpression
®ex
,
124 bool include_inlines
,
125 lldb_private::SymbolContextList
&sc_list
) override
;
128 FindGlobalVariables(lldb_private::ConstString name
,
129 const lldb_private::CompilerDeclContext
&parent_decl_ctx
,
130 uint32_t max_matches
,
131 lldb_private::VariableList
&variables
) override
;
133 void FindGlobalVariables(const lldb_private::RegularExpression
®ex
,
134 uint32_t max_matches
,
135 lldb_private::VariableList
&variables
) override
;
137 enum TypeKind
: uint32_t {
156 enum Flags
: uint32_t {
157 eFlagCompress
= (1u << 0),
158 eFlagNewFuncInfo
= (1u << 1),
159 eFlagIdxSorted
= (1u << 2),
160 eFlagDynStr
= (1u << 3),
163 enum IntEncoding
: uint32_t {
170 struct ctf_preamble_t
{
176 struct ctf_header_t
{
177 ctf_preamble_t preamble
;
207 bool IsLargeType() const { return size
== 0xffff; }
208 uint32_t GetStructSize() const {
210 return sizeof(ctf_type_t
);
211 return sizeof(ctf_stype_t
);
213 uint32_t GetType() const { return type
; }
214 uint32_t GetSize() const { return size
; }
217 llvm::Expected
<std::unique_ptr
<CTFType
>> ParseType(lldb::offset_t
&offset
,
218 lldb::user_id_t uid
);
220 llvm::Expected
<lldb::TypeSP
> CreateType(CTFType
*ctf_type
);
221 llvm::Expected
<lldb::TypeSP
> CreateInteger(const CTFInteger
&ctf_integer
);
222 llvm::Expected
<lldb::TypeSP
> CreateModifier(const CTFModifier
&ctf_modifier
);
223 llvm::Expected
<lldb::TypeSP
> CreateTypedef(const CTFTypedef
&ctf_typedef
);
224 llvm::Expected
<lldb::TypeSP
> CreateArray(const CTFArray
&ctf_array
);
225 llvm::Expected
<lldb::TypeSP
> CreateEnum(const CTFEnum
&ctf_enum
);
226 llvm::Expected
<lldb::TypeSP
> CreateFunction(const CTFFunction
&ctf_function
);
227 llvm::Expected
<lldb::TypeSP
> CreateRecord(const CTFRecord
&ctf_record
);
228 llvm::Expected
<lldb::TypeSP
> CreateForward(const CTFForward
&ctf_forward
);
230 llvm::StringRef
ReadString(lldb::offset_t offset
) const;
232 std::vector
<uint16_t> GetFieldSizes(lldb::offset_t field_offset
,
233 uint32_t fields
, uint32_t struct_size
);
235 DataExtractor m_data
;
237 /// The start offset of the CTF body into m_data. If the body is uncompressed,
238 /// m_data contains the header and the body and the body starts after the
239 /// header. If the body is compressed, m_data only contains the body and the
241 lldb::offset_t m_body_offset
= 0;
243 TypeSystemClang
*m_ast
;
244 lldb::CompUnitSP m_comp_unit_sp
;
246 std::optional
<ctf_header_t
> m_header
;
248 /// Parsed CTF types.
249 llvm::DenseMap
<lldb::user_id_t
, std::unique_ptr
<CTFType
>> m_ctf_types
;
251 /// Parsed LLDB types.
252 llvm::DenseMap
<lldb::user_id_t
, lldb::TypeSP
> m_types
;
254 /// To complete types, we need a way to map (imcomplete) compiler types back
255 /// to parsed CTF types.
256 llvm::DenseMap
<lldb::opaque_compiler_type_t
, const CTFType
*>
259 std::vector
<lldb::FunctionSP
> m_functions
;
260 std::vector
<lldb::VariableSP
> m_variables
;
262 static constexpr uint16_t g_ctf_magic
= 0xcff1;
263 static constexpr uint8_t g_ctf_version
= 4;
264 static constexpr uint16_t g_ctf_field_threshold
= 0x2000;
266 } // namespace lldb_private
268 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H