Skip to content

Commit

Permalink
[lldb] Move GetSupportedArchitectureAtIndex to PlatformDarwin
Browse files Browse the repository at this point in the history
All other platforms use GetSupportedArchitectures now.
  • Loading branch information
labath committed Nov 24, 2021
1 parent 5ba795c commit 96beb30
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 46 deletions.
20 changes: 1 addition & 19 deletions lldb/include/lldb/Target/Platform.h
Expand Up @@ -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<ArchSpec> GetSupportedArchitectures();
virtual std::vector<ArchSpec> GetSupportedArchitectures() = 0;

virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target,
BreakpointSite *bp_site);
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Expand Up @@ -102,6 +102,8 @@ class PlatformDarwin : public PlatformPOSIX {
/// 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);
Expand Down Expand Up @@ -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<std::string> m_sdk_path;
std::mutex m_sdk_path_mutex;
Expand Down
16 changes: 0 additions & 16 deletions lldb/source/Target/Platform.cpp
Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions lldb/source/Target/RemoteAwarePlatform.cpp
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions lldb/unittests/Target/RemoteAwarePlatformTest.cpp
Expand Up @@ -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<ArchSpec>());
MOCK_METHOD4(Attach,
ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &));
MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
Expand All @@ -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<ArchSpec>());
MOCK_METHOD4(Attach,
ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &));
MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
Expand All @@ -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)));

Expand Down

0 comments on commit 96beb30

Please sign in to comment.