Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Show First 20 Lines • Show All 360 Lines • ▼ Show 20 Lines | |||||
UniqueDWARFASTTypeMap &SymbolFileDWARF::GetUniqueDWARFASTTypeMap() { | UniqueDWARFASTTypeMap &SymbolFileDWARF::GetUniqueDWARFASTTypeMap() { | ||||
SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | ||||
if (debug_map_symfile) | if (debug_map_symfile) | ||||
return debug_map_symfile->GetUniqueDWARFASTTypeMap(); | return debug_map_symfile->GetUniqueDWARFASTTypeMap(); | ||||
else | else | ||||
return m_unique_ast_type_map; | return m_unique_ast_type_map; | ||||
} | } | ||||
TypeSystem *SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) { | llvm::Expected<TypeSystem &> | ||||
SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) { | ||||
TypeSystem *type_system; | if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) | ||||
if (debug_map_symfile) { | return debug_map_symfile->GetTypeSystemForLanguage(language); | ||||
type_system = debug_map_symfile->GetTypeSystemForLanguage(language); | |||||
} else { | auto type_system_or_err = | ||||
type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language); | m_obj_file->GetModule()->GetTypeSystemForLanguage(language); | ||||
if (type_system) | if (type_system_or_err) { | ||||
type_system->SetSymbolFile(this); | type_system_or_err->SetSymbolFile(this); | ||||
} | } | ||||
return type_system; | return type_system_or_err; | ||||
} | } | ||||
void SymbolFileDWARF::InitializeObject() { | void SymbolFileDWARF::InitializeObject() { | ||||
Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); | ||||
if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) { | if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) { | ||||
DWARFDataExtractor apple_names, apple_namespaces, apple_types, apple_objc; | DWARFDataExtractor apple_names, apple_namespaces, apple_types, apple_objc; | ||||
LoadSectionData(eSectionTypeDWARFAppleNames, apple_names); | LoadSectionData(eSectionTypeDWARFAppleNames, apple_names); | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | if (auto *dwarf_cu = llvm::cast_or_null<DWARFCompileUnit>( | ||||
return ParseCompileUnit(*dwarf_cu); | return ParseCompileUnit(*dwarf_cu); | ||||
} | } | ||||
return {}; | return {}; | ||||
} | } | ||||
Function *SymbolFileDWARF::ParseFunction(CompileUnit &comp_unit, | Function *SymbolFileDWARF::ParseFunction(CompileUnit &comp_unit, | ||||
const DWARFDIE &die) { | const DWARFDIE &die) { | ||||
ASSERT_MODULE_LOCK(this); | ASSERT_MODULE_LOCK(this); | ||||
if (die.IsValid()) { | if (!die.IsValid()) | ||||
TypeSystem *type_system = | return nullptr; | ||||
GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); | |||||
if (type_system) { | auto type_system_or_err = | ||||
DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); | GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); | ||||
if (dwarf_ast) | if (auto err = type_system_or_err.takeError()) { | ||||
return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die); | LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), | ||||
} | std::move(err), "Unable to parse function"); | ||||
return nullptr; | |||||
JDevlieghere: Remove the braces for consistency with the `if`s below. | |||||
} | } | ||||
DWARFASTParser *dwarf_ast = type_system_or_err->GetDWARFParser(); | |||||
if (!dwarf_ast) | |||||
return nullptr; | return nullptr; | ||||
return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die); | |||||
} | } | ||||
bool SymbolFileDWARF::FixupAddress(Address &addr) { | bool SymbolFileDWARF::FixupAddress(Address &addr) { | ||||
SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | ||||
if (debug_map_symfile) { | if (debug_map_symfile) { | ||||
return debug_map_symfile->LinkOSOAddress(addr); | return debug_map_symfile->LinkOSOAddress(addr); | ||||
} | } | ||||
// This is a normal DWARF file, no address fixups need to happen | // This is a normal DWARF file, no address fixups need to happen | ||||
▲ Show 20 Lines • Show All 420 Lines • ▼ Show 20 Lines | for (DWARFDIE die = parent_die.GetFirstChild(); die; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) { | void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) { | ||||
TypeSystem *type_system = decl_ctx.GetTypeSystem(); | auto *type_system = decl_ctx.GetTypeSystem(); | ||||
if (!type_system) | |||||
return; | |||||
DWARFASTParser *ast_parser = type_system->GetDWARFParser(); | DWARFASTParser *ast_parser = type_system->GetDWARFParser(); | ||||
std::vector<DWARFDIE> decl_ctx_die_list = | std::vector<DWARFDIE> decl_ctx_die_list = | ||||
ast_parser->GetDIEForDeclContext(decl_ctx); | ast_parser->GetDIEForDeclContext(decl_ctx); | ||||
for (DWARFDIE decl_ctx_die : decl_ctx_die_list) | for (DWARFDIE decl_ctx_die : decl_ctx_die_list) | ||||
for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl; | for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl; | ||||
decl = decl.GetSibling()) | decl = decl.GetSibling()) | ||||
ast_parser->GetDeclForUIDFromDWARF(decl); | ast_parser->GetDeclForUIDFromDWARF(decl); | ||||
▲ Show 20 Lines • Show All 756 Lines • ▼ Show 20 Lines | bool SymbolFileDWARF::DeclContextMatchesThisSymbolFile( | ||||
if (decl_ctx == nullptr || !decl_ctx->IsValid()) { | if (decl_ctx == nullptr || !decl_ctx->IsValid()) { | ||||
// Invalid namespace decl which means we aren't matching only things in | // Invalid namespace decl which means we aren't matching only things in | ||||
// this symbol file, so return true to indicate it matches this symbol | // this symbol file, so return true to indicate it matches this symbol | ||||
// file. | // file. | ||||
return true; | return true; | ||||
} | } | ||||
TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem(); | TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem(); | ||||
TypeSystem *type_system = GetTypeSystemForLanguage( | auto type_system_or_err = GetTypeSystemForLanguage( | ||||
decl_ctx_type_system->GetMinimumLanguage(nullptr)); | decl_ctx_type_system->GetMinimumLanguage(nullptr)); | ||||
if (decl_ctx_type_system == type_system) | if (auto err = type_system_or_err.takeError()) { | ||||
LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), | |||||
std::move(err), | |||||
"Unable to match namespace decl using TypeSystem"); | |||||
return false; | |||||
} | |||||
if (decl_ctx_type_system == &type_system_or_err.get()) | |||||
return true; // The type systems match, return true | return true; // The type systems match, return true | ||||
// The namespace AST was valid, and it does not match... | // The namespace AST was valid, and it does not match... | ||||
Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | ||||
if (log) | if (log) | ||||
GetObjectFile()->GetModule()->LogMessage( | GetObjectFile()->GetModule()->LogMessage( | ||||
log, "Valid namespace does not match symbol file"); | log, "Valid namespace does not match symbol file"); | ||||
▲ Show 20 Lines • Show All 883 Lines • ▼ Show 20 Lines | if (type_name) { | ||||
DIEArray die_offsets; | DIEArray die_offsets; | ||||
m_index->GetTypes(dwarf_decl_ctx, die_offsets); | m_index->GetTypes(dwarf_decl_ctx, die_offsets); | ||||
const size_t num_matches = die_offsets.size(); | const size_t num_matches = die_offsets.size(); | ||||
// Get the type system that we are looking to find a type for. We will | // Get the type system that we are looking to find a type for. We will | ||||
// use this to ensure any matches we find are in a language that this | // use this to ensure any matches we find are in a language that this | ||||
// type system supports | // type system supports | ||||
const LanguageType language = dwarf_decl_ctx.GetLanguage(); | const LanguageType language = dwarf_decl_ctx.GetLanguage(); | ||||
TypeSystem *type_system = (language == eLanguageTypeUnknown) | TypeSystem *type_system = nullptr; | ||||
? nullptr | if (language != eLanguageTypeUnknown) { | ||||
: GetTypeSystemForLanguage(language); | auto type_system_or_err = GetTypeSystemForLanguage(language); | ||||
if (auto err = type_system_or_err.takeError()) { | |||||
LLDB_LOG_ERROR( | |||||
lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), | |||||
std::move(err), "Cannot get TypeSystem for language {}", | |||||
Language::GetNameForLanguageType(language)); | |||||
} else { | |||||
type_system = &type_system_or_err.get(); | |||||
} | |||||
} | |||||
if (num_matches) { | if (num_matches) { | ||||
for (size_t i = 0; i < num_matches; ++i) { | for (size_t i = 0; i < num_matches; ++i) { | ||||
const DIERef &die_ref = die_offsets[i]; | const DIERef &die_ref = die_offsets[i]; | ||||
DWARFDIE type_die = GetDIE(die_ref); | DWARFDIE type_die = GetDIE(die_ref); | ||||
if (type_die) { | if (type_die) { | ||||
// Make sure type_die's langauge matches the type system we are | // Make sure type_die's langauge matches the type system we are | ||||
// looking for. We don't want to find a "Foo" type from Java if we | // looking for. We don't want to find a "Foo" type from Java if we | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( | ||||
return type_sp; | return type_sp; | ||||
} | } | ||||
TypeSP SymbolFileDWARF::ParseType(const SymbolContext &sc, const DWARFDIE &die, | TypeSP SymbolFileDWARF::ParseType(const SymbolContext &sc, const DWARFDIE &die, | ||||
bool *type_is_new_ptr) { | bool *type_is_new_ptr) { | ||||
if (!die) | if (!die) | ||||
return {}; | return {}; | ||||
TypeSystem *type_system = | auto type_system_or_err = | ||||
GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); | GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); | ||||
if (!type_system) | if (auto err = type_system_or_err.takeError()) { | ||||
LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), | |||||
std::move(err), "Unable to parse type"); | |||||
return {}; | return {}; | ||||
} | |||||
DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); | DWARFASTParser *dwarf_ast = type_system_or_err->GetDWARFParser(); | ||||
if (!dwarf_ast) | if (!dwarf_ast) | ||||
return {}; | return {}; | ||||
Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); | ||||
TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr); | TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr); | ||||
if (type_sp) { | if (type_sp) { | ||||
GetTypeList().Insert(type_sp); | GetTypeList().Insert(type_sp); | ||||
▲ Show 20 Lines • Show All 735 Lines • ▼ Show 20 Lines | |||||
uint32_t SymbolFileDWARF::GetPluginVersion() { return 1; } | uint32_t SymbolFileDWARF::GetPluginVersion() { return 1; } | ||||
void SymbolFileDWARF::Dump(lldb_private::Stream &s) { | void SymbolFileDWARF::Dump(lldb_private::Stream &s) { | ||||
SymbolFile::Dump(s); | SymbolFile::Dump(s); | ||||
m_index->Dump(s); | m_index->Dump(s); | ||||
} | } | ||||
void SymbolFileDWARF::DumpClangAST(Stream &s) { | void SymbolFileDWARF::DumpClangAST(Stream &s) { | ||||
TypeSystem *ts = GetTypeSystemForLanguage(eLanguageTypeC_plus_plus); | auto ts_or_err = GetTypeSystemForLanguage(eLanguageTypeC_plus_plus); | ||||
ClangASTContext *clang = llvm::dyn_cast_or_null<ClangASTContext>(ts); | if (!ts_or_err) | ||||
return; | |||||
ClangASTContext *clang = llvm::dyn_cast_or_null<ClangASTContext>(&ts_or_err.get()); | |||||
if (!clang) | if (!clang) | ||||
return; | return; | ||||
clang->Dump(s); | clang->Dump(s); | ||||
} | } | ||||
SymbolFileDWARFDebugMap *SymbolFileDWARF::GetDebugMapSymfile() { | SymbolFileDWARFDebugMap *SymbolFileDWARF::GetDebugMapSymfile() { | ||||
if (m_debug_map_symfile == nullptr && !m_debug_map_module_wp.expired()) { | if (m_debug_map_symfile == nullptr && !m_debug_map_module_wp.expired()) { | ||||
lldb::ModuleSP module_sp(m_debug_map_module_wp.lock()); | lldb::ModuleSP module_sp(m_debug_map_module_wp.lock()); | ||||
Show All 34 Lines |
Remove the braces for consistency with the ifs below.