Commit Graph

54 Commits

Author SHA1 Message Date
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
Alastair Houghton
d3352ef272 [Backtracing] memserver_req/resp and thread are only for Linux.
These types only exist on Linux, so need to be conditionalised here.

rdar://137201928
2025-01-15 11:21:25 +00:00
Alastair Houghton
f0974bd227 [Backtracing] Turn off MemberImportVisibility.
Also fixed a couple of other minor issues preventing this PR from
building on its own.

rdar://137201928
2025-01-14 12:13:58 +00:00
Alastair Houghton
9329776a5d [Backtracing] Use C++ interop to fix elf.h issue on Linux.
We have some problems on Linux where Glibc pulls in `<elf.h>` and then
we end up with conflicting definitions.  Fix by using C++ interop and
putting our definitions into a namespace.

rdar://137201928
2025-01-10 13:49:14 +00:00
Alastair Houghton
293842a9d0 [Backtracing] Update module maps.
Now that Darwin is provided by the system, we no longer need to disable the
system module maps in favour of our own, which also resolves a few other
problems that doing that was creating.

rdar://137201928
2024-12-12 15:58:40 +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
4c47540ecf [Backtracer][macOS] Fix crashing thread index when Rosetta is in use.
If you're using Rosetta 2, there are ARM64 threads in your process as
well, which the backtracer skips.  Unfortunately doing that messed up
the crashing thread index, so the backtracer might have crashed or
told you that a different thread was crashing than the one you
thought.

This only affects running x86-64 code on an Apple Silicon Mac.

rdar://135787913
2024-09-11 10:44:35 +01:00
Allan Shortlidge
28bc3ca834 Backtracing: Use internal import in swift-backtracing.
The `swift-backtracing` module is an executable rather than a library so it
should have no reason to use the deprecated `@_implementationOnly import` over
`internal import`.
2024-09-09 12:48:28 -07:00
Alastair Houghton
02f87e3d8e [Build][Backtracing] Make sure the deployment target for OS X is over 10.14.4.
We need to make sure that we build swift-backtrace with a deployment target
newer than 10.14.4 in order that we get linked against
`/usr/lib/swift/libswiftCore.dylib` rather than using an `@rpath`-based
path.

If we fail to do that, dyld becomes confused and we end up crashing with
weird errors about missing method implementations on `Swift.__StringStorage`.

To make this work, add support for `DEPLOYMENT_VERSION_*` in the
`add_swift_target_executable()` CMake function.  And since I spotted a bug
in it, fix the existing support in `add_swift_target_library()` while I'm
there.

rdar://132710670
2024-08-06 15:03:01 +01:00
Alexander Cyon
c21b1e68fd [stdlib] Fix typos 2024-07-06 13:09:57 +02: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
1fc2ca35e8 [Backtracing] Add a caching wrapper for MemoryReader.
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
2023-11-03 14:36:19 +00:00
Alastair Houghton
2efd1beabe [Linux] Provide a statically linked swift-backtrace binary.
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
2023-09-28 18:18:39 +01:00
Alastair Houghton
df8e698308 [Backtracing][Linux] Remove some stray "public" annotations.
We don't need these here.  They were a leftover from previous code.

rdar://110262673
2023-06-07 09:06:34 +01: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
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
e5680de071 [Backtracing] Security improvements.
Use `task_read_for_pid()` rather than having the crashing program pass its
own task port through.  This opts us in to additional OS security measures
surrounding the use of this call.

rdar://107362003
2023-04-12 12:48:33 +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
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
3ec2e6723d [Backtracing] Really only build for OS X.
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.
2023-03-04 08:00:09 +00:00
Alastair Houghton
9e58b2c401 [Backtracing] Make this macOS only 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.
2023-03-04 08:00:09 +00:00
Alastair Houghton
eb38d80655 [Backtracing] Fix Windows build.
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
2023-03-04 08:00:09 +00:00