Author: Jan Kratochvil Date: 2020-04-03T21:58:11+02:00 New Revision: 80237523193d1311e8744b84faa077a1295d80da
URL: https://github.com/llvm/llvm-project/commit/80237523193d1311e8744b84faa077a1295d80da DIFF: https://github.com/llvm/llvm-project/commit/80237523193d1311e8744b84faa077a1295d80da.diff LOG: [nfc] [lldb] Unindent code - obvious part It is an obvious part of D77326. It removes some needless deep indentation and some redundant statements. It prepares the code for a more clean next patch - DWARF index callbacks in D77327. Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index 50b3a2cba61f..027eb08e5621 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -53,8 +53,9 @@ std::unique_ptr<AppleDWARFIndex> AppleDWARFIndex::Create( } void AppleDWARFIndex::GetGlobalVariables(ConstString basename, DIEArray &offsets) { - if (m_apple_names_up) - m_apple_names_up->FindByName(basename.GetStringRef(), offsets); + if (!m_apple_names_up) + return; + m_apple_names_up->FindByName(basename.GetStringRef(), offsets); } void AppleDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, @@ -80,22 +81,24 @@ void AppleDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, void AppleDWARFIndex::GetObjCMethods(ConstString class_name, DIEArray &offsets) { - if (m_apple_objc_up) - m_apple_objc_up->FindByName(class_name.GetStringRef(), offsets); + if (!m_apple_objc_up) + return; + m_apple_objc_up->FindByName(class_name.GetStringRef(), offsets); } void AppleDWARFIndex::GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, DIEArray &offsets) { - if (m_apple_types_up) { - m_apple_types_up->FindCompleteObjCClassByName( - class_name.GetStringRef(), offsets, must_be_implementation); - } + if (!m_apple_types_up) + return; + m_apple_types_up->FindCompleteObjCClassByName( + class_name.GetStringRef(), offsets, must_be_implementation); } void AppleDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { - if (m_apple_types_up) - m_apple_types_up->FindByName(name.GetStringRef(), offsets); + if (!m_apple_types_up) + return; + m_apple_types_up->FindByName(name.GetStringRef(), offsets); } void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context, @@ -149,8 +152,9 @@ void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context, } void AppleDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { - if (m_apple_namespaces_up) - m_apple_namespaces_up->FindByName(name.GetStringRef(), offsets); + if (!m_apple_namespaces_up) + return; + m_apple_namespaces_up->FindByName(name.GetStringRef(), offsets); } void AppleDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 5a2fa70138dd..d3a4b92b7e3e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -165,9 +165,8 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(ConstString class_name, // If we find the complete version we're done. offsets.push_back(*ref); return; - } else { - incomplete_types.push_back(*ref); } + incomplete_types.push_back(*ref); } offsets.insert(offsets.end(), incomplete_types.begin(), diff --git a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp index aa01668ba05c..5f01b8176b98 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp @@ -21,19 +21,19 @@ void DWARFMappedHash::ExtractDIEArray(const DIEInfoArray &die_info_array, DIEArray &die_offsets) { if (tag == 0) { ExtractDIEArray(die_info_array, die_offsets); - } else { - const size_t count = die_info_array.size(); - for (size_t i = 0; i < count; ++i) { - const dw_tag_t die_tag = die_info_array[i].tag; - bool tag_matches = die_tag == 0 || tag == die_tag; - if (!tag_matches) { - if (die_tag == DW_TAG_class_type || die_tag == DW_TAG_structure_type) - tag_matches = - tag == DW_TAG_structure_type || tag == DW_TAG_class_type; - } - if (tag_matches) - die_offsets.emplace_back(die_info_array[i]); + return; + } + + const size_t count = die_info_array.size(); + for (size_t i = 0; i < count; ++i) { + const dw_tag_t die_tag = die_info_array[i].tag; + bool tag_matches = die_tag == 0 || tag == die_tag; + if (!tag_matches) { + if (die_tag == DW_TAG_class_type || die_tag == DW_TAG_structure_type) + tag_matches = tag == DW_TAG_structure_type || tag == DW_TAG_class_type; } + if (tag_matches) + die_offsets.emplace_back(die_info_array[i]); } } @@ -43,21 +43,21 @@ void DWARFMappedHash::ExtractDIEArray(const DIEInfoArray &die_info_array, DIEArray &die_offsets) { if (tag == 0) { ExtractDIEArray(die_info_array, die_offsets); - } else { - const size_t count = die_info_array.size(); - for (size_t i = 0; i < count; ++i) { - if (qualified_name_hash != die_info_array[i].qualified_name_hash) - continue; - const dw_tag_t die_tag = die_info_array[i].tag; - bool tag_matches = die_tag == 0 || tag == die_tag; - if (!tag_matches) { - if (die_tag == DW_TAG_class_type || die_tag == DW_TAG_structure_type) - tag_matches = - tag == DW_TAG_structure_type || tag == DW_TAG_class_type; - } - if (tag_matches) - die_offsets.emplace_back(die_info_array[i]); + return; + } + + const size_t count = die_info_array.size(); + for (size_t i = 0; i < count; ++i) { + if (qualified_name_hash != die_info_array[i].qualified_name_hash) + continue; + const dw_tag_t die_tag = die_info_array[i].tag; + bool tag_matches = die_tag == 0 || tag == die_tag; + if (!tag_matches) { + if (die_tag == DW_TAG_class_type || die_tag == DW_TAG_structure_type) + tag_matches = tag == DW_TAG_structure_type || tag == DW_TAG_class_type; } + if (tag_matches) + die_offsets.emplace_back(die_info_array[i]); } } @@ -67,22 +67,22 @@ void DWARFMappedHash::ExtractClassOrStructDIEArray( const size_t count = die_info_array.size(); for (size_t i = 0; i < count; ++i) { const dw_tag_t die_tag = die_info_array[i].tag; - if (die_tag == 0 || die_tag == DW_TAG_class_type || - die_tag == DW_TAG_structure_type) { - if (die_info_array[i].type_flags & eTypeFlagClassIsImplementation) { - if (return_implementation_only_if_available) { - // We found the one true definition for this class, so only return - // that - die_offsets.clear(); - die_offsets.emplace_back(die_info_array[i]); - return; - } else { - // Put the one true definition as the first entry so it matches first - die_offsets.emplace(die_offsets.begin(), die_info_array[i]); - } - } else { + if (die_tag != 0 && die_tag != DW_TAG_class_type && + die_tag != DW_TAG_structure_type) + continue; + if (die_info_array[i].type_flags & eTypeFlagClassIsImplementation) { + if (return_implementation_only_if_available) { + // We found the one true definition for this class, so only return + // that + die_offsets.clear(); die_offsets.emplace_back(die_info_array[i]); + return; + } else { + // Put the one true definition as the first entry so it matches first + die_offsets.emplace(die_offsets.begin(), die_info_array[i]); } + } else { + die_offsets.emplace_back(die_info_array[i]); } } } @@ -548,24 +548,24 @@ size_t DWARFMappedHash::MemoryTable::FindByNameAndTagAndQualifiedNameHash( size_t DWARFMappedHash::MemoryTable::FindCompleteObjCClassByName( llvm::StringRef name, DIEArray &die_offsets, bool must_be_implementation) { DIEInfoArray die_info_array; - if (FindByName(name, die_info_array)) { - if (must_be_implementation && - GetHeader().header_data.ContainsAtom(eAtomTypeTypeFlags)) { - // If we have two atoms, then we have the DIE offset and the type flags - // so we can find the objective C class efficiently. - DWARFMappedHash::ExtractTypesFromDIEArray(die_info_array, UINT32_MAX, - eTypeFlagClassIsImplementation, - die_offsets); - } else { - // We don't only want the one true definition, so try and see what we can - // find, and only return class or struct DIEs. If we do have the full - // implementation, then return it alone, else return all possible - // matches. - const bool return_implementation_only_if_available = true; - DWARFMappedHash::ExtractClassOrStructDIEArray( - die_info_array, return_implementation_only_if_available, die_offsets); - } + if (!FindByName(name, die_info_array)) + return 0; + if (must_be_implementation && + GetHeader().header_data.ContainsAtom(eAtomTypeTypeFlags)) { + // If we have two atoms, then we have the DIE offset and the type flags + // so we can find the objective C class efficiently. + DWARFMappedHash::ExtractTypesFromDIEArray(die_info_array, UINT32_MAX, + eTypeFlagClassIsImplementation, + die_offsets); + return die_offsets.size(); } + // We don't only want the one true definition, so try and see what we can + // find, and only return class or struct DIEs. If we do have the full + // implementation, then return it alone, else return all possible + // matches. + const bool return_implementation_only_if_available = true; + DWARFMappedHash::ExtractClassOrStructDIEArray( + die_info_array, return_implementation_only_if_available, die_offsets); return die_offsets.size(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index cdeb30964987..cb783314d320 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -426,8 +426,9 @@ void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, DWARFDIE die = dwarf.GetDIE(die_ref); if (!die) continue; - if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - dies.push_back(die); + if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) + continue; + dies.push_back(die); } } if (name_type_mask & eFunctionNameTypeBase) { @@ -437,18 +438,20 @@ void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, DWARFDIE die = dwarf.GetDIE(die_ref); if (!die) continue; - if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - dies.push_back(die); + if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) + continue; + dies.push_back(die); } - offsets.clear(); } if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) { DIEArray offsets; m_set.function_methods.Find(name, offsets); for (const DIERef &die_ref: offsets) { - if (DWARFDIE die = dwarf.GetDIE(die_ref)) - dies.push_back(die); + DWARFDIE die = dwarf.GetDIE(die_ref); + if (!die) + continue; + dies.push_back(die); } } @@ -457,8 +460,10 @@ void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, DIEArray offsets; m_set.function_selectors.Find(name, offsets); for (const DIERef &die_ref: offsets) { - if (DWARFDIE die = dwarf.GetDIE(die_ref)) - dies.push_back(die); + DWARFDIE die = dwarf.GetDIE(die_ref); + if (!die) + continue; + dies.push_back(die); } } } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 3453068bff61..1113ed1195a3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2142,25 +2142,23 @@ void SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex, assert(sc.module_sp); const size_t num_matches = die_offsets.size(); - if (num_matches) { - for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; + DWARFDIE die = GetDIE(die_ref); + if (!die) { + m_index->ReportInvalidDIERef(die_ref, regex.GetText()); + continue; + } - if (die) { - DWARFCompileUnit *dwarf_cu = - llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); - if (!dwarf_cu) - continue; - sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); + DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); + if (!dwarf_cu) + continue; + sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); - ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); + ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); - if (variables.GetSize() - original_size >= max_matches) - break; - } else - m_index->ReportInvalidDIERef(die_ref, regex.GetText()); - } + if (variables.GetSize() - original_size >= max_matches) + break; } } @@ -2274,7 +2272,6 @@ void SymbolFileDWARF::FindFunctions(ConstString name, const uint32_t original_size = sc_list.GetSize(); llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies; - DIEArray offsets; std::vector<DWARFDIE> dies; m_index->GetFunctions(name, *this, parent_decl_ctx, name_type_mask, dies); @@ -2388,21 +2385,23 @@ void SymbolFileDWARF::FindTypes( for (size_t i = 0; i < num_die_matches; ++i) { const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); - if (die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) - continue; // The containing decl contexts don't match - - Type *matching_type = ResolveType(die, true, true); - if (matching_type) { - // We found a type pointer, now find the shared pointer form our type - // list - types.InsertUnique(matching_type->shared_from_this()); - if (types.GetSize() >= max_matches) - break; - } - } else { + if (!die) { m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); + continue; } + + if (!DIEInDeclContext(parent_decl_ctx, die)) + continue; // The containing decl contexts don't match + + Type *matching_type = ResolveType(die, true, true); + if (!matching_type) + continue; + + // We found a type pointer, now find the shared pointer form our type + // list + types.InsertUnique(matching_type->shared_from_this()); + if (types.GetSize() >= max_matches) + break; } // Next search through the reachable Clang modules. This only applies for @@ -2460,11 +2459,11 @@ void SymbolFileDWARF::FindTypes( for (size_t i = 0; i < num_die_matches; ++i) { const DIERef &die_ref = die_offsets[i]; DWARFDIE die = GetDIE(die_ref); - if (!die) { m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); continue; } + if (!languages[GetLanguage(*die.GetCU())]) continue; @@ -2511,24 +2510,24 @@ SymbolFileDWARF::FindNamespace(ConstString name, DIEArray die_offsets; m_index->GetNamespaces(name, die_offsets); const size_t num_matches = die_offsets.size(); - if (num_matches) { - for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; + DWARFDIE die = GetDIE(die_ref); + if (!die) { + m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); + continue; + } - if (die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) - continue; // The containing decl contexts don't match + if (!DIEInDeclContext(parent_decl_ctx, die)) + continue; // The containing decl contexts don't match - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) { - namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); - if (namespace_decl_ctx) - break; - } - } else { - m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); - } - } + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); + if (!dwarf_ast) + continue; + + namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); + if (namespace_decl_ctx) + break; } if (log && namespace_decl_ctx) { GetObjectFile()->GetModule()->LogMessage( @@ -3102,19 +3101,18 @@ size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) { m_index->GetGlobalVariables(dwarf_cu->GetNonSkeletonUnit(), die_offsets); const size_t num_matches = die_offsets.size(); - if (num_matches) { - for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); - if (die) { - VariableSP var_sp( - ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); - if (var_sp) { - variables->AddVariableIfUnique(var_sp); - ++vars_added; - } - } else - m_index->ReportInvalidDIERef(die_ref, ""); + for (size_t i = 0; i < num_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; + DWARFDIE die = GetDIE(die_ref); + if (!die) { + m_index->ReportInvalidDIERef(die_ref, ""); + continue; + } + + VariableSP var_sp(ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); + if (var_sp) { + variables->AddVariableIfUnique(var_sp); + ++vars_added; } } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits