Commit Graph

24 Commits

Author SHA1 Message Date
Alastair Houghton
9d462a7b69 [Backtracing] Add an indication that we're working on a backtrace.
When we crash, emit a message straight away that says we're working
on a backtrace.  If starting the backtracer fails, report that also.

Finally, add a duration to the messages output by the backtracer, so
that we can see how long it took.

rdar://118055527
2023-11-09 18:12:18 +00:00
Alastair Houghton
dd7acb1739 [Backtracing][Linux] Properly align the stacks.
We have two stacks that we set up during crash handling, both of
which were potentially misaligned.  This only tripped us up on
Ubuntu 20.04 on aarch64 - my guess is that maybe `clone()` aligns
the stack pointer on newer kernels which is why we didn't see it
on 22.04.

rdar://110743884
2023-06-14 13:40:51 +01:00
Alastair Houghton
2f0e42ba8d [Backtracing] Use stderr by default unless interactive.
This means we don't need to specify `output-to` in CI.

rdar://110371557
2023-06-07 13:54:36 +01:00
Alastair Houghton
5d03a72dcb Merge pull request #66338 from al45tair/eng/PR-101623265
[Backtracing][Linux] Enable Linux backtracing, add tests.
2023-06-07 13:49:49 +01:00
Alastair Houghton
d67354473f Merge pull request #66335 from al45tair/eng/PR-110261712
[Backtracing][Linux] Add support for Linux in the _Backtracing module.
2023-06-07 13:48:46 +01:00
Alastair Houghton
3042cd742e [Backtracing][Linux] Enable backtrace-on-crash for Linux.
This reverts commit e5f4c2015e.

rdar://101623265
2023-06-07 09:08:18 +01:00
Alastair Houghton
ae9a0c1007 Merge pull request #66334 from al45tair/eng/PR-110261430
[Backtracing][Linux] Add Linux crash handler to the runtime.
2023-06-07 08:41:28 +01:00
Alastair Houghton
1262518ee4 [Backtracing][Linux] Add a comment about __cxa_demangle.
`__cxa_demangle()` is a rather unusual API; one of its "features" is that
the pointer you pass in must either be `nullptr`, in which case it
will call `malloc()` itself, _or_ it has to be a pointer to a block
of memory allocated with `malloc()`, because `__cxa_demangle()` may
`realloc()` it for you.

This seems to me to be something of a non-obvious footgun, so we never
pass the caller's pointer through to `__cxa_demangle()`, which lets them
decide how they want to allocate space.

rdar://110261712
2023-06-07 08:22:40 +01:00
Alastair Houghton
582946b3ee [Backtracing][Linux] Remove status argument.
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
2023-06-07 08:19:13 +01:00
Alastair Houghton
438ab7fa29 [Backtracing][Linux] Add Linux support to the _Backtracing module.
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
2023-06-06 16:16:20 +01:00
Alastair Houghton
979b749a0d [Backtracing][Linux] Move doc comment to header.
Moved the comment for `_swift_backtrace_demangle` into the header file
instead of it being in the implementation.

rdar://110261430
2023-06-06 16:12:47 +01:00
Alastair Houghton
14fcdbd389 [Backtracing][Linux] Tidy a few things up after review.
Mike and Max made various helpful suggestions, so I've added and updated
various comments and amended the code to cope with partial reads and
writes.

rdar://110261430
2023-06-06 16:06:21 +01:00
Alastair Houghton
e5f4c2015e [Backtracing][Linux] Disable backtrace-on-crash until enabling PR.
This should have been disabled until #66338.

rdar://110261430
2023-06-05 22:28:53 +01:00
Alastair Houghton
2dcaa6f14f [Backtracing][Linux] Add Linux crash handler to the runtime.
This also adds a function to demangle a symbol, and a way for the
backtracing code to report warning messages to the same place as
the main runtime.

I'd like to rename the _swift_isThunkFunction() SPI also, but we
can't do that until we've made the changes to the _Backtracing
library, so we'll do that there instead.

rdar://110261430
2023-06-05 15:39:50 +01:00
Alastair Houghton
d58183306f [Runtime][Backtracing] Conditionalise initialisation of the spawnattr.
We don't need to initialise the posix_spawnattr unless we're enabling the
backtracer, so don't.

rdar://109354306
2023-05-15 16:07:58 +01:00
Alastair Houghton
0261a29fee [Backtracing] Support specifying a hard-coded path for swift-backtrace.
Add a way to disable dynamic lookup of the backtracer path, for situations
where a hard-coded path makes more sense.

rdar://107360391
2023-03-29 15:08:48 +01:00
Alastair Houghton
9209bdd8c4 [Backtracing] Add an option to output to stderr.
In CI, it would be better if the backtraces went to stderr rather than
stdout, so provide an option for that.

rdar://107192120
2023-03-24 17:13:52 +00:00
Alastair Houghton
725d2e1d1b [Backtracing] Disable the warning about not finding swift-backtrace.
This needs to be disabled for now.  We'll re-enable it later.

rdar://106813646
2023-03-16 17:13:10 +00:00
Alastair Houghton
1258d45152 [Backtracing] Build work.
Additional shimming required for some builds, as well as a few other build
related tweaks.

rdar://106234311
2023-03-04 15:46:30 +00:00
Alastair Houghton
43ac069ad0 [Backtracing] Add control over symbol caching.
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
2023-03-04 08:00:09 +00:00
Alastair Houghton
0c5aedaaf2 [Backtracing][Runtime] Fix Linux build to use getauxval(AT_SECURE).
Linux doesn't have `issetugid()`, so use `getauxval(AT_SECURE)` there
instead.

rdar://105391747
2023-03-04 07:56:03 +00:00
Alastair Houghton
b63a227a2e [Backtracing][Runtime] Renamed getAuxiliaryExecutablePath upstream.
Need to change this to `swift_copyAuxiliaryExecutablePath()`.

rdar://105391747
2023-03-04 07:56:03 +00:00
Alastair Houghton
44be8cfc21 [Backtracing][Runtime] Disable backtraces for setuid binaries.
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
2023-03-04 07:56:03 +00:00
Alastair Houghton
8a29657f4c [Runtime] [Darwin] Add code to trigger the external backtracer.
When a Swift program crashes, we should catch the crash and execute the
external backtracer.

rdar://105391747
2023-03-04 07:56:02 +00:00