asmith created this revision. asmith added reviewers: zturner, llvm-commits. Herald added a subscriber: lldb-commits.
When a process is loaded, update its sections with the load address to resolve any created breakpoints. For the remote debugging case, the debugged process is launched remotely so GetFileLoadAddress is intended to pass the load address from remote to LLDB (client). Repository: rLLDB LLDB https://reviews.llvm.org/D56237 Files: source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp source/Plugins/Process/Windows/Common/ProcessWindows.cpp source/Plugins/Process/Windows/Common/ProcessWindows.h
Index: source/Plugins/Process/Windows/Common/ProcessWindows.h =================================================================== --- source/Plugins/Process/Windows/Common/ProcessWindows.h +++ source/Plugins/Process/Windows/Common/ProcessWindows.h @@ -55,6 +55,9 @@ ConstString GetPluginName() override; uint32_t GetPluginVersion() override; + Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded, + lldb::addr_t &load_addr) override; + Status EnableBreakpointSite(BreakpointSite *bp_site) override; Status DisableBreakpointSite(BreakpointSite *bp_site) override; Index: source/Plugins/Process/Windows/Common/ProcessWindows.cpp =================================================================== --- source/Plugins/Process/Windows/Common/ProcessWindows.cpp +++ source/Plugins/Process/Windows/Common/ProcessWindows.cpp @@ -855,6 +855,37 @@ return error; } +Status ProcessWindows::GetFileLoadAddress(const FileSpec &file, bool &is_loaded, + lldb::addr_t &load_addr) { + FileSpec file_spec(file); + FileSystem::Instance().Resolve(file_spec); + ModuleSpec module_spec(file_spec); + Status error; + ModuleSP module = GetTarget().GetSharedModule(module_spec, &error); + if (!module) + return error; + + load_addr = LLDB_INVALID_ADDRESS; + is_loaded = false; + SectionList *section_list = module->GetSectionList(); + for (int idx = 0; idx < section_list->GetSize(); ++idx) { + SectionSP section_sp(section_list->GetSectionAtIndex(idx)); + if (section_sp && !section_sp->IsThreadSpecific()) { + // FIXME: Calculate the load address manually because + // SectionLoadList::GetSectionLoadAddress appears inaccurate + load_addr = section_sp->GetLoadBaseAddress(&GetTarget()) - + section_sp->GetFileAddress(); + load_addr += module->GetObjectFile()->GetFileOffset(); + break; + } + } + if (load_addr != LLDB_INVALID_ADDRESS) { + is_loaded = true; + return Status(); + } + return Status("Moudle is not loaded"); +} + lldb::addr_t ProcessWindows::GetImageInfoAddress() { Target &target = GetTarget(); ObjectFile *obj_file = target.GetExecutableModule()->GetObjectFile(); Index: source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp =================================================================== --- source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp +++ source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp @@ -1,5 +1,4 @@ -//===-- DynamicLoaderWindowsDYLD.cpp --------------------------------*- C++ -//-*-===// +//===-- DynamicLoaderWindowsDYLD.cpp -----------------------------*- C++-*-===// // // The LLVM Compiler Infrastructure // @@ -63,7 +62,7 @@ } void DynamicLoaderWindowsDYLD::DidAttach() { - Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); if (log) log->Printf("DynamicLoaderWindowsDYLD::%s()", __FUNCTION__); @@ -75,19 +74,13 @@ // Try to fetch the load address of the file from the process, since there // could be randomization of the load address. - // It might happen that the remote has a different dir for the file, so we - // only send the basename of the executable in the query. I think this is safe - // because I doubt that two executables with the same basenames are loaded in - // memory... - FileSpec file_spec( - executable->GetPlatformFileSpec().GetFilename().GetCString()); + FileSpec file_spec(executable->GetPlatformFileSpec()); bool is_loaded; - addr_t base_addr = 0; - lldb::addr_t load_addr; + lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; Status error = m_process->GetFileLoadAddress(file_spec, is_loaded, load_addr); - if (error.Success() && is_loaded) { - base_addr = load_addr; - UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, base_addr, false); + if (error.Success() && is_loaded && load_addr != LLDB_INVALID_ADDRESS) { + // Update the loaded sections so that the breakpoints can be resolved. + UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_addr, false); } ModuleList module_list; @@ -96,7 +89,7 @@ m_process->LoadModules(); } -void DynamicLoaderWindowsDYLD::DidLaunch() {} +void DynamicLoaderWindowsDYLD::DidLaunch() { DidAttach(); } Status DynamicLoaderWindowsDYLD::CanLoadImage() { return Status(); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits