[Lldb-commits] [lldb] support attaching by name for platform	android (PR #160931)
    Roy Shi via lldb-commits 
    lldb-commits at lists.llvm.org
       
    Mon Sep 29 06:43:46 PDT 2025
    
    
  
================
@@ -477,6 +477,85 @@ std::string PlatformAndroid::GetRunAs() {
   }
   return run_as.str();
 }
+uint32_t
+PlatformAndroid::FindProcesses(const ProcessInstanceInfoMatch &match_info,
+                               ProcessInstanceInfoList &proc_infos) {
+  // Use the parent implementation for host platform
+  if (IsHost())
+    return PlatformLinux::FindProcesses(match_info, proc_infos);
+
+  // For remote Android platform, implement process name lookup using adb
+  proc_infos.clear();
+
+  // Check if we're looking for a process by name
+  const ProcessInstanceInfo &match_process_info = match_info.GetProcessInfo();
+  if (!match_process_info.GetExecutableFile() ||
+      match_info.GetNameMatchType() == NameMatch::Ignore) {
+    // Fall back to the parent implementation if not searching by name
+    return PlatformLinux::FindProcesses(match_info, proc_infos);
+  }
+
+  std::string process_name = match_process_info.GetExecutableFile().GetPath();
+  if (process_name.empty())
+    return 0;
+
+  // Use adb to find the process by name
+  Status error;
+  AdbClientUP adb(GetAdbClient(error));
+  if (error.Fail()) {
+    Log *log = GetLog(LLDBLog::Platform);
+    LLDB_LOGF(log, "PlatformAndroid::%s failed to get ADB client: %s",
+              __FUNCTION__, error.AsCString());
+    return 0;
+  }
+
+  // Use 'pidof' command to get the PID for the process name
+  std::string pidof_output;
+  std::string command = "pidof " + process_name;
+  error = adb->Shell(command.c_str(), seconds(5), &pidof_output);
----------------
royitaqi wrote:
Can path contain special characters (e.g. space)? If so, maybe wrap with quotes?
https://github.com/llvm/llvm-project/pull/160931
    
    
More information about the lldb-commits
mailing list