diff options
author | Pavel Labath <pavel@labath.sk> | 2019-10-11 10:56:54 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-10-11 10:56:54 +0000 |
commit | a8b18baa0f9e49bb5c957e28027f5c5adae28cda (patch) | |
tree | 959e1e5d184ce1c9b2b19570e30c2ec050556adc | |
parent | 30c2441a3262228990b5317eb3bc2b24ff06d316 (diff) | |
download | bcm5719-llvm-a8b18baa0f9e49bb5c957e28027f5c5adae28cda.tar.gz bcm5719-llvm-a8b18baa0f9e49bb5c957e28027f5c5adae28cda.zip |
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
llvm-svn: 374529
-rw-r--r-- | lldb/include/lldb/Utility/ProcessInfo.h | 12 | ||||
-rw-r--r-- | lldb/source/Host/macosx/objcxx/Host.mm | 18 | ||||
-rw-r--r-- | lldb/source/Utility/ProcessInfo.cpp | 28 | ||||
-rw-r--r-- | lldb/unittests/Utility/ProcessInstanceInfoTest.cpp | 17 |
4 files changed, 57 insertions, 18 deletions
diff --git a/lldb/include/lldb/Utility/ProcessInfo.h b/lldb/include/lldb/Utility/ProcessInfo.h index 7be25bb2ef9..9188bf3b709 100644 --- a/lldb/include/lldb/Utility/ProcessInfo.h +++ b/lldb/include/lldb/Utility/ProcessInfo.h @@ -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; diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm index 742c38fd0fd..fe31830b93e 100644 --- a/lldb/source/Host/macosx/objcxx/Host.mm +++ b/lldb/source/Host/macosx/objcxx/Host.mm @@ -677,14 +677,16 @@ uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info, 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); } } } diff --git a/lldb/source/Utility/ProcessInfo.cpp b/lldb/source/Utility/ProcessInfo.cpp index 832e5efae29..fa418f333be 100644 --- a/lldb/source/Utility/ProcessInfo.cpp +++ b/lldb/source/Utility/ProcessInfo.cpp @@ -243,8 +243,14 @@ void ProcessInstanceInfo::DumpAsTableRow(Stream &s, UserIDResolver &resolver, } } +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::NameMatches(const char *process_name) const { 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) diff --git a/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp b/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp index 73978836c5b..1d363ac80a3 100644 --- a/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp +++ b/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp @@ -91,3 +91,20 @@ TEST(ProcessInstanceInfo, DumpTable_invalidUID) { )", 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)); +} |