diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 956b29e45dbab..e645e3ca95bee 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -310,25 +310,7 @@ class Platform : public PluginInterface { /// Get the platform's supported architectures in the order in which they /// should be searched. - /// - /// \param[in] idx - /// A zero based architecture index - /// - /// \param[out] arch - /// A copy of the architecture at index if the return value is - /// \b true. - /// - /// \return - /// \b true if \a arch was filled in and is valid, \b false - /// otherwise. - virtual bool GetSupportedArchitectureAtIndex(uint32_t idx, - ArchSpec &arch); - - /// Get the platform's supported architectures in the order in which they - /// should be searched. - /// NB: This implementation is mutually recursive with - /// GetSupportedArchitectureAtIndex. Subclasses should implement one of them. - virtual std::vector GetSupportedArchitectures(); + virtual std::vector GetSupportedArchitectures() = 0; virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 995b0703bc459..f5ce3017a8f1b 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1367,3 +1367,11 @@ FileSpec PlatformDarwin::GetCurrentCommandLineToolsDirectory() { return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools")); return {}; } + +std::vector PlatformDarwin::GetSupportedArchitectures() { + std::vector result; + ArchSpec arch; + for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(idx, arch); ++idx) + result.push_back(arch); + return result; +} diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index 28f257300571e..1a97c22cafffb 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -102,6 +102,8 @@ class PlatformDarwin : public PlatformPOSIX { /// located in. static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory(); + std::vector GetSupportedArchitectures() override; + protected: static const char *GetCompatibleArch(lldb_private::ArchSpec::Core core, size_t idx); @@ -172,6 +174,10 @@ class PlatformDarwin : public PlatformPOSIX { static std::string FindComponentInPath(llvm::StringRef path, llvm::StringRef component); + virtual bool + GetSupportedArchitectureAtIndex(uint32_t idx, + lldb_private::ArchSpec &arch) = 0; + std::string m_developer_directory; llvm::StringMap m_sdk_path; std::mutex m_sdk_path_mutex; diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index bd455310f08e9..d75e11b0ab450 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -1222,22 +1222,6 @@ Platform::CreateArchList(llvm::ArrayRef archs, return list; } -bool Platform::GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) { - const auto &archs = GetSupportedArchitectures(); - if (idx >= archs.size()) - return false; - arch = archs[idx]; - return true; -} - -std::vector Platform::GetSupportedArchitectures() { - std::vector result; - ArchSpec arch; - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(idx, arch); ++idx) - result.push_back(arch); - return result; -} - /// Lets a platform answer if it is compatible with a given /// architecture and the target triple contained within. bool Platform::IsCompatibleArchitecture(const ArchSpec &arch, diff --git a/lldb/source/Target/RemoteAwarePlatform.cpp b/lldb/source/Target/RemoteAwarePlatform.cpp index eb39fc6db304e..b92d4d5fcaa70 100644 --- a/lldb/source/Target/RemoteAwarePlatform.cpp +++ b/lldb/source/Target/RemoteAwarePlatform.cpp @@ -131,9 +131,9 @@ Status RemoteAwarePlatform::ResolveExecutable( // 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) { + llvm::ListSeparator LS; + for (const ArchSpec &arch : GetSupportedArchitectures()) { + resolved_module_spec.GetArchitecture() = arch; error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, module_search_paths_ptr, nullptr, nullptr); // Did we find an executable using one of the @@ -144,10 +144,7 @@ Status RemoteAwarePlatform::ResolveExecutable( error.SetErrorToGenericError(); } - if (idx > 0) - arch_names.PutCString(", "); - arch_names.PutCString( - resolved_module_spec.GetArchitecture().GetArchitectureName()); + arch_names << LS << arch.GetArchitectureName(); } if (error.Fail() || !exe_module_sp) { diff --git a/lldb/unittests/Target/RemoteAwarePlatformTest.cpp b/lldb/unittests/Target/RemoteAwarePlatformTest.cpp index dba4f81b6cd5f..1cd6330ae5f16 100644 --- a/lldb/unittests/Target/RemoteAwarePlatformTest.cpp +++ b/lldb/unittests/Target/RemoteAwarePlatformTest.cpp @@ -26,7 +26,7 @@ class RemoteAwarePlatformTester : public RemoteAwarePlatform { MOCK_METHOD0(GetDescription, llvm::StringRef()); MOCK_METHOD0(GetPluginName, llvm::StringRef()); - MOCK_METHOD2(GetSupportedArchitectureAtIndex, bool(uint32_t, ArchSpec &)); + MOCK_METHOD0(GetSupportedArchitectures, std::vector()); MOCK_METHOD4(Attach, ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); @@ -53,7 +53,7 @@ class TargetPlatformTester : public Platform { MOCK_METHOD0(GetDescription, llvm::StringRef()); MOCK_METHOD0(GetPluginName, llvm::StringRef()); - MOCK_METHOD2(GetSupportedArchitectureAtIndex, bool(uint32_t, ArchSpec &)); + MOCK_METHOD0(GetSupportedArchitectures, std::vector()); MOCK_METHOD4(Attach, ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); @@ -73,8 +73,8 @@ TEST_F(RemoteAwarePlatformTest, TestResolveExecutabelOnClientByPlatform) { ModuleSP expected_executable(new Module(executable_spec)); RemoteAwarePlatformTester platform(false); - EXPECT_CALL(platform, GetSupportedArchitectureAtIndex(_, _)) - .WillRepeatedly(Return(false)); + EXPECT_CALL(platform, GetSupportedArchitectures()) + .WillRepeatedly(Return(std::vector())); EXPECT_CALL(platform, ResolveRemoteExecutable(_, _)) .WillRepeatedly(Return(std::make_pair(Status(), expected_executable)));