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 "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "llvm/ADT/SmallVector.h"
16 
17 #include "DWARFASTParser.h"
18 #include "DWARFDIE.h"
19 #include "DWARFDefines.h"
20 #include "DWARFFormValue.h"
21 #include "LogChannelDWARF.h"
23 
26 
27 #include <vector>
28 
29 namespace lldb_private {
30 class CompileUnit;
31 }
33 class SymbolFileDWARF;
34 
36 
38 public:
40 
41  ~DWARFASTParserClang() override;
42 
43  // DWARFASTParser interface.
44  lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc,
45  const DWARFDIE &die,
46  bool *type_is_new_ptr) override;
47 
49  ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit,
50  const DWARFDIE &die) override;
51 
52  bool
53  CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type,
54  lldb_private::CompilerType &compiler_type) override;
55 
57  GetDeclForUIDFromDWARF(const DWARFDIE &die) override;
58 
59  void EnsureAllDIEsInDeclContextHaveBeenParsed(
60  lldb_private::CompilerDeclContext decl_context) override;
61 
63  GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override;
64 
66  GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override;
67 
68  lldb_private::ClangASTImporter &GetClangASTImporter();
69 
70 protected:
71  /// Protected typedefs and members.
72  /// @{
74  typedef std::vector<DelayedAddObjCClassProperty> DelayedPropertyList;
75 
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 *,
84  typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::Decl *>
86  typedef llvm::DenseMap<const clang::Decl *, DIEPointerSet> DeclToDIEMap;
87 
90  DeclToDIEMap m_decl_to_die;
94  std::unique_ptr<lldb_private::ClangASTImporter> m_clang_ast_importer_up;
95  /// @}
96 
97  clang::DeclContext *GetDeclContextForBlock(const DWARFDIE &die);
98 
99  clang::BlockDecl *ResolveBlockDIE(const DWARFDIE &die);
100 
101  clang::NamespaceDecl *ResolveNamespaceDIE(const DWARFDIE &die);
102 
103  bool ParseTemplateDIE(const DWARFDIE &die,
105  &template_param_infos);
106  bool ParseTemplateParameterInfos(
107  const DWARFDIE &parent_die,
109  &template_param_infos);
110 
111  bool ParseChildMembers(
112  const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type,
113  const lldb::LanguageType class_language,
114  std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
115  std::vector<int> &member_accessibilities,
116  std::vector<DWARFDIE> &member_function_dies,
117  DelayedPropertyList &delayed_properties,
118  lldb::AccessType &default_accessibility, bool &is_a_class,
120 
121  size_t
122  ParseChildParameters(clang::DeclContext *containing_decl_ctx,
123  const DWARFDIE &parent_die, bool skip_artificial,
124  bool &is_static, bool &is_variadic,
125  bool &has_template_params,
126  std::vector<lldb_private::CompilerType> &function_args,
127  std::vector<clang::ParmVarDecl *> &function_param_decls,
128  unsigned &type_quals);
129 
130  size_t ParseChildEnumerators(lldb_private::CompilerType &compiler_type,
131  bool is_signed, uint32_t enumerator_byte_size,
132  const DWARFDIE &parent_die);
133 
134  /// Parse a structure, class, or union type DIE.
135  lldb::TypeSP ParseStructureLikeDIE(const lldb_private::SymbolContext &sc,
136  const DWARFDIE &die,
138 
139  lldb_private::Type *GetTypeForDIE(const DWARFDIE &die);
140 
141  clang::Decl *GetClangDeclForDIE(const DWARFDIE &die);
142 
143  clang::DeclContext *GetClangDeclContextForDIE(const DWARFDIE &die);
144 
145  clang::DeclContext *GetClangDeclContextContainingDIE(const DWARFDIE &die,
146  DWARFDIE *decl_ctx_die);
147  lldb_private::OptionalClangModuleID GetOwningClangModule(const DWARFDIE &die);
148 
149  bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die,
150  const DWARFDIE &dst_class_die,
151  lldb_private::Type *class_type,
152  std::vector<DWARFDIE> &failures);
153 
154  clang::DeclContext *GetCachedClangDeclContextForDIE(const DWARFDIE &die);
155 
156  void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die);
157 
158  void LinkDeclToDIE(clang::Decl *decl, const DWARFDIE &die);
159 
160  /// If \p type_sp is valid, calculate and set its symbol context scope, and
161  /// update the type list for its backing symbol file.
162  ///
163  /// Returns \p type_sp.
164  lldb::TypeSP
165  UpdateSymbolContextScopeForType(const lldb_private::SymbolContext &sc,
166  const DWARFDIE &die, lldb::TypeSP type_sp);
167 
168  /// Follow Clang Module Skeleton CU references to find a type definition.
169  lldb::TypeSP ParseTypeFromClangModule(const lldb_private::SymbolContext &sc,
170  const DWARFDIE &die,
171  lldb_private::Log *log);
172 
173  // Return true if this type is a declaration to a type in an external
174  // module.
175  lldb::ModuleSP GetModuleForType(const DWARFDIE &die);
176 
177 private:
178  struct FieldInfo {
179  uint64_t bit_size = 0;
180  uint64_t bit_offset = 0;
181  bool is_bitfield = false;
182 
183  FieldInfo() = default;
184 
185  void SetIsBitfield(bool flag) { is_bitfield = flag; }
186  bool IsBitfield() { return is_bitfield; }
187 
188  bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const {
189  // Any subsequent bitfields must not overlap and must be at a higher
190  // bit offset than any previous bitfield + size.
191  return (bit_size + bit_offset) <= next_bit_offset;
192  }
193  };
194 
195  void
196  ParseSingleMember(const DWARFDIE &die, const DWARFDIE &parent_die,
197  const lldb_private::CompilerType &class_clang_type,
198  const lldb::LanguageType class_language,
199  std::vector<int> &member_accessibilities,
200  lldb::AccessType default_accessibility,
201  DelayedPropertyList &delayed_properties,
203  FieldInfo &last_field_info);
204 
205  bool CompleteRecordType(const DWARFDIE &die, lldb_private::Type *type,
206  lldb_private::CompilerType &clang_type);
207  bool CompleteEnumType(const DWARFDIE &die, lldb_private::Type *type,
208  lldb_private::CompilerType &clang_type);
209 
210  lldb::TypeSP ParseTypeModifier(const lldb_private::SymbolContext &sc,
211  const DWARFDIE &die,
213  lldb::TypeSP ParseEnum(const lldb_private::SymbolContext &sc,
214  const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs);
215  lldb::TypeSP ParseSubroutine(const DWARFDIE &die,
217  // FIXME: attrs should be passed as a const reference.
218  lldb::TypeSP ParseArrayType(const DWARFDIE &die,
220  lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die,
221  const ParsedDWARFTypeAttributes &attrs);
222 };
223 
224 /// Parsed form of all attributes that are relevant for type reconstruction.
225 /// Some attributes are relevant for all kinds of types (declaration), while
226 /// others are only meaningful to a specific type (is_virtual)
228  explicit ParsedDWARFTypeAttributes(const DWARFDIE &die);
229 
231  bool is_artificial = false;
232  bool is_complete_objc_class = false;
233  bool is_explicit = false;
234  bool is_forward_declaration = false;
235  bool is_inline = false;
236  bool is_scoped_enum = false;
237  bool is_vector = false;
238  bool is_virtual = false;
239  bool is_objc_direct_call = false;
240  bool exports_symbols = false;
241  clang::StorageClass storage = clang::SC_None;
242  const char *mangled_name = nullptr;
252  llvm::Optional<uint64_t> byte_size;
253  size_t calling_convention = llvm::dwarf::DW_CC_normal;
254  uint32_t bit_stride = 0;
255  uint32_t byte_stride = 0;
256  uint32_t encoding = 0;
257 };
258 
259 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFASTPARSERCLANG_H
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb_private::OptionalClangModuleID > DIEToModuleMap
std::unique_ptr< lldb_private::ClangASTImporter > m_clang_ast_importer_up
DeclContextToDIEMap m_decl_ctx_to_die
A class that represents a running process on the host machine.
Represents a generic declaration context in a program.
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
A TypeSystem implementation based on Clang.
std::multimap< const clang::DeclContext *, const DWARFDIE > DeclContextToDIEMap
llvm::Optional< uint64_t > byte_size
A class that describes a function.
Definition: Function.h:409
lldb_private::Declaration decl
A class that describes a compilation unit.
Definition: CompileUnit.h:37
DIEToDeclContextMap m_die_to_decl_ctx
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
DIEToModuleMap m_die_to_module
LanguageType
Programming language type.
lldb_private::ConstString name
llvm::DenseMap< const DWARFDebugInfoEntry *, clang::Decl * > DIEToDeclMap
lldb_private::TypeSystemClang & m_ast
std::vector< DelayedAddObjCClassProperty > DelayedPropertyList
llvm::SmallPtrSet< const DWARFDebugInfoEntry *, 4 > DIEPointerSet
llvm::DenseMap< const clang::Decl *, DIEPointerSet > DeclToDIEMap
A uniqued constant string class.
Definition: ConstString.h:40
Unknown or invalid language value.
Represents a generic type in a programming language.
Definition: CompilerType.h:33
bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const
Parsed form of all attributes that are relevant for type reconstruction.
llvm::DenseMap< const DWARFDebugInfoEntry *, clang::DeclContext * > DIEToDeclContextMap
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28