[Lldb-commits] [lldb] f893b29 - [lldb] [Host/{free, net}bsd] Fix process matching by name

Michał Górny via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 3 00:46:31 PST 2020


Author: Michał Górny
Date: 2020-11-03T09:45:50+01:00
New Revision: f893b2939781910fd52ad70a30484255a3cf0f6e

URL: https://github.com/llvm/llvm-project/commit/f893b2939781910fd52ad70a30484255a3cf0f6e
DIFF: https://github.com/llvm/llvm-project/commit/f893b2939781910fd52ad70a30484255a3cf0f6e.diff

LOG: [lldb] [Host/{free,net}bsd] Fix process matching by name

Fix process matching by name to make 'process attach -n ...' work.

The process finding code has an optimization that defers getting
the process name and executable format after the numeric (PID, UID...)
parameters are tested.  However, the ProcessInstanceInfoMatch.Matches()
method has been matching process name against the incomplete process
information as well, and effectively no process ever matched.

In order to fix this, create a copy of ProcessInstanceInfoMatch, set
it to ignore process name and se this copy for the initial match.
The same fix applies to FreeBSD and NetBSD host code.

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

Added: 
    

Modified: 
    lldb/source/Host/freebsd/Host.cpp
    lldb/source/Host/netbsd/HostNetBSD.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp
index 09547e48afa9..460a535cf1e0 100644
--- a/lldb/source/Host/freebsd/Host.cpp
+++ b/lldb/source/Host/freebsd/Host.cpp
@@ -175,6 +175,9 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
 
   const size_t actual_pid_count = (pid_data_size / sizeof(struct kinfo_proc));
 
+  ProcessInstanceInfoMatch match_info_noname{match_info};
+  match_info_noname.SetNameMatchType(NameMatch::Ignore);
+
   for (size_t i = 0; i < actual_pid_count; i++) {
     const struct kinfo_proc &kinfo = kinfos[i];
 
@@ -212,7 +215,7 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
     process_info.SetEffectiveGroupID(kinfo.ki_svgid);
 
     // Make sure our info matches before we go fetch the name and cpu type
-    if (match_info.Matches(process_info) &&
+    if (match_info_noname.Matches(process_info) &&
         GetFreeBSDProcessArgs(&match_info, process_info)) {
       GetFreeBSDProcessCPUType(process_info);
       if (match_info.Matches(process_info))

diff  --git a/lldb/source/Host/netbsd/HostNetBSD.cpp b/lldb/source/Host/netbsd/HostNetBSD.cpp
index 38e2aa5c1e05..1945f9f9052f 100644
--- a/lldb/source/Host/netbsd/HostNetBSD.cpp
+++ b/lldb/source/Host/netbsd/HostNetBSD.cpp
@@ -200,6 +200,9 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
     return 0;
   }
 
+  ProcessInstanceInfoMatch match_info_noname{match_info};
+  match_info_noname.SetNameMatchType(NameMatch::Ignore);
+
   for (int i = 0; i < nproc; i++) {
     if (proc_kinfo[i].p_pid < 1)
       continue; /* not valid */
@@ -237,7 +240,7 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
     process_info.SetEffectiveUserID(proc_kinfo[i].p_uid);
     process_info.SetEffectiveGroupID(proc_kinfo[i].p_gid);
     // Make sure our info matches before we go fetch the name and cpu type
-    if (match_info.Matches(process_info) &&
+    if (match_info_noname.Matches(process_info) &&
         GetNetBSDProcessArgs(&match_info, process_info)) {
       GetNetBSDProcessCPUType(process_info);
       if (match_info.Matches(process_info))


        


More information about the lldb-commits mailing list