[lldb] Move GetSupportedArchitectureAtIndex to PlatformDarwin
authorPavel Labath <pavel@labath.sk>
Wed, 24 Nov 2021 14:47:20 +0000 (15:47 +0100)
committerPavel Labath <pavel@labath.sk>
Wed, 24 Nov 2021 14:48:23 +0000 (15:48 +0100)
All other platforms use GetSupportedArchitectures now.

lldb/include/lldb/Target/Platform.h
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
lldb/source/Target/Platform.cpp
lldb/source/Target/RemoteAwarePlatform.cpp
lldb/unittests/Target/RemoteAwarePlatformTest.cpp

index 956b29e45dbababa0575a8ef723fe1a4eea85ff8..e645e3ca95bee242c5a4d8ebddf480417e2a62c7 100644 (file)
@@ -310,25 +310,7 @@ public:
 
   /// 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<ArchSpec> GetSupportedArchitectures();
+  virtual std::vector<ArchSpec> GetSupportedArchitectures() = 0;
 
   virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target,
                                                  BreakpointSite *bp_site);
index 995b0703bc459915310dd77f03d31487dcf5535c..f5ce3017a8f1b7cba894a4a274336e0ce6c50f39 100644 (file)
@@ -1367,3 +1367,11 @@ FileSpec PlatformDarwin::GetCurrentCommandLineToolsDirectory() {
     return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
   return {};
 }
+
+std::vector<ArchSpec> PlatformDarwin::GetSupportedArchitectures() {
+  std::vector<ArchSpec> result;
+  ArchSpec arch;
+  for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(idx, arch); ++idx)
+    result.push_back(arch);
+  return result;
+}
index 28f257300571e2c0f9306e3bd1f91f7d2da25d46..1a97c22cafffbfa620bea84c3a3418a10cc2f941 100644 (file)
@@ -102,6 +102,8 @@ public:
   /// located in.
   static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory();
 
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
+
 protected:
   static const char *GetCompatibleArch(lldb_private::ArchSpec::Core core,
                                        size_t idx);
@@ -172,6 +174,10 @@ protected:
   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<std::string> m_sdk_path;
   std::mutex m_sdk_path_mutex;
index bd455310f08e9c80bb89cf7f6b405c63be4d71b9..d75e11b0ab450f6bc5700db4745f1d4d1bcf46b1 100644 (file)
@@ -1222,22 +1222,6 @@ Platform::CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> 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<ArchSpec> Platform::GetSupportedArchitectures() {
-  std::vector<ArchSpec> 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,
index eb39fc6db304e20a06d6920938f8cff65e3653a6..b92d4d5fcaa70700cbb85a7e16cbb1c26146052f 100644 (file)
@@ -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) {
index dba4f81b6cd5f8cd9c81abc8bb93c8612180641c..1cd6330ae5f1661ef39be5467c7c69a151f5520c 100644 (file)
@@ -26,7 +26,7 @@ public:
 
   MOCK_METHOD0(GetDescription, llvm::StringRef());
   MOCK_METHOD0(GetPluginName, llvm::StringRef());
-  MOCK_METHOD2(GetSupportedArchitectureAtIndex, bool(uint32_t, ArchSpec &));
+  MOCK_METHOD0(GetSupportedArchitectures, std::vector<ArchSpec>());
   MOCK_METHOD4(Attach,
                ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &));
   MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
@@ -53,7 +53,7 @@ public:
 
   MOCK_METHOD0(GetDescription, llvm::StringRef());
   MOCK_METHOD0(GetPluginName, llvm::StringRef());
-  MOCK_METHOD2(GetSupportedArchitectureAtIndex, bool(uint32_t, ArchSpec &));
+  MOCK_METHOD0(GetSupportedArchitectures, std::vector<ArchSpec>());
   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<ArchSpec>()));
   EXPECT_CALL(platform, ResolveRemoteExecutable(_, _))
       .WillRepeatedly(Return(std::make_pair(Status(), expected_executable)));