diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -943,8 +943,7 @@ virtual void CalculateTrapHandlerSymbolNames() = 0; Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, - Platform &remote_platform); + const FileSpecList *module_search_paths_ptr); virtual Status DownloadModuleSlice(const FileSpec &src_file_spec, const uint64_t src_offset, @@ -956,6 +955,11 @@ virtual const char *GetCacheHostname(); + virtual Status + ResolveRemoteExecutable(const ModuleSpec &module_spec, + lldb::ModuleSP &exe_module_sp, + const FileSpecList *module_search_paths_ptr); + private: typedef std::function ModuleResolver; @@ -969,8 +973,7 @@ Status LoadCachedExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, - Platform &remote_platform); + const FileSpecList *module_search_paths_ptr); FileSpec GetModuleCacheRoot(); }; diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h @@ -40,10 +40,6 @@ llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } // lldb_private::Platform functions - Status - ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr) override; - bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override; diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -89,76 +89,6 @@ return GetDescriptionStatic(); } -Status PlatformRemoteGDBServer::ResolveExecutable( - const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, - const FileSpecList *module_search_paths_ptr) { - // copied from PlatformRemoteiOS - - Status error; - // Nothing special to do here, just use the actual file and architecture - - ModuleSpec resolved_module_spec(module_spec); - - // Resolve any executable within an apk on Android? - // Host::ResolveExecutableInBundle (resolved_module_spec.GetFileSpec()); - - if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) || - module_spec.GetUUID().IsValid()) { - if (resolved_module_spec.GetArchitecture().IsValid() || - resolved_module_spec.GetUUID().IsValid()) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, nullptr, - nullptr); - - if (exe_module_sp && exe_module_sp->GetObjectFile()) - return error; - exe_module_sp.reset(); - } - // No valid architecture was specified or the exact arch wasn't found so - // ask the platform for the architectures that we should be using (in the - // correct order) and see if we can find a match that way - StreamString arch_names; - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( - idx, resolved_module_spec.GetArchitecture()); - ++idx) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, nullptr, - nullptr); - // Did we find an executable using one of the - if (error.Success()) { - if (exe_module_sp && exe_module_sp->GetObjectFile()) - break; - else - error.SetErrorToGenericError(); - } - - if (idx > 0) - arch_names.PutCString(", "); - arch_names.PutCString( - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - - if (error.Fail() || !exe_module_sp) { - if (FileSystem::Instance().Readable(resolved_module_spec.GetFileSpec())) { - error.SetErrorStringWithFormatv( - "'{0}' doesn't contain any '{1}' platform architectures: {2}", - resolved_module_spec.GetFileSpec(), GetPluginName(), - arch_names.GetData()); - } else { - error.SetErrorStringWithFormat( - "'%s' is not readable", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } - } else { - error.SetErrorStringWithFormat( - "'%s' does not exist", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - - return error; -} - bool PlatformRemoteGDBServer::GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) { diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -833,6 +833,7 @@ lldb::ModuleSP &exe_module_sp, const FileSpecList *module_search_paths_ptr) { Status error; + if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) { if (module_spec.GetArchitecture().IsValid()) { error = ModuleList::GetSharedModule(module_spec, exe_module_sp, @@ -855,9 +856,77 @@ } } } else { - error.SetErrorStringWithFormat("'%s' does not exist", - module_spec.GetFileSpec().GetPath().c_str()); + error.SetErrorStringWithFormat( + "'%s' does not exist", module_spec.GetFileSpec().GetPath().c_str()); + } + return error; +} + +Status +Platform::ResolveRemoteExecutable(const ModuleSpec &module_spec, + lldb::ModuleSP &exe_module_sp, + const FileSpecList *module_search_paths_ptr) { + Status error; + + // We may connect to a process and use the provided executable (Don't use + // local $PATH). + ModuleSpec resolved_module_spec(module_spec); + + // Resolve any executable within a bundle on MacOSX + Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); + + if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) || + module_spec.GetUUID().IsValid()) { + if (resolved_module_spec.GetArchitecture().IsValid() || + resolved_module_spec.GetUUID().IsValid()) { + error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, + module_search_paths_ptr, nullptr, + nullptr); + + if (exe_module_sp && exe_module_sp->GetObjectFile()) + return error; + exe_module_sp.reset(); + } + // No valid architecture was specified or the exact arch wasn't found so + // ask the platform for the architectures that we should be using (in the + // correct order) and see if we can find a match that way + StreamString arch_names; + for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( + idx, resolved_module_spec.GetArchitecture()); + ++idx) { + error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, + module_search_paths_ptr, nullptr, + nullptr); + // Did we find an executable using one of the + if (error.Success()) { + if (exe_module_sp && exe_module_sp->GetObjectFile()) + break; + else + error.SetErrorToGenericError(); + } + + if (idx > 0) + arch_names.PutCString(", "); + arch_names.PutCString( + resolved_module_spec.GetArchitecture().GetArchitectureName()); + } + + if (error.Fail() || !exe_module_sp) { + if (FileSystem::Instance().Readable(resolved_module_spec.GetFileSpec())) { + error.SetErrorStringWithFormatv( + "'{0}' doesn't contain any '{1}' platform architectures: {2}", + resolved_module_spec.GetFileSpec(), GetPluginName(), + arch_names.GetData()); + } else { + error.SetErrorStringWithFormatv("'{0}' is not readable", + resolved_module_spec.GetFileSpec()); + } + } + } else { + error.SetErrorStringWithFormatv("'{0}' does not exist", + resolved_module_spec.GetFileSpec()); } + return error; } @@ -1507,12 +1576,13 @@ return m_trap_handlers; } -Status Platform::GetCachedExecutable( - ModuleSpec &module_spec, lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, Platform &remote_platform) { +Status +Platform::GetCachedExecutable(ModuleSpec &module_spec, + lldb::ModuleSP &module_sp, + const FileSpecList *module_search_paths_ptr) { const auto platform_spec = module_spec.GetFileSpec(); - const auto error = LoadCachedExecutable( - module_spec, module_sp, module_search_paths_ptr, remote_platform); + const auto error = + LoadCachedExecutable(module_spec, module_sp, module_search_paths_ptr); if (error.Success()) { module_spec.GetFileSpec() = module_sp->GetFileSpec(); module_spec.GetPlatformFileSpec() = platform_spec; @@ -1521,15 +1591,17 @@ return error; } -Status Platform::LoadCachedExecutable( - const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, Platform &remote_platform) { - return GetRemoteSharedModule(module_spec, nullptr, module_sp, - [&](const ModuleSpec &spec) { - return remote_platform.ResolveExecutable( - spec, module_sp, module_search_paths_ptr); - }, - nullptr); +Status +Platform::LoadCachedExecutable(const ModuleSpec &module_spec, + lldb::ModuleSP &module_sp, + const FileSpecList *module_search_paths_ptr) { + return GetRemoteSharedModule( + module_spec, nullptr, module_sp, + [&](const ModuleSpec &spec) { + return ResolveRemoteExecutable(spec, module_sp, + module_search_paths_ptr); + }, + nullptr); } Status Platform::GetRemoteSharedModule(const ModuleSpec &module_spec, diff --git a/lldb/source/Target/RemoteAwarePlatform.cpp b/lldb/source/Target/RemoteAwarePlatform.cpp --- a/lldb/source/Target/RemoteAwarePlatform.cpp +++ b/lldb/source/Target/RemoteAwarePlatform.cpp @@ -72,8 +72,7 @@ } else { if (m_remote_platform_sp) { return GetCachedExecutable(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, - *m_remote_platform_sp); + module_search_paths_ptr); } // We may connect to a process and use the provided executable (Don't use diff --git a/lldb/unittests/Target/RemoteAwarePlatformTest.cpp b/lldb/unittests/Target/RemoteAwarePlatformTest.cpp --- a/lldb/unittests/Target/RemoteAwarePlatformTest.cpp +++ b/lldb/unittests/Target/RemoteAwarePlatformTest.cpp @@ -31,6 +31,17 @@ ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); + MOCK_METHOD2(ResolveRemoteExecutable, + std::pair(const ModuleSpec &, + const FileSpecList *)); + Status ResolveRemoteExecutable( + const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, + const FileSpecList *module_search_paths_ptr) /*override*/ { + auto pair = ResolveRemoteExecutable(module_spec, module_search_paths_ptr); + exe_module_sp = pair.second; + return pair.first; + } + void SetRemotePlatform(lldb::PlatformSP platform) { m_remote_platform_sp = platform; } @@ -47,18 +58,6 @@ ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); MOCK_METHOD0(GetUserIDResolver, UserIDResolver &()); - - MOCK_METHOD2(ResolveExecutable, - std::pair(const ModuleSpec &, - const FileSpecList *)); - Status - ResolveExecutable(const ModuleSpec &module_spec, - lldb::ModuleSP &exe_module_sp, - const FileSpecList *module_search_paths_ptr) /*override*/ { - auto pair = ResolveExecutable(module_spec, module_search_paths_ptr); - exe_module_sp = pair.second; - return pair.first; - } }; namespace { @@ -73,15 +72,13 @@ ModuleSpec executable_spec; ModuleSP expected_executable(new Module(executable_spec)); - auto platform_sp = std::make_shared(false); - EXPECT_CALL(*platform_sp, ResolveExecutable(_, _)) - .WillRepeatedly(Return(std::make_pair(Status(), expected_executable))); - RemoteAwarePlatformTester platform(false); EXPECT_CALL(platform, GetSupportedArchitectureAtIndex(_, _)) .WillRepeatedly(Return(false)); + EXPECT_CALL(platform, ResolveRemoteExecutable(_, _)) + .WillRepeatedly(Return(std::make_pair(Status(), expected_executable))); - platform.SetRemotePlatform(platform_sp); + platform.SetRemotePlatform(std::make_shared(false)); ModuleSP resolved_sp; lldb_private::Status status =