labath created this revision.
labath added reviewers: JDevlieghere, teemperor, jingham.
The previous attempt at making nameless process not match when searching for a
given name failed because the macos implementation was depending on this detail
in its partial matching strategy. Doing partial matching to avoid expensive
lookups is a perfectly valid thing to do, the way it was implemented seems
somewhat unexpected.
This patch implements it differently by providing special
methods in the ProcessInstanceInfoMatch which match only a subset of fields,
and changes mac host code to use those instead.
Then, it re-applies r373925 to get make the ProcessInstanceInfoMatch with a
name *not* match a nameless process.
https://reviews.llvm.org/D68631
Files:
include/lldb/Utility/ProcessInfo.h
source/Host/macosx/objcxx/Host.mm
source/Utility/ProcessInfo.cpp
unittests/Utility/ProcessInstanceInfoTest.cpp
Index: unittests/Utility/ProcessInstanceInfoTest.cpp
===================================================================
--- unittests/Utility/ProcessInstanceInfoTest.cpp
+++ unittests/Utility/ProcessInstanceInfoTest.cpp
@@ -91,3 +91,20 @@
)",
s.GetData());
}
+
+TEST(ProcessInstanceInfoMatch, Name) {
+ ProcessInstanceInfo info_bar, info_empty;
+ info_bar.GetExecutableFile().SetFile("/foo/bar", FileSpec::Style::posix);
+
+ ProcessInstanceInfoMatch match;
+ match.SetNameMatchType(NameMatch::Equals);
+ match.GetProcessInfo().GetExecutableFile().SetFile("bar",
+ FileSpec::Style::posix);
+
+ EXPECT_TRUE(match.Matches(info_bar));
+ EXPECT_FALSE(match.Matches(info_empty));
+
+ match.GetProcessInfo().GetExecutableFile() = FileSpec();
+ EXPECT_TRUE(match.Matches(info_bar));
+ EXPECT_TRUE(match.Matches(info_empty));
+}
Index: source/Utility/ProcessInfo.cpp
===================================================================
--- source/Utility/ProcessInfo.cpp
+++ source/Utility/ProcessInfo.cpp
@@ -243,8 +243,14 @@
}
}
+bool ProcessInstanceInfoMatch::ArchitectureMatches(
+ const ArchSpec &arch_spec) const {
+ return !m_match_info.GetArchitecture().IsValid() ||
+ m_match_info.GetArchitecture().IsCompatibleMatch(arch_spec);
+}
+
bool ProcessInstanceInfoMatch::NameMatches(const char *process_name) const {
- if (m_name_match_type == NameMatch::Ignore || process_name == nullptr)
+ if (m_name_match_type == NameMatch::Ignore)
return true;
const char *match_name = m_match_info.GetName();
if (!match_name)
@@ -253,11 +259,8 @@
return lldb_private::NameMatches(process_name, m_name_match_type, match_name);
}
-bool ProcessInstanceInfoMatch::Matches(
+bool ProcessInstanceInfoMatch::ProcessIDsMatch(
const ProcessInstanceInfo &proc_info) const {
- if (!NameMatches(proc_info.GetName()))
- return false;
-
if (m_match_info.ProcessIDIsValid() &&
m_match_info.GetProcessID() != proc_info.GetProcessID())
return false;
@@ -265,7 +268,11 @@
if (m_match_info.ParentProcessIDIsValid() &&
m_match_info.GetParentProcessID() != proc_info.GetParentProcessID())
return false;
+ return true;
+}
+bool ProcessInstanceInfoMatch::UserIDsMatch(
+ const ProcessInstanceInfo &proc_info) const {
if (m_match_info.UserIDIsValid() &&
m_match_info.GetUserID() != proc_info.GetUserID())
return false;
@@ -281,13 +288,14 @@
if (m_match_info.EffectiveGroupIDIsValid() &&
m_match_info.GetEffectiveGroupID() != proc_info.GetEffectiveGroupID())
return false;
-
- if (m_match_info.GetArchitecture().IsValid() &&
- !m_match_info.GetArchitecture().IsCompatibleMatch(
- proc_info.GetArchitecture()))
- return false;
return true;
}
+bool ProcessInstanceInfoMatch::Matches(
+ const ProcessInstanceInfo &proc_info) const {
+ return ArchitectureMatches(proc_info.GetArchitecture()) &&
+ ProcessIDsMatch(proc_info) && UserIDsMatch(proc_info) &&
+ NameMatches(proc_info.GetName());
+}
bool ProcessInstanceInfoMatch::MatchAllProcesses() const {
if (m_name_match_type != NameMatch::Ignore)
Index: source/Host/macosx/objcxx/Host.mm
===================================================================
--- source/Host/macosx/objcxx/Host.mm
+++ source/Host/macosx/objcxx/Host.mm
@@ -677,14 +677,16 @@
process_info.SetEffectiveGroupID(UINT32_MAX);
// Make sure our info matches before we go fetch the name and cpu type
- if (match_info.Matches(process_info)) {
- // Get CPU type first so we can know to look for iOS simulator is we have
- // x86 or x86_64
- if (GetMacOSXProcessCPUType(process_info)) {
- if (GetMacOSXProcessArgs(&match_info, process_info)) {
- if (match_info.Matches(process_info))
- process_infos.Append(process_info);
- }
+ if (!match_info.UserIDsMatch(process_info) ||
+ !match_info.ProcessIDsMatch(process_info))
+ continue;
+
+ // Get CPU type first so we can know to look for iOS simulator is we have
+ // x86 or x86_64
+ if (GetMacOSXProcessCPUType(process_info)) {
+ if (GetMacOSXProcessArgs(&match_info, process_info)) {
+ if (match_info.Matches(process_info))
+ process_infos.Append(process_info);
}
}
}
Index: include/lldb/Utility/ProcessInfo.h
===================================================================
--- include/lldb/Utility/ProcessInfo.h
+++ include/lldb/Utility/ProcessInfo.h
@@ -223,8 +223,20 @@
m_name_match_type = name_match_type;
}
+ /// Return true iff the architecture in this object matches arch_spec.
+ bool ArchitectureMatches(const ArchSpec &arch_spec) const;
+
+ /// Return true iff the process name in this object matches process_name.
bool NameMatches(const char *process_name) const;
+ /// Return true iff the process ID and parent process IDs in this object match
+ /// the ones in proc_info.
+ bool ProcessIDsMatch(const ProcessInstanceInfo &proc_info) const;
+
+ /// Return true iff the (both effective and real) user and group IDs in this
+ /// object match the ones in proc_info.
+ bool UserIDsMatch(const ProcessInstanceInfo &proc_info) const;
+
bool Matches(const ProcessInstanceInfo &proc_info) const;
bool MatchAllProcesses() const;
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits