-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[swift-inspect] implement basic GNU/Linux support #77938
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
78d7c51
to
59d39a1
Compare
tools/swift-inspect/Sources/swift-inspect/Operations/DumpArray.swift
Outdated
Show resolved
Hide resolved
The ELF code should probably not be here; we should share (and if need be extend) the existing ELF reading code in (I know @weissi was encouraging me to move it out into a separate package, which probably does make sense also. But having two sets of it doesn't.) |
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.
I left a few comments, didn't look too deeply into the Linux-specific parts as I don't know that stuff, but it looks great overall.
tools/swift-inspect/Sources/SwiftInspectLinux/SymbolCache.swift
Outdated
Show resolved
Hide resolved
tools/swift-inspect/Sources/swift-inspect/LinuxRemoteProcess.swift
Outdated
Show resolved
Hide resolved
tools/swift-inspect/Sources/swift-inspect/LinuxRemoteProcess.swift
Outdated
Show resolved
Hide resolved
@al45tair thanks for pointing out the duplication here. I took a quick look at stdlib/public/Backtracing/Elf.swift and I think it has the functionality needed by swift-inspect for symbol lookup. Do you have any pointers on how share it between the projects? I'm new to Swift and am not sure how to go about that. |
229d007
to
671db08
Compare
Thank you @compnerd, @mikeash, and @al45tair for the feedback. I believe I have addressed the bulk of your comments. I have revised the ELF parsing code to be as small as possible: it contains only what is required for loading symbol tables from ELF64 files. Dropping ELF32 (which wasn't supported yet for other reasons) simplified it quite a bit. Since there is no clear way to share the ELF parsing code with the |
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.
One more tiny suggestion, looking good!
@al45tair do you have any additional thoughts on this PR? It seems worth the minimal code duplication of ELF parsing (I've reduced it to a single 160 line source file) to enable swift-inspect support for Linux and Android (coming next). It can eventually be updated to share the ELF code with the backtrace library if that gets extracted to its own foundation library. |
@andrurogerz I'm OK with it if Mike is; the duplication is something we should aim to remove in the medium to long term, to avoid having to maintain two sets of ELF code, but I have no objection to this going in. |
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
@swift-ci please test |
tools/swift-inspect/Sources/swift-inspect/LinuxRemoteProcess.swift
Outdated
Show resolved
Hide resolved
tools/swift-inspect/Sources/SwiftInspectLinux/SymbolCache.swift
Outdated
Show resolved
Hide resolved
@swift-ci please smoke test |
@swift-ci please smoke test |
Hm, the Windows test failure doesn't look like it could have been caused by this PR |
@swift-ci please smoke test Windows |
Purpose
Implement support for Linux in the
swift-inspect
tool. Omits support for heap iteration, for which there is no standard GNU/Linux mechanism (see #63576). Currently supports only 64-bit processes, though minimal changes are required to support 32-bit (elf32 parsing is included).Overview
DumpArray
functionality from Linux builds (does not work without heap iteration)SwiftInspectLinux
build target with the Linux-specific implementation:process_vm_readv
/proc/<pid>/maps
/proc/<pid>/auxv
used to locate debugger link mapSwiftInspectLinux/SystemHeaders
target to pull-in the required Linux C headersREADME.md
to reflect Linux supportBackground
I have a locally working implementation of
swift-inspect
for Android, and I realized that, other than the heap iteration implementation, it is not Android-specific. This PR extracts the GNU/Linux functionality into stand-alone Linux support.Linux support has one glaring omission: heap iteration is not supported. There is no standard GNU/Linux heap iteration interface. Further, Linux programs often use alternative heap implementations (scudo, jemalloc, mimalloc, etc) so parsing raw heap structures gets complex (see see #63576). Fortunately, only the
dump-arrays
anddump-concurrency
commands rely on heap iteration-- the other commands work fine without it.Validation
swift build
on Fedora Linux (6.11.8-200.fc40.x86_64)SWIFT_DEBUG_ENABLE_METADATA_ALLOCATION_ITERATION=1
andSWIFT_DEBUG_ENABLE_METADATA_BACKTRACE_LOGGING=1
--backtrace
and--backtrace-long
arguments.Note to reviewers
This is my first non-trivial Swift project, so feedback on Swift style/patterns/etc is appreciated.