Push down more common code into PlatformPOSIX

Summary:
- GetFileWithUUID: All platforms except PlatformDarwin had this.
However, I see no reason why this code would not apply there as well.

- GetProcessInfo, FindProcesses: The implementation was the same in all classes.

- GetFullNameForDylib: This code should apply to all non-darwin
platforms. I've kept the PlatformDarwin override as the situation is
different there.

Reviewers: clayborg, krytarowski, emaste

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D29496

llvm-svn: 294019
This commit is contained in:
Pavel Labath 2017-02-03 17:42:04 +00:00
parent bd26de5021
commit ec9bc8ccd4
12 changed files with 51 additions and 226 deletions

View File

@ -134,21 +134,6 @@ Error PlatformFreeBSD::RunShellCommand(const char *command,
}
}
// From PlatformMacOSX only
Error PlatformFreeBSD::GetFileWithUUID(const FileSpec &platform_file,
const UUID *uuid_ptr,
FileSpec &local_file) {
if (IsRemote()) {
if (m_remote_platform_sp)
return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
local_file);
}
// Default to the local case
local_file = platform_file;
return Error();
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
@ -256,33 +241,6 @@ Error PlatformFreeBSD::DisconnectRemote() {
return error;
}
bool PlatformFreeBSD::GetProcessInfo(lldb::pid_t pid,
ProcessInstanceInfo &process_info) {
bool success = false;
if (IsHost()) {
success = Platform::GetProcessInfo(pid, process_info);
} else if (m_remote_platform_sp) {
success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
}
return success;
}
uint32_t
PlatformFreeBSD::FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
uint32_t match_count = 0;
if (IsHost()) {
// Let the base class figure out the host details
match_count = Platform::FindProcesses(match_info, process_infos);
} else {
// If we are remote, we can only return results if we are connected
if (m_remote_platform_sp)
match_count =
m_remote_platform_sp->FindProcesses(match_info, process_infos);
}
return match_count;
}
const char *PlatformFreeBSD::GetUserName(uint32_t uid) {
// Check the cache in Platform in case we have already looked this uid up
const char *user_name = Platform::GetUserName(uid);

View File

@ -84,11 +84,6 @@ public:
const char *GetGroupName(uint32_t gid) override;
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) override;
Error LaunchProcess(ProcessLaunchInfo &launch_info) override;
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
@ -97,10 +92,6 @@ public:
// FreeBSD processes can not be launched by spawning and attaching.
bool CanDebugProcess() override { return false; }
// Only on PlatformMacOSX:
Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
FileSpec &local_file) override;
Error GetSharedModule(const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,

View File

@ -84,12 +84,6 @@ void PlatformKalimba::Terminate() {
Platform::Terminate();
}
Error PlatformKalimba::GetFileWithUUID(const FileSpec & /*platform_file*/,
const UUID * /*uuid_ptr*/,
FileSpec & /*local_file*/) {
return Error();
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
@ -105,18 +99,6 @@ PlatformKalimba::PlatformKalimba(bool is_host)
//------------------------------------------------------------------
PlatformKalimba::~PlatformKalimba() {}
bool PlatformKalimba::GetProcessInfo(lldb::pid_t pid,
ProcessInstanceInfo &process_info) {
bool success = false;
if (IsHost()) {
success = false;
} else {
if (m_remote_platform_sp)
success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
}
return success;
}
bool PlatformKalimba::GetSupportedArchitectureAtIndex(uint32_t idx,
ArchSpec &arch) {
if (idx == 0) {

View File

@ -51,11 +51,6 @@ public:
void GetStatus(Stream &strm) override;
Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
FileSpec &local_file) override;
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
size_t GetSoftwareBreakpointTrapOpcode(Target &target,

View File

@ -205,20 +205,6 @@ void PlatformLinux::Terminate() {
PlatformPOSIX::Terminate();
}
Error PlatformLinux::GetFileWithUUID(const FileSpec &platform_file,
const UUID *uuid_ptr,
FileSpec &local_file) {
if (IsRemote()) {
if (m_remote_platform_sp)
return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
local_file);
}
// Default to the local case
local_file = platform_file;
return Error();
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
@ -226,42 +212,8 @@ PlatformLinux::PlatformLinux(bool is_host)
: PlatformPOSIX(is_host) // This is the local host platform
{}
//------------------------------------------------------------------
/// Destructor.
///
/// The destructor is virtual since this class is designed to be
/// inherited from by the plug-in instance.
//------------------------------------------------------------------
PlatformLinux::~PlatformLinux() = default;
bool PlatformLinux::GetProcessInfo(lldb::pid_t pid,
ProcessInstanceInfo &process_info) {
bool success = false;
if (IsHost()) {
success = Platform::GetProcessInfo(pid, process_info);
} else {
if (m_remote_platform_sp)
success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
}
return success;
}
uint32_t
PlatformLinux::FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
uint32_t match_count = 0;
if (IsHost()) {
// Let the base class figure out the host details
match_count = Platform::FindProcesses(match_info, process_infos);
} else {
// If we are remote, we can only return results if we are connected
if (m_remote_platform_sp)
match_count =
m_remote_platform_sp->FindProcesses(match_info, process_infos);
}
return match_count;
}
bool PlatformLinux::GetSupportedArchitectureAtIndex(uint32_t idx,
ArchSpec &arch) {
if (IsHost()) {
@ -582,11 +534,3 @@ uint64_t PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
return flags_platform;
}
ConstString PlatformLinux::GetFullNameForDylib(ConstString basename) {
if (basename.IsEmpty())
return basename;
StreamString stream;
stream.Printf("lib%s.so", basename.GetCString());
return ConstString(stream.GetString());
}

View File

@ -53,14 +53,6 @@ public:
void GetStatus(Stream &strm) override;
Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
FileSpec &local_file) override;
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) override;
bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
int32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;
@ -76,8 +68,6 @@ public:
uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) override;
ConstString GetFullNameForDylib(ConstString basename) override;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformLinux);
};

View File

@ -489,34 +489,6 @@ PlatformDarwin::GetSoftwareBreakpointTrapOpcode(Target &target,
return 0;
}
bool PlatformDarwin::GetProcessInfo(lldb::pid_t pid,
ProcessInstanceInfo &process_info) {
bool success = false;
if (IsHost()) {
success = Platform::GetProcessInfo(pid, process_info);
} else {
if (m_remote_platform_sp)
success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
}
return success;
}
uint32_t
PlatformDarwin::FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
uint32_t match_count = 0;
if (IsHost()) {
// Let the base class figure out the host details
match_count = Platform::FindProcesses(match_info, process_infos);
} else {
// If we are remote, we can only return results if we are connected
if (m_remote_platform_sp)
match_count =
m_remote_platform_sp->FindProcesses(match_info, process_infos);
}
return match_count;
}
bool PlatformDarwin::ModuleIsExcludedForUnconstrainedSearches(
lldb_private::Target &target, const lldb::ModuleSP &module_sp) {
if (!module_sp)

View File

@ -51,16 +51,9 @@ public:
lldb_private::Target &target,
lldb_private::BreakpointSite *bp_site) override;
bool GetProcessInfo(lldb::pid_t pid,
lldb_private::ProcessInstanceInfo &proc_info) override;
lldb::BreakpointSP
SetThreadCreationBreakpoint(lldb_private::Target &target) override;
uint32_t
FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info,
lldb_private::ProcessInstanceInfoList &process_infos) override;
bool ModuleIsExcludedForUnconstrainedSearches(
lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;

View File

@ -126,21 +126,6 @@ Error PlatformNetBSD::RunShellCommand(const char *command,
}
}
// From PlatformMacOSX only
Error PlatformNetBSD::GetFileWithUUID(const FileSpec &platform_file,
const UUID *uuid_ptr,
FileSpec &local_file) {
if (IsRemote()) {
if (m_remote_platform_sp)
return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
local_file);
}
// Default to the local case
local_file = platform_file;
return Error();
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
@ -238,33 +223,6 @@ Error PlatformNetBSD::DisconnectRemote() {
return error;
}
bool PlatformNetBSD::GetProcessInfo(lldb::pid_t pid,
ProcessInstanceInfo &process_info) {
bool success = false;
if (IsHost()) {
success = Platform::GetProcessInfo(pid, process_info);
} else if (m_remote_platform_sp) {
success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
}
return success;
}
uint32_t
PlatformNetBSD::FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
uint32_t match_count = 0;
if (IsHost()) {
// Let the base class figure out the host details
match_count = Platform::FindProcesses(match_info, process_infos);
} else {
// If we are remote, we can only return results if we are connected
if (m_remote_platform_sp)
match_count =
m_remote_platform_sp->FindProcesses(match_info, process_infos);
}
return match_count;
}
const char *PlatformNetBSD::GetUserName(uint32_t uid) {
// Check the cache in Platform in case we have already looked this uid up
const char *user_name = Platform::GetUserName(uid);

View File

@ -81,11 +81,6 @@ public:
const char *GetGroupName(uint32_t gid) override;
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) override;
Error LaunchProcess(ProcessLaunchInfo &launch_info) override;
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
@ -94,10 +89,6 @@ public:
// NetBSD processes can not be launched by spawning and attaching.
bool CanDebugProcess() override { return false; }
// Only on PlatformMacOSX:
Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
FileSpec &local_file) override;
Error GetSharedModule(const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,

View File

@ -250,6 +250,38 @@ Error PlatformPOSIX::ResolveExecutable(const ModuleSpec &module_spec,
return error;
}
Error PlatformPOSIX::GetFileWithUUID(const FileSpec &platform_file,
const UUID *uuid_ptr,
FileSpec &local_file) {
if (IsRemote() && m_remote_platform_sp)
return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
local_file);
// Default to the local case
local_file = platform_file;
return Error();
}
bool PlatformPOSIX::GetProcessInfo(lldb::pid_t pid,
ProcessInstanceInfo &process_info) {
if (IsHost())
return Platform::GetProcessInfo(pid, process_info);
if (m_remote_platform_sp)
return m_remote_platform_sp->GetProcessInfo(pid, process_info);
return false;
}
uint32_t
PlatformPOSIX::FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
if (IsHost())
return Platform::FindProcesses(match_info, process_infos);
if (m_remote_platform_sp)
return
m_remote_platform_sp->FindProcesses(match_info, process_infos);
return 0;
}
Error PlatformPOSIX::MakeDirectory(const FileSpec &file_spec,
uint32_t file_permissions) {
if (m_remote_platform_sp)
@ -1003,3 +1035,12 @@ size_t PlatformPOSIX::ConnectToWaitingProcesses(Debugger &debugger,
return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error);
return Platform::ConnectToWaitingProcesses(debugger, error);
}
ConstString PlatformPOSIX::GetFullNameForDylib(ConstString basename) {
if (basename.IsEmpty())
return basename;
StreamString stream;
stream.Printf("lib%s.so", basename.GetCString());
return ConstString(stream.GetString());
}

View File

@ -105,6 +105,14 @@ public:
lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr) override;
lldb_private::Error GetFileWithUUID(const lldb_private::FileSpec &platform_file, const lldb_private::UUID *uuid,
lldb_private::FileSpec &local_file) override;
bool GetProcessInfo(lldb::pid_t pid, lldb_private::ProcessInstanceInfo &proc_info) override;
uint32_t FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info,
lldb_private::ProcessInstanceInfoList &process_infos) override;
lldb_private::Error MakeDirectory(const lldb_private::FileSpec &file_spec,
uint32_t mode) override;
@ -169,6 +177,8 @@ public:
size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger,
lldb_private::Error &error) override;
lldb_private::ConstString GetFullNameForDylib(lldb_private::ConstString basename) override;
protected:
std::unique_ptr<lldb_private::OptionGroupPlatformRSync>
m_option_group_platform_rsync;