From f7bd5bffede5c97f92caaa5804f1768c0c7bbbc4 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 7 Oct 2019 17:17:53 +0000 Subject: [PATCH] ProcessInstanceInfoMatch: Don't match processes with no name if a name match was requested Since D68289, a couple of tests on linux started being extremely flaky. All of them were doing name-based attaching and were failing because they couldn't find an unambiguous process to attach to. The patch above changed the process finding logic, so that failure to find a process name does not constitute an error. This meant that a lot more transient processes showed up in the process list during the test suite run. Previously, these processes would not appear as they would be gone by the time we went to read their executable name, arguments, etc. Now, this alone should not cause an issue were it not for the fact that we were considering a process with no name as if it matched by default (even if we were explicitly searching for a process with a specified name). This meant that any of the "transient" processes with no name would make the name match ambiguous. That clearly seems like a bug to me so I fix that. llvm-svn: 373925 --- lldb/source/Utility/ProcessInfo.cpp | 2 +- lldb/unittests/Utility/ProcessInstanceInfoTest.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lldb/source/Utility/ProcessInfo.cpp b/lldb/source/Utility/ProcessInfo.cpp index 832e5ef..6be47d3 100644 --- a/lldb/source/Utility/ProcessInfo.cpp +++ b/lldb/source/Utility/ProcessInfo.cpp @@ -244,7 +244,7 @@ void ProcessInstanceInfo::DumpAsTableRow(Stream &s, UserIDResolver &resolver, } 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) diff --git a/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp b/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp index 7397883..1d363ac 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)); +} -- 2.7.4