[Lldb-commits] [lldb] 638b06c - [lldb/Utility] Replace ProcessInstanceInfoList with std::vector. (NFCI)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 12 14:19:43 PDT 2020
Author: Jonas Devlieghere
Date: 2020-03-12T14:10:25-07:00
New Revision: 638b06cf298bc622c3ffd93dc4715c6f806de5b5
URL: https://github.com/llvm/llvm-project/commit/638b06cf298bc622c3ffd93dc4715c6f806de5b5
DIFF: https://github.com/llvm/llvm-project/commit/638b06cf298bc622c3ffd93dc4715c6f806de5b5.diff
LOG: [lldb/Utility] Replace ProcessInstanceInfoList with std::vector. (NFCI)
Replace ProcessInstanceInfoList with std::vector<ProcessInstanceInfo>
and update the call sites.
Added:
Modified:
lldb/include/lldb/Host/Host.h
lldb/include/lldb/Target/Platform.h
lldb/include/lldb/Utility/ProcessInfo.h
lldb/include/lldb/lldb-forward.h
lldb/source/Commands/CommandObjectPlatform.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Host/freebsd/Host.cpp
lldb/source/Host/linux/Host.cpp
lldb/source/Host/macosx/objcxx/Host.mm
lldb/source/Host/netbsd/Host.cpp
lldb/source/Host/openbsd/Host.cpp
lldb/source/Host/windows/Host.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/source/Target/Process.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index 884c5cf63213..269bb18571b0 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/include/lldb/Host/Host.h
@@ -27,8 +27,8 @@ namespace lldb_private {
class FileAction;
class ProcessLaunchInfo;
class ProcessInstanceInfo;
-class ProcessInstanceInfoList;
class ProcessInstanceInfoMatch;
+typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
// Exit Type for inferior processes
struct WaitStatus {
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 7c2746ddec68..06290b34ac0e 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -33,8 +33,8 @@
namespace lldb_private {
class ProcessInstanceInfo;
-class ProcessInstanceInfoList;
class ProcessInstanceInfoMatch;
+typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
class ModuleCache;
enum MmapFlags { eMmapFlagsPrivate = 1, eMmapFlagsAnon = 2 };
diff --git a/lldb/include/lldb/Utility/ProcessInfo.h b/lldb/include/lldb/Utility/ProcessInfo.h
index c00b41c3ffd5..d2ad40487224 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -155,41 +155,7 @@ class ProcessInstanceInfo : public ProcessInfo {
lldb::pid_t m_parent_pid;
};
-class ProcessInstanceInfoList {
-public:
- ProcessInstanceInfoList() = default;
-
- void Clear() { m_infos.clear(); }
-
- size_t GetSize() { return m_infos.size(); }
-
- void Append(const ProcessInstanceInfo &info) { m_infos.push_back(info); }
-
- llvm::StringRef GetProcessNameAtIndex(size_t idx) {
- return ((idx < m_infos.size()) ? m_infos[idx].GetNameAsStringRef() : "");
- }
-
- lldb::pid_t GetProcessIDAtIndex(size_t idx) {
- return ((idx < m_infos.size()) ? m_infos[idx].GetProcessID() : 0);
- }
-
- bool GetInfoAtIndex(size_t idx, ProcessInstanceInfo &info) {
- if (idx < m_infos.size()) {
- info = m_infos[idx];
- return true;
- }
- return false;
- }
-
- // You must ensure "idx" is valid before calling this function
- const ProcessInstanceInfo &GetProcessInfoAtIndex(size_t idx) const {
- assert(idx < m_infos.size());
- return m_infos[idx];
- }
-
-protected:
- std::vector<ProcessInstanceInfo> m_infos;
-};
+typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
// ProcessInstanceInfoMatch
//
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index faca8fac62ef..6b22e50a553d 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -156,7 +156,6 @@ class Process;
class ProcessAttachInfo;
class ProcessInfo;
class ProcessInstanceInfo;
-class ProcessInstanceInfoList;
class ProcessInstanceInfoMatch;
class ProcessLaunchInfo;
class ProcessModID;
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index e473756f1e93..5a6573307c61 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1128,7 +1128,7 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
m_options.verbose);
for (uint32_t i = 0; i < matches; ++i) {
- proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(
+ proc_infos[i].DumpAsTableRow(
ostrm, platform_sp->GetUserIDResolver(),
m_options.show_args, m_options.verbose);
}
@@ -1462,12 +1462,12 @@ class CommandObjectPlatformProcessAttach : public CommandObjectParsed {
match_info.SetNameMatchType(NameMatch::StartsWith);
}
platform_sp->FindProcesses(match_info, process_infos);
- const uint32_t num_matches = process_infos.GetSize();
+ const uint32_t num_matches = process_infos.size();
if (num_matches == 0)
return;
for (uint32_t i = 0; i < num_matches; ++i) {
- request.AddCompletion(process_infos.GetProcessNameAtIndex(i));
+ request.AddCompletion(process_infos[i].GetNameAsStringRef());
}
return;
}
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index 20bbf95dca82..043765a0c09c 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -348,11 +348,11 @@ class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach {
match_info.SetNameMatchType(NameMatch::StartsWith);
}
platform_sp->FindProcesses(match_info, process_infos);
- const size_t num_matches = process_infos.GetSize();
+ const size_t num_matches = process_infos.size();
if (num_matches == 0)
return;
for (size_t i = 0; i < num_matches; ++i) {
- request.AddCompletion(process_infos.GetProcessNameAtIndex(i));
+ request.AddCompletion(process_infos[i].GetNameAsStringRef());
}
}
diff --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp
index 21fdeaea0898..1e8981b00e53 100644
--- a/lldb/source/Host/freebsd/Host.cpp
+++ b/lldb/source/Host/freebsd/Host.cpp
@@ -195,10 +195,10 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
bool already_registered = false;
for (uint32_t pi = 0;
!already_registered && (const int)kinfo.ki_numthreads > 1 &&
- pi < (const uint32_t)process_infos.GetSize();
+ pi < (const uint32_t)process_infos.size();
pi++)
already_registered =
- (process_infos.GetProcessIDAtIndex(pi) == (uint32_t)kinfo.ki_pid);
+ (process_infos[pi].GetProcessID() == (uint32_t)kinfo.ki_pid);
if (already_registered)
continue;
@@ -216,11 +216,11 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
GetFreeBSDProcessArgs(&match_info, process_info)) {
GetFreeBSDProcessCPUType(process_info);
if (match_info.Matches(process_info))
- process_infos.Append(process_info);
+ process_infos.push_back(process_info);
}
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index c31aac6784b2..3e002ca2f77a 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -262,14 +262,14 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
continue;
if (match_info.Matches(process_info)) {
- process_infos.Append(process_info);
+ process_infos.push_back(process_info);
}
}
closedir(dirproc);
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool Host::FindProcessThreads(const lldb::pid_t pid, TidMap &tids_to_attach) {
diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm
index 233734109c41..0e668713d4bd 100644
--- a/lldb/source/Host/macosx/objcxx/Host.mm
+++ b/lldb/source/Host/macosx/objcxx/Host.mm
@@ -660,11 +660,11 @@ static bool GetMacOSXProcessUserAndGroup(ProcessInstanceInfo &process_info) {
if (GetMacOSXProcessCPUType(process_info)) {
if (GetMacOSXProcessArgs(&match_info, process_info)) {
if (match_info.Matches(process_info))
- process_infos.Append(process_info);
+ process_infos.push_back(process_info);
}
}
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
diff --git a/lldb/source/Host/netbsd/Host.cpp b/lldb/source/Host/netbsd/Host.cpp
index fb0be47e1171..10c0c78beed7 100644
--- a/lldb/source/Host/netbsd/Host.cpp
+++ b/lldb/source/Host/netbsd/Host.cpp
@@ -219,8 +219,8 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
// list if a process with given identifier is already registered there.
if (proc_kinfo[i].p_nlwps > 1) {
bool already_registered = false;
- for (size_t pi = 0; pi < process_infos.GetSize(); pi++) {
- if (process_infos.GetProcessIDAtIndex(pi) == proc_kinfo[i].p_pid) {
+ for (size_t pi = 0; pi < process_infos.size(); pi++) {
+ if (process_infos[pi].GetProcessID() == proc_kinfo[i].p_pid) {
already_registered = true;
break;
}
@@ -241,13 +241,13 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
GetNetBSDProcessArgs(&match_info, process_info)) {
GetNetBSDProcessCPUType(process_info);
if (match_info.Matches(process_info))
- process_infos.Append(process_info);
+ process_infos.push_back(process_info);
}
}
kvm_close(kdp); /* XXX: we don't check for error here */
- return process_infos.GetSize();
+ return process_infos.size();
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
diff --git a/lldb/source/Host/openbsd/Host.cpp b/lldb/source/Host/openbsd/Host.cpp
index 8474bc9f6713..8fc8801775f3 100644
--- a/lldb/source/Host/openbsd/Host.cpp
+++ b/lldb/source/Host/openbsd/Host.cpp
@@ -193,11 +193,11 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
GetOpenBSDProcessArgs(&match_info, process_info)) {
GetOpenBSDProcessCPUType(process_info);
if (match_info.Matches(process_info))
- process_infos.Append(process_info);
+ process_infos.push_back(process_info);
}
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp
index 599d94802812..28e78885519a 100644
--- a/lldb/source/Host/windows/Host.cpp
+++ b/lldb/source/Host/windows/Host.cpp
@@ -156,10 +156,10 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
GetProcessExecutableAndTriple(handle, process);
if (match_info.MatchAllProcesses() || match_info.Matches(process))
- process_infos.Append(process);
+ process_infos.push_back(process);
} while (Process32NextW(snapshot.get(), &pe));
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
index c4c5bdc02f20..7e3e7c92f180 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
@@ -361,13 +361,12 @@ uint32_t PlatformAppleTVSimulator::FindProcesses(
// Now we filter them down to only the TvOS triples
for (uint32_t i = 0; i < n; ++i) {
- const ProcessInstanceInfo &proc_info =
- all_osx_process_infos.GetProcessInfoAtIndex(i);
+ const ProcessInstanceInfo &proc_info = all_osx_process_infos[i];
if (proc_info.GetArchitecture().GetTriple().getOS() == llvm::Triple::TvOS) {
- process_infos.Append(proc_info);
+ process_infos.push_back(proc_info);
}
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool PlatformAppleTVSimulator::GetSupportedArchitectureAtIndex(uint32_t idx,
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
index dc016b455ee7..e24923609d4a 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
@@ -361,14 +361,13 @@ uint32_t PlatformAppleWatchSimulator::FindProcesses(
// Now we filter them down to only the WatchOS triples
for (uint32_t i = 0; i < n; ++i) {
- const ProcessInstanceInfo &proc_info =
- all_osx_process_infos.GetProcessInfoAtIndex(i);
+ const ProcessInstanceInfo &proc_info = all_osx_process_infos[i];
if (proc_info.GetArchitecture().GetTriple().getOS() ==
llvm::Triple::WatchOS) {
- process_infos.Append(proc_info);
+ process_infos.push_back(proc_info);
}
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool PlatformAppleWatchSimulator::GetSupportedArchitectureAtIndex(
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
index 4fe82e34b624..375ddd072262 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
@@ -366,13 +366,12 @@ PlatformiOSSimulator::FindProcesses(const ProcessInstanceInfoMatch &match_info,
// Now we filter them down to only the iOS triples
for (uint32_t i = 0; i < n; ++i) {
- const ProcessInstanceInfo &proc_info =
- all_osx_process_infos.GetProcessInfoAtIndex(i);
+ const ProcessInstanceInfo &proc_info = all_osx_process_infos[i];
if (proc_info.GetArchitecture().GetTriple().getOS() == llvm::Triple::IOS) {
- process_infos.Append(proc_info);
+ process_infos.push_back(proc_info);
}
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool PlatformiOSSimulator::GetSupportedArchitectureAtIndex(uint32_t idx,
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 500527221ebb..edbd408622f1 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2154,7 +2154,7 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
uint32_t GDBRemoteCommunicationClient::FindProcesses(
const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
- process_infos.Clear();
+ process_infos.clear();
if (m_supports_qfProcessInfo) {
StreamString packet;
@@ -2234,7 +2234,7 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
ProcessInstanceInfo process_info;
if (!DecodeProcessInfoResponse(response, process_info))
break;
- process_infos.Append(process_info);
+ process_infos.push_back(process_info);
response = StringExtractorGDBRemote();
} while (SendPacketAndWaitForResponse("qsProcessInfo", response, false) ==
PacketResult::Success);
@@ -2243,7 +2243,7 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
return 0;
}
}
- return process_infos.GetSize();
+ return process_infos.size();
}
bool GDBRemoteCommunicationClient::GetUserName(uint32_t uid,
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index ff3836d467a4..bd4a254433e9 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -20,6 +20,7 @@
#include "lldb/Host/File.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/GDBRemote.h"
+#include "lldb/Utility/ProcessInfo.h"
#include "lldb/Utility/StructuredData.h"
#if defined(_WIN32)
#include "lldb/Host/windows/PosixApi.h"
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index 3aec013ef6f3..08d489851799 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -334,7 +334,7 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo(
StringExtractorGDBRemote &packet) {
m_proc_infos_index = 0;
- m_proc_infos.Clear();
+ m_proc_infos.clear();
ProcessInstanceInfoMatch match_info;
packet.SetFilePos(::strlen("qfProcessInfo"));
@@ -416,10 +416,9 @@ GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo(
StringExtractorGDBRemote &packet) {
- if (m_proc_infos_index < m_proc_infos.GetSize()) {
+ if (m_proc_infos_index < m_proc_infos.size()) {
StreamString response;
- CreateProcessInfoResponse(
- m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response);
+ CreateProcessInfoResponse(m_proc_infos[m_proc_infos_index], response);
++m_proc_infos_index;
return SendPacketNoLock(response.GetString());
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 7938d2b9a9b2..af990c945bec 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -2799,9 +2799,9 @@ Status Process::Attach(ProcessAttachInfo &attach_info) {
match_info.GetProcessInfo() = attach_info;
match_info.SetNameMatchType(NameMatch::Equals);
platform_sp->FindProcesses(match_info, process_infos);
- const uint32_t num_matches = process_infos.GetSize();
+ const uint32_t num_matches = process_infos.size();
if (num_matches == 1) {
- attach_pid = process_infos.GetProcessIDAtIndex(0);
+ attach_pid = process_infos[0].GetProcessID();
// Fall through and attach using the above process ID
} else {
match_info.GetProcessInfo().GetExecutableFile().GetPath(
@@ -2810,7 +2810,7 @@ Status Process::Attach(ProcessAttachInfo &attach_info) {
StreamString s;
ProcessInstanceInfo::DumpTableHeader(s, true, false);
for (size_t i = 0; i < num_matches; i++) {
- process_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(
+ process_infos[i].DumpAsTableRow(
s, platform_sp->GetUserIDResolver(), true, false);
}
error.SetErrorStringWithFormat(
More information about the lldb-commits
mailing list