#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFASTPARSERCLANG_H
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFASTPARSERCLANG_H
#include "clang/AST/CharUnits.h"
#include "clang/AST/Type.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "DWARFASTParser.h"
#include "DWARFDIE.h"
#include "DWARFDefines.h"
#include "DWARFFormValue.h"
#include "LogChannelDWARF.h"
#include "lldb/Core/PluginInterface.h"
#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"
#include "Plugins/Language/ObjC/ObjCLanguage.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include <optional>
#include <vector>
namespace lldb_private {
class CompileUnit;
}
namespace lldb_private::plugin {
namespace dwarf {
class DWARFDebugInfoEntry;
class SymbolFileDWARF;
}
}
struct ParsedDWARFTypeAttributes;
class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser {
public:
DWARFASTParserClang(lldb_private::TypeSystemClang &ast);
~DWARFASTParserClang() override;
lldb::TypeSP
ParseTypeFromDWARF(const lldb_private::SymbolContext &sc,
const lldb_private::plugin::dwarf::DWARFDIE &die,
bool *type_is_new_ptr) override;
lldb_private::ConstString ConstructDemangledNameFromDWARF(
const lldb_private::plugin::dwarf::DWARFDIE &die) override;
lldb_private::Function *
ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit,
const lldb_private::plugin::dwarf::DWARFDIE &die,
const lldb_private::AddressRange &func_range) override;
bool
CompleteTypeFromDWARF(const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::Type *type,
lldb_private::CompilerType &compiler_type) override;
lldb_private::CompilerDecl GetDeclForUIDFromDWARF(
const lldb_private::plugin::dwarf::DWARFDIE &die) override;
void EnsureAllDIEsInDeclContextHaveBeenParsed(
lldb_private::CompilerDeclContext decl_context) override;
lldb_private::CompilerDeclContext GetDeclContextForUIDFromDWARF(
const lldb_private::plugin::dwarf::DWARFDIE &die) override;
lldb_private::CompilerDeclContext GetDeclContextContainingUIDFromDWARF(
const lldb_private::plugin::dwarf::DWARFDIE &die) override;
lldb_private::ClangASTImporter &GetClangASTImporter();
llvm::Expected<llvm::APInt> ExtractIntFromFormValue(
const lldb_private::CompilerType &int_type,
const lldb_private::plugin::dwarf::DWARFFormValue &form_value) const;
std::string GetDIEClassTemplateParams(
const lldb_private::plugin::dwarf::DWARFDIE &die) override;
void MapDeclDIEToDefDIE(const lldb_private::plugin::dwarf::DWARFDIE &decl_die,
const lldb_private::plugin::dwarf::DWARFDIE &def_die);
protected:
class DelayedAddObjCClassProperty;
typedef std::vector<DelayedAddObjCClassProperty> DelayedPropertyList;
typedef llvm::DenseMap<
const lldb_private::plugin::dwarf::DWARFDebugInfoEntry *,
clang::DeclContext *>
DIEToDeclContextMap;
typedef std::multimap<const clang::DeclContext *,
const lldb_private::plugin::dwarf::DWARFDIE>
DeclContextToDIEMap;
typedef llvm::DenseMap<
const lldb_private::plugin::dwarf::DWARFDebugInfoEntry *,
lldb_private::OptionalClangModuleID>
DIEToModuleMap;
typedef llvm::DenseMap<
const lldb_private::plugin::dwarf::DWARFDebugInfoEntry *, clang::Decl *>
DIEToDeclMap;
lldb_private::TypeSystemClang &m_ast;
DIEToDeclMap m_die_to_decl;
DIEToDeclContextMap m_die_to_decl_ctx;
DeclContextToDIEMap m_decl_ctx_to_die;
DIEToModuleMap m_die_to_module;
std::unique_ptr<lldb_private::ClangASTImporter> m_clang_ast_importer_up;
clang::DeclContext *
GetDeclContextForBlock(const lldb_private::plugin::dwarf::DWARFDIE &die);
clang::BlockDecl *
ResolveBlockDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
clang::NamespaceDecl *
ResolveNamespaceDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
clang::NamespaceDecl *ResolveImportedDeclarationDIE(
const lldb_private::plugin::dwarf::DWARFDIE &die);
bool ParseTemplateDIE(const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::TypeSystemClang::TemplateParameterInfos
&template_param_infos);
bool ParseTemplateParameterInfos(
const lldb_private::plugin::dwarf::DWARFDIE &parent_die,
lldb_private::TypeSystemClang::TemplateParameterInfos
&template_param_infos);
void GetUniqueTypeNameAndDeclaration(
const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb::LanguageType language, lldb_private::ConstString &unique_typename,
lldb_private::Declaration &decl_declaration);
bool ParseChildMembers(
const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::CompilerType &class_compiler_type,
std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
std::vector<lldb_private::plugin::dwarf::DWARFDIE> &member_function_dies,
std::vector<lldb_private::plugin::dwarf::DWARFDIE> &contained_type_dies,
DelayedPropertyList &delayed_properties,
const lldb::AccessType default_accessibility,
lldb_private::ClangASTImporter::LayoutInfo &layout_info);
size_t
ParseChildParameters(clang::DeclContext *containing_decl_ctx,
const lldb_private::plugin::dwarf::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);
size_t ParseChildEnumerators(
lldb_private::CompilerType &compiler_type, bool is_signed,
uint32_t enumerator_byte_size,
const lldb_private::plugin::dwarf::DWARFDIE &parent_die);
lldb::TypeSP
ParseStructureLikeDIE(const lldb_private::SymbolContext &sc,
const lldb_private::plugin::dwarf::DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs);
clang::Decl *
GetClangDeclForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
clang::DeclContext *
GetClangDeclContextForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
clang::DeclContext *GetClangDeclContextContainingDIE(
const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::plugin::dwarf::DWARFDIE *decl_ctx_die);
lldb_private::OptionalClangModuleID
GetOwningClangModule(const lldb_private::plugin::dwarf::DWARFDIE &die);
bool CopyUniqueClassMethodTypes(
const lldb_private::plugin::dwarf::DWARFDIE &src_class_die,
const lldb_private::plugin::dwarf::DWARFDIE &dst_class_die,
lldb_private::Type *class_type,
std::vector<lldb_private::plugin::dwarf::DWARFDIE> &failures);
clang::DeclContext *GetCachedClangDeclContextForDIE(
const lldb_private::plugin::dwarf::DWARFDIE &die);
void LinkDeclContextToDIE(clang::DeclContext *decl_ctx,
const lldb_private::plugin::dwarf::DWARFDIE &die);
void LinkDeclToDIE(clang::Decl *decl,
const lldb_private::plugin::dwarf::DWARFDIE &die);
lldb::TypeSP UpdateSymbolContextScopeForType(
const lldb_private::SymbolContext &sc,
const lldb_private::plugin::dwarf::DWARFDIE &die, lldb::TypeSP type_sp);
lldb::TypeSP
ParseTypeFromClangModule(const lldb_private::SymbolContext &sc,
const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::Log *log);
lldb::ModuleSP
GetModuleForType(const lldb_private::plugin::dwarf::DWARFDIE &die);
static bool classof(const DWARFASTParser *Parser) {
return Parser->GetKind() == Kind::DWARFASTParserClang;
}
private:
struct FieldInfo {
uint64_t bit_size = 0;
uint64_t bit_offset = 0;
bool is_bitfield = false;
bool is_artificial = false;
FieldInfo() = default;
void SetIsBitfield(bool flag) { is_bitfield = flag; }
bool IsBitfield() { return is_bitfield; }
void SetIsArtificial(bool flag) { is_artificial = flag; }
bool IsArtificial() const { return is_artificial; }
bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const {
return (bit_size + bit_offset) <= next_bit_offset;
}
};
struct MemberAttributes {
explicit MemberAttributes(
const lldb_private::plugin::dwarf::DWARFDIE &die,
const lldb_private::plugin::dwarf::DWARFDIE &parent_die,
lldb::ModuleSP module_sp);
const char *name = nullptr;
int64_t bit_offset = 0;
size_t bit_size = 0;
uint64_t data_bit_offset = UINT64_MAX;
lldb::AccessType accessibility = lldb::eAccessNone;
std::optional<uint64_t> byte_size;
std::optional<lldb_private::plugin::dwarf::DWARFFormValue> const_value_form;
lldb_private::plugin::dwarf::DWARFFormValue encoding_form;
uint32_t member_byte_offset = UINT32_MAX;
bool is_artificial = false;
bool is_declaration = false;
};
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;
void
ParseObjCProperty(const lldb_private::plugin::dwarf::DWARFDIE &die,
const lldb_private::plugin::dwarf::DWARFDIE &parent_die,
const lldb_private::CompilerType &class_clang_type,
DelayedPropertyList &delayed_properties);
void
ParseSingleMember(const lldb_private::plugin::dwarf::DWARFDIE &die,
const lldb_private::plugin::dwarf::DWARFDIE &parent_die,
const lldb_private::CompilerType &class_clang_type,
lldb::AccessType default_accessibility,
lldb_private::ClangASTImporter::LayoutInfo &layout_info,
FieldInfo &last_field_info);
void CreateStaticMemberVariable(
const lldb_private::plugin::dwarf::DWARFDIE &die,
const MemberAttributes &attrs,
const lldb_private::CompilerType &class_clang_type);
bool CompleteRecordType(const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::Type *type,
lldb_private::CompilerType &clang_type);
bool CompleteEnumType(const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::Type *type,
lldb_private::CompilerType &clang_type);
lldb::TypeSP
ParseTypeModifier(const lldb_private::SymbolContext &sc,
const lldb_private::plugin::dwarf::DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs);
lldb::TypeSP ParseEnum(const lldb_private::SymbolContext &sc,
const lldb_private::plugin::dwarf::DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs);
lldb::TypeSP ParseSubroutine(const lldb_private::plugin::dwarf::DWARFDIE &die,
const ParsedDWARFTypeAttributes &attrs);
bool
ParseObjCMethod(const lldb_private::ObjCLanguage::MethodName &objc_method,
const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::CompilerType clang_type,
const ParsedDWARFTypeAttributes &attrs, bool is_variadic);
std::pair<bool, lldb::TypeSP>
ParseCXXMethod(const lldb_private::plugin::dwarf::DWARFDIE &die,
lldb_private::CompilerType clang_type,
const ParsedDWARFTypeAttributes &attrs,
const lldb_private::plugin::dwarf::DWARFDIE &decl_ctx_die,
bool is_static, bool &ignore_containing_context);
lldb::TypeSP ParseArrayType(const lldb_private::plugin::dwarf::DWARFDIE &die,
const ParsedDWARFTypeAttributes &attrs);
lldb::TypeSP
ParsePointerToMemberType(const lldb_private::plugin::dwarf::DWARFDIE &die,
const ParsedDWARFTypeAttributes &attrs);
void ParseInheritance(
const lldb_private::plugin::dwarf::DWARFDIE &die,
const lldb_private::plugin::dwarf::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);
void
ParseRustVariantPart(lldb_private::plugin::dwarf::DWARFDIE &die,
const lldb_private::plugin::dwarf::DWARFDIE &parent_die,
lldb_private::CompilerType &class_clang_type,
const lldb::AccessType default_accesibility,
lldb_private::ClangASTImporter::LayoutInfo &layout_info);
};
struct ParsedDWARFTypeAttributes {
explicit ParsedDWARFTypeAttributes(
const lldb_private::plugin::dwarf::DWARFDIE &die);
lldb::AccessType accessibility = lldb::eAccessNone;
bool is_artificial = false;
bool is_complete_objc_class = false;
bool is_explicit = false;
bool is_forward_declaration = false;
bool is_inline = false;
bool is_scoped_enum = false;
bool is_vector = false;
bool is_virtual = false;
bool is_objc_direct_call = false;
bool exports_symbols = false;
clang::StorageClass storage = clang::SC_None;
const char *mangled_name = nullptr;
lldb_private::ConstString name;
lldb_private::Declaration decl;
lldb_private::plugin::dwarf::DWARFDIE object_pointer;
lldb_private::plugin::dwarf::DWARFFormValue abstract_origin;
lldb_private::plugin::dwarf::DWARFFormValue containing_type;
lldb_private::plugin::dwarf::DWARFFormValue signature;
lldb_private::plugin::dwarf::DWARFFormValue specification;
lldb_private::plugin::dwarf::DWARFFormValue type;
lldb::LanguageType class_language = lldb::eLanguageTypeUnknown;
std::optional<uint64_t> byte_size;
std::optional<uint64_t> alignment;
size_t calling_convention = llvm::dwarf::DW_CC_normal;
uint32_t bit_stride = 0;
uint32_t byte_stride = 0;
uint32_t encoding = 0;
clang::RefQualifierKind ref_qual =
clang::RQ_None;
};
#endif