[Lldb-commits] [lldb] support attaching by name for platform android (PR #160931)

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 9 06:52:44 PDT 2025


================
@@ -477,6 +477,248 @@ std::string PlatformAndroid::GetRunAs() {
   }
   return run_as.str();
 }
+
+// Helper function to populate process status information from
+// /proc/[pid]/status
+void PlatformAndroid::PopulateProcessStatusInfo(
+    lldb::pid_t pid, ProcessInstanceInfo &process_info) {
+  // Read /proc/[pid]/status to get parent PID, UIDs, and GIDs
+  Status error;
+  auto status_adb = GetAdbClient(error);
+  if (error.Fail())
+    return;
+
+  std::string status_output;
+  StreamString status_cmd;
+  status_cmd.Printf(
+      "cat /proc/%llu/status 2>/dev/null | grep -E '^(PPid|Uid|Gid):'",
+      (unsigned long long)pid);
+  Status status_error =
+      status_adb->Shell(status_cmd.GetData(), seconds(5), &status_output);
+
+  if (status_error.Fail() || status_output.empty())
+    return;
+
+  llvm::SmallVector<llvm::StringRef, 16> lines;
+  llvm::StringRef(status_output).split(lines, '\n');
+
+  for (llvm::StringRef line : lines) {
+    line = line.trim();
+    if (line.starts_with("PPid:")) {
+      llvm::StringRef ppid_str = line.substr(5).trim();
+      lldb::pid_t ppid;
+      if (llvm::to_integer(ppid_str, ppid))
+        process_info.SetParentProcessID(ppid);
+    } else if (line.starts_with("Uid:")) {
+      llvm::SmallVector<llvm::StringRef, 4> uid_parts;
+      line.substr(4).trim().split(uid_parts, '\t', -1, false);
+      if (uid_parts.size() >= 2) {
+        uint32_t uid, euid;
+        if (llvm::to_integer(uid_parts[0].trim(), uid))
+          process_info.SetUserID(uid);
+        if (llvm::to_integer(uid_parts[1].trim(), euid))
+          process_info.SetEffectiveUserID(euid);
+      }
+    } else if (line.starts_with("Gid:")) {
+      llvm::SmallVector<llvm::StringRef, 4> gid_parts;
+      line.substr(4).trim().split(gid_parts, '\t', -1, false);
+      if (gid_parts.size() >= 2) {
+        uint32_t gid, egid;
+        if (llvm::to_integer(gid_parts[0].trim(), gid))
+          process_info.SetGroupID(gid);
+        if (llvm::to_integer(gid_parts[1].trim(), egid))
+          process_info.SetEffectiveGroupID(egid);
+      }
+    }
+  }
+}
+
+// Helper function to populate command line arguments from /proc/[pid]/cmdline
+void PlatformAndroid::PopulateProcessCommandLine(
+    lldb::pid_t pid, ProcessInstanceInfo &process_info) {
+  // Read /proc/[pid]/cmdline to get command line arguments
+  Status error;
+  auto cmdline_adb = GetAdbClient(error);
----------------
walter-erquinigo wrote:

ditto

https://github.com/llvm/llvm-project/pull/160931


More information about the lldb-commits mailing list