mgorny created this revision.
mgorny added reviewers: labath, krytarowski, emaste.
Herald added a subscriber: arichardson.
mgorny requested review of this revision.

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.


https://reviews.llvm.org/D90454

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


Index: lldb/source/Host/netbsd/HostNetBSD.cpp
===================================================================
--- lldb/source/Host/netbsd/HostNetBSD.cpp
+++ lldb/source/Host/netbsd/HostNetBSD.cpp
@@ -200,6 +200,9 @@
     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 @@
     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))
Index: lldb/source/Host/freebsd/Host.cpp
===================================================================
--- lldb/source/Host/freebsd/Host.cpp
+++ lldb/source/Host/freebsd/Host.cpp
@@ -175,6 +175,9 @@
 
   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 @@
     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))


Index: lldb/source/Host/netbsd/HostNetBSD.cpp
===================================================================
--- lldb/source/Host/netbsd/HostNetBSD.cpp
+++ lldb/source/Host/netbsd/HostNetBSD.cpp
@@ -200,6 +200,9 @@
     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 @@
     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))
Index: lldb/source/Host/freebsd/Host.cpp
===================================================================
--- lldb/source/Host/freebsd/Host.cpp
+++ lldb/source/Host/freebsd/Host.cpp
@@ -175,6 +175,9 @@
 
   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 @@
     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))
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to