Skip to content

Conversation

@al45tair
Copy link
Contributor

@al45tair al45tair commented Mar 2, 2023

This PR adds on-crash backtracing for Swift programs on macOS.

@al45tair
Copy link
Contributor Author

al45tair commented Mar 2, 2023

@swift-ci Please test

@al45tair
Copy link
Contributor Author

al45tair commented Mar 2, 2023

The individual pieces of this have already been reviewed as a set of stacked PRs:

PR Title
al45tair#8 [Backtracing] Add support for looking up paths for auxiliary executables
al45tair#9 [Backtracing][Runtime][Darwin] Add code to trigger the external backtracer
al45tair#10 [Backtracing] Add _Backtracing library to the build
al45tair#11 [Backtracing][Frontend] Add support for implicit import of _Backtracing
al45tair#12 [Backtracing] Add swift-backtrace to the build
al45tair#13 [Backtracing][Docs] Add an explanation of the workings of the backtracer
al45tair#14 [Backtracing] Add control over symbol caching

@al45tair al45tair force-pushed the backtracing/cache-control branch 7 times, most recently from f8d18e5 to 19c212e Compare March 3, 2023 00:08
al45tair added 13 commits March 3, 2023 08:08
When a Swift program crashes, we should catch the crash and execute the
external backtracer.

rdar://105391747
In order for the runtime PR to work as a separate PR, it does need a little
bit of code in the `_SwiftBacktracing.h` header in SwiftShims.

rdar://105391747
We really, really shouldn't be running the external backtracer for setuid
binaries.  It's just too dangerous.

So don't do that.  And if someone tries to force us, emit a warning.

rdar://105391747
If we find signal handlers already installed, leave them alone.

rdar://105391747
Need to change this to `swift_copyAuxiliaryExecutablePath()`.

rdar://105391747
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
We need to enable MASM/MARMASM and we need to add a get-cpu-context.asm
file for it to build.

rdar://104336548
The correct name for the runtime library appears to be CRT, not MSVCRT.

rdar://104336548
Some of the `TARGET` and `os()` conditionals needed to be updated.

rdar://104336548
Linux doesn't have `issetugid()`, so use `getauxval(AT_SECURE)` there
instead.

rdar://105391747
Accidentally wrote `thread_resume()` instead of `thread_suspend()`.

rdar://105391747
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
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.
@al45tair al45tair force-pushed the backtracing/cache-control branch 3 times, most recently from 9a6d247 to e2aa440 Compare March 3, 2023 08:42
@al45tair al45tair force-pushed the backtracing/cache-control branch from 26f36a3 to 4cbc511 Compare March 3, 2023 10:27
iOS doesn't have <libproc.h>.  We don't need it anyway there.

rdar://104336548
@al45tair al45tair force-pushed the backtracing/cache-control branch 2 times, most recently from ce97f92 to 4476a76 Compare March 3, 2023 11:34
al45tair added 8 commits March 3, 2023 11:46
Once the API has gone through Swift Evolution, we will want to implicitly
import the _Backtracing module.  Add code to do that, but set it to off
by default for now.

rdar://105394140
This is Swift's external backtracer.  It's written in Swift, and it's
responsible for generating nice backtraces when Swift programs crash.
It makes use of the new `_Backtracing` library, which is also (mostly,
aside from some assembly language) implemented in Swift.

rdar://103442000
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
The name of the C library on Windows is CRT, apparently.

rdar://105452194
…cer.

Add some discussion of how the new external backtracer works and what
options are available.

rdar://105394365
…cOS.

Added a list of handled signals and some notes on what the runtime will
do if it finds signal handlers already configured.

rdar://105394365
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
@al45tair al45tair force-pushed the backtracing/cache-control branch 6 times, most recently from ca7ca18 to 7fd02a9 Compare March 3, 2023 18:54
@al45tair
Copy link
Contributor Author

al45tair commented Mar 3, 2023

@swift-ci Please test

@xedin xedin removed their request for review March 3, 2023 23:17
@al45tair al45tair force-pushed the backtracing/cache-control branch from 9e41d45 to 13af9c6 Compare March 4, 2023 07:46
@al45tair
Copy link
Contributor Author

al45tair commented Mar 4, 2023

Re-created PR as #64100 after rebasing on main to solve conflict (it wasn't just a simple conflict; other files needed editing too).

@al45tair al45tair closed this Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant