[lldb][NFCI] Platforms should own their SDKBuild and SDKRootDirectory strings
These don't need to be ConstStrings. They don't really benefit much from deduplication and comparing them isn't on a hot path, so they don't really benefit much from quick comparisons. Differential Revision: https://reviews.llvm.org/D152331
This commit is contained in:
@@ -47,22 +47,24 @@ public:
|
||||
m_platform_name.clear();
|
||||
}
|
||||
|
||||
ConstString GetSDKRootDirectory() const { return m_sdk_sysroot; }
|
||||
const std::string &GetSDKRootDirectory() const { return m_sdk_sysroot; }
|
||||
|
||||
void SetSDKRootDirectory(ConstString sdk_root_directory) {
|
||||
m_sdk_sysroot = sdk_root_directory;
|
||||
void SetSDKRootDirectory(std::string sdk_root_directory) {
|
||||
m_sdk_sysroot = std::move(sdk_root_directory);
|
||||
}
|
||||
|
||||
ConstString GetSDKBuild() const { return m_sdk_build; }
|
||||
const std::string &GetSDKBuild() const { return m_sdk_build; }
|
||||
|
||||
void SetSDKBuild(ConstString sdk_build) { m_sdk_build = sdk_build; }
|
||||
void SetSDKBuild(std::string sdk_build) {
|
||||
m_sdk_build = std::move(sdk_build);
|
||||
}
|
||||
|
||||
bool PlatformMatches(const lldb::PlatformSP &platform_sp) const;
|
||||
|
||||
protected:
|
||||
std::string m_platform_name;
|
||||
ConstString m_sdk_sysroot;
|
||||
ConstString m_sdk_build;
|
||||
std::string m_sdk_sysroot;
|
||||
std::string m_sdk_build;
|
||||
llvm::VersionTuple m_os_version;
|
||||
bool m_include_platform_option;
|
||||
};
|
||||
|
||||
@@ -448,13 +448,15 @@ public:
|
||||
// Used for column widths
|
||||
size_t GetMaxGroupIDNameLength() const { return m_max_gid_name_len; }
|
||||
|
||||
ConstString GetSDKRootDirectory() const { return m_sdk_sysroot; }
|
||||
const std::string &GetSDKRootDirectory() const { return m_sdk_sysroot; }
|
||||
|
||||
void SetSDKRootDirectory(ConstString dir) { m_sdk_sysroot = dir; }
|
||||
void SetSDKRootDirectory(std::string dir) { m_sdk_sysroot = std::move(dir); }
|
||||
|
||||
ConstString GetSDKBuild() const { return m_sdk_build; }
|
||||
const std::string &GetSDKBuild() const { return m_sdk_build; }
|
||||
|
||||
void SetSDKBuild(ConstString sdk_build) { m_sdk_build = sdk_build; }
|
||||
void SetSDKBuild(std::string sdk_build) {
|
||||
m_sdk_build = std::move(sdk_build);
|
||||
}
|
||||
|
||||
// Override this to return true if your platform supports Clang modules. You
|
||||
// may also need to override AddClangModuleCompilationOptions to pass the
|
||||
@@ -900,9 +902,9 @@ protected:
|
||||
// the once we call HostInfo::GetOSVersion().
|
||||
bool m_os_version_set_while_connected;
|
||||
bool m_system_arch_set_while_connected;
|
||||
ConstString
|
||||
std::string
|
||||
m_sdk_sysroot; // the root location of where the SDK files are all located
|
||||
ConstString m_sdk_build;
|
||||
std::string m_sdk_build;
|
||||
FileSpec m_working_dir; // The working directory which is used when installing
|
||||
// modules that have no install path set
|
||||
std::string m_remote_url;
|
||||
|
||||
@@ -488,7 +488,7 @@ uint32_t SBPlatform::GetOSUpdateVersion() {
|
||||
void SBPlatform::SetSDKRoot(const char *sysroot) {
|
||||
LLDB_INSTRUMENT_VA(this, sysroot);
|
||||
if (PlatformSP platform_sp = GetSP())
|
||||
platform_sp->SetSDKRootDirectory(ConstString(sysroot));
|
||||
platform_sp->SetSDKRootDirectory(sysroot);
|
||||
}
|
||||
|
||||
SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
|
||||
|
||||
@@ -50,10 +50,10 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
|
||||
if (!m_os_version.empty())
|
||||
platform_sp->SetOSVersion(m_os_version);
|
||||
|
||||
if (m_sdk_sysroot)
|
||||
if (!m_sdk_sysroot.empty())
|
||||
platform_sp->SetSDKRootDirectory(m_sdk_sysroot);
|
||||
|
||||
if (m_sdk_build)
|
||||
if (!m_sdk_build.empty())
|
||||
platform_sp->SetSDKBuild(m_sdk_build);
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
|
||||
void OptionGroupPlatform::OptionParsingStarting(
|
||||
ExecutionContext *execution_context) {
|
||||
m_platform_name.clear();
|
||||
m_sdk_sysroot.Clear();
|
||||
m_sdk_build.Clear();
|
||||
m_sdk_sysroot.clear();
|
||||
m_sdk_build.clear();
|
||||
m_os_version = llvm::VersionTuple();
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
|
||||
|
||||
switch (short_option) {
|
||||
case 'p':
|
||||
m_platform_name.assign(std::string(option_arg));
|
||||
m_platform_name.assign(option_arg.str());
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
@@ -113,11 +113,11 @@ OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
m_sdk_build.SetString(option_arg);
|
||||
m_sdk_build.assign(option_arg.str());
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
m_sdk_sysroot.SetString(option_arg);
|
||||
m_sdk_sysroot.assign(option_arg.str());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -128,21 +128,21 @@ OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
|
||||
|
||||
bool OptionGroupPlatform::PlatformMatches(
|
||||
const lldb::PlatformSP &platform_sp) const {
|
||||
if (platform_sp) {
|
||||
if (!m_platform_name.empty()) {
|
||||
if (platform_sp->GetName() != m_platform_name)
|
||||
return false;
|
||||
}
|
||||
if (!platform_sp)
|
||||
return false;
|
||||
|
||||
if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild())
|
||||
return false;
|
||||
if (!m_platform_name.empty() && platform_sp->GetName() != m_platform_name)
|
||||
return false;
|
||||
|
||||
if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory())
|
||||
return false;
|
||||
if (!m_sdk_build.empty() && platform_sp->GetSDKBuild() != m_sdk_build)
|
||||
return false;
|
||||
|
||||
if (!m_os_version.empty() && m_os_version != platform_sp->GetOSVersion())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (!m_sdk_sysroot.empty() &&
|
||||
platform_sp->GetSDKRootDirectory() != m_sdk_sysroot)
|
||||
return false;
|
||||
|
||||
if (!m_os_version.empty() && platform_sp->GetOSVersion() != m_os_version)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ bool PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
|
||||
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());
|
||||
if (!m_sdk_sysroot.empty()) {
|
||||
FileSpec sdk_sysroot_fspec(m_sdk_sysroot.c_str());
|
||||
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);
|
||||
@@ -43,7 +43,7 @@ bool PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
|
||||
LLDB_LOGF(log,
|
||||
"PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded added "
|
||||
"--sysroot SDK directory %s",
|
||||
m_sdk_sysroot.GetCString());
|
||||
m_sdk_sysroot.c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -152,20 +152,20 @@ PlatformDarwinDevice::GetSDKDirectoryForCurrentOSVersion() {
|
||||
std::vector<bool> check_sdk_info(num_sdk_infos, true);
|
||||
|
||||
// Prefer the user SDK build string.
|
||||
ConstString build = GetSDKBuild();
|
||||
std::string build = GetSDKBuild();
|
||||
|
||||
// Fall back to the platform's build string.
|
||||
if (!build) {
|
||||
if (std::optional<std::string> os_build_str = GetOSBuildString()) {
|
||||
build = ConstString(*os_build_str);
|
||||
}
|
||||
if (build.empty()) {
|
||||
if (std::optional<std::string> os_build_str = GetOSBuildString())
|
||||
build.assign(*os_build_str);
|
||||
}
|
||||
|
||||
// If we have a build string, only check platforms for which the build
|
||||
// string matches.
|
||||
if (build) {
|
||||
if (!build.empty()) {
|
||||
for (i = 0; i < num_sdk_infos; ++i)
|
||||
check_sdk_info[i] = m_sdk_directory_infos[i].build == build;
|
||||
check_sdk_info[i] = m_sdk_directory_infos[i].build.GetStringRef() ==
|
||||
llvm::StringRef(build);
|
||||
}
|
||||
|
||||
// If we are connected we can find the version of the OS the platform us
|
||||
@@ -201,7 +201,7 @@ PlatformDarwinDevice::GetSDKDirectoryForCurrentOSVersion() {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (build) {
|
||||
} else if (!build.empty()) {
|
||||
// No version, just a build number, return the first one that matches.
|
||||
for (i = 0; i < num_sdk_infos; ++i)
|
||||
if (check_sdk_info[i])
|
||||
@@ -248,8 +248,8 @@ const char *PlatformDarwinDevice::GetDeviceSupportDirectory() {
|
||||
}
|
||||
|
||||
const char *PlatformDarwinDevice::GetDeviceSupportDirectoryForOSVersion() {
|
||||
if (m_sdk_sysroot)
|
||||
return m_sdk_sysroot.GetCString();
|
||||
if (!m_sdk_sysroot.empty())
|
||||
return m_sdk_sysroot.c_str();
|
||||
|
||||
if (m_device_support_directory_for_os_version.empty()) {
|
||||
const PlatformDarwinDevice::SDKDirectoryInfo *sdk_dir_info =
|
||||
|
||||
@@ -191,8 +191,8 @@ lldb::ProcessSP PlatformQemuUser::DebugProcess(ProcessLaunchInfo &launch_info,
|
||||
launch_info.SetArguments(args, true);
|
||||
|
||||
Environment emulator_env = Host::GetEnvironment();
|
||||
if (ConstString sysroot = GetSDKRootDirectory())
|
||||
emulator_env["QEMU_LD_PREFIX"] = sysroot.GetStringRef().str();
|
||||
if (const std::string &sysroot = GetSDKRootDirectory(); !sysroot.empty())
|
||||
emulator_env["QEMU_LD_PREFIX"] = sysroot;
|
||||
for (const auto &KV : GetGlobalProperties().GetEmulatorEnvVars())
|
||||
emulator_env[KV.first()] = KV.second;
|
||||
launch_info.GetEnvironment() = ComputeLaunchEnvironment(
|
||||
|
||||
@@ -210,11 +210,10 @@ Status Platform::GetSharedModule(
|
||||
Status error(eErrorTypeGeneric);
|
||||
ModuleSpec resolved_spec;
|
||||
// Check if we have sysroot set.
|
||||
if (m_sdk_sysroot) {
|
||||
if (!m_sdk_sysroot.empty()) {
|
||||
// Prepend sysroot to module spec.
|
||||
resolved_spec = spec;
|
||||
resolved_spec.GetFileSpec().PrependPathComponent(
|
||||
m_sdk_sysroot.GetStringRef());
|
||||
resolved_spec.GetFileSpec().PrependPathComponent(m_sdk_sysroot);
|
||||
// Try to get shared module with resolved spec.
|
||||
error = ModuleList::GetSharedModule(resolved_spec, module_sp,
|
||||
module_search_paths_ptr, old_modules,
|
||||
@@ -312,9 +311,9 @@ void Platform::GetStatus(Stream &strm) {
|
||||
strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
|
||||
}
|
||||
|
||||
if (GetSDKRootDirectory()) {
|
||||
strm.Format(" Sysroot: {0}\n", GetSDKRootDirectory());
|
||||
}
|
||||
if (const std::string &sdk_root = GetSDKRootDirectory(); !sdk_root.empty())
|
||||
strm.Format(" Sysroot: {0}\n", sdk_root);
|
||||
|
||||
if (GetWorkingDirectory()) {
|
||||
strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetPath().c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user