-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[swift-inspect] implement Android support including remote heap iteration #78275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good to me!
@swift-ci please test |
…into swift-inspect-android
@swift-ci please test |
I made a couple of updates since this PR is still pending:
@compnerd please have a look when you get a chance and request test run if you're good with the changes. Thanks! |
@swift-ci please test |
@swift-ci please smoke test |
@swift-ci please test Windows platform |
Purpose
Implement
swift-inspect
Android support, building on the Linux implementation added in #77938. The bulk of this PR is focused on implementing remote heap iteration using Android'smalloc_iterate
, which is not supported on Linux.Overview
LinuxRemoteProcess
class with a newAndroidRemoteProcess
class, overriding and implementing theiterateHeap
methodptrace
calls to theSwiftInspectLinux
module for use in heap iteration/proc/<pid>/maps
to identify heap regions in the target processptrace
mmap
(andmunmap
) usingptrace
malloc_iterate
usingptrace
with a custom callback copied to the the process usingprocess_vm_writev
malloc_disable
andmalloc_enable
before and after calls tomalloc_iterate
in the remote process to ensure a consistent snapshot of heap allocationsprocess_vm_readv
to fetch heap-iteration metadata from the remote processREADME.md
to reflect Android supportBackground
While there is no standard heap iteration interface on Linux, Android supports
malloc_iterate
to walk all heap allocations in the current process. This API is supported on the newer scudo heap as well as older jemalloc heap (which may still be used on low memory devices). The API is not part of the public NDK, but is used by the AOSPlibmemunreachable
tool.Validation
swift build
on Windows 11 using recent Android Swift SDK and NDK r26bSWIFT_DEBUG_ENABLE_METADATA_ALLOCATION_ITERATION=1
andSWIFT_DEBUG_ENABLE_METADATA_BACKTRACE_LOGGING=1
on an x86_64 emulator (Android 15) and arm64 device (Pixel 6a + Android 13)SWIFT_DEBUG_
env vars fromApplication.onCreate
) withswift-inspect
copied to its sandbox on an x86_64 emulator (Android 15) and arm64 device (Pixel 6a + Android 13)--backtrace
and--backtrace-long
argumentsswift-inspect
still builds for Linux with CMake andswift build