Commit Graph

80 Commits

Author SHA1 Message Date
Alastair Houghton
ceaba82d6d [Backtracing] Updates after review.
Tweaked the comment in `Runtime/Config.h`.

Fixed a couple of incorrect ARM64 instruction mnemonics.  This still needs
testing on ARM64 Windows.

Fixed an out-of-date comment in `swift-backtrace`.

Use a macro in `Backtrace.cpp` to guarantee we don't overrun the buffer,
and in the process simplify the code slightly.

rdar://101623384
2026-02-06 08:53:16 +00:00
Alastair Houghton
d9b0031f09 [Backtracing] Build and test fixes.
Tweak things to build on Linux and macOS again.

Also fix a few things in the tests.

rdar://101623384
2026-02-06 08:53:15 +00:00
Alastair Houghton
f6af22c402 [Backtracing] Don't pull in windows.h unnecessarily.
Also, fix two files that managed to use Windows API without
importing `WinSDK` as a result of the leakage caused by including
`windows.h` from `codeview.h`.

rdar://101623384
2026-02-06 08:53:15 +00:00
Alastair Houghton
7f8398e60b [Backtracing] Improve debug option on Windows.
Made the debug option on Windows work better.

rdar://101623384
2026-02-03 18:23:30 +00:00
Alastair Houghton
0682923f45 [Backtracing] Make the debug option work on Windows.
Hitting `D` when in the backtracer should do the same on Windows
that it does on macOS, namely launching `lldb` and attaching it to
the crashed program.

rdar://101623384
2026-02-03 18:23:30 +00:00
Alastair Houghton
54f9cee919 [Backtracing] Fix typos, tidy up.
Fix a couple of typos and remove some `print()` statements that
were added for debugging.

rdar://101623384
2026-02-03 18:23:30 +00:00
Alastair Houghton
a677131c96 [Backtracing] Tweak a few things after rebasing.
Fix a couple of issues with the rebase.

Also, add code to handle the debug exceptions (which we don't want
to crash the process).

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
6d930d39ec [Backtracing] Make tests work, plus various fixes.
Made the tests run, then fixed various issues with them.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
4f90a96640 [Backtracing][Windows] Fix things to install swift-backtrace
We needed to modify `build.ps1` to copy `swift-backtrace.exe` into
position.  Also tidy up the code in `AddSwiftStdlib.cmake`.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
e0845e1483 [Backtracing] Made on-crash backtraces work for 64-bit.
On-crash backtracing is basically there for 64-bit Windows.  It
won't work on 32-bit because of a Swift compiler issue, and there
is a little more work to do yet, but it is now working!

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
38f91e2dbd [Backtracing] Fix Linux and macOS builds.
There was a case-sensitivity problem, and a missing source file.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
d13988bd5f [Backtracing][Windows] Initial Windows support.
This doesn't have a working symbolicator yet, but it does build and
it can obtain a basic backtrace.

It also doesn't include a working `swift-backtrace` program yet.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
e0486a47bd [Backtracing] Add some more availability annotations.
We needed a few more annotations, it turns out.  Also, we need to disable
availability checking when building swift-backtrace.

rdar://164850733
2026-01-09 15:48:37 +00:00
Alastair Houghton
7fb395ab4b Merge pull request #86212 from AZero13/fixtypo
target.pid should be pid
2026-01-06 16:53:03 +00:00
Alastair Houghton
7458a46b87 Merge pull request #86215 from AZero13/mains
Remove extraneous ) in backtrace
2026-01-06 16:51:25 +00:00
Alastair Houghton
68ae4e6012 Merge pull request #86213 from AZero13/spawns
posix_spawn returns error in result, not errno
2026-01-06 16:47:35 +00:00
AZero13
144aacce92 Remove extraneous ) in backtrace 2025-12-26 19:44:38 -05:00
AZero13
6d43a13ab2 Ansi has cyan and magenta swapped
magenta is 35, cyan is 36!
2025-12-26 19:40:12 -05:00
AZero13
7e1bab7329 posix_spawn returns error in result, not errno
Throw errno as in result. It does not set errno.
2025-12-26 19:38:38 -05:00
AZero13
1ef6e4b111 target.pid should be pid
Otherwise this does not compile
2025-12-26 19:34:34 -05:00
Carl Peto
740f2d4c81 pr feedback and unit test fixes 2025-12-12 16:32:02 +00:00
Carl Peto
8f8d4585c1 pr feedback
Changed the way swift-backtrace works for JSON, so that it captures
into a CrashLog, then writes to JSON from the CrashLog. Separating out
the two sets of logic so that writing the CrashLog to JSON becomes
simpler and more modular.
2025-12-08 11:29:33 +00:00
Carl Peto
237c99f135 move JSON formatter into Runtime module 2025-12-08 11:29:33 +00:00
Carl Peto
060fa8d1af complete refactoring of JSON formatting code out from swift-backtrace specific code (prior to move) 2025-12-08 11:29:32 +00:00
Carl Peto
c42dcfcbce refactor JSON.swift from swift-backtrace to be useable by swift-symbolicate 2025-12-08 11:29:32 +00:00
Carl Peto
ddc8c2b14d [Backtrace] show the crashed thread first in standard crash logs
It can be hard to find the crashed thread. This always shows it first, before
any other threads.

rdar://164566321
2025-11-21 16:23:03 +00:00
Ian Anderson
15345ef2d5 [CMake][Darwin] Remove support for building the SDK overlays on Apple platforms
The SDK overlays have been provided in the Apple SDKs for many years, and the interface and implementation has diverged in more recent years such that trying to build the Swift version no longer works. Remove all of the dead code.

rdar://151889154
2025-05-23 23:38:08 -07:00
Eric Miotto
8c7e8550aa CMake: add explicit dependency to _Builtin_float to targets...
... that would import that as a result of importing Darwin from the SDK.

Amend my previous change to Differentiation and Distributed in this
sense.

Addresses rdar://150400049
2025-05-05 10:39:14 -07:00
Alastair Houghton
75b9c8f2cf [Backtracing] Rename unsafeFirst to consumingFirst.
This seems like a better name.
2025-03-21 21:18:31 +00:00
Max Desiatov
5be82d18cb Fix variable never mutated warning in swift-backtrace (#80055)
```
stdlib/public/libexec/swift-backtrace/main.swift:590:15: warning: variable 'now' was never mutated; consider changing to 'let' constant
 588 |           let name = target!.name
 589 |           let pid = target!.pid
 590 |           var now = timespec(tv_sec: 0, tv_nsec: 0)
     |               `- warning: variable 'now' was never mutated; consider changing to 'let' constant
 591 |
 592 |           let ext: String
```
2025-03-17 08:30:16 -07:00
Alastair Houghton
6138992dfe [Backtracing] Fix a couple of Linux specific issues.
Linux gives the main thread a name based on the process name, and also
we need to tolerate an extra slash on the `<compiler-generated>` filename
for some reason.

rdar://121430255
2025-02-26 21:31:45 +00:00
Alastair Houghton
b85bf05a82 [Backtracing] Update copyright dates in boilerplate.
rdar://121430255
2025-02-26 14:12:21 +00:00
Alastair Houghton
fbab10397d [Backtracing] Use reserveCapacity to optimize escaping slightly.
We know we need at least as much space as the number of UTF-8
characters.

rdar://121430255
2025-02-26 14:12:21 +00:00
Alastair Houghton
583a2f8df4 [Backtracing] Update JSON output slightly after review.
Always put `registers` in the thread record, and always use the `threads`
top level key, even if we ask for only the crashed thread.  Also add an
`omittedThreads` key.

rdar://121430255
2025-02-26 14:12:21 +00:00
Alastair Houghton
3964879a18 [Test][Backtracing] Added tests for JSON backtrace output.
Check that we generate valid JSON crash reports.

rdar://121430255
2025-02-26 14:12:20 +00:00
Alastair Houghton
b4d4a27b85 [Backtracing] Fix JSON output when not giving backtraces for all threads.
I'd omitted the key from the dictionary by mistake.

rdar://121430255
2025-02-26 14:12:20 +00:00
Alastair Houghton
bc2722e2cc [Backtracing] Add platform and architecture to JSON output.
The JSON output should include platform and architecture data.

rdar://121430255
2025-02-26 14:12:20 +00:00
Alastair Houghton
75204522df [Backtracing] Fix memory capture output.
A couple of commas were in the wrong place.
2025-02-26 14:12:20 +00:00
Alastair Houghton
b5461aeb22 [Backtracing] Added JSON crash log option.
Also made it so the `sanitize` option causes the crash logs to not
include memory dumps.

Fixes #71057
rdar://121430255
2025-02-26 14:12:17 +00:00
Allan Shortlidge
972bc1898b swift-backtrace: Fix a timespec initialization warning.
NFC.
2025-02-22 12:09:23 -08:00
Alastair Houghton
f0050df4c9 Merge pull request #79007 from al45tair/eng/PR-136977833
[Backtracing] Support redirection to a named file.
2025-02-14 16:59:29 +00:00
Allan Shortlidge
e65aab74dd stdlib: Fix an unused variable warning. 2025-02-01 10:28:27 -08:00
Alastair Houghton
857c96300f [Backtracing] Bump minimum deployment targets.
We need a minimum deployment target of 10.15 now, because of the use
of `some Sequence<T>` in the Runtime module interface.

rdar://143869185
2025-01-31 14:16:07 +00:00
Alastair Houghton
255a39573f [Backtracing] Handle EINTR while trying to create a crash log.
Mike rightly points out that it's possible for `open()` to fail
with `EINTR`, which we should handle here.

rdar://136977833
2025-01-29 16:15:38 +00:00
Alastair Houghton
9bdd9e73dc [Backtracing] Support redirection to a named file.
Add the ability to specify a filename or directory name as the output-to
setting in `SWIFT_BACKTRACE`.  If the option is set to a directory name,
generate a unique filename in that directory using the process name,
process ID and timestamp.

rdar://136977833
2025-01-29 10:20:15 +00:00
Alastair Houghton
c9c5dc0de1 [Backtracing] Add platform and architecture information.
It's useful to capture the platform and platform version with the image map.
Also, display both the platform and architecture information when generating
a crash log.

rdar://124913332
2025-01-27 15:44:28 +00:00
Alastair Houghton
4a7ca682d5 [Backtracing] Fix dependency for static swift-backtrace.
We'd missed renaming a CMake variable, which led to link errors.

rdar://124913332
2025-01-17 10:09:37 +00:00
Alastair Houghton
4826d60bc2 [Backtracing] Implement Codable for Backtrace.
Add support for Codable to Bactkrace.

rdar://124913332
2025-01-17 10:09:37 +00:00
Alastair Houghton
0e3e9efcd3 [Backtracing] Add ImageMap instead of just using an Array.
We want to be able to efficiently serialise lists of images, and to do so
it makes most sense to create a separate `ImageMap` type.  This also provides
a useful place to put methods to e.g. find an image by address or by build
ID.

rdar://124913332
2025-01-17 10:09:36 +00:00
Alastair Houghton
760cc57bef [Backtracing] Rename _Backtracing to Runtime.
Move the backtracing code into a new Runtime module.  This means renaming
the Swift Runtime's CMake target because otherwise there will be a name
clash.

rdar://124913332
2025-01-17 10:09:36 +00:00