Skip to content

Commit

Permalink
Modernize Platform::GetOSKernelDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
labath committed Oct 27, 2021
1 parent b9e3af1 commit f5158ca
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 37 deletions.
7 changes: 3 additions & 4 deletions lldb/include/lldb/Target/Platform.h
Expand Up @@ -214,7 +214,7 @@ class Platform : public PluginInterface {

llvm::Optional<std::string> GetOSBuildString();

bool GetOSKernelDescription(std::string &s);
llvm::Optional<std::string> GetOSKernelDescription();

// Returns the name of the platform
ConstString GetName();
Expand Down Expand Up @@ -244,9 +244,8 @@ class Platform : public PluginInterface {
return llvm::None;
}

virtual bool GetRemoteOSKernelDescription(std::string &s) {
s.clear();
return false;
virtual llvm::Optional<std::string> GetRemoteOSKernelDescription() {
return llvm::None;
}

// Remote Platform subclasses need to override this function
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Target/RemoteAwarePlatform.h
Expand Up @@ -65,7 +65,7 @@ class RemoteAwarePlatform : public Platform {

bool GetRemoteOSVersion() override;
llvm::Optional<std::string> GetRemoteOSBuildString() override;
bool GetRemoteOSKernelDescription(std::string &s) override;
llvm::Optional<std::string> GetRemoteOSKernelDescription() override;
ArchSpec GetRemoteSystemArchitecture() override;

Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir,
Expand Down
12 changes: 5 additions & 7 deletions lldb/source/API/SBPlatform.cpp
Expand Up @@ -473,13 +473,11 @@ const char *SBPlatform::GetOSDescription() {

PlatformSP platform_sp(GetSP());
if (platform_sp) {
std::string s;
if (platform_sp->GetOSKernelDescription(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->GetOSKernelDescription().getValueOr("");
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();
}
}
return nullptr;
Expand Down
Expand Up @@ -240,8 +240,9 @@ llvm::Optional<std::string> PlatformRemoteGDBServer::GetRemoteOSBuildString() {
return m_gdb_client.GetOSBuildString();
}

bool PlatformRemoteGDBServer::GetRemoteOSKernelDescription(std::string &s) {
return m_gdb_client.GetOSKernelDescription(s);
llvm::Optional<std::string>
PlatformRemoteGDBServer::GetRemoteOSKernelDescription() {
return m_gdb_client.GetOSKernelDescription();
}

// Remote Platform subclasses need to override this function
Expand Down
Expand Up @@ -79,7 +79,7 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {

llvm::Optional<std::string> GetRemoteOSBuildString() override;

bool GetRemoteOSKernelDescription(std::string &s) override;
llvm::Optional<std::string> GetRemoteOSKernelDescription() override;

// Remote Platform subclasses need to override this function
ArchSpec GetRemoteSystemArchitecture() override;
Expand Down
Expand Up @@ -978,15 +978,13 @@ llvm::Optional<std::string> GDBRemoteCommunicationClient::GetOSBuildString() {
return llvm::None;
}

bool GDBRemoteCommunicationClient::GetOSKernelDescription(std::string &s) {
llvm::Optional<std::string>
GDBRemoteCommunicationClient::GetOSKernelDescription() {
if (GetHostInfo()) {
if (!m_os_kernel.empty()) {
s = m_os_kernel;
return true;
}
if (!m_os_kernel.empty())
return m_os_kernel;
}
s.clear();
return false;
return llvm::None;
}

bool GDBRemoteCommunicationClient::GetHostname(std::string &s) {
Expand Down
Expand Up @@ -241,7 +241,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase {

llvm::Optional<std::string> GetOSBuildString();

bool GetOSKernelDescription(std::string &s);
llvm::Optional<std::string> GetOSKernelDescription();

ArchSpec GetSystemArchitecture();

Expand Down
16 changes: 6 additions & 10 deletions lldb/source/Target/Platform.cpp
Expand Up @@ -439,9 +439,8 @@ 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());
if (llvm::Optional<std::string> s = GetOSKernelDescription())
strm.Format(" Kernel: {0}\n", *s);
}

llvm::VersionTuple Platform::GetOSVersion(Process *process) {
Expand Down Expand Up @@ -492,13 +491,10 @@ llvm::Optional<std::string> Platform::GetOSBuildString() {
return GetRemoteOSBuildString();
}

bool Platform::GetOSKernelDescription(std::string &s) {
if (IsHost()) {
llvm::Optional<std::string> desc = HostInfo::GetOSKernelDescription();
s = desc.getValueOr("");
return desc.hasValue();
}
return GetRemoteOSKernelDescription(s);
llvm::Optional<std::string> Platform::GetOSKernelDescription() {
if (IsHost())
return HostInfo::GetOSKernelDescription();
return GetRemoteOSKernelDescription();
}

void Platform::AddClangModuleCompilationOptions(
Expand Down
7 changes: 3 additions & 4 deletions lldb/source/Target/RemoteAwarePlatform.cpp
Expand Up @@ -338,11 +338,10 @@ llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() {
return llvm::None;
}

bool RemoteAwarePlatform::GetRemoteOSKernelDescription(std::string &s) {
llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSKernelDescription() {
if (m_remote_platform_sp)
return m_remote_platform_sp->GetRemoteOSKernelDescription(s);
s.clear();
return false;
return m_remote_platform_sp->GetRemoteOSKernelDescription();
return llvm::None;
}

ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() {
Expand Down

0 comments on commit f5158ca

Please sign in to comment.