wallace updated this revision to Diff 221837.
wallace added a comment.

remove unwanted files


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68048/new/

https://reviews.llvm.org/D68048

Files:
  lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h

Index: lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
===================================================================
--- lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
@@ -38,6 +38,9 @@
                                  lldb_private::Target *target,
                                  lldb_private::Status &error) override;
 
+  uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
+                         ProcessInstanceInfoList &process_infos) override;
+
 protected:
   std::string m_device_id;
   std::map<lldb::pid_t, uint16_t> m_port_forwards;
Index: lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
===================================================================
--- lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -9,6 +9,7 @@
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/common/TCPSocket.h"
 #include "lldb/Utility/Log.h"
+#include "lldb/Utility/ProcessInfo.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/UriParser.h"
 
@@ -225,3 +226,117 @@
   return PlatformRemoteGDBServer::ConnectProcess(new_connect_url, plugin_name,
                                                  debugger, target, error);
 }
+
+#define INVALID_INDEX -1
+struct PsColumnsIndices {
+  int user;
+  int pid;
+  int ppid;
+  int name;
+  PsColumnsIndices() { user = pid = ppid = name = INVALID_INDEX; }
+  bool isValid() { return pid != INVALID_INDEX && name != INVALID_INDEX; }
+};
+
+bool parsePsHeader(const std::string &line, PsColumnsIndices &indices) {
+  std::stringstream line_stream(line);
+  std::string column;
+  for (int columnIndex = 0; line_stream >> column; columnIndex++) {
+    if (column.empty()) {
+      continue;
+    }
+    if (column == "USER") {
+      indices.user = columnIndex;
+    } else if (column == "PID") {
+      indices.pid = columnIndex;
+    } else if (column == "PPID") {
+      indices.ppid = columnIndex;
+    } else if (column == "NAME") {
+      indices.name = columnIndex;
+    }
+  }
+  return indices.isValid();
+}
+
+void parsePsProcessLine(const std::string &line,
+                        const PsColumnsIndices &column_indices,
+                        ProcessInstanceInfo &process_info) {
+  std::string user, name;
+  lldb::pid_t pid, ppid;
+  std::stringstream line_stream(line);
+  std::string column;
+  // It is assumed that the name will be the last column because it can
+  // contain spaces or tab separators
+  for (int columnIndex = 0;
+       columnIndex < column_indices.name && line_stream >> column;
+       columnIndex++) {
+    if (column.empty()) {
+      continue;
+    }
+    if (column_indices.user == columnIndex) {
+      user = column;
+    } else if (column_indices.pid == columnIndex) {
+      std::stringstream column_stream(column);
+      column_stream >> pid;
+    } else if (column_indices.ppid == columnIndex) {
+      std::stringstream column_stream(column);
+      column_stream >> ppid;
+    }
+  }
+  std::string name_prefix;
+  line_stream >> name_prefix;
+  getline(line_stream, name, '\n');
+  name = name + name_prefix;
+
+  process_info.SetProcessID(pid);
+  process_info.SetParentProcessID(ppid);
+  process_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
+  // TODO: set architecture: process_info.GetArchitecture().SetTriple(...);
+  // TODO: set user id, we only have the name: process_info.SetUserID(...)
+}
+
+bool findProcessFromCommand(const std::string command,
+                            ProcessInstanceInfoList &process_infos,
+                            AdbClient &adb) {
+  process_infos.Clear();
+  std::string output;
+  auto status = adb.Shell(command.c_str(), std::chrono::seconds(5), &output);
+  if (status.Fail()) {
+    return false;
+  }
+  std::stringstream output_stream(output);
+  std::string line;
+  getline(output_stream, line, '\n');
+  PsColumnsIndices column_indices;
+  if (!parsePsHeader(line, column_indices)) {
+    return false;
+  }
+
+  while (getline(output_stream, line, '\n')) {
+    ProcessInstanceInfo process_info;
+    parsePsProcessLine(line, column_indices, process_info);
+    process_infos.Append(process_info);
+  }
+  return true;
+}
+
+bool findProcessesWithAdb(ProcessInstanceInfoList &process_infos,
+                          const std::string device_id) {
+  AdbClient adb;
+  auto error = AdbClient::CreateByDeviceID(device_id, adb);
+  if (error.Fail()) {
+    return false;
+  }
+
+  return findProcessFromCommand("ps -A", process_infos, adb) ||
+         findProcessFromCommand("ps", process_infos, adb);
+}
+
+uint32_t PlatformAndroidRemoteGDBServer::FindProcesses(
+    const ProcessInstanceInfoMatch &match_info,
+    ProcessInstanceInfoList &process_infos) {
+  if (findProcessesWithAdb(process_infos, m_device_id)) {
+    return process_infos.GetSize();
+  } else {
+    return PlatformRemoteGDBServer::FindProcesses(match_info, process_infos);
+  }
+}
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to