Skip to content

Commit

Permalink
[LLDB][NFC] Remove DWARFASTParserClang as friend from SymbolFileDWARF (
Browse files Browse the repository at this point in the history
…llvm#70157)

This effectively moves a few functions from protected to public. In any
case, for the sake of having a cleaner SymbolFileDWARF API, it's better
if it's not a friend of a one of its consumers, DWARFASTParserClang.
Another effect of this change is that I can use SymbolFileDWARF for the
out-of-tree mojo dwarf parser, which relies on pretty much the same
functions that DWARFASTParserClang needs from SymbolFileDWARF.
  • Loading branch information
walter-erquinigo authored and zahiraam committed Oct 26, 2023
1 parent 3c97be0 commit ba3c721
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 59 deletions.
18 changes: 9 additions & 9 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,9 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,

CompilerType enumerator_clang_type;
CompilerType clang_type;
clang_type =
CompilerType(m_ast.weak_from_this(),
dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE()));
clang_type = CompilerType(
m_ast.weak_from_this(),
dwarf->GetForwardDeclDIEToCompilerType().lookup(die.GetDIE()));
if (!clang_type) {
if (attrs.type.IsValid()) {
Type *enumerator_type =
Expand Down Expand Up @@ -1764,9 +1764,9 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
assert(tag_decl_kind != -1);
(void)tag_decl_kind;
bool clang_type_was_created = false;
clang_type =
CompilerType(m_ast.weak_from_this(),
dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE()));
clang_type = CompilerType(
m_ast.weak_from_this(),
dwarf->GetForwardDeclDIEToCompilerType().lookup(die.GetDIE()));
if (!clang_type) {
clang::DeclContext *decl_ctx =
GetClangDeclContextContainingDIE(die, nullptr);
Expand Down Expand Up @@ -1896,16 +1896,16 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
// the SymbolFile virtual function
// "SymbolFileDWARF::CompleteType(Type *)" When the definition
// needs to be defined.
assert(!dwarf->GetForwardDeclClangTypeToDie().count(
assert(!dwarf->GetForwardDeclCompilerTypeToDIE().count(
ClangUtil::RemoveFastQualifiers(clang_type)
.GetOpaqueQualType()) &&
"Type already in the forward declaration map!");
// Can't assume m_ast.GetSymbolFile() is actually a
// SymbolFileDWARF, it can be a SymbolFileDWARFDebugMap for Apple
// binaries.
dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] =
dwarf->GetForwardDeclDIEToCompilerType()[die.GetDIE()] =
clang_type.GetOpaqueQualType();
dwarf->GetForwardDeclClangTypeToDie().try_emplace(
dwarf->GetForwardDeclCompilerTypeToDIE().try_emplace(
ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType(),
*die.GetDIERef());
m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true);
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,11 +1532,11 @@ Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die,
// This function is used when SymbolFileDWARFDebugMap owns a bunch of
// SymbolFileDWARF objects to detect if this DWARF file is the one that can
// resolve a compiler_type.
bool SymbolFileDWARF::HasForwardDeclForClangType(
bool SymbolFileDWARF::HasForwardDeclForCompilerType(
const CompilerType &compiler_type) {
CompilerType compiler_type_no_qualifiers =
ClangUtil::RemoveFastQualifiers(compiler_type);
if (GetForwardDeclClangTypeToDie().count(
if (GetForwardDeclCompilerTypeToDIE().count(
compiler_type_no_qualifiers.GetOpaqueQualType())) {
return true;
}
Expand Down Expand Up @@ -1564,9 +1564,9 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
// We have a struct/union/class/enum that needs to be fully resolved.
CompilerType compiler_type_no_qualifiers =
ClangUtil::RemoveFastQualifiers(compiler_type);
auto die_it = GetForwardDeclClangTypeToDie().find(
auto die_it = GetForwardDeclCompilerTypeToDIE().find(
compiler_type_no_qualifiers.GetOpaqueQualType());
if (die_it == GetForwardDeclClangTypeToDie().end()) {
if (die_it == GetForwardDeclCompilerTypeToDIE().end()) {
// We have already resolved this type...
return true;
}
Expand All @@ -1577,7 +1577,7 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
// declaration map in case anyone child members or other types require this
// type to get resolved. The type will get resolved when all of the calls
// to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done.
GetForwardDeclClangTypeToDie().erase(die_it);
GetForwardDeclCompilerTypeToDIE().erase(die_it);

Type *type = GetDIEToType().lookup(dwarf_die.GetDIE());

Expand Down
76 changes: 40 additions & 36 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
friend class DWARFCompileUnit;
friend class DWARFDIE;
friend class DWARFASTParser;
friend class ::DWARFASTParserClang;

// Static Functions
static void Initialize();
Expand Down Expand Up @@ -138,7 +137,6 @@ class SymbolFileDWARF : public SymbolFileCommon {

size_t ParseVariablesForContext(const SymbolContext &sc) override;

Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
std::optional<ArrayInfo>
GetDynamicArrayInfoForUID(lldb::user_id_t type_uid,
const ExecutionContext *exe_ctx) override;
Expand Down Expand Up @@ -225,7 +223,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
DWARFDIE
GetDeclContextDIEContainingDIE(const DWARFDIE &die);

bool HasForwardDeclForClangType(const CompilerType &compiler_type);
bool HasForwardDeclForCompilerType(const CompilerType &compiler_type);

CompileUnit *GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu);

Expand Down Expand Up @@ -325,14 +323,46 @@ class SymbolFileDWARF : public SymbolFileCommon {
m_file_index = file_index;
}

protected:
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> DIEToTypePtr;
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
DIEToVariableSP;

virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }

typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
lldb::opaque_compiler_type_t>
DIEToClangType;
typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE;
DIEToCompilerType;

virtual DIEToCompilerType &GetForwardDeclDIEToCompilerType() {
return m_forward_decl_die_to_compiler_type;
}

typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef>
CompilerTypeToDIE;

virtual CompilerTypeToDIE &GetForwardDeclCompilerTypeToDIE() {
return m_forward_decl_compiler_type_to_die;
}

virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();

bool ClassOrStructIsVirtual(const DWARFDIE &die);

SymbolFileDWARFDebugMap *GetDebugMapSymfile();

virtual lldb::TypeSP
FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die);

virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
const DWARFDIE &die, ConstString type_name, bool must_be_implementation);

Type *ResolveTypeUID(lldb::user_id_t type_uid) override;

Type *ResolveTypeUID(const DWARFDIE &die, bool assert_not_being_parsed);

Type *ResolveTypeUID(const DIERef &die_ref);

protected:
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
DIEToVariableSP;

SymbolFileDWARF(const SymbolFileDWARF &) = delete;
const SymbolFileDWARF &operator=(const SymbolFileDWARF &) = delete;
Expand Down Expand Up @@ -371,10 +401,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
bool ParseSupportFiles(DWARFUnit &dwarf_cu, const lldb::ModuleSP &module,
FileSpecList &support_files);

Type *ResolveTypeUID(const DWARFDIE &die, bool assert_not_being_parsed);

Type *ResolveTypeUID(const DIERef &die_ref);

lldb::VariableSP ParseVariableDIE(const SymbolContext &sc,
const DWARFDIE &die,
const lldb::addr_t func_low_pc);
Expand Down Expand Up @@ -402,8 +428,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
DIEArray MergeBlockAbstractParameters(const DWARFDIE &block_die,
DIEArray &&variable_dies);

bool ClassOrStructIsVirtual(const DWARFDIE &die);

// Given a die_offset, figure out the symbol context representing that die.
bool ResolveFunction(const DWARFDIE &die, bool include_inlines,
SymbolContextList &sc_list);
Expand All @@ -415,12 +439,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
void ResolveFunctionAndBlock(lldb::addr_t file_vm_addr, bool lookup_block,
SymbolContext &sc);

virtual lldb::TypeSP
FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die);

virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
const DWARFDIE &die, ConstString type_name, bool must_be_implementation);

Symbol *GetObjCClassSymbol(ConstString objc_class_name);

lldb::TypeSP GetTypeForDIE(const DWARFDIE &die,
Expand All @@ -430,8 +448,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
m_debug_map_module_wp = module_sp;
}

SymbolFileDWARFDebugMap *GetDebugMapSymfile();

DWARFDIE
FindBlockContainingSpecification(const DIERef &func_die_ref,
dw_offset_t spec_block_die_offset);
Expand All @@ -440,8 +456,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
FindBlockContainingSpecification(const DWARFDIE &die,
dw_offset_t spec_block_die_offset);

virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();

bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2);

bool ClassContainsSelector(const DWARFDIE &class_die, ConstString selector);
Expand Down Expand Up @@ -473,18 +487,8 @@ class SymbolFileDWARF : public SymbolFileCommon {

void UpdateExternalModuleListIfNeeded();

virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }

virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }

virtual DIEToClangType &GetForwardDeclDieToClangType() {
return m_forward_decl_die_to_clang_type;
}

virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() {
return m_forward_decl_clang_type_to_die;
}

void BuildCuTranslationTable();
std::optional<uint32_t> GetDWARFUnitIndex(uint32_t cu_idx);

Expand Down Expand Up @@ -528,8 +532,8 @@ class SymbolFileDWARF : public SymbolFileCommon {
UniqueDWARFASTTypeMap m_unique_ast_type_map;
DIEToTypePtr m_die_to_type;
DIEToVariableSP m_die_to_variable_sp;
DIEToClangType m_forward_decl_die_to_clang_type;
ClangTypeToDIE m_forward_decl_clang_type_to_die;
DIEToCompilerType m_forward_decl_die_to_compiler_type;
CompilerTypeToDIE m_forward_decl_compiler_type_to_die;
llvm::DenseMap<dw_offset_t, FileSpecList> m_type_unit_support_files;
std::vector<uint32_t> m_lldb_cu_to_dwarf_unit;
/// DWARF does not provide a good way for traditional (concatenating) linkers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ bool SymbolFileDWARFDebugMap::CompleteType(CompilerType &compiler_type) {
bool success = false;
if (compiler_type) {
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
if (oso_dwarf->HasForwardDeclForClangType(compiler_type)) {
if (oso_dwarf->HasForwardDeclForCompilerType(compiler_type)) {
oso_dwarf->CompleteType(compiler_type);
success = true;
return true;
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() {
return GetBaseSymbolFile().GetDIEToVariable();
}

SymbolFileDWARF::DIEToClangType &
SymbolFileDWARFDwo::GetForwardDeclDieToClangType() {
return GetBaseSymbolFile().GetForwardDeclDieToClangType();
SymbolFileDWARF::DIEToCompilerType &
SymbolFileDWARFDwo::GetForwardDeclDIEToCompilerType() {
return GetBaseSymbolFile().GetForwardDeclDIEToCompilerType();
}

SymbolFileDWARF::ClangTypeToDIE &
SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() {
return GetBaseSymbolFile().GetForwardDeclClangTypeToDie();
SymbolFileDWARF::CompilerTypeToDIE &
SymbolFileDWARFDwo::GetForwardDeclCompilerTypeToDIE() {
return GetBaseSymbolFile().GetForwardDeclCompilerTypeToDIE();
}

void SymbolFileDWARFDwo::GetObjCMethods(
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF {

DIEToVariableSP &GetDIEToVariable() override;

DIEToClangType &GetForwardDeclDieToClangType() override;
DIEToCompilerType &GetForwardDeclDIEToCompilerType() override;

ClangTypeToDIE &GetForwardDeclClangTypeToDie() override;
CompilerTypeToDIE &GetForwardDeclCompilerTypeToDIE() override;

UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() override;

Expand Down

0 comments on commit ba3c721

Please sign in to comment.