LLDB mainline
DWARFASTParserClang.h
Go to the documentation of this file.
1//===-- DWARFASTParserClang.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_DWARF_DWARFASTPARSERCLANG_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFASTPARSERCLANG_H
11
12#include "clang/AST/CharUnits.h"
13#include "clang/AST/Type.h"
14#include "llvm/ADT/DenseMap.h"
15#include "llvm/ADT/SmallPtrSet.h"
16#include "llvm/ADT/SmallVector.h"
17
18#include "DWARFASTParser.h"
19#include "DWARFDIE.h"
20#include "DWARFDefines.h"
21#include "DWARFFormValue.h"
22#include "LogChannelDWARF.h"
24
27
28#include <optional>
29#include <vector>
30
31namespace lldb_private {
32class CompileUnit;
33}
35class SymbolFileDWARF;
36
38
40public:
42
44
45 // DWARFASTParser interface.
47 const DWARFDIE &die,
48 bool *type_is_new_ptr) override;
49
51 ConstructDemangledNameFromDWARF(const DWARFDIE &die) override;
52
55 const DWARFDIE &die,
56 const lldb_private::AddressRange &func_range) override;
57
58 bool
60 lldb_private::CompilerType &compiler_type) override;
61
63 GetDeclForUIDFromDWARF(const DWARFDIE &die) override;
64
66 lldb_private::CompilerDeclContext decl_context) override;
67
69 GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override;
70
73
75
76 /// Extracts an value for a given Clang integer type from a DWARFFormValue.
77 ///
78 /// \param int_type The Clang type that defines the bit size and signedness
79 /// of the integer that should be extracted. Has to be either
80 /// an integer type or an enum type. For enum types the
81 /// underlying integer type will be considered as the
82 /// expected integer type that should be extracted.
83 /// \param form_value The DWARFFormValue that contains the integer value.
84 /// \return An APInt containing the same integer value as the given
85 /// DWARFFormValue with the bit width of the given integer type.
86 /// Returns an error if the value in the DWARFFormValue does not fit
87 /// into the given integer type or the integer type isn't supported.
88 llvm::Expected<llvm::APInt>
90 const DWARFFormValue &form_value) const;
91
92 /// Returns the template parameters of a class DWARFDIE as a string.
93 ///
94 /// This is mostly useful for -gsimple-template-names which omits template
95 /// parameters from the DIE name and instead always adds template parameter
96 /// children DIEs.
97 ///
98 /// \param die The struct/class DWARFDIE containing template parameters.
99 /// \return A string, including surrounding '<>', of the template parameters.
100 /// If the DIE's name already has '<>', returns an empty ConstString because
101 /// it's assumed that the caller is using the DIE name anyway.
103 GetDIEClassTemplateParams(const DWARFDIE &die) override;
104
105protected:
106 /// Protected typedefs and members.
107 /// @{
109 typedef std::vector<DelayedAddObjCClassProperty> DelayedPropertyList;
110
111 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::DeclContext *>
113 typedef std::multimap<const clang::DeclContext *, const DWARFDIE>
115 typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
118 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::Decl *>
120
126 std::unique_ptr<lldb_private::ClangASTImporter> m_clang_ast_importer_up;
127 /// @}
128
129 clang::DeclContext *GetDeclContextForBlock(const DWARFDIE &die);
130
131 clang::BlockDecl *ResolveBlockDIE(const DWARFDIE &die);
132
133 clang::NamespaceDecl *ResolveNamespaceDIE(const DWARFDIE &die);
134
135 /// Returns the namespace decl that a DW_TAG_imported_declaration imports.
136 ///
137 /// \param[in] die The import declaration to resolve. If the DIE is not a
138 /// DW_TAG_imported_declaration the behaviour is undefined.
139 ///
140 /// \returns The decl corresponding to the namespace that the specified
141 /// 'die' imports. If the imported entity is not a namespace
142 /// or another import declaration, returns nullptr. If an error
143 /// occurs, returns nullptr.
144 clang::NamespaceDecl *ResolveImportedDeclarationDIE(const DWARFDIE &die);
145
146 bool ParseTemplateDIE(const DWARFDIE &die,
148 &template_param_infos);
149
151 const DWARFDIE &parent_die,
153 &template_param_infos);
154
155 std::string GetCPlusPlusQualifiedName(const DWARFDIE &die);
156
158 const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type,
159 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
160 std::vector<DWARFDIE> &member_function_dies,
161 DelayedPropertyList &delayed_properties,
162 const lldb::AccessType default_accessibility,
164
165 size_t
166 ParseChildParameters(clang::DeclContext *containing_decl_ctx,
167 const DWARFDIE &parent_die, bool skip_artificial,
168 bool &is_static, bool &is_variadic,
169 bool &has_template_params,
170 std::vector<lldb_private::CompilerType> &function_args,
171 std::vector<clang::ParmVarDecl *> &function_param_decls,
172 unsigned &type_quals);
173
175 bool is_signed, uint32_t enumerator_byte_size,
176 const DWARFDIE &parent_die);
177
178 /// Parse a structure, class, or union type DIE.
180 const DWARFDIE &die,
182
184
185 clang::Decl *GetClangDeclForDIE(const DWARFDIE &die);
186
187 clang::DeclContext *GetClangDeclContextForDIE(const DWARFDIE &die);
188
189 clang::DeclContext *GetClangDeclContextContainingDIE(const DWARFDIE &die,
190 DWARFDIE *decl_ctx_die);
192
193 bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die,
194 const DWARFDIE &dst_class_die,
195 lldb_private::Type *class_type,
196 std::vector<DWARFDIE> &failures);
197
198 clang::DeclContext *GetCachedClangDeclContextForDIE(const DWARFDIE &die);
199
200 void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die);
201
202 void LinkDeclToDIE(clang::Decl *decl, const DWARFDIE &die);
203
204 /// If \p type_sp is valid, calculate and set its symbol context scope, and
205 /// update the type list for its backing symbol file.
206 ///
207 /// Returns \p type_sp.
208 lldb::TypeSP
210 const DWARFDIE &die, lldb::TypeSP type_sp);
211
212 /// Follow Clang Module Skeleton CU references to find a type definition.
214 const DWARFDIE &die,
215 lldb_private::Log *log);
216
217 // Return true if this type is a declaration to a type in an external
218 // module.
219 lldb::ModuleSP GetModuleForType(const DWARFDIE &die);
220
221private:
222 struct FieldInfo {
223 uint64_t bit_size = 0;
224 uint64_t bit_offset = 0;
225 bool is_bitfield = false;
226 bool is_artificial = false;
227
228 FieldInfo() = default;
229
230 void SetIsBitfield(bool flag) { is_bitfield = flag; }
231 bool IsBitfield() { return is_bitfield; }
232
233 void SetIsArtificial(bool flag) { is_artificial = flag; }
234 bool IsArtificial() const { return is_artificial; }
235
236 bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const {
237 // Any subsequent bitfields must not overlap and must be at a higher
238 // bit offset than any previous bitfield + size.
239 return (bit_size + bit_offset) <= next_bit_offset;
240 }
241 };
242
243 /// Returns 'true' if we should create an unnamed bitfield
244 /// and add it to the parser's current AST.
245 ///
246 /// \param[in] last_field_info FieldInfo of the previous DW_TAG_member
247 /// we parsed.
248 /// \param[in] last_field_end Offset (in bits) where the last parsed field
249 /// ended.
250 /// \param[in] this_field_info FieldInfo of the current DW_TAG_member
251 /// being parsed.
252 /// \param[in] layout_info Layout information of all decls parsed by the
253 /// current parser.
255 FieldInfo const &last_field_info, uint64_t last_field_end,
256 FieldInfo const &this_field_info,
257 lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const;
258
259 /// Parses a DW_TAG_APPLE_property DIE and appends the parsed data to the
260 /// list of delayed Objective-C properties.
261 ///
262 /// Note: The delayed property needs to be finalized to actually create the
263 /// property declarations in the module AST.
264 ///
265 /// \param die The DW_TAG_APPLE_property DIE that will be parsed.
266 /// \param parent_die The parent DIE.
267 /// \param class_clang_type The Objective-C class that will contain the
268 /// created property.
269 /// \param delayed_properties The list of delayed properties that the result
270 /// will be appended to.
271 void ParseObjCProperty(const DWARFDIE &die, const DWARFDIE &parent_die,
272 const lldb_private::CompilerType &class_clang_type,
273 DelayedPropertyList &delayed_properties);
274
275 void
276 ParseSingleMember(const DWARFDIE &die, const DWARFDIE &parent_die,
277 const lldb_private::CompilerType &class_clang_type,
278 lldb::AccessType default_accessibility,
280 FieldInfo &last_field_info);
281
282 bool CompleteRecordType(const DWARFDIE &die, lldb_private::Type *type,
283 lldb_private::CompilerType &clang_type);
284 bool CompleteEnumType(const DWARFDIE &die, lldb_private::Type *type,
285 lldb_private::CompilerType &clang_type);
286
287 lldb::TypeSP ParseTypeModifier(const lldb_private::SymbolContext &sc,
288 const DWARFDIE &die,
290 lldb::TypeSP ParseEnum(const lldb_private::SymbolContext &sc,
291 const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs);
292 lldb::TypeSP ParseSubroutine(const DWARFDIE &die,
294 lldb::TypeSP ParseArrayType(const DWARFDIE &die,
295 const ParsedDWARFTypeAttributes &attrs);
296 lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die,
297 const ParsedDWARFTypeAttributes &attrs);
298
299 /// Parses a DW_TAG_inheritance DIE into a base/super class.
300 ///
301 /// \param die The DW_TAG_inheritance DIE to parse.
302 /// \param parent_die The parent DIE of the given DIE.
303 /// \param class_clang_type The C++/Objective-C class representing parent_die.
304 /// For an Objective-C class this method sets the super class on success. For
305 /// a C++ class this will *not* add the result as a base class.
306 /// \param default_accessibility The default accessibility that is given to
307 /// base classes if they don't have an explicit accessibility set.
308 /// \param module_sp The current Module.
309 /// \param base_classes The list of C++ base classes that will be appended
310 /// with the parsed base class on success.
311 /// \param layout_info The layout information that will be updated for C++
312 /// base classes with the base offset.
313 void ParseInheritance(
314 const DWARFDIE &die, const DWARFDIE &parent_die,
315 const lldb_private::CompilerType class_clang_type,
316 const lldb::AccessType default_accessibility,
317 const lldb::ModuleSP &module_sp,
318 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
320};
321
322/// Parsed form of all attributes that are relevant for type reconstruction.
323/// Some attributes are relevant for all kinds of types (declaration), while
324/// others are only meaningful to a specific type (is_virtual)
326 explicit ParsedDWARFTypeAttributes(const DWARFDIE &die);
327
329 bool is_artificial = false;
331 bool is_explicit = false;
333 bool is_inline = false;
334 bool is_scoped_enum = false;
335 bool is_vector = false;
336 bool is_virtual = false;
338 bool exports_symbols = false;
339 clang::StorageClass storage = clang::SC_None;
340 const char *mangled_name = nullptr;
350 std::optional<uint64_t> byte_size;
351 size_t calling_convention = llvm::dwarf::DW_CC_normal;
355 clang::RefQualifierKind ref_qual =
356 clang::RQ_None; ///< Indicates ref-qualifier of
357 ///< C++ member function if present.
358 ///< Is RQ_None otherwise.
359};
360
361#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFASTPARSERCLANG_H
bool CompleteRecordType(const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &clang_type)
bool CompleteEnumType(const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &clang_type)
lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs)
std::multimap< const clang::DeclContext *, const DWARFDIE > DeclContextToDIEMap
bool ParseTemplateDIE(const DWARFDIE &die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos)
llvm::Expected< llvm::APInt > ExtractIntFromFormValue(const lldb_private::CompilerType &int_type, const DWARFFormValue &form_value) const
Extracts an value for a given Clang integer type from a DWARFFormValue.
std::unique_ptr< lldb_private::ClangASTImporter > m_clang_ast_importer_up
lldb::TypeSP ParseSubroutine(const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
size_t ParseChildParameters(clang::DeclContext *containing_decl_ctx, const DWARFDIE &parent_die, bool skip_artificial, bool &is_static, bool &is_variadic, bool &has_template_params, std::vector< lldb_private::CompilerType > &function_args, std::vector< clang::ParmVarDecl * > &function_param_decls, unsigned &type_quals)
lldb_private::TypeSystemClang & m_ast
bool ShouldCreateUnnamedBitfield(FieldInfo const &last_field_info, uint64_t last_field_end, FieldInfo const &this_field_info, lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const
Returns 'true' if we should create an unnamed bitfield and add it to the parser's current AST.
lldb_private::Function * ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit, const DWARFDIE &die, const lldb_private::AddressRange &func_range) override
void LinkDeclToDIE(clang::Decl *decl, const DWARFDIE &die)
lldb_private::ClangASTImporter & GetClangASTImporter()
clang::NamespaceDecl * ResolveNamespaceDIE(const DWARFDIE &die)
lldb_private::CompilerDeclContext GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override
void ParseObjCProperty(const DWARFDIE &die, const DWARFDIE &parent_die, const lldb_private::CompilerType &class_clang_type, DelayedPropertyList &delayed_properties)
Parses a DW_TAG_APPLE_property DIE and appends the parsed data to the list of delayed Objective-C pro...
lldb_private::CompilerDeclContext GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override
DIEToDeclContextMap m_die_to_decl_ctx
lldb_private::Type * GetTypeForDIE(const DWARFDIE &die)
std::string GetCPlusPlusQualifiedName(const DWARFDIE &die)
void EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompilerDeclContext decl_context) override
lldb::TypeSP ParseArrayType(const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs)
size_t ParseChildEnumerators(lldb_private::CompilerType &compiler_type, bool is_signed, uint32_t enumerator_byte_size, const DWARFDIE &parent_die)
clang::DeclContext * GetCachedClangDeclContextForDIE(const DWARFDIE &die)
clang::NamespaceDecl * ResolveImportedDeclarationDIE(const DWARFDIE &die)
Returns the namespace decl that a DW_TAG_imported_declaration imports.
bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, lldb_private::Type *class_type, std::vector< DWARFDIE > &failures)
lldb::TypeSP UpdateSymbolContextScopeForType(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb::TypeSP type_sp)
If type_sp is valid, calculate and set its symbol context scope, and update the type list for its bac...
lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc, const DWARFDIE &die, bool *type_is_new_ptr) override
clang::DeclContext * GetClangDeclContextContainingDIE(const DWARFDIE &die, DWARFDIE *decl_ctx_die)
lldb::TypeSP ParseTypeModifier(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
~DWARFASTParserClang() override
bool CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &compiler_type) override
std::vector< DelayedAddObjCClassProperty > DelayedPropertyList
lldb::ModuleSP GetModuleForType(const DWARFDIE &die)
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb_private::OptionalClangModuleID > DIEToModuleMap
clang::BlockDecl * ResolveBlockDIE(const DWARFDIE &die)
lldb::TypeSP ParseStructureLikeDIE(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
Parse a structure, class, or union type DIE.
lldb::TypeSP ParseEnum(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
clang::DeclContext * GetDeclContextForBlock(const DWARFDIE &die)
lldb::TypeSP ParseTypeFromClangModule(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb_private::Log *log)
Follow Clang Module Skeleton CU references to find a type definition.
bool ParseChildMembers(const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type, std::vector< std::unique_ptr< clang::CXXBaseSpecifier > > &base_classes, std::vector< DWARFDIE > &member_function_dies, DelayedPropertyList &delayed_properties, const lldb::AccessType default_accessibility, lldb_private::ClangASTImporter::LayoutInfo &layout_info)
llvm::DenseMap< const DWARFDebugInfoEntry *, clang::DeclContext * > DIEToDeclContextMap
DIEToModuleMap m_die_to_module
DeclContextToDIEMap m_decl_ctx_to_die
llvm::DenseMap< const DWARFDebugInfoEntry *, clang::Decl * > DIEToDeclMap
void ParseInheritance(const DWARFDIE &die, const DWARFDIE &parent_die, const lldb_private::CompilerType class_clang_type, const lldb::AccessType default_accessibility, const lldb::ModuleSP &module_sp, std::vector< std::unique_ptr< clang::CXXBaseSpecifier > > &base_classes, lldb_private::ClangASTImporter::LayoutInfo &layout_info)
Parses a DW_TAG_inheritance DIE into a base/super class.
lldb_private::OptionalClangModuleID GetOwningClangModule(const DWARFDIE &die)
lldb_private::ConstString GetDIEClassTemplateParams(const DWARFDIE &die) override
Returns the template parameters of a class DWARFDIE as a string.
void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die)
void ParseSingleMember(const DWARFDIE &die, const DWARFDIE &parent_die, const lldb_private::CompilerType &class_clang_type, lldb::AccessType default_accessibility, lldb_private::ClangASTImporter::LayoutInfo &layout_info, FieldInfo &last_field_info)
lldb_private::ConstString ConstructDemangledNameFromDWARF(const DWARFDIE &die) override
bool ParseTemplateParameterInfos(const DWARFDIE &parent_die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos)
clang::DeclContext * GetClangDeclContextForDIE(const DWARFDIE &die)
clang::Decl * GetClangDeclForDIE(const DWARFDIE &die)
lldb_private::CompilerDecl GetDeclForUIDFromDWARF(const DWARFDIE &die) override
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
A section + offset based address range class.
Definition: AddressRange.h:25
Manages and observes all Clang AST node importing in LLDB.
A class that describes a compilation unit.
Definition: CompileUnit.h:41
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
A class that describes a function.
Definition: Function.h:409
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
A TypeSystem implementation based on Clang.
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const
Parsed form of all attributes that are relevant for type reconstruction.
lldb_private::Declaration decl
lldb_private::ConstString name
lldb::LanguageType class_language
std::optional< uint64_t > byte_size
clang::RefQualifierKind ref_qual
Indicates ref-qualifier of C++ member function if present.