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
[Backtracing][Linux] Add Linux support. #66248
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Linux backtraces work (yay)!
Registers in Linux are in `int64_t`s, so casting to `UInt64` could fail when they're negative. Also, the vaddrs in loaded images don't get updated, so we need to add the image base address.
We were (a) stuck in an infinite loop fetching threads, and (b) all the threads were spinning at 100% CPU. Both of these were wrong, so fix them.
We sort the threads by ID, with the proviso that the main thread always sorts first (even if the IDs have wrapped). We also now scan through the list to find the correct index for the crashing thread.
This needs testing; the issue here is we need to extract data from the mcontext_t structure, which is different for every architecture.
I can't easily test 32-bit Linux at the moment, so only enable backtracing for 64-bit x86 and ARM.
Adds support for zlib, zstd and liblzma compressed debug information, as well as debug info in alternate files.
Add tests for debug section lookup, including in cases where it's compressed.
Warnings should go through the runtime's error/warning output code.
No demangling or line numbers yet.
We're only interested in looking up functions. So ignore everything else.
Also fix a bug wherein we weren't fetching debug symbols.
libdispatch, it turns out, sets threads' signal masks to block all signals except for a handful that get delivered directly to the affected thread. Unfortunately, this includes SIGUSR1, which is what we were using the pause threads. SIGPROF is a reasonable alternative, so switch to using that.
We support async frames on Linux as long as we have symbols for them. Also fix a demangling issue (the return from the outputBufferSize argument of `_swift_backtrace_demangle` is the buffer size, not the result length).
Added support for line number/source file information.
A few fixes and some additional Dwarf attribute support were required, but the Backtracing tests now all pass on Linux.
al45tair
force-pushed
the
alastair/backtracing-linux
branch
2 times, most recently
from
June 2, 2023 08:26
bfdb934
to
f1efc3a
Compare
A handful of fixes to get the build going again on macOS after the Linux work changed a few things. Most of this is due to rearranging the way we import the various bits of OS functionality (especially SPI) to not rely on SwiftShims.
al45tair
force-pushed
the
alastair/backtracing-linux
branch
from
June 2, 2023 11:40
f1efc3a
to
7025164
Compare
A couple of tests needed tweaking, as did the precise behaviour of one or two things. Also, include definitions for zlib/zstd/liblzma directly, so that we don't create an unnecessary build dependency while we're soft linking.
We sometimes picked the wrong symbol because of this.
al45tair
force-pushed
the
alastair/backtracing-linux
branch
4 times, most recently
from
June 4, 2023 20:20
4ad370a
to
aa10b3a
Compare
al45tair
force-pushed
the
alastair/backtracing-linux
branch
7 times, most recently
from
June 5, 2023 13:19
effea5c
to
a7c2f5a
Compare
It turns out that major and minor numbers can be larger than 0xff.
al45tair
force-pushed
the
alastair/backtracing-linux
branch
from
June 5, 2023 13:23
a7c2f5a
to
60dbd6f
Compare
@swift-ci Please smoke test Linux platform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Linux support for the backtracer.