[Lldb-commits] [PATCH] D138164: [LLDB][Android] Fix Android serial number handling

Kazuki Sakamoto via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 16 16:53:09 PST 2022


splhack created this revision.
Herald added a subscriber: danielkiss.
Herald added a project: All.
splhack added a reviewer: clayborg.
splhack updated this revision to Diff 475962.
splhack added a comment.
splhack published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

First, recap: what is the Android serial number.
In Android ADB protocal, the serial number following the `host-serial:` is URL-safe string and it could be a `host:port` string.

https://cs.android.com/android/platform/superproject/+/763ab7bb17e9c63b238222085e1e69552d978367:packages/modules/adb/sockets.cpp;l=825?q=host-serial:

  if (android::base::ConsumePrefix(&service, "host-serial:")) {
      // serial number should follow "host:" and could be a host:port string.

Second, LLDB is not able to connect it to Android device when multiple devices are connected to the host.

  (lldb) platform select remote-android
  (lldb) platform connect unix-abstract-connect:///data/local/tmp/debug.sock
  error: Expected a single connected device, got instead 2 - try setting 'ANDROID_SERIAL'

However setting ANDROID_SERIAL environment variable is not always a viable option.
For instance, VS Code + lldb-server and debugging multiple Android devices at the same time.

The potential solution is to use platform connect URL.

  (lldb) platform select remote-android
  (lldb) platform connect unix-abstract-connect://emulator-5554/data/local/tmp/debug.sock

This works for USB-connected devices and emulators.
But it does not work for TCP/IP-connected devices.

  (lldb) platform select remote-android
  (lldb) platform connect unix-abstract-connect://127.0.0.1:5556/data/local/tmp/debug.sock

The reason is that the current code only uses the hostname part of the URL.

https://github.com/llvm/llvm-project/blob/ed9638c44bc0c95314694fb878b21006e6c87510/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp#L154-L155

So m_device_id will be `127.0.0.1`. But this should be `127.0.0.1:5556`
Also `localhost` should not be skipped when the port number is available. m_device_id should be `localhost:5556`

  (lldb) platform connect unix-abstract-connect://localhost:5556/data/local/tmp/debug.sock

Third, the host could be IPv6, for instance `[::1]`.

  (lldb) platform connect unix-abstract-connect://[::1]:5556/data/local/tmp/debug.sock

This is a valid URL and serial number `[::1]:5556`.

The parsed_url does not look it has the information of IPv6 brackets. Thus, `GetDeviceIDFromURL` checks the raw URL again for the bracket.

Fourth, when a port number is available in the connect URL, `MakeConnectURL` function create a new TCP/IP forwarding with the port number. When `adb devices` shows a device with `host:port` style serial number, the port in the serial number is already connected or forwarded to the adb server. `host-serial:host:port` should work.

https://github.com/llvm/llvm-project/blob/ed9638c44bc0c95314694fb878b21006e6c87510/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp#L191-L192

https://github.com/llvm/llvm-project/blob/ed9638c44bc0c95314694fb878b21006e6c87510/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp#L42-L46


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138164

Files:
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
  lldb/unittests/Platform/Android/CMakeLists.txt
  lldb/unittests/Platform/Android/PlatformAndroidRemoteGDBServerTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138164.475962.patch
Type: text/x-patch
Size: 6134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221117/f1b6ee2d/attachment.bin>


More information about the lldb-commits mailing list