diff options
author | Chad Smith <cssmith@fb.com> | 2025-10-09 11:28:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-10-09 11:28:13 -0700 |
commit | a19c9a8ba1b01f324f893481d825a375a5a68bc6 (patch) | |
tree | 2ba95e720e0b111233d8f343ab51eb5bf0daa5aa /lldb/packages/Python/lldbsuite/test/lldbgdbclient.py | |
parent | b0d252da3cbc1c6e5747b618c301881da663de86 (diff) | |
download | llvm-a19c9a8ba1b01f324f893481d825a375a5a68bc6.zip llvm-a19c9a8ba1b01f324f893481d825a375a5a68bc6.tar.gz llvm-a19c9a8ba1b01f324f893481d825a375a5a68bc6.tar.bz2 |
support attaching by name for platform android (#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
```
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbgdbclient.py')
0 files changed, 0 insertions, 0 deletions