Rather than just on or off, I've changed it to allow "off", "fast",
or "full". "fast" means that we'll do symbol lookup, but we won't
try to find inline frames and we won't run line number programs
(those are the things that are taking considerable time in some
cases).
rdar://122302117
Symbolication can take some time, depending on the binaries involved.
In certain contexts it's better for the backtrace to finish quickly,
and then symbolication could be done offline.
rdar://122302117
Swift has some module maps it overlays on Linux and Windows that groups all of the C standard library headers into a single module. This doesn’t allow clang and C++ headers to layer properly with the OS/SDK modules. clang will set -fbuiltin-headers-in-system-modules as necessary for Apple SDKs, but Swift will need to pass that flag itself when required by its module maps.
Because the cache uses the page addresses as its keys, we should have
a precondition to check that we haven't passed an address within a page.
The latter would result in confusing behaviour so it's worth diagnosing
up front.
rdar://117681625
Currently we read many small chunks from the process we're backtracing.
If it so happens that it's the local process, that isn't really a big
problem, but if it's a remote process, especially on Linux where we have
to use the memory server, it's probably a little slow.
Fix by adding a caching layer.
rdar://117681625
It was pointed out that there was a more Swift-y way to write the
bounds checks for the `fetch<T>` implementation, so do that instead.
rdar://117590155
We don't really need it after calling `mmap()`, and not keeping it around
means it's easy to make sure it gets closed properly in all cases.
rdar://117590155
On Linux we use FileImageSource to read data from ELF images. We were
doing this in a fairly naive manner, which turns out to be a performance
issue with larger statically linked binaries on Linux.
Change FileImageSource to use mmap() instead.
rdar://117590155
This adds a new binary, `swift-backtrace-static`, to the build. The runtime
will not by default use this binary as the backtracer, but if you want to
statically link your own binaries against the standard library you can copy
`swift-backtrace-static` rather than `swift-backtrace` alongside your binary,
naming it `swift-backtrace`, and the runtime should find and use it, which
will mean you don't need to have `libswiftCore.so` et al installed.
rdar://115278959
Support parsing the following format:
```
0x0000104b: DW_TAG_subprogram
DW_AT_specification (0x00000d23 "$s8CrashOpt6level1yyF")
DW_AT_inline (DW_INL_inlined)
```
The code that looks up line numbers wasn't respecting the end-sequence
flag, so it could "find" a line number between the end of one sequence
and the beginning of another. That was wrong.
rdar://112595022
On Linux specifically, it was possible for it to return `nil` to signal
the end of the unwind, then subsequently return non-`nil` again. That
violates the expectations of the code layered above it, and can cause
an "Index out of range" error to occur.
rdar://112534548
This seems to be happening because we're hitting an invalid frame
on the stack where the program counter value is read back as zero.
If we find one of those, treat it as the end of our stack walk.
rdar://110846253
We were using a regular expression to scan `/proc/<pid>/maps`, but we
shouldn't really do that because it breaks non-bootstrapped builds.
rdar://110452324
The `status` argument to the `_swift_backtrace_demangle()` function
isn't especially useful, won't match behaviour on Windows, and we
actually don't use it in the Swift code that calls this SPI.
Remove it.
rdar://110261712
Use the new module structure rather the old SwiftShims header. This
is much cleaner and lets us include operating system headers to get
the relevant definitions where possible.
Add code to support ELF and DWARF, including decompression using
zlib, zstd and liblzma if those turn out to be required and available.
rdar://110261712
Using `SwiftShims` is undesirable - it creates all kinds of build issues,
and means shipping the `_SwiftBacktracing.h` header in the SDK, which is
not necessary.
While we're doing this, add the necessary definitions for reading ELF
and DWARF information.
rdar://110261712
These weren't working correctly because I made the unwinder call
`_swift_task_getCurrent()`, but of course when out-of-process, it calls
that in `swift-backtrace`, which is wrong. Remove that for now.
While I'm here, I also tweaked the formatting slightly, and I noticed
that we were saying that all thunks were also system functions, which
seemed unnecessary and odd.
Plus there were a couple of extra system functions I added to make the
async crash backtraces nicer in friendly mode.
rdar://106363539
The `withCurrentContext()` methods on the `Context` structs need to be
inlined, even in debug builds, otherwise we would need to skip an extra
frame at the top of the backtrace.
This fixes test failures in debug stdlib builds.
rdar://106276227
On ARM Windows, we need MARMASM to assemble the context capture code,
but CMake doesn't support MARMASM until version 3.26, which isn't yet
released.
(Confusingly it appears to have partial but non-working support in the
present versions.)
rdar://106284325
Added some extra code to AddSwiftStdlib.cmake so executable targets can
specify target SDKs the same way libraries currently can.
Updated the Backtracing targets to specify just OS X for now.
The Linux Swift compiler is ICEing when building _Backtracing, while
Windows still needs some tweaks. In order to land this sooner, disable
this code except for macOS.
While I was doing this, it turns out Saleem was fixing things to avoid
having to patch the Windows include directories, which is awesome but
necessitates an extra change to the backtracing stuff to make the build
not fail on Windows.
rdar://105409147
Some symbolication frameworks have a symbol cache; we probably don't want
to use that for test cases, to avoid running into problems where the cache
holds stale information.
rdar://105409147
Fixed the colours so that they work with all of the default Terminal
presets. Also changed things so that when colour is off, we only use
ASCII characters in our source code displays.
rdar://105452194
Just use `UInt` for `Address`. This is still the subject of some discussion
on the forums, but I haven't decided precisely what to do about it and `UInt`
makes sense for now. This also necessitated some casts elsewhere.
Improve some comments.
Made `limit` robust against silly negative values.
A couple of formatting fixes.
Don't bother supporting the macOS 10.12.2 SDK as Xcode now supports a minimum
of 10.13.
Removed some unnecessary memory rebinding.
Made `CFString` conversion slightly more efficient.
Provide the `SharedCacheInfo` fields everywhere, but make it optional all
over as well.
rdar://104336548
Adds a new swift_Backtracing library, with a corresponding _Backtracing
module, to the build. Also add some tests.
This is not public API at this point, but will be used by the external
backtracing program, `swift-backtrace`.
rdar://104336548