[lldb] Modernize Platform::GetOSBuildString

This commit is contained in:
Pavel Labath 2021-10-25 15:58:29 +02:00
parent 7d549acbb6
commit 40e4ac3e5b
11 changed files with 31 additions and 43 deletions

View File

@ -212,7 +212,7 @@ public:
bool SetOSVersion(llvm::VersionTuple os_version);
bool GetOSBuildString(std::string &s);
llvm::Optional<std::string> GetOSBuildString();
bool GetOSKernelDescription(std::string &s);
@ -240,9 +240,8 @@ public:
// HostInfo::GetOSVersion().
virtual bool GetRemoteOSVersion() { return false; }
virtual bool GetRemoteOSBuildString(std::string &s) {
s.clear();
return false;
virtual llvm::Optional<std::string> GetRemoteOSBuildString() {
return llvm::None;
}
virtual bool GetRemoteOSKernelDescription(std::string &s) {

View File

@ -64,7 +64,7 @@ public:
FileSpec &local_file) override;
bool GetRemoteOSVersion() override;
bool GetRemoteOSBuildString(std::string &s) override;
llvm::Optional<std::string> GetRemoteOSBuildString() override;
bool GetRemoteOSKernelDescription(std::string &s) override;
ArchSpec GetRemoteSystemArchitecture() override;

View File

@ -458,13 +458,11 @@ const char *SBPlatform::GetOSBuild() {
PlatformSP platform_sp(GetSP());
if (platform_sp) {
std::string s;
if (platform_sp->GetOSBuildString(s)) {
if (!s.empty()) {
// Const-ify the string so we don't need to worry about the lifetime of
// the string
return ConstString(s.c_str()).GetCString();
}
std::string s = platform_sp->GetOSBuildString().getValueOr("");
if (!s.empty()) {
// Const-ify the string so we don't need to worry about the lifetime of
// the string
return ConstString(s).GetCString();
}
}
return nullptr;

View File

@ -630,13 +630,12 @@ Status PlatformRemoteDarwinDevice::GetSharedModule(
uint32_t PlatformRemoteDarwinDevice::GetConnectedSDKIndex() {
if (IsConnected()) {
if (m_connected_module_sdk_idx == UINT32_MAX) {
std::string build;
if (GetRemoteOSBuildString(build)) {
if (llvm::Optional<std::string> build = GetRemoteOSBuildString()) {
const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
for (uint32_t i = 0; i < num_sdk_infos; ++i) {
const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[i];
if (strstr(sdk_dir_info.directory.GetFilename().AsCString(""),
build.c_str())) {
build->c_str())) {
m_connected_module_sdk_idx = i;
}
}

View File

@ -163,8 +163,8 @@ lldb_private::Status PlatformRemoteMacOSX::GetFileWithUUID(
#if !defined(__linux__)
local_os_build = HostInfo::GetOSBuildString().getValueOr("");
#endif
std::string remote_os_build;
m_remote_platform_sp->GetOSBuildString(remote_os_build);
llvm::Optional<std::string> remote_os_build =
m_remote_platform_sp->GetOSBuildString();
if (local_os_build == remote_os_build) {
// same OS version: the local file is good enough
local_file = platform_file;

View File

@ -241,8 +241,8 @@ bool PlatformRemoteGDBServer::GetRemoteOSVersion() {
return !m_os_version.empty();
}
bool PlatformRemoteGDBServer::GetRemoteOSBuildString(std::string &s) {
return m_gdb_client.GetOSBuildString(s);
llvm::Optional<std::string> PlatformRemoteGDBServer::GetRemoteOSBuildString() {
return m_gdb_client.GetOSBuildString();
}
bool PlatformRemoteGDBServer::GetRemoteOSKernelDescription(std::string &s) {

View File

@ -79,7 +79,7 @@ public:
bool GetRemoteOSVersion() override;
bool GetRemoteOSBuildString(std::string &s) override;
llvm::Optional<std::string> GetRemoteOSBuildString() override;
bool GetRemoteOSKernelDescription(std::string &s) override;

View File

@ -970,15 +970,12 @@ llvm::VersionTuple GDBRemoteCommunicationClient::GetMacCatalystVersion() {
return m_maccatalyst_version;
}
bool GDBRemoteCommunicationClient::GetOSBuildString(std::string &s) {
llvm::Optional<std::string> GDBRemoteCommunicationClient::GetOSBuildString() {
if (GetHostInfo()) {
if (!m_os_build.empty()) {
s = m_os_build;
return true;
}
if (!m_os_build.empty())
return m_os_build;
}
s.clear();
return false;
return llvm::None;
}
bool GDBRemoteCommunicationClient::GetOSKernelDescription(std::string &s) {

View File

@ -239,7 +239,7 @@ public:
llvm::VersionTuple GetMacCatalystVersion();
bool GetOSBuildString(std::string &s);
llvm::Optional<std::string> GetOSBuildString();
bool GetOSKernelDescription(std::string &s);

View File

@ -398,7 +398,6 @@ Platform::Platform(bool is_host)
Platform::~Platform() = default;
void Platform::GetStatus(Stream &strm) {
std::string s;
strm.Format(" Platform: {0}\n", GetPluginName());
ArchSpec arch(GetSystemArchitecture());
@ -414,8 +413,8 @@ void Platform::GetStatus(Stream &strm) {
if (!os_version.empty()) {
strm.Format("OS Version: {0}", os_version.getAsString());
if (GetOSBuildString(s))
strm.Printf(" (%s)", s.c_str());
if (llvm::Optional<std::string> s = GetOSBuildString())
strm.Format(" ({0})", *s);
strm.EOL();
}
@ -440,6 +439,7 @@ void Platform::GetStatus(Stream &strm) {
if (!specific_info.empty())
strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
std::string s;
if (GetOSKernelDescription(s))
strm.Printf(" Kernel: %s\n", s.c_str());
}
@ -486,14 +486,10 @@ llvm::VersionTuple Platform::GetOSVersion(Process *process) {
return llvm::VersionTuple();
}
bool Platform::GetOSBuildString(std::string &s) {
if (IsHost()) {
llvm::Optional<std::string> str = HostInfo::GetOSBuildString();
s = str.getValueOr("");
return str.hasValue();
}
s.clear();
return GetRemoteOSBuildString(s);
llvm::Optional<std::string> Platform::GetOSBuildString() {
if (IsHost())
return HostInfo::GetOSBuildString();
return GetRemoteOSBuildString();
}
bool Platform::GetOSKernelDescription(std::string &s) {

View File

@ -332,11 +332,10 @@ bool RemoteAwarePlatform::GetRemoteOSVersion() {
return false;
}
bool RemoteAwarePlatform::GetRemoteOSBuildString(std::string &s) {
llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() {
if (m_remote_platform_sp)
return m_remote_platform_sp->GetRemoteOSBuildString(s);
s.clear();
return false;
return m_remote_platform_sp->GetRemoteOSBuildString();
return llvm::None;
}
bool RemoteAwarePlatform::GetRemoteOSKernelDescription(std::string &s) {