summaryrefslogtreecommitdiff
path: root/source/Symbol/CompileUnit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Symbol/CompileUnit.cpp')
-rw-r--r--source/Symbol/CompileUnit.cpp87
1 files changed, 38 insertions, 49 deletions
diff --git a/source/Symbol/CompileUnit.cpp b/source/Symbol/CompileUnit.cpp
index a4f0d4231e2f..74512c891440 100644
--- a/source/Symbol/CompileUnit.cpp
+++ b/source/Symbol/CompileUnit.cpp
@@ -21,8 +21,8 @@ CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
const char *pathname, const lldb::user_id_t cu_sym_id,
lldb::LanguageType language,
lldb_private::LazyBool is_optimized)
- : ModuleChild(module_sp), FileSpec(pathname, false), UserID(cu_sym_id),
- m_user_data(user_data), m_language(language), m_flags(0), m_functions(),
+ : ModuleChild(module_sp), FileSpec(pathname), UserID(cu_sym_id),
+ m_user_data(user_data), m_language(language), m_flags(0),
m_support_files(), m_line_table_ap(), m_variables(),
m_is_optimized(is_optimized) {
if (language != eLanguageTypeUnknown)
@@ -35,7 +35,7 @@ CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
lldb::LanguageType language,
lldb_private::LazyBool is_optimized)
: ModuleChild(module_sp), FileSpec(fspec), UserID(cu_sym_id),
- m_user_data(user_data), m_language(language), m_flags(0), m_functions(),
+ m_user_data(user_data), m_language(language), m_flags(0),
m_support_files(), m_line_table_ap(), m_variables(),
m_is_optimized(is_optimized) {
if (language != eLanguageTypeUnknown)
@@ -66,6 +66,22 @@ void CompileUnit::GetDescription(Stream *s,
<< (const FileSpec &)*this << "\", language = \"" << language << '"';
}
+void CompileUnit::ForeachFunction(
+ llvm::function_ref<bool(const FunctionSP &)> lambda) const {
+ std::vector<lldb::FunctionSP> sorted_functions;
+ sorted_functions.reserve(m_functions_by_uid.size());
+ for (auto &p : m_functions_by_uid)
+ sorted_functions.push_back(p.second);
+ llvm::sort(sorted_functions.begin(), sorted_functions.end(),
+ [](const lldb::FunctionSP &a, const lldb::FunctionSP &b) {
+ return a->GetID() < b->GetID();
+ });
+
+ for (auto &f : sorted_functions)
+ if (lambda(f))
+ return;
+}
+
//----------------------------------------------------------------------
// Dump the current contents of this object. No functions that cause on demand
// parsing of functions, globals, statics are called, so this is a good
@@ -89,13 +105,12 @@ void CompileUnit::Dump(Stream *s, bool show_context) const {
s->IndentLess();
}
- if (!m_functions.empty()) {
+ if (!m_functions_by_uid.empty()) {
s->IndentMore();
- std::vector<FunctionSP>::const_iterator pos;
- std::vector<FunctionSP>::const_iterator end = m_functions.end();
- for (pos = m_functions.begin(); pos != end; ++pos) {
- (*pos)->Dump(s, show_context);
- }
+ ForeachFunction([&s, show_context](const FunctionSP &f) {
+ f->Dump(s, show_context);
+ return false;
+ });
s->IndentLess();
s->EOL();
@@ -106,15 +121,7 @@ void CompileUnit::Dump(Stream *s, bool show_context) const {
// Add a function to this compile unit
//----------------------------------------------------------------------
void CompileUnit::AddFunction(FunctionSP &funcSP) {
- // TODO: order these by address
- m_functions.push_back(funcSP);
-}
-
-FunctionSP CompileUnit::GetFunctionAtIndex(size_t idx) {
- FunctionSP funcSP;
- if (idx < m_functions.size())
- funcSP = m_functions[idx];
- return funcSP;
+ m_functions_by_uid[funcSP->GetID()] = funcSP;
}
//----------------------------------------------------------------------
@@ -163,18 +170,10 @@ FunctionSP CompileUnit::GetFunctionAtIndex(size_t idx) {
//}
FunctionSP CompileUnit::FindFunctionByUID(lldb::user_id_t func_uid) {
- FunctionSP funcSP;
- if (!m_functions.empty()) {
- std::vector<FunctionSP>::const_iterator pos;
- std::vector<FunctionSP>::const_iterator end = m_functions.end();
- for (pos = m_functions.begin(); pos != end; ++pos) {
- if ((*pos)->GetID() == func_uid) {
- funcSP = *pos;
- break;
- }
- }
- }
- return funcSP;
+ auto it = m_functions_by_uid.find(func_uid);
+ if (it == m_functions_by_uid.end())
+ return FunctionSP();
+ return it->second;
}
lldb::LanguageType CompileUnit::GetLanguage() {
@@ -183,9 +182,7 @@ lldb::LanguageType CompileUnit::GetLanguage() {
m_flags.Set(flagsParsedLanguage);
SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor();
if (symbol_vendor) {
- SymbolContext sc;
- CalculateSymbolContext(&sc);
- m_language = symbol_vendor->ParseCompileUnitLanguage(sc);
+ m_language = symbol_vendor->ParseLanguage(*this);
}
}
}
@@ -197,11 +194,8 @@ LineTable *CompileUnit::GetLineTable() {
if (m_flags.IsClear(flagsParsedLineTable)) {
m_flags.Set(flagsParsedLineTable);
SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor();
- if (symbol_vendor) {
- SymbolContext sc;
- CalculateSymbolContext(&sc);
- symbol_vendor->ParseCompileUnitLineTable(sc);
- }
+ if (symbol_vendor)
+ symbol_vendor->ParseLineTable(*this);
}
}
return m_line_table_ap.get();
@@ -221,9 +215,7 @@ DebugMacros *CompileUnit::GetDebugMacros() {
m_flags.Set(flagsParsedDebugMacros);
SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor();
if (symbol_vendor) {
- SymbolContext sc;
- CalculateSymbolContext(&sc);
- symbol_vendor->ParseCompileUnitDebugMacros(sc);
+ symbol_vendor->ParseDebugMacros(*this);
}
}
}
@@ -279,7 +271,8 @@ uint32_t CompileUnit::FindLineEntry(uint32_t start_idx, uint32_t line,
uint32_t CompileUnit::ResolveSymbolContext(const FileSpec &file_spec,
uint32_t line, bool check_inlines,
- bool exact, uint32_t resolve_scope,
+ bool exact,
+ SymbolContextItem resolve_scope,
SymbolContextList &sc_list) {
// First find all of the file indexes that match our "file_spec". If
// "file_spec" has an empty directory, then only compare the basenames when
@@ -291,7 +284,7 @@ uint32_t CompileUnit::ResolveSymbolContext(const FileSpec &file_spec,
// If we are not looking for inlined functions and our file spec doesn't
// match then we are done...
- if (file_spec_matches_cu_file_spec == false && check_inlines == false)
+ if (!file_spec_matches_cu_file_spec && !check_inlines)
return 0;
uint32_t file_idx =
@@ -387,9 +380,7 @@ bool CompileUnit::GetIsOptimized() {
if (m_is_optimized == eLazyBoolCalculate) {
m_is_optimized = eLazyBoolNo;
if (SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor()) {
- SymbolContext sc;
- CalculateSymbolContext(&sc);
- if (symbol_vendor->ParseCompileUnitIsOptimized(sc))
+ if (symbol_vendor->ParseIsOptimized(*this))
m_is_optimized = eLazyBoolYes;
}
}
@@ -419,9 +410,7 @@ FileSpecList &CompileUnit::GetSupportFiles() {
m_flags.Set(flagsParsedSupportFiles);
SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor();
if (symbol_vendor) {
- SymbolContext sc;
- CalculateSymbolContext(&sc);
- symbol_vendor->ParseCompileUnitSupportFiles(sc, m_support_files);
+ symbol_vendor->ParseSupportFiles(*this, m_support_files);
}
}
}