Context:
The android platform is using the bare PlatformRemoteGDBServer to find the list of processes, which returns a very small subset of processes. For example, I got this on my machine
(lldb) platform process list 2 matching processes were found on "remote-android" PID PARENT USER TRIPLE NAME ====== ====== ========== ======================== ============================ 23291 3177 aarch64-unknown-linux-android sh 23301 23291 aarch64-unknown-linux-android lldb-server
However, "adb shell ps -A" manages to get more than 700 processes on my machine.
Problem: We should make the android platform smarter so that it can show the output of all those processes
Solution:
Given that most modern android devices, including Samsung's, support "ps -A", the least effort solution for now is to use "ps -A" as the source of processes.
For devices that don't support "ps -A", a fallback to a plain "ps" invocation is included.
And even if "ps" fails, which I remember to have seen in super old feature phones, a fallback to the bare PlatformRemoteGDBServer is being included.
The output right now looks like this:
(lldb) platform process list 713 matching processes were found on "remote-android" PID PARENT USER TRIPLE NAME ====== ====== ========== ======================== ============================ 1 0 init 2 0 [kthreadd] 3 2 0] 5 2 0:0H] 7 2 [rcu_preempt] ... 23500 2 u16:15] 26985 978 com.samsung.android.oneconnect:Receiver 27594 978 com.samsung.android.dialer 27602 978 com.samsung.android.contacts 29464 2 7:0] 29497 2 [intr_syncd] 29999 979 com.tencent.mm:push 30134 978 com.google.android.googlequicksearchbox:search 30260 2 u17:0] 30272 978 com.sec.spp.push 31552 2 3:0] 32201 2 u16:7]
Help needed:
There are some things still left.
- architecture:
I don't know if we can simply reuse an existing variable and set it for all processes, or if we should really find the architecture of each process.
- user id:
ps returns a user name, but ProcessInfo expects a numeric user ID. Examples of user names are u0_a306, u0_a84, root, bluetooth, etc. Generally there's a new user name when an apk runs IIRC. Should we include a user name field in ProcessInfo for these cases?
- process name:
ProcessInfo stores its process name as a FileSpec, which does path splitting by / or \. For some problematic system processes, ps shows a process name between brackets like [irq/159-arm-smm]. The FileSpec file will try to parse it as an actual path and the output of the process list command will just include 159-arm-smm].
I imagine that it's reasonable to discard all the processes that have names between brackets.
- long process list:
Should we discard system and root processes? These are a lot (hundreds on my devices) and can't be debugged.
- c++:
I haven't written c++ in years, and i have forgotten almost everything. Please make as many advices as possible :)
You could return the PsColumsnIndices directly instead of returning the bool, then have the caller check for validity.