You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
support attaching by name for platform android (llvm#160931)
## Bug
Trying to attach to an android process by name fails:
```
(lldb) process attach -n com.android.bluetooth
error: attach failed: could not find a process named com.android.bluetooth
```
## Root Cause
PlatformAndroid does not implement the `FindProcesses` method.
As described in `include/lldb/Target/Platform.h`:
```
// The base class Platform will take care of the host platform. Subclasses
// will need to fill in the remote case.
virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &proc_infos);
```
## Fix
Implement the `FindProcesses` method in PlatformAndroid. Use adb to get
the pid of the process name on the device with the adb client connection
using `adb shell pidof <name>`.
## Reproduce
With an android device connected, run the following
Install and start lldb-server on device
```
adb push lldb-server /data/local/tmp/
adb shell chmod +x /data/local/tmp/lldb-server
adb shell /data/local/tmp/lldb-server platform --listen 127.0.0.1:9500 --server
```
Start lldb, and run
```
platform select remote-android
platform connect connect://127.0.0.1:9500
log enable lldb platform
```
Connect to the process by name:
```
process attach -n com.android.bluetooth
```
## Test Plan
Before:
```
(lldb) process attach -n com.android.bluetooth
error: attach failed: could not find a process named com.android.bluetooth
```
After:
```
(lldb) process attach -n com.android.bluetooth
lldb AdbClient::ResolveDeviceID Resolved device ID: 127.0.0.1
lldb AdbClient::AdbClient(device_id='127.0.0.1') - Creating AdbClient with device ID
lldb Connecting to ADB server at connect://127.0.0.1:5037
lldb Connected to Android device "127.0.0.1"
lldb Forwarding remote TCP port 38315 to local TCP port 35243
lldb AdbClient::~AdbClient() - Destroying AdbClient for device: 127.0.0.1
lldb gdbserver connect URL: connect://127.0.0.1:35243
lldb AdbClient::AdbClient(device_id='127.0.0.1') - Creating AdbClient with device ID
lldb Connecting to ADB server at connect://127.0.0.1:5037
lldb Selecting device: 127.0.0.1
lldb PlatformAndroid::FindProcesses found process 'com.android.bluetooth' with PID 2223
lldb AdbClient::~AdbClient() - Destroying AdbClient for device: 127.0.0.1
llvm-worker-48 PlatformRemoteGDBServer::GetModuleSpec - got module info for (/apex/com.android.art/lib64/libc++.so:aarch64-unknown-linux-android) : file = '/apex/com.android.art/lib64/libc++.so', arch = aarch64-unknown-linux-android, uuid = 552995D0-A86D-055F-1F03-C13783A2A16C, object size = 754128
llvm-worker-9 PlatformRemoteGDBServer::GetModuleSpec - got module info for (/apex/com.android.art/lib64/liblzma.so:aarch64-unknown-linux-android) : file = '/apex/com.android.art/lib64/liblzma.so', arch = aarch64-unknown-linux-android, uuid = E51CAC98-666F-6C3F-F605-1498079542E0, object size = 179944
Process 2223 stopped
```
0 commit comments