diff options
Diffstat (limited to 'lldb/source/Core/ModuleList.cpp')
-rw-r--r-- | lldb/source/Core/ModuleList.cpp | 318 |
1 files changed, 65 insertions, 253 deletions
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 2325bde0bc0..9ba911921fb 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -289,109 +289,18 @@ ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, return sc_list.GetSize() - initial_size; } -class ModuleMatches -{ -public: - //-------------------------------------------------------------- - /// Construct with the user ID to look for. - //-------------------------------------------------------------- - ModuleMatches (const FileSpec *file_spec_ptr, - const ArchSpec *arch_ptr, - const lldb_private::UUID *uuid_ptr, - const ConstString *object_name, - bool file_spec_is_platform) : - m_file_spec_ptr (file_spec_ptr), - m_arch_ptr (arch_ptr), - m_uuid_ptr (uuid_ptr), - m_object_name (object_name), - m_file_spec_compare_basename_only (false), - m_file_spec_is_platform (file_spec_is_platform) - { - if (file_spec_ptr) - m_file_spec_compare_basename_only = file_spec_ptr->GetDirectory(); - } - - - //-------------------------------------------------------------- - /// Unary predicate function object callback. - //-------------------------------------------------------------- - bool - operator () (const ModuleSP& module_sp) const - { - if (m_file_spec_ptr) - { - if (m_file_spec_is_platform) - { - if (!FileSpec::Equal (*m_file_spec_ptr, - module_sp->GetPlatformFileSpec(), - m_file_spec_compare_basename_only)) - return false; - - } - else - { - if (!FileSpec::Equal (*m_file_spec_ptr, - module_sp->GetFileSpec(), - m_file_spec_compare_basename_only)) - return false; - } - } - - if (m_arch_ptr && m_arch_ptr->IsValid()) - { - if (module_sp->GetArchitecture() != *m_arch_ptr) - return false; - } - - if (m_uuid_ptr && m_uuid_ptr->IsValid()) - { - if (module_sp->GetUUID() != *m_uuid_ptr) - return false; - } - - if (m_object_name) - { - if (module_sp->GetObjectName() != *m_object_name) - return false; - } - return true; - } - -private: - //-------------------------------------------------------------- - // Member variables. - //-------------------------------------------------------------- - const FileSpec * m_file_spec_ptr; - const ArchSpec * m_arch_ptr; - const lldb_private::UUID * m_uuid_ptr; - const ConstString * m_object_name; - bool m_file_spec_compare_basename_only; - bool m_file_spec_is_platform; -}; - size_t -ModuleList::FindModules -( - const FileSpec *file_spec_ptr, - const ArchSpec *arch_ptr, - const lldb_private::UUID *uuid_ptr, - const ConstString *object_name, - ModuleList& matching_module_list -) const +ModuleList::FindModules (const ModuleSpec &module_spec, ModuleList& matching_module_list) const { size_t existing_matches = matching_module_list.GetSize(); - ModuleMatches matcher (file_spec_ptr, arch_ptr, uuid_ptr, object_name, false); Mutex::Locker locker(m_modules_mutex); - collection::const_iterator end = m_modules.end(); - collection::const_iterator pos; - - for (pos = std::find_if (m_modules.begin(), end, matcher); - pos != end; - pos = std::find_if (++pos, end, matcher)) + collection::const_iterator pos, end = m_modules.end(); + for (pos = m_modules.begin(); pos != end; ++pos) { ModuleSP module_sp(*pos); - matching_module_list.Append(module_sp); + if (module_sp->MatchesModuleSpec (module_spec)) + matching_module_list.Append(module_sp); } return matching_module_list.GetSize() - existing_matches; } @@ -464,58 +373,21 @@ ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool ap } ModuleSP -ModuleList::FindFirstModuleForFileSpec (const FileSpec &file_spec, - const ArchSpec *arch_ptr, - const ConstString *object_name) +ModuleList::FindFirstModule (const ModuleSpec &module_spec) { ModuleSP module_sp; - ModuleMatches matcher (&file_spec, - arch_ptr, - NULL, - object_name, - false); - - // Scope for "locker" + Mutex::Locker locker(m_modules_mutex); + collection::const_iterator pos, end = m_modules.end(); + for (pos = m_modules.begin(); pos != end; ++pos) { - Mutex::Locker locker(m_modules_mutex); - collection::const_iterator end = m_modules.end(); - collection::const_iterator pos = m_modules.begin(); - - pos = std::find_if (pos, end, matcher); - if (pos != end) - module_sp = (*pos); + ModuleSP module_sp(*pos); + if (module_sp->MatchesModuleSpec (module_spec)) + return module_sp; } return module_sp; } -ModuleSP -ModuleList::FindFirstModuleForPlatormFileSpec (const FileSpec &file_spec, - const ArchSpec *arch_ptr, - const ConstString *object_name) -{ - ModuleSP module_sp; - ModuleMatches matcher (&file_spec, - arch_ptr, - NULL, - object_name, - true); - - // Scope for "locker" - { - Mutex::Locker locker(m_modules_mutex); - collection::const_iterator end = m_modules.end(); - collection::const_iterator pos = m_modules.begin(); - - pos = std::find_if (pos, end, matcher); - if (pos != end) - module_sp = (*pos); - } - return module_sp; - -} - - size_t ModuleList::GetSize() const { @@ -674,17 +546,9 @@ ModuleList::ModuleIsInCache (const Module *module_ptr) } size_t -ModuleList::FindSharedModules -( - const FileSpec& in_file_spec, - const ArchSpec& arch, - const lldb_private::UUID *uuid_ptr, - const ConstString *object_name_ptr, - ModuleList &matching_module_list -) +ModuleList::FindSharedModules (const ModuleSpec &module_spec, ModuleList &matching_module_list) { - ModuleList &shared_module_list = GetSharedModuleList (); - return shared_module_list.FindModules (&in_file_spec, &arch, uuid_ptr, object_name_ptr, matching_module_list); + return GetSharedModuleList ().FindModules (module_spec, matching_module_list); } uint32_t @@ -692,42 +556,11 @@ ModuleList::RemoveOrphanSharedModules () { return GetSharedModuleList ().RemoveOrphans(); } -//#define ENABLE_MODULE_SP_LOGGING -#if defined (ENABLE_MODULE_SP_LOGGING) -#include "lldb/Core/StreamFile.h" -#include "lldb/Host/Host.h" -static void -ModuleSharedPtrLogger(void* p, const ModuleSP& sp, bool will_decrement) -{ - if (sp.get()) - { - const char *module_basename = sp->GetFileSpec().GetFilename().GetCString(); - // If "p" is set, then it is the basename of a module to watch for. This - // basename MUST be uniqued first by getting it from a ConstString or this - // won't work. - if (p && p != module_basename) - { - return; - } - long use_count = sp.use_count(); - if (will_decrement) - --use_count; - - printf("\nModuleSP(%p): %c %p {%lu} %s/%s\n", &sp, will_decrement ? '-' : '+', sp.get(), use_count, sp->GetFileSpec().GetDirectory().GetCString(), module_basename); - StreamFile stdout_strm(stdout, false); - Host::Backtrace (stdout_strm, 512); - } -} -#endif Error ModuleList::GetSharedModule ( - const FileSpec& in_file_spec, - const ArchSpec& arch, - const lldb_private::UUID *uuid_ptr, - const ConstString *object_name_ptr, - off_t object_offset, + const ModuleSpec &module_spec, ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, ModuleSP *old_module_sp_ptr, @@ -749,82 +582,68 @@ ModuleList::GetSharedModule if (old_module_sp_ptr) old_module_sp_ptr->reset(); + const UUID *uuid_ptr = module_spec.GetUUIDPtr(); + const FileSpec &module_file_spec = module_spec.GetFileSpec(); + const ArchSpec &arch = module_spec.GetArchitecture(); - // First just try and get the file where it purports to be (path in - // in_file_spec), then check and uuid. - - if (in_file_spec) + // Make sure no one else can try and get or create a module while this + // function is actively working on it by doing an extra lock on the + // global mutex list. + if (always_create == false) { - // Make sure no one else can try and get or create a module while this - // function is actively working on it by doing an extra lock on the - // global mutex list. - if (always_create == false) + ModuleList matching_module_list; + const size_t num_matching_modules = shared_module_list.FindModules (module_spec, matching_module_list); + if (num_matching_modules > 0) { - ModuleList matching_module_list; - const size_t num_matching_modules = shared_module_list.FindModules (&in_file_spec, &arch, NULL, object_name_ptr, matching_module_list); - if (num_matching_modules > 0) + for (uint32_t module_idx = 0; module_idx < num_matching_modules; ++module_idx) { - for (uint32_t module_idx = 0; module_idx < num_matching_modules; ++module_idx) + module_sp = matching_module_list.GetModuleAtIndex(module_idx); + if (module_file_spec) { - module_sp = matching_module_list.GetModuleAtIndex(module_idx); - if (uuid_ptr && uuid_ptr->IsValid()) + // If we didn't have a UUID in mind when looking for the object file, + // then we should make sure the modification time hasn't changed! + TimeValue file_spec_mod_time(module_file_spec.GetModificationTime()); + if (file_spec_mod_time.IsValid()) { - // We found the module we were looking for. - if (module_sp->GetUUID() == *uuid_ptr) + if (file_spec_mod_time == module_sp->GetModificationTime()) return error; } - else - { - // If we didn't have a UUID in mind when looking for the object file, - // then we should make sure the modification time hasn't changed! - TimeValue file_spec_mod_time(in_file_spec.GetModificationTime()); - if (file_spec_mod_time.IsValid()) - { - if (file_spec_mod_time == module_sp->GetModificationTime()) - return error; - } - } - if (old_module_sp_ptr && !old_module_sp_ptr->get()) - *old_module_sp_ptr = module_sp; - shared_module_list.Remove (module_sp); - module_sp.reset(); } + if (old_module_sp_ptr && !old_module_sp_ptr->get()) + *old_module_sp_ptr = module_sp; + shared_module_list.Remove (module_sp); + module_sp.reset(); } } + } + if (module_sp) + return error; + else + { + module_sp.reset (new Module (module_spec)); + // Make sure there are a module and an object file since we can specify + // a valid file path with an architecture that might not be in that file. + // By getting the object file we can guarantee that the architecture matches if (module_sp) - return error; - else { -#if defined ENABLE_MODULE_SP_LOGGING - ModuleSP logging_module_sp (new Module (in_file_spec, arch, object_name_ptr, object_offset), ModuleSharedPtrLogger, (void *)ConstString("a.out").GetCString()); - module_sp = logging_module_sp; -#else - module_sp.reset (new Module (in_file_spec, arch, object_name_ptr, object_offset)); -#endif - // Make sure there are a module and an object file since we can specify - // a valid file path with an architecture that might not be in that file. - // By getting the object file we can guarantee that the architecture matches - if (module_sp) + if (module_sp->GetObjectFile()) { - if (module_sp->GetObjectFile()) + // If we get in here we got the correct arch, now we just need + // to verify the UUID if one was given + if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) + module_sp.reset(); + else { - // If we get in here we got the correct arch, now we just need - // to verify the UUID if one was given - if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) - module_sp.reset(); - else - { - if (did_create_ptr) - *did_create_ptr = true; - - shared_module_list.Append(module_sp); - return error; - } + if (did_create_ptr) + *did_create_ptr = true; + + shared_module_list.Append(module_sp); + return error; } - else - module_sp.reset(); } + else + module_sp.reset(); } } @@ -834,19 +653,17 @@ ModuleList::GetSharedModule // Fixup the incoming path in case the path points to a valid file, yet // the arch or UUID (if one was passed in) don't match. - FileSpec file_spec = Symbols::LocateExecutableObjectFile (in_file_spec ? &in_file_spec : NULL, - arch.IsValid() ? &arch : NULL, - uuid_ptr); + FileSpec file_spec = Symbols::LocateExecutableObjectFile (module_spec); // Don't look for the file if it appears to be the same one we already // checked for above... - if (file_spec != in_file_spec) + if (file_spec != module_file_spec) { if (!file_spec.Exists()) { file_spec.GetPath(path, sizeof(path)); if (path[0] == '\0') - in_file_spec.GetPath(path, sizeof(path)); + module_file_spec.GetPath(path, sizeof(path)); if (file_spec.Exists()) { if (uuid_ptr && uuid_ptr->IsValid()) @@ -877,13 +694,13 @@ ModuleList::GetSharedModule // function is actively working on it by doing an extra lock on the // global mutex list. ModuleList matching_module_list; - if (shared_module_list.FindModules (&file_spec, &arch, uuid_ptr, object_name_ptr, matching_module_list) > 0) + if (shared_module_list.FindModules (module_spec, matching_module_list) > 0) { module_sp = matching_module_list.GetModuleAtIndex(0); // If we didn't have a UUID in mind when looking for the object file, // then we should make sure the modification time hasn't changed! - if (uuid_ptr == NULL) + if (module_spec.GetUUIDPtr() == NULL) { TimeValue file_spec_mod_time(file_spec.GetModificationTime()); if (file_spec_mod_time.IsValid()) @@ -901,12 +718,7 @@ ModuleList::GetSharedModule if (module_sp.get() == NULL) { -#if defined ENABLE_MODULE_SP_LOGGING - ModuleSP logging_module_sp (new Module (file_spec, arch, object_name_ptr, object_offset), ModuleSharedPtrLogger, 0); - module_sp = logging_module_sp; -#else - module_sp.reset (new Module (file_spec, arch, object_name_ptr, object_offset)); -#endif + module_sp.reset (new Module (module_spec)); // Make sure there are a module and an object file since we can specify // a valid file path with an architecture that might not be in that file. // By getting the object file we can guarantee that the architecture matches |