Commit Graph

22 Commits

Author SHA1 Message Date
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
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
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
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
Alastair Houghton
2cc93cf7b0 [Backtracing] Bail out earlier for privileged binaries on macOS.
Also remove the code that deals with file descriptors; we will now
only start the backtracer for processes that have the get-task-allow
entitlement, which means that they've been specifically signed for
debugging, and *that* means that it is no longer critical to ensure
that unexpectedly inherited fds are closed.

rdar://137551812
2024-10-22 12:21:58 +01:00
Alastair Houghton
f4bf27852f [Backtracing] Make the backtracer work for fully-static Linux.
The backtracer and its build system need a couple of changes to make
them work with the new fully-static Linux support.

rdar://123507656
2024-05-07 16:51:34 +01:00
Alastair Houghton
dd0b826235 [Runtime] Improved symbolication option for backtracing.
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
2024-02-06 17:38:20 +00:00
Alastair Houghton
8269bf72eb [Runtime] Add an option to produce non-symbolicated backtraces.
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
2024-02-05 12:56:47 +00:00
Alastair Houghton
7e4bfc995e [Backtracing] Test Developer Mode before allowing interactivity.
On systems where Developer Mode is disabled, we should not allow
interactivity.

rdar://109667503
2024-01-15 17:56:56 +00:00
Alastair Houghton
9ca81c63b1 [Backtracing] Massage the output a little in various cases.
We shouldn't try to erase the message when in non-color mode; mostly
that's intended for redirected output scenarios anyway, and in that case
we don't really want garbage in the output.

Also, improve the failure messages when the backtracer itself goes
wrong or can't be executed.

Finally, change the behaviour slightly so that *if* we're explicitly
enabled, *and* the backtracer path wasn't explicitly specified, *and*
we can't find the backtracer, we print a warning on start-up.  We
don't do that in any other case because we don't want spurious warnings
everywhere.

rdar://118055527
2023-11-09 18:12:18 +00:00
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
a9ce1cdaee [Backtracing][Linux] Add Linux support to swift-backtrace.
We need a Linux specific `Target` implementation, and a couple of minor
tweaks to make things build everywhere.

rdar://110262673
2023-06-07 09:06:34 +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
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
dc6f97c274 [Backtracing][Windows] Use CRT not MSVCRT.
The name of the C library on Windows is CRT, apparently.

rdar://105452194
2023-03-04 08:00:09 +00:00
Alastair Houghton
65a6aae04e [Backtracing] Add swift-backtrace to the build.
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
2023-03-04 08:00:09 +00:00