[Lldb-commits] [lldb] r374529 - ProcessInstanceInfoMatch: Don't match processes with no name if a name match was requested, take 2

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 11 03:56:54 PDT 2019


Author: labath
Date: Fri Oct 11 03:56:54 2019
New Revision: 374529

URL: http://llvm.org/viewvc/llvm-project?rev=374529&view=rev
Log:
ProcessInstanceInfoMatch: Don't match processes with no name if a name match was requested, take 2

Summary:
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.

Reviewers: JDevlieghere, teemperor, jingham

Subscribers: wallace, lldb-commits

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

Modified:
    lldb/trunk/include/lldb/Utility/ProcessInfo.h
    lldb/trunk/source/Host/macosx/objcxx/Host.mm
    lldb/trunk/source/Utility/ProcessInfo.cpp
    lldb/trunk/unittests/Utility/ProcessInstanceInfoTest.cpp

Modified: lldb/trunk/include/lldb/Utility/ProcessInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/ProcessInfo.h?rev=374529&r1=374528&r2=374529&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/ProcessInfo.h (original)
+++ lldb/trunk/include/lldb/Utility/ProcessInfo.h Fri Oct 11 03:56:54 2019
@@ -223,8 +223,20 @@ public:
     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;

Modified: lldb/trunk/source/Host/macosx/objcxx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/objcxx/Host.mm?rev=374529&r1=374528&r2=374529&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/objcxx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/objcxx/Host.mm Fri Oct 11 03:56:54 2019
@@ -677,14 +677,16 @@ uint32_t Host::FindProcesses(const Proce
       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);
       }
     }
   }

Modified: lldb/trunk/source/Utility/ProcessInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ProcessInfo.cpp?rev=374529&r1=374528&r2=374529&view=diff
==============================================================================
--- lldb/trunk/source/Utility/ProcessInfo.cpp (original)
+++ lldb/trunk/source/Utility/ProcessInfo.cpp Fri Oct 11 03:56:54 2019
@@ -243,8 +243,14 @@ void ProcessInstanceInfo::DumpAsTableRow
   }
 }
 
+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 @@ bool ProcessInstanceInfoMatch::NameMatch
   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 @@ bool ProcessInstanceInfoMatch::Matches(
   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 @@ bool ProcessInstanceInfoMatch::Matches(
   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)

Modified: lldb/trunk/unittests/Utility/ProcessInstanceInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ProcessInstanceInfoTest.cpp?rev=374529&r1=374528&r2=374529&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ProcessInstanceInfoTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ProcessInstanceInfoTest.cpp Fri Oct 11 03:56:54 2019
@@ -91,3 +91,20 @@ TEST(ProcessInstanceInfo, DumpTable_inva
 )",
       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));
+}




More information about the lldb-commits mailing list