Skip to content
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
wants to merge 23 commits into from

Conversation

al45tair
Copy link
Contributor

Add Linux support for the backtracer.

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.
@MaxDesiatov MaxDesiatov added the Linux Platform: Linux label May 31, 2023
@al45tair al45tair force-pushed the alastair/backtracing-linux branch 2 times, most recently from bfdb934 to f1efc3a Compare June 2, 2023 08:26
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 al45tair force-pushed the alastair/backtracing-linux branch from f1efc3a to 7025164 Compare June 2, 2023 11:40
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 al45tair force-pushed the alastair/backtracing-linux branch 4 times, most recently from 4ad370a to aa10b3a Compare June 4, 2023 20:20
@al45tair al45tair force-pushed the alastair/backtracing-linux branch 7 times, most recently from effea5c to a7c2f5a Compare June 5, 2023 13:19
It turns out that major and minor numbers can be larger than 0xff.
@al45tair al45tair force-pushed the alastair/backtracing-linux branch from a7c2f5a to 60dbd6f Compare June 5, 2023 13:23
@al45tair
Copy link
Contributor Author

al45tair commented Jun 5, 2023

@swift-ci Please smoke test Linux platform

@al45tair
Copy link
Contributor Author

al45tair commented Jun 5, 2023

I've split this apart into #66333, #66334, #66335, #66337 and #66338 (plus #66340 which we don't need just yet).

@al45tair al45tair closed this Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux Platform: Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants