diff options
author | Matt Kopec <Matt.Kopec@intel.com> | 2013-09-13 22:14:50 +0000 |
---|---|---|
committer | Matt Kopec <Matt.Kopec@intel.com> | 2013-09-13 22:14:50 +0000 |
commit | d678d30bac1a04aeaeaf43a4517cbad1aa2bbb90 (patch) | |
tree | 471859ad7757bc2888953cb326934c2b80033862 /lldb/source/Plugins/DynamicLoader | |
parent | 881dff36831f30d6b4792e398bc5a28775ac2757 (diff) | |
download | bcm5719-llvm-d678d30bac1a04aeaeaf43a4517cbad1aa2bbb90.tar.gz bcm5719-llvm-d678d30bac1a04aeaeaf43a4517cbad1aa2bbb90.zip |
This fixes two issues with the POSIX dynamic loader:
1. existing breakpoints weren't being re-resolved after the sections of a library were loaded (ie. through dlopen).
2. loaded sections weren't being removed after a shared library had been unloaded.
llvm-svn: 190727
Diffstat (limited to 'lldb/source/Plugins/DynamicLoader')
-rw-r--r-- | lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp | 46 | ||||
-rw-r--r-- | lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h | 9 |
2 files changed, 53 insertions, 2 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index 91c7cd3dfca..58008de135a 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -211,9 +211,11 @@ DynamicLoaderPOSIXDYLD::CanLoadImage() void DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module, addr_t base_addr) { - ObjectFile *obj_file = module->GetObjectFile(); - SectionList *sections = obj_file->GetSectionList(); SectionLoadList &load_list = m_process->GetTarget().GetSectionLoadList(); + const SectionList *sections = GetSectionListFromModule(module); + + assert(sections && "SectionList missing from loaded module."); + const size_t num_sections = sections->GetSize(); for (unsigned i = 0; i < num_sections; ++i) @@ -234,6 +236,22 @@ DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module, addr_t base_addr) } void +DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module) +{ + SectionLoadList &load_list = m_process->GetTarget().GetSectionLoadList(); + const SectionList *sections = GetSectionListFromModule(module); + + assert(sections && "SectionList missing from unloaded module."); + + const size_t num_sections = sections->GetSize(); + for (auto i = 0; i < num_sections; ++i) + { + SectionSP section_sp (sections->GetSectionAtIndex(i)); + load_list.SetSectionUnloaded(section_sp); + } +} + +void DynamicLoaderPOSIXDYLD::ProbeEntry() { Breakpoint *entry_break; @@ -321,8 +339,12 @@ DynamicLoaderPOSIXDYLD::RefreshModules() FileSpec file(I->path.c_str(), true); ModuleSP module_sp = LoadModuleAtAddress(file, I->base_addr); if (module_sp.get()) + { loaded_modules.AppendIfNeeded(module_sp); + new_modules.Append(module_sp); + } } + m_process->GetTarget().ModulesDidLoad(new_modules); } if (m_rendezvous.ModulesDidUnload()) @@ -336,10 +358,15 @@ DynamicLoaderPOSIXDYLD::RefreshModules() ModuleSpec module_spec (file); ModuleSP module_sp = loaded_modules.FindFirstModule (module_spec); + if (module_sp.get()) + { old_modules.Append(module_sp); + UnloadSections(module_sp); + } } loaded_modules.Remove(old_modules); + m_process->GetTarget().ModulesDidUnload(old_modules); } } @@ -479,3 +506,18 @@ DynamicLoaderPOSIXDYLD::GetEntryPoint() m_entry_point = static_cast<addr_t>(I->value); return m_entry_point; } + +const SectionList * +DynamicLoaderPOSIXDYLD::GetSectionListFromModule(const ModuleSP module) const +{ + SectionList *sections = nullptr; + if (module.get()) + { + ObjectFile *obj_file = module->GetObjectFile(); + if (obj_file) + { + sections = obj_file->GetSectionList(); + } + } + return sections; +} diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h index 0476e45d046..414f12098cf 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h @@ -122,6 +122,12 @@ protected: UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t base_addr = 0); + /// Removes the loaded sections from the target in @p module. + /// + /// @param module The module to traverse. + void + UnloadSections(const lldb::ModuleSP module); + /// Locates or creates a module given by @p file and updates/loads the /// resulting module at the virtual base address @p base_addr. lldb::ModuleSP @@ -165,6 +171,9 @@ protected: private: DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); + + const lldb_private::SectionList * + GetSectionListFromModule(const lldb::ModuleSP module) const; }; #endif // liblldb_DynamicLoaderPOSIXDYLD_H_ |