diff --git a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h --- a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h +++ b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h @@ -47,22 +47,24 @@ 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; }; diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -448,13 +448,15 @@ // 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 @@ // 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; diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp --- a/lldb/source/API/SBPlatform.cpp +++ b/lldb/source/API/SBPlatform.cpp @@ -488,7 +488,7 @@ 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) { diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp --- a/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -50,10 +50,10 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp @@ -34,8 +34,8 @@ std::lock_guard 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 @@ 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 @@ std::vector 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 os_build_str = GetOSBuildString()) { - build = ConstString(*os_build_str); - } + if (build.empty()) { + if (std::optional 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 @@ } } } - } 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::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 = diff --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp --- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp +++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp @@ -191,8 +191,8 @@ 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( diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -210,11 +210,10 @@ 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 @@ 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()); }