[Lldb-commits] [lldb] 41c0ff1 - [lldb] Hoist device support out of PlatformRemoteDarwinDevice (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon May 2 17:34:51 PDT 2022
Author: Jonas Devlieghere
Date: 2022-05-02T17:34:40-07:00
New Revision: 41c0ff1e740bc0962104a2619b908f8c24e28741
URL: https://github.com/llvm/llvm-project/commit/41c0ff1e740bc0962104a2619b908f8c24e28741
DIFF: https://github.com/llvm/llvm-project/commit/41c0ff1e740bc0962104a2619b908f8c24e28741.diff
LOG: [lldb] Hoist device support out of PlatformRemoteDarwinDevice (NFC)
Refactoring in preparation of D124801.
Differential revision: https://reviews.llvm.org/D124799
Added:
lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.h
Modified:
lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt
lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt b/lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt
index bd9343773b3c2..3b43598741ed4 100644
--- a/lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt
+++ b/lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt
@@ -8,6 +8,7 @@ lldb_tablegen(PlatformMacOSXPropertiesEnum.inc -gen-lldb-property-enum-defs
list(APPEND PLUGIN_PLATFORM_MACOSX_SOURCES
PlatformDarwin.cpp
+ PlatformDarwinDevice.cpp
PlatformDarwinKernel.cpp
PlatformMacOSX.cpp
PlatformRemoteAppleBridge.cpp
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
new file mode 100644
index 0000000000000..90aacc3b4ca64
--- /dev/null
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
@@ -0,0 +1,265 @@
+//===-- PlatformDarwinDevice.cpp ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "PlatformDarwinDevice.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+PlatformDarwinDevice::~PlatformDarwinDevice() = default;
+
+FileSystem::EnumerateDirectoryResult
+PlatformDarwinDevice::GetContainedFilesIntoVectorOfStringsCallback(
+ void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) {
+ ((PlatformDarwinDevice::SDKDirectoryInfoCollection *)baton)
+ ->push_back(PlatformDarwinDevice::SDKDirectoryInfo(FileSpec(path)));
+ return FileSystem::eEnumerateDirectoryResultNext;
+}
+
+bool PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
+ Log *log = GetLog(LLDBLog::Host);
+ std::lock_guard<std::mutex> guard(m_sdk_dir_mutex);
+ if (m_sdk_directory_infos.empty()) {
+ // A --sysroot option was supplied - add it to our list of SDKs to check
+ if (m_sdk_sysroot) {
+ FileSpec sdk_sysroot_fspec(m_sdk_sysroot.GetCString());
+ FileSystem::Instance().Resolve(sdk_sysroot_fspec);
+ const SDKDirectoryInfo sdk_sysroot_directory_info(sdk_sysroot_fspec);
+ m_sdk_directory_infos.push_back(sdk_sysroot_directory_info);
+ if (log) {
+ LLDB_LOGF(log,
+ "PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded added "
+ "--sysroot SDK directory %s",
+ m_sdk_sysroot.GetCString());
+ }
+ return true;
+ }
+ const char *device_support_dir = GetDeviceSupportDirectory();
+ if (log) {
+ LLDB_LOGF(log,
+ "PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded Got "
+ "DeviceSupport directory %s",
+ device_support_dir);
+ }
+ if (device_support_dir) {
+ const bool find_directories = true;
+ const bool find_files = false;
+ const bool find_other = false;
+
+ SDKDirectoryInfoCollection builtin_sdk_directory_infos;
+ FileSystem::Instance().EnumerateDirectory(
+ m_device_support_directory, find_directories, find_files, find_other,
+ GetContainedFilesIntoVectorOfStringsCallback,
+ &builtin_sdk_directory_infos);
+
+ // Only add SDK directories that have symbols in them, some SDKs only
+ // contain developer disk images and no symbols, so they aren't useful to
+ // us.
+ FileSpec sdk_symbols_symlink_fspec;
+ for (const auto &sdk_directory_info : builtin_sdk_directory_infos) {
+ sdk_symbols_symlink_fspec = sdk_directory_info.directory;
+ sdk_symbols_symlink_fspec.AppendPathComponent("Symbols");
+ if (FileSystem::Instance().Exists(sdk_symbols_symlink_fspec)) {
+ m_sdk_directory_infos.push_back(sdk_directory_info);
+ if (log) {
+ LLDB_LOGF(log,
+ "PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
+ "added builtin SDK directory %s",
+ sdk_symbols_symlink_fspec.GetPath().c_str());
+ }
+ }
+ }
+
+ const uint32_t num_installed = m_sdk_directory_infos.size();
+ llvm::StringRef dirname = GetDeviceSupportDirectoryName();
+ std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
+ local_sdk_cache_str += std::string(dirname);
+ FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
+ FileSystem::Instance().Resolve(local_sdk_cache);
+ if (FileSystem::Instance().Exists(local_sdk_cache)) {
+ if (log) {
+ LLDB_LOGF(log,
+ "PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
+ "searching %s for additional SDKs",
+ local_sdk_cache.GetPath().c_str());
+ }
+ char path[PATH_MAX];
+ if (local_sdk_cache.GetPath(path, sizeof(path))) {
+ FileSystem::Instance().EnumerateDirectory(
+ path, find_directories, find_files, find_other,
+ GetContainedFilesIntoVectorOfStringsCallback,
+ &m_sdk_directory_infos);
+ const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
+ // First try for an exact match of major, minor and update
+ for (uint32_t i = num_installed; i < num_sdk_infos; ++i) {
+ m_sdk_directory_infos[i].user_cached = true;
+ if (log) {
+ LLDB_LOGF(log,
+ "PlatformDarwinDevice::"
+ "UpdateSDKDirectoryInfosIfNeeded "
+ "user SDK directory %s",
+ m_sdk_directory_infos[i].directory.GetPath().c_str());
+ }
+ }
+ }
+ }
+
+ const char *addtional_platform_dirs = getenv("PLATFORM_SDK_DIRECTORY");
+ if (addtional_platform_dirs) {
+ SDKDirectoryInfoCollection env_var_sdk_directory_infos;
+ FileSystem::Instance().EnumerateDirectory(
+ addtional_platform_dirs, find_directories, find_files, find_other,
+ GetContainedFilesIntoVectorOfStringsCallback,
+ &env_var_sdk_directory_infos);
+ FileSpec sdk_symbols_symlink_fspec;
+ for (const auto &sdk_directory_info : env_var_sdk_directory_infos) {
+ sdk_symbols_symlink_fspec = sdk_directory_info.directory;
+ sdk_symbols_symlink_fspec.AppendPathComponent("Symbols");
+ if (FileSystem::Instance().Exists(sdk_symbols_symlink_fspec)) {
+ m_sdk_directory_infos.push_back(sdk_directory_info);
+ if (log) {
+ LLDB_LOGF(log,
+ "PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
+ "added env var SDK directory %s",
+ sdk_symbols_symlink_fspec.GetPath().c_str());
+ }
+ }
+ }
+ }
+ }
+ }
+ return !m_sdk_directory_infos.empty();
+}
+
+const PlatformDarwinDevice::SDKDirectoryInfo *
+PlatformDarwinDevice::GetSDKDirectoryForCurrentOSVersion() {
+ uint32_t i;
+ if (UpdateSDKDirectoryInfosIfNeeded()) {
+ const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
+
+ // Check to see if the user specified a build string. If they did, then be
+ // sure to match it.
+ std::vector<bool> check_sdk_info(num_sdk_infos, true);
+ ConstString build(m_sdk_build);
+ if (build) {
+ for (i = 0; i < num_sdk_infos; ++i)
+ check_sdk_info[i] = m_sdk_directory_infos[i].build == build;
+ }
+
+ // If we are connected we can find the version of the OS the platform us
+ // running on and select the right SDK
+ llvm::VersionTuple version = GetOSVersion();
+ if (!version.empty()) {
+ if (UpdateSDKDirectoryInfosIfNeeded()) {
+ // First try for an exact match of major, minor and update
+ for (i = 0; i < num_sdk_infos; ++i) {
+ if (check_sdk_info[i]) {
+ if (m_sdk_directory_infos[i].version == version)
+ return &m_sdk_directory_infos[i];
+ }
+ }
+ // First try for an exact match of major and minor
+ for (i = 0; i < num_sdk_infos; ++i) {
+ if (check_sdk_info[i]) {
+ if (m_sdk_directory_infos[i].version.getMajor() ==
+ version.getMajor() &&
+ m_sdk_directory_infos[i].version.getMinor() ==
+ version.getMinor()) {
+ return &m_sdk_directory_infos[i];
+ }
+ }
+ }
+ // Lastly try to match of major version only..
+ for (i = 0; i < num_sdk_infos; ++i) {
+ if (check_sdk_info[i]) {
+ if (m_sdk_directory_infos[i].version.getMajor() ==
+ version.getMajor()) {
+ return &m_sdk_directory_infos[i];
+ }
+ }
+ }
+ }
+ } else if (build) {
+ // No version, just a build number, search for the first one that matches
+ for (i = 0; i < num_sdk_infos; ++i)
+ if (check_sdk_info[i])
+ return &m_sdk_directory_infos[i];
+ }
+ }
+ return nullptr;
+}
+
+const PlatformDarwinDevice::SDKDirectoryInfo *
+PlatformDarwinDevice::GetSDKDirectoryForLatestOSVersion() {
+ const PlatformDarwinDevice::SDKDirectoryInfo *result = nullptr;
+ if (UpdateSDKDirectoryInfosIfNeeded()) {
+ auto max = std::max_element(
+ m_sdk_directory_infos.begin(), m_sdk_directory_infos.end(),
+ [](const SDKDirectoryInfo &a, const SDKDirectoryInfo &b) {
+ return a.version < b.version;
+ });
+ if (max != m_sdk_directory_infos.end())
+ result = &*max;
+ }
+ return result;
+}
+
+const char *PlatformDarwinDevice::GetDeviceSupportDirectory() {
+ std::string platform_dir =
+ ("/Platforms/" + GetPlatformName() + "/DeviceSupport").str();
+ if (m_device_support_directory.empty()) {
+ if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
+ m_device_support_directory = fspec.GetPath();
+ m_device_support_directory.append(platform_dir.c_str());
+ } else {
+ // Assign a single NULL character so we know we tried to find the device
+ // support directory and we don't keep trying to find it over and over.
+ m_device_support_directory.assign(1, '\0');
+ }
+ }
+ // We should have put a single NULL character into m_device_support_directory
+ // or it should have a valid path if the code gets here
+ assert(m_device_support_directory.empty() == false);
+ if (m_device_support_directory[0])
+ return m_device_support_directory.c_str();
+ return nullptr;
+}
+
+const char *PlatformDarwinDevice::GetDeviceSupportDirectoryForOSVersion() {
+ if (m_sdk_sysroot)
+ return m_sdk_sysroot.GetCString();
+
+ if (m_device_support_directory_for_os_version.empty()) {
+ const PlatformDarwinDevice::SDKDirectoryInfo *sdk_dir_info =
+ GetSDKDirectoryForCurrentOSVersion();
+ if (sdk_dir_info == nullptr)
+ sdk_dir_info = GetSDKDirectoryForLatestOSVersion();
+ if (sdk_dir_info) {
+ char path[PATH_MAX];
+ if (sdk_dir_info->directory.GetPath(path, sizeof(path))) {
+ m_device_support_directory_for_os_version = path;
+ return m_device_support_directory_for_os_version.c_str();
+ }
+ } else {
+ // Assign a single NULL character so we know we tried to find the device
+ // support directory and we don't keep trying to find it over and over.
+ m_device_support_directory_for_os_version.assign(1, '\0');
+ }
+ }
+ // We should have put a single NULL character into
+ // m_device_support_directory_for_os_version or it should have a valid path
+ // if the code gets here
+ assert(m_device_support_directory_for_os_version.empty() == false);
+ if (m_device_support_directory_for_os_version[0])
+ return m_device_support_directory_for_os_version.c_str();
+ return nullptr;
+}
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.h
new file mode 100644
index 0000000000000..a3c9128a2c5c2
--- /dev/null
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.h
@@ -0,0 +1,62 @@
+//===-- PlatformDarwinDevice.h ----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINDEVICE_H
+#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINDEVICE_H
+
+#include "PlatformDarwin.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <string>
+
+namespace lldb_private {
+
+/// Abstract Darwin platform with a potential device support directory.
+class PlatformDarwinDevice : public PlatformDarwin {
+public:
+ using PlatformDarwin::PlatformDarwin;
+ ~PlatformDarwinDevice() override;
+
+protected:
+ struct SDKDirectoryInfo {
+ SDKDirectoryInfo(const FileSpec &sdk_dir_spec);
+ FileSpec directory;
+ ConstString build;
+ llvm::VersionTuple version;
+ bool user_cached;
+ };
+
+ typedef std::vector<SDKDirectoryInfo> SDKDirectoryInfoCollection;
+
+ bool UpdateSDKDirectoryInfosIfNeeded();
+
+ const SDKDirectoryInfo *GetSDKDirectoryForLatestOSVersion();
+ const SDKDirectoryInfo *GetSDKDirectoryForCurrentOSVersion();
+
+ static FileSystem::EnumerateDirectoryResult
+ GetContainedFilesIntoVectorOfStringsCallback(void *baton,
+ llvm::sys::fs::file_type ft,
+ llvm::StringRef path);
+
+ const char *GetDeviceSupportDirectory();
+ const char *GetDeviceSupportDirectoryForOSVersion();
+
+ virtual llvm::StringRef GetPlatformName() = 0;
+ virtual llvm::StringRef GetDeviceSupportDirectoryName() = 0;
+
+ std::mutex m_sdk_dir_mutex;
+ SDKDirectoryInfoCollection m_sdk_directory_infos;
+
+private:
+ std::string m_device_support_directory;
+ std::string m_device_support_directory_for_os_version;
+};
+} // namespace lldb_private
+
+#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINDEVICE_H
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
index 83e98ff4e06a2..7dd8c38015677 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
@@ -38,9 +38,7 @@ PlatformRemoteDarwinDevice::SDKDirectoryInfo::SDKDirectoryInfo(
/// Default Constructor
PlatformRemoteDarwinDevice::PlatformRemoteDarwinDevice()
- : PlatformDarwin(false), // This is a remote platform
- m_sdk_directory_infos(), m_device_support_directory(),
- m_device_support_directory_for_os_version(), m_build_update() {}
+ : PlatformDarwinDevice(false) {} // This is a remote platform
/// Destructor.
///
@@ -129,259 +127,6 @@ Status PlatformRemoteDarwinDevice::ResolveExecutable(
return error;
}
-FileSystem::EnumerateDirectoryResult
-PlatformRemoteDarwinDevice::GetContainedFilesIntoVectorOfStringsCallback(
- void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) {
- ((PlatformRemoteDarwinDevice::SDKDirectoryInfoCollection *)baton)
- ->push_back(PlatformRemoteDarwinDevice::SDKDirectoryInfo(FileSpec(path)));
- return FileSystem::eEnumerateDirectoryResultNext;
-}
-
-bool PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
- Log *log = GetLog(LLDBLog::Host);
- std::lock_guard<std::mutex> guard(m_sdk_dir_mutex);
- if (m_sdk_directory_infos.empty()) {
- // A --sysroot option was supplied - add it to our list of SDKs to check
- if (m_sdk_sysroot) {
- FileSpec sdk_sysroot_fspec(m_sdk_sysroot.GetCString());
- FileSystem::Instance().Resolve(sdk_sysroot_fspec);
- const SDKDirectoryInfo sdk_sysroot_directory_info(sdk_sysroot_fspec);
- m_sdk_directory_infos.push_back(sdk_sysroot_directory_info);
- if (log) {
- LLDB_LOGF(
- log,
- "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded added "
- "--sysroot SDK directory %s",
- m_sdk_sysroot.GetCString());
- }
- return true;
- }
- const char *device_support_dir = GetDeviceSupportDirectory();
- if (log) {
- LLDB_LOGF(
- log,
- "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded Got "
- "DeviceSupport directory %s",
- device_support_dir);
- }
- if (device_support_dir) {
- const bool find_directories = true;
- const bool find_files = false;
- const bool find_other = false;
-
- SDKDirectoryInfoCollection builtin_sdk_directory_infos;
- FileSystem::Instance().EnumerateDirectory(
- m_device_support_directory, find_directories, find_files, find_other,
- GetContainedFilesIntoVectorOfStringsCallback,
- &builtin_sdk_directory_infos);
-
- // Only add SDK directories that have symbols in them, some SDKs only
- // contain developer disk images and no symbols, so they aren't useful to
- // us.
- FileSpec sdk_symbols_symlink_fspec;
- for (const auto &sdk_directory_info : builtin_sdk_directory_infos) {
- sdk_symbols_symlink_fspec = sdk_directory_info.directory;
- sdk_symbols_symlink_fspec.AppendPathComponent("Symbols");
- if (FileSystem::Instance().Exists(sdk_symbols_symlink_fspec)) {
- m_sdk_directory_infos.push_back(sdk_directory_info);
- if (log) {
- LLDB_LOGF(
- log,
- "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
- "added builtin SDK directory %s",
- sdk_symbols_symlink_fspec.GetPath().c_str());
- }
- }
- }
-
- const uint32_t num_installed = m_sdk_directory_infos.size();
- llvm::StringRef dirname = GetDeviceSupportDirectoryName();
- std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
- local_sdk_cache_str += std::string(dirname);
- FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
- FileSystem::Instance().Resolve(local_sdk_cache);
- if (FileSystem::Instance().Exists(local_sdk_cache)) {
- if (log) {
- LLDB_LOGF(
- log,
- "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
- "searching %s for additional SDKs",
- local_sdk_cache.GetPath().c_str());
- }
- char path[PATH_MAX];
- if (local_sdk_cache.GetPath(path, sizeof(path))) {
- FileSystem::Instance().EnumerateDirectory(
- path, find_directories, find_files, find_other,
- GetContainedFilesIntoVectorOfStringsCallback,
- &m_sdk_directory_infos);
- const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
- // First try for an exact match of major, minor and update
- for (uint32_t i = num_installed; i < num_sdk_infos; ++i) {
- m_sdk_directory_infos[i].user_cached = true;
- if (log) {
- LLDB_LOGF(log,
- "PlatformRemoteDarwinDevice::"
- "UpdateSDKDirectoryInfosIfNeeded "
- "user SDK directory %s",
- m_sdk_directory_infos[i].directory.GetPath().c_str());
- }
- }
- }
- }
-
- const char *addtional_platform_dirs = getenv("PLATFORM_SDK_DIRECTORY");
- if (addtional_platform_dirs) {
- SDKDirectoryInfoCollection env_var_sdk_directory_infos;
- FileSystem::Instance().EnumerateDirectory(
- addtional_platform_dirs, find_directories, find_files, find_other,
- GetContainedFilesIntoVectorOfStringsCallback,
- &env_var_sdk_directory_infos);
- FileSpec sdk_symbols_symlink_fspec;
- for (const auto &sdk_directory_info : env_var_sdk_directory_infos) {
- sdk_symbols_symlink_fspec = sdk_directory_info.directory;
- sdk_symbols_symlink_fspec.AppendPathComponent("Symbols");
- if (FileSystem::Instance().Exists(sdk_symbols_symlink_fspec)) {
- m_sdk_directory_infos.push_back(sdk_directory_info);
- if (log) {
- LLDB_LOGF(
- log,
- "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
- "added env var SDK directory %s",
- sdk_symbols_symlink_fspec.GetPath().c_str());
- }
- }
- }
- }
-
- }
- }
- return !m_sdk_directory_infos.empty();
-}
-
-const PlatformRemoteDarwinDevice::SDKDirectoryInfo *
-PlatformRemoteDarwinDevice::GetSDKDirectoryForCurrentOSVersion() {
- uint32_t i;
- if (UpdateSDKDirectoryInfosIfNeeded()) {
- const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
-
- // Check to see if the user specified a build string. If they did, then be
- // sure to match it.
- std::vector<bool> check_sdk_info(num_sdk_infos, true);
- ConstString build(m_sdk_build);
- if (build) {
- for (i = 0; i < num_sdk_infos; ++i)
- check_sdk_info[i] = m_sdk_directory_infos[i].build == build;
- }
-
- // If we are connected we can find the version of the OS the platform us
- // running on and select the right SDK
- llvm::VersionTuple version = GetOSVersion();
- if (!version.empty()) {
- if (UpdateSDKDirectoryInfosIfNeeded()) {
- // First try for an exact match of major, minor and update
- for (i = 0; i < num_sdk_infos; ++i) {
- if (check_sdk_info[i]) {
- if (m_sdk_directory_infos[i].version == version)
- return &m_sdk_directory_infos[i];
- }
- }
- // First try for an exact match of major and minor
- for (i = 0; i < num_sdk_infos; ++i) {
- if (check_sdk_info[i]) {
- if (m_sdk_directory_infos[i].version.getMajor() ==
- version.getMajor() &&
- m_sdk_directory_infos[i].version.getMinor() ==
- version.getMinor()) {
- return &m_sdk_directory_infos[i];
- }
- }
- }
- // Lastly try to match of major version only..
- for (i = 0; i < num_sdk_infos; ++i) {
- if (check_sdk_info[i]) {
- if (m_sdk_directory_infos[i].version.getMajor() ==
- version.getMajor()) {
- return &m_sdk_directory_infos[i];
- }
- }
- }
- }
- } else if (build) {
- // No version, just a build number, search for the first one that matches
- for (i = 0; i < num_sdk_infos; ++i)
- if (check_sdk_info[i])
- return &m_sdk_directory_infos[i];
- }
- }
- return nullptr;
-}
-
-const PlatformRemoteDarwinDevice::SDKDirectoryInfo *
-PlatformRemoteDarwinDevice::GetSDKDirectoryForLatestOSVersion() {
- const PlatformRemoteDarwinDevice::SDKDirectoryInfo *result = nullptr;
- if (UpdateSDKDirectoryInfosIfNeeded()) {
- auto max = std::max_element(
- m_sdk_directory_infos.begin(), m_sdk_directory_infos.end(),
- [](const SDKDirectoryInfo &a, const SDKDirectoryInfo &b) {
- return a.version < b.version;
- });
- if (max != m_sdk_directory_infos.end())
- result = &*max;
- }
- return result;
-}
-
-const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectory() {
- std::string platform_dir =
- ("/Platforms/" + GetPlatformName() + "/DeviceSupport").str();
- if (m_device_support_directory.empty()) {
- if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
- m_device_support_directory = fspec.GetPath();
- m_device_support_directory.append(platform_dir.c_str());
- } else {
- // Assign a single NULL character so we know we tried to find the device
- // support directory and we don't keep trying to find it over and over.
- m_device_support_directory.assign(1, '\0');
- }
- }
- // We should have put a single NULL character into m_device_support_directory
- // or it should have a valid path if the code gets here
- assert(m_device_support_directory.empty() == false);
- if (m_device_support_directory[0])
- return m_device_support_directory.c_str();
- return nullptr;
-}
-
-const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectoryForOSVersion() {
- if (m_sdk_sysroot)
- return m_sdk_sysroot.GetCString();
-
- if (m_device_support_directory_for_os_version.empty()) {
- const PlatformRemoteDarwinDevice::SDKDirectoryInfo *sdk_dir_info =
- GetSDKDirectoryForCurrentOSVersion();
- if (sdk_dir_info == nullptr)
- sdk_dir_info = GetSDKDirectoryForLatestOSVersion();
- if (sdk_dir_info) {
- char path[PATH_MAX];
- if (sdk_dir_info->directory.GetPath(path, sizeof(path))) {
- m_device_support_directory_for_os_version = path;
- return m_device_support_directory_for_os_version.c_str();
- }
- } else {
- // Assign a single NULL character so we know we tried to find the device
- // support directory and we don't keep trying to find it over and over.
- m_device_support_directory_for_os_version.assign(1, '\0');
- }
- }
- // We should have put a single NULL character into
- // m_device_support_directory_for_os_version or it should have a valid path
- // if the code gets here
- assert(m_device_support_directory_for_os_version.empty() == false);
- if (m_device_support_directory_for_os_version[0])
- return m_device_support_directory_for_os_version.c_str();
- return nullptr;
-}
-
bool PlatformRemoteDarwinDevice::GetFileInSDK(const char *platform_file_path,
uint32_t sdk_idx,
lldb_private::FileSpec &local_file) {
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h
index 6623a94f5745c..c604866040995 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h
@@ -1,5 +1,4 @@
-//===-- PlatformRemoteDarwinDevice.h -------------------------------------*- C++
-//-*-===//
+//===-- PlatformRemoteDarwinDevice.h ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,7 +9,7 @@
#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEDARWINDEVICE_H
#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEDARWINDEVICE_H
-#include "PlatformDarwin.h"
+#include "PlatformDarwinDevice.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"
@@ -34,7 +33,7 @@ class Stream;
class Target;
class UUID;
-class PlatformRemoteDarwinDevice : public PlatformDarwin {
+class PlatformRemoteDarwinDevice : public PlatformDarwinDevice {
public:
PlatformRemoteDarwinDevice();
@@ -64,39 +63,10 @@ class PlatformRemoteDarwinDevice : public PlatformDarwin {
}
protected:
- struct SDKDirectoryInfo {
- SDKDirectoryInfo(const FileSpec &sdk_dir_spec);
- FileSpec directory;
- ConstString build;
- llvm::VersionTuple version;
- bool user_cached;
- };
-
- typedef std::vector<SDKDirectoryInfo> SDKDirectoryInfoCollection;
-
- std::mutex m_sdk_dir_mutex;
- SDKDirectoryInfoCollection m_sdk_directory_infos;
- std::string m_device_support_directory;
- std::string m_device_support_directory_for_os_version;
std::string m_build_update;
uint32_t m_last_module_sdk_idx = UINT32_MAX;
uint32_t m_connected_module_sdk_idx = UINT32_MAX;
- bool UpdateSDKDirectoryInfosIfNeeded();
-
- const char *GetDeviceSupportDirectory();
-
- const char *GetDeviceSupportDirectoryForOSVersion();
-
- const SDKDirectoryInfo *GetSDKDirectoryForLatestOSVersion();
-
- const SDKDirectoryInfo *GetSDKDirectoryForCurrentOSVersion();
-
- static FileSystem::EnumerateDirectoryResult
- GetContainedFilesIntoVectorOfStringsCallback(void *baton,
- llvm::sys::fs::file_type ft,
- llvm::StringRef path);
-
bool GetFileInSDK(const char *platform_file_path, uint32_t sdk_idx,
FileSpec &local_file);
@@ -106,9 +76,6 @@ class PlatformRemoteDarwinDevice : public PlatformDarwin {
// UINT32_MAX if that SDK not found.
uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info);
- virtual llvm::StringRef GetDeviceSupportDirectoryName() = 0;
- virtual llvm::StringRef GetPlatformName() = 0;
-
private:
PlatformRemoteDarwinDevice(const PlatformRemoteDarwinDevice &) = delete;
const PlatformRemoteDarwinDevice &
More information about the lldb-commits
mailing list