[Lldb-commits] [lldb] r233838 - Fixed the way SymbolFileDWARFDebugMap iterates across object
Sean Callanan
scallanan at apple.com
Wed Apr 1 13:43:23 PDT 2015
Author: spyffe
Date: Wed Apr 1 15:43:23 2015
New Revision: 233838
URL: http://llvm.org/viewvc/llvm-project?rev=233838&view=rev
Log:
Fixed the way SymbolFileDWARFDebugMap iterates across object
files. Before we'd give up if we found a .o that doesn't have
DWARF associated with it; now we iterate through them all.
Also made this iteration a higher-order function so that people
don't have to remember to do this right.
<rdar://problem/20261196>
Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=233838&r1=233837&r2=233838&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Wed Apr 1 15:43:23 2015
@@ -909,31 +909,33 @@ SymbolFileDWARFDebugMap::FindGlobalVaria
const uint32_t original_size = variables.GetSize();
uint32_t total_matches = 0;
- SymbolFileDWARF *oso_dwarf;
- for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
+
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (name,
namespace_decl,
- true,
- max_matches,
+ true,
+ max_matches,
variables);
if (oso_matches > 0)
{
total_matches += oso_matches;
-
+
// Are we getting all matches?
if (max_matches == UINT32_MAX)
- continue; // Yep, continue getting everything
-
+ return false; // Yep, continue getting everything
+
// If we have found enough matches, lets get out
if (max_matches >= total_matches)
- break;
-
+ return true;
+
// Update the max matches for any subsequent calls to find globals
// in any other object files with DWARF
max_matches -= oso_matches;
}
- }
+
+ return false;
+ });
+
// Return the number of variable that were appended to the list
return variables.GetSize() - original_size;
}
@@ -951,10 +953,8 @@ SymbolFileDWARFDebugMap::FindGlobalVaria
const uint32_t original_size = variables.GetSize();
uint32_t total_matches = 0;
- SymbolFileDWARF *oso_dwarf;
- for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
- const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (regex,
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
+ const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (regex,
true,
max_matches,
variables);
@@ -964,17 +964,20 @@ SymbolFileDWARFDebugMap::FindGlobalVaria
// Are we getting all matches?
if (max_matches == UINT32_MAX)
- continue; // Yep, continue getting everything
+ return false; // Yep, continue getting everything
// If we have found enough matches, lets get out
if (max_matches >= total_matches)
- break;
+ return true;
// Update the max matches for any subsequent calls to find globals
// in any other object files with DWARF
max_matches -= oso_matches;
}
- }
+
+ return false;
+ });
+
// Return the number of variable that were appended to the list
return variables.GetSize() - original_size;
}
@@ -1099,16 +1102,14 @@ SymbolFileDWARFDebugMap::FindFunctions(c
else
sc_list.Clear();
- uint32_t oso_idx = 0;
- SymbolFileDWARF *oso_dwarf;
- while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
- {
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
uint32_t sc_idx = sc_list.GetSize();
if (oso_dwarf->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, true, sc_list))
{
RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
}
- }
+ return false;
+ });
return sc_list.GetSize() - initial_size;
}
@@ -1127,17 +1128,15 @@ SymbolFileDWARFDebugMap::FindFunctions (
else
sc_list.Clear();
- uint32_t oso_idx = 0;
- SymbolFileDWARF *oso_dwarf;
- while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
- {
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
uint32_t sc_idx = sc_list.GetSize();
if (oso_dwarf->FindFunctions(regex, include_inlines, true, sc_list))
{
RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
}
- }
+ return false;
+ });
return sc_list.GetSize() - initial_size;
}
@@ -1169,11 +1168,10 @@ SymbolFileDWARFDebugMap::GetTypes (Symbo
}
else
{
- uint32_t oso_idx = 0;
- while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
- {
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
oso_dwarf->GetTypes (sc_scope, type_mask, type_list);
- }
+ return false;
+ });
}
return type_list.GetSize() - initial_size;
}
@@ -1183,13 +1181,10 @@ TypeSP
SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx)
{
TypeSP type_sp;
- SymbolFileDWARF *oso_dwarf;
- for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
- if (type_sp)
- break;
- }
+ return ((bool)type_sp);
+ });
return type_sp;
}
@@ -1201,15 +1196,14 @@ SymbolFileDWARFDebugMap::Supports_DW_AT_
if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
{
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
- SymbolFileDWARF *oso_dwarf;
- for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
if (skip_dwarf_oso != oso_dwarf && oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(NULL))
{
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
- break;
+ return true;
}
- }
+ return false;
+ });
}
return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
}
@@ -1268,12 +1262,14 @@ SymbolFileDWARFDebugMap::FindCompleteObj
// the code above should have found it.
if (must_be_implementation == false)
{
- for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
- TypeSP type_sp (oso_dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name, must_be_implementation));
- if (type_sp)
- return type_sp;
- }
+ TypeSP type_sp;
+
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
+ type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name, must_be_implementation);
+ return (bool)type_sp;
+ });
+
+ return type_sp;
}
return TypeSP();
}
@@ -1303,9 +1299,9 @@ SymbolFileDWARFDebugMap::FindTypes
}
else
{
- uint32_t oso_idx = 0;
- while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types);
+ });
}
return types.GetSize() - initial_types_size;
@@ -1338,15 +1334,11 @@ SymbolFileDWARFDebugMap::FindNamespace (
}
else
{
- for (uint32_t oso_idx = 0;
- ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL);
- ++oso_idx)
- {
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl);
- if (matching_namespace)
- break;
- }
+ return (bool)matching_namespace;
+ });
}
return matching_namespace;
@@ -1441,16 +1433,14 @@ SymbolFileDWARFDebugMap::CompleteTagDecl
ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
if (clang_type)
{
- SymbolFileDWARF *oso_dwarf;
-
- for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
+ symbol_file_dwarf->ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
if (oso_dwarf->HasForwardDeclForClangType (clang_type))
{
oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
- return;
+ return true;
}
- }
+ return false;
+ });
}
}
@@ -1461,16 +1451,14 @@ SymbolFileDWARFDebugMap::CompleteObjCInt
ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
if (clang_type)
{
- SymbolFileDWARF *oso_dwarf;
-
- for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
+ symbol_file_dwarf->ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
if (oso_dwarf->HasForwardDeclForClangType (clang_type))
{
oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
- return;
+ return true;
}
- }
+ return false;
+ });
}
}
@@ -1482,13 +1470,11 @@ SymbolFileDWARFDebugMap::LayoutRecordTyp
llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
{
SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
- SymbolFileDWARF *oso_dwarf;
- for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
- {
- if (oso_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets))
- return true;
- }
- return false;
+ bool laid_out = false;
+ symbol_file_dwarf->ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
+ return (laid_out = oso_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets));
+ });
+ return laid_out;
}
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=233838&r1=233837&r2=233838&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Wed Apr 1 15:43:23 2015
@@ -226,6 +226,23 @@ protected:
SymbolFileDWARF *
GetSymbolFileByOSOIndex (uint32_t oso_idx);
+
+ // If closure returns "false", iteration continues. If it returns
+ // "true", iteration terminates.
+ void
+ ForEachSymbolFile (std::function<bool (SymbolFileDWARF *)> closure)
+ {
+ for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
+ oso_idx < num_oso_idxs;
+ ++oso_idx)
+ {
+ if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx))
+ {
+ if (closure(oso_dwarf))
+ return;
+ }
+ }
+ }
CompileUnitInfo *
GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
More information about the lldb-commits
mailing list