1 //===-- DWARFASTParserClang.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 SymbolFileDWARF_DWARFASTParserClang_h_
10 #define SymbolFileDWARF_DWARFASTParserClang_h_
12 #include "clang/AST/CharUnits.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "llvm/ADT/SmallVector.h"
17 #include "DWARFASTParser.h"
19 #include "DWARFDefines.h"
20 #include "DWARFFormValue.h"
21 #include "LogChannelDWARF.h"
22 #include "lldb/Core/ClangForward.h"
23 #include "lldb/Core/PluginInterface.h"
24 #include "lldb/Symbol/ClangASTContext.h"
25 #include "lldb/Symbol/ClangASTImporter.h"
29 namespace lldb_private {
32 class DWARFDebugInfoEntry;
33 class SymbolFileDWARF;
35 struct ParsedDWARFTypeAttributes;
37 class DWARFASTParserClang : public DWARFASTParser {
39 DWARFASTParserClang(lldb_private::ClangASTContext &ast);
41 ~DWARFASTParserClang() override;
43 // DWARFASTParser interface.
44 lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc,
46 bool *type_is_new_ptr) override;
48 lldb_private::Function *
49 ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit,
50 const DWARFDIE &die) override;
53 CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type,
54 lldb_private::CompilerType &compiler_type) override;
56 lldb_private::CompilerDecl
57 GetDeclForUIDFromDWARF(const DWARFDIE &die) override;
59 void EnsureAllDIEsInDeclContextHaveBeenParsed(
60 lldb_private::CompilerDeclContext decl_context) override;
62 lldb_private::CompilerDeclContext
63 GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override;
65 lldb_private::CompilerDeclContext
66 GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override;
68 lldb_private::ClangASTImporter &GetClangASTImporter();
71 /// Protected typedefs and members.
73 class DelayedAddObjCClassProperty;
74 typedef std::vector<DelayedAddObjCClassProperty> DelayedPropertyList;
76 typedef llvm::SmallPtrSet<const DWARFDebugInfoEntry *, 4> DIEPointerSet;
77 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::DeclContext *>
79 typedef std::multimap<const clang::DeclContext *, const DWARFDIE>
81 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::Decl *>
83 typedef llvm::DenseMap<const clang::Decl *, DIEPointerSet> DeclToDIEMap;
85 lldb_private::ClangASTContext &m_ast;
86 DIEToDeclMap m_die_to_decl;
87 DeclToDIEMap m_decl_to_die;
88 DIEToDeclContextMap m_die_to_decl_ctx;
89 DeclContextToDIEMap m_decl_ctx_to_die;
90 std::unique_ptr<lldb_private::ClangASTImporter> m_clang_ast_importer_up;
93 clang::DeclContext *GetDeclContextForBlock(const DWARFDIE &die);
95 clang::BlockDecl *ResolveBlockDIE(const DWARFDIE &die);
97 clang::NamespaceDecl *ResolveNamespaceDIE(const DWARFDIE &die);
99 bool ParseTemplateDIE(const DWARFDIE &die,
100 lldb_private::ClangASTContext::TemplateParameterInfos
101 &template_param_infos);
102 bool ParseTemplateParameterInfos(
103 const DWARFDIE &parent_die,
104 lldb_private::ClangASTContext::TemplateParameterInfos
105 &template_param_infos);
107 bool ParseChildMembers(
108 const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type,
109 const lldb::LanguageType class_language,
110 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
111 std::vector<int> &member_accessibilities,
112 std::vector<DWARFDIE> &member_function_dies,
113 DelayedPropertyList &delayed_properties,
114 lldb::AccessType &default_accessibility, bool &is_a_class,
115 lldb_private::ClangASTImporter::LayoutInfo &layout_info);
118 ParseChildParameters(clang::DeclContext *containing_decl_ctx,
119 const DWARFDIE &parent_die, bool skip_artificial,
120 bool &is_static, bool &is_variadic,
121 bool &has_template_params,
122 std::vector<lldb_private::CompilerType> &function_args,
123 std::vector<clang::ParmVarDecl *> &function_param_decls,
124 unsigned &type_quals);
126 size_t ParseChildEnumerators(lldb_private::CompilerType &compiler_type,
127 bool is_signed, uint32_t enumerator_byte_size,
128 const DWARFDIE &parent_die);
130 /// Parse a structure, class, or union type DIE.
131 lldb::TypeSP ParseStructureLikeDIE(const DWARFDIE &die,
132 ParsedDWARFTypeAttributes &attrs);
134 lldb_private::Type *GetTypeForDIE(const DWARFDIE &die);
136 clang::Decl *GetClangDeclForDIE(const DWARFDIE &die);
138 clang::DeclContext *GetClangDeclContextForDIE(const DWARFDIE &die);
140 clang::DeclContext *GetClangDeclContextContainingDIE(const DWARFDIE &die,
141 DWARFDIE *decl_ctx_die);
143 bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die,
144 const DWARFDIE &dst_class_die,
145 lldb_private::Type *class_type,
146 std::vector<DWARFDIE> &failures);
148 clang::DeclContext *GetCachedClangDeclContextForDIE(const DWARFDIE &die);
150 void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die);
152 void LinkDeclToDIE(clang::Decl *decl, const DWARFDIE &die);
154 /// If \p type_sp is valid, calculate and set its symbol context scope, and
155 /// update the type list for its backing symbol file.
157 /// Returns \p type_sp.
159 UpdateSymbolContextScopeForType(const lldb_private::SymbolContext &sc,
160 const DWARFDIE &die, lldb::TypeSP type_sp);
162 lldb::TypeSP ParseTypeFromDWO(const DWARFDIE &die, lldb_private::Log *log);
164 // Return true if this type is a declaration to a type in an external
166 lldb::ModuleSP GetModuleForType(const DWARFDIE &die);
169 /// Parsed form of all attributes that are relevant for type reconstruction.
170 /// Some attributes are relevant for all kinds of types (declaration), while
171 /// others are only meaningful to a specific type (is_virtual)
172 struct ParsedDWARFTypeAttributes {
173 explicit ParsedDWARFTypeAttributes(const DWARFDIE &die);
175 lldb::AccessType accessibility = lldb::eAccessNone;
176 bool is_artificial = false;
177 bool is_complete_objc_class = false;
178 bool is_explicit = false;
179 bool is_forward_declaration = false;
180 bool is_inline = false;
181 bool is_scoped_enum = false;
182 bool is_vector = false;
183 bool is_virtual = false;
184 clang::StorageClass storage = clang::SC_None;
185 const char *mangled_name = nullptr;
186 lldb_private::ConstString name;
187 lldb_private::Declaration decl;
188 DWARFDIE object_pointer;
189 DWARFFormValue abstract_origin;
190 DWARFFormValue containing_type;
191 DWARFFormValue signature;
192 DWARFFormValue specification;
194 lldb::LanguageType class_language = lldb::eLanguageTypeUnknown;
195 llvm::Optional<uint64_t> byte_size;
196 size_t calling_convention = llvm::dwarf::DW_CC_normal;
197 uint32_t bit_stride = 0;
198 uint32_t byte_stride = 0;
199 uint32_t encoding = 0;
202 #endif // SymbolFileDWARF_DWARFASTParserClang_h_