Commit Graph

56 Commits

Author SHA1 Message Date
Carl Peto
4a664da0e4 Temporarily disable CrashWithThreads cosmetic test on Linux (#85848)
This test is destabilising the pipeline on Linux and only tests cosmetic functionality. Disable it for now.

rdar://165728982
2025-12-04 19:23:52 -08:00
Carl Peto
2b1b10c7e1 pr feedback 2025-12-03 11:48:25 +00:00
Carl Peto
959dc1bdb7 [Test] Fix unstable Backtracing unit test
There was a problem in CrashWithThreads where it failed about 10% of the time. This fixes it.
rdar://165728982
2025-12-03 11:31:37 +00:00
Carl Peto
dd9543f126 Merge pull request #85589 from carlpeto/eng/PR-164566321
Always show the crashed thread first
2025-12-02 15:05:52 +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
Carl Peto
4d57a809e8 [Backtracing][Tests] add unit tests for coloured/uncoloured output
rdar://164624364
2025-11-21 11:53:36 +00:00
Kavon Farvardin
afd633d25d nfc: refactor Backtracing/Crash.swift
This test fused both the CHECK directives and the
source code into one file, and is sensitive to the line numbers
that source code appears on in that file. Thus, any attempts to
add new lines to this test would break it.

This refactoring moves the source code to a separate file so
its line numbers stay stable.
2025-08-11 21: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
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
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
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
ca86836133 [Backtracing][Tests] Improve debugability of CompactImageMap test.
If this test fails in CI, we could do with being able to see the
output from the test program in full.

rdar://124913332
2025-01-22 10:39:44 +00:00
Alastair Houghton
2300577b56 [Backtracing] Fix symbol lookup on Linux.
Also removed a spurious `print()` that got left in by accident,
and disabled the `CodableBacktrace.swift` test on Linux since we
need Foundation and we don't have it there.

rdar://124913332
2025-01-21 19:05:08 +00:00
Alastair Houghton
c7bb91d8fe [Backtracing] Tweak tests slightly.
`JSONEncoder` by default will escape slashes, which results in a string
that isn't technically valid Base64.  Since that behaviour is optional,
turn it off, and at the same time tell it to output in lexical key
order, which makes the test slightly simpler (no `CHECK-DAG` needed).

Also fixed a typo in `test_swift.py`

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
18496c5626 [Backtracing] Remove support for implicit import of _Backtracing.
We're going to rename the module to Runtime, and it isn't going to be an
implicit import, so we don't need any of this.

rdar://124913332
2025-01-17 10:09:36 +00:00
Felipe de Azevedo Piovezan
f7f869c88d [DebugInfo] Don't inherit debug location of previous instruction
Prior to this commit, when lowering SIL instructions that should are
"hidden" for the purposes of debugging, the compiler just attaches the
location of the previous instruction in the name of keeping a simpler
line table.

However, this is wrong for many reasons. One such reason is this: at the
start of a basic block, inheriting the previous debug location will
almost certainly cause the instruction to have a random location in the
code, as it will depend on whatever BB was visited previously.

Other examples can be seen in the tests affect by this commit, which
changes lowering to use Line 0 instead of the line number of the
previous instruction.

CodeView doesn't handle line 0 the same way DWARF does, so this commit
preserves the old behavior for the CodeView path.

The test changes here are effectively undoing some of the diffs from
158772c2ab.

rdar://139826231&110187845
2024-11-18 10:23:41 -08:00
Michael Gottesman
3685cdd674 Fix backtrace test 2024-06-21 06:56:34 -07:00
Adrian Prantl
aab0cb09cc Root the virtual <compiler-generated> file in the root directory.
Using CWD gives a false sense of accuracy.

rdar://124233848
2024-03-12 16:57:04 -07:00
John McCall
0a282c044f Unify all of the task-creation builtins coming out of SILGen.
We've been building up this exponential explosion of task-creation
builtins because it's not currently possible to overload builtins.
As long as all of the operands are scalar, though, it's pretty easy
to peephole optional injections in IRGen, which means we can at
least just use a single builtin in SIL and then break it apart in
IRGen to decide which options to set.

I also eliminated the metadata argument, which can easily be recreated
from the substitutions.  I also added proper verification for the builtin,
which required (1) getting `@Sendable` right more consistently and (2)
updating a bunch of tests checking for things that are not actually
valid, like passing a function that returns an Int directly.
2024-03-06 22:21:12 -05:00
Ian Anderson
288f37b2c1 [Concurrency] [shims] Don't declare exit in the concurrency shims
Don't delete the OS declaration of `exit` because the concurrency shims aren't always imported, and so the shim declaration might not always be available.
Don't override the OS declaration of `exit` in the concurrency shims since we can't just delete the OS one. Instead, set up internal shims just for building Concurrency that forward declares `exit`.
2024-01-29 16:25:46 -08:00
Alastair Houghton
e2732f3b2f [Backtracing] Fix macOS test failure.
Apparently I forgot to code sign the test binaries.

rdar://118055527
2023-11-13 10:22:57 +00:00
Alastair Houghton
c164b761f8 [Backtracing] Add some more tests.
Add tests for the new immediate on-crash message and the backtrace timing
message.

rdar://118055527
2023-11-10 10:57:11 +00:00
Alastair Houghton
93e05cd1bb [Linux] Disable fatalError() backtraces when the runtime backtracer is active.
There's no need for fatalError() to try to generate its own backtraces
when the runtime's backtracer is enabled.  Not only is the code it uses
more fragile but it also doesn't support async or inline frames and it
can't look-up symbols properly either.

rdar://117470489
2023-11-01 09:18:21 +00:00
Alastair Houghton
6e9151f2f7 [Test][Backtracing] Only disable FatalError for macOS.
Actually, we only need to disable this for macOS.  It should be fine
on Linux.
2023-10-19 15:33:05 +01:00
Alastair Houghton
4e6ad2e872 [Test][Backtracing] Disable FatalError test temporarily.
Some CI nodes currently cause this test to fail because of outdated
software.  Disable it for now.
2023-10-19 15:31:33 +01:00
Alastair Houghton
256e3cd499 [Test][Backtracing] Make FatalError test more lenient.
Somehow since this passed PR testing, `Builtin.int_trap()` has changed
from generating `SIGILL` to `SIGTRAP`.  Accept either.

rdar://116584708
2023-10-06 18:05:37 +01:00
Alastair Houghton
2cbc064a9e [Backtracing][Tests] Tweak the new fatalError test slightly.
The test needs tweaking a little to work on Linux and macOS.

rdar://116112040
2023-10-05 18:04:58 +01:00
Alastair Houghton
7b7f77eeaa [Linux] Enable frame pointers when building Swift libraries.
Turn on frame pointers for the Swift runtime libraries.  This makes
backtraces that go through the runtimes more reliable without having
to parse DWARF data.

rdar://116112040
2023-10-05 16:11:20 +01: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
20ad4333ca [Linux][Test] Use import-static-libdispatch not import-libdispatch.
We want the static version of Dispatch here.  If we don't use that version,
we'll fail the tests on the release branches (but strangely not on main
for some reason).

rdar://115774613
2023-09-25 17:45:22 +01:00
Alastair Houghton
598bce2404 [Linux] Force the inclusion of the backtracing code when static linking.
When we're statically linking the standard library, we need to force
the inclusion of the backtracing code in the runtime, otherwise we don't
get on-crash backtraces.

Also, add a test to make sure that this works.

rdar://115774613
2023-09-21 15:03:51 +01:00
Daniel Rodríguez Troitiño
309ad399c0 [backtracing] Mark two tests with REQUIRES (#67074)
The test were enabled even if Backtracing was not enabled in the build
settings. Backtracing is enabled with the build script, but not in the
default CMake configuration.
2023-07-01 11:06:05 -07:00
Yuta Saito
059bbf51ef [test][Backtracing] Fix crash message pattern for single threaded mode
With libdispatch executor, `level` function is called on non-main thread
because it does not specify main executor explicitly. Therefore, the
crash message from swift-backtrace says `Thread 1 crashed: ...`.
However, with single threaded executor, all jobs are executed on the
main thread, and main thread always has its name, so the message can be
thread name 'Thread 0 "CrashAsync" crashed:'.
2023-06-22 08:06:29 +00:00
Alastair Houghton
fe0c14fe42 [Backtracing] Make StackOverflow test less sensitive.
Depending on the platform, architecture and stack layout, we may or
may not have line numbers for the very first frame.

rdar://110418951
2023-06-07 21:52:07 +01:00
Alastair Houghton
646c2212c9 [Backtracing][Tests] Fix a test I missed.
Apparently I missed a redirection in `Crash.swift`.

rdar://110371557
2023-06-07 13:55:17 +01:00
Alastair Houghton
210ca2a067 [Backtracing][Tests] Fix tests to redirect output from stderr.
Some of the backtracing tests expected output on stdout.

rdar://110371557
2023-06-07 13:55:15 +01:00
Alastair Houghton
ee5596428f [Backtracing][Linux] Enable Linux backtracing, add tests.
Turn on the Linux backtracing implementation and update the tests.

rdar://101623265
2023-06-07 09:08:18 +01:00
Adrian Prantl
158772c2ab Rebase SILScope generation on top of ASTScope.
This patch replaces the stateful generation of SILScope information in
SILGenFunction with data derived from the ASTScope hierarchy, which should be
100% in sync with the scopes needed for local variables. The goal is to
eliminate the surprising effects that the stack of cleanup operations can have
on the current state of SILBuilder leading to a fully deterministic (in the
sense of: predictible by a human) association of SILDebugScopes with
SILInstructions. The patch also eliminates the need to many workarounds. There
are still some accomodations for several Sema transformation passes such as
ResultBuilders, which don't correctly update the source locations when moving
around nodes. If these were implemented as macros, this problem would disappear.

This necessary rewrite of the macro scope handling included in this patch also
adds proper support nested macro expansions.

This fixes

rdar://88274783

and either fixes or at least partially addresses the following:

rdar://89252827
rdar://105186946
rdar://105757810
rdar://105997826
rdar://105102288
2023-04-04 15:20:11 -07:00
Alastair Houghton
3e78f840f6 [Backtracing][Tests] Disable crashing tests under ASAN.
If ASAN is enabled, it will catch the crashes and the backtracing code
won't, so in that case the tests will fail.  Fix by disabling them for
ASAN.

rdar://107129465
2023-03-23 12:09:21 +00:00
Alastair Houghton
fc9d0a02c5 [Backtracing][Tests] Don't fail CrashAsync for missing line numbers.
If libswift_Concurrency.dylib's line numbers couldn't be resolved, we'd
end up failing this test for no good reason.

rdar://106502985
2023-03-09 16:51:57 +00:00
Alastair Houghton
9061d4e874 [Backtracing][Tests] Don't demangle in CrashAsync.
The CI nodes currently run an older macOS version that can't demangle the
async function names.  So, to pass PR testing and CI, we'll need to turn
demangling off for this test for now.  No big deal.

rdar://106363539
2023-03-08 10:56:17 +00:00
Alastair Houghton
43375e7a23 [Backtracing] Fix out-of-process async backtraces.
These weren't working correctly because I made the unwinder call
`_swift_task_getCurrent()`, but of course when out-of-process, it calls
that in `swift-backtrace`, which is wrong.  Remove that for now.

While I'm here, I also tweaked the formatting slightly, and I noticed
that we were saying that all thunks were also system functions, which
seemed unnecessary and odd.

Plus there were a couple of extra system functions I added to make the
async crash backtraces nicer in friendly mode.

rdar://106363539
2023-03-08 09:35:18 +00:00
Alastair Houghton
2043498a39 [Backtracing] Don't run tests when testing OS stdlib.
We need a symbol from the standard library that isn't in the older
versions of the stdlib.

rdar://106293913
2023-03-07 14:42:28 +00:00
Alastair Houghton
106dd1956e [Backtracing] Fix test failures.
I'd inserted an extra line, which upset the line numbers in the backtracing
tests.

Also tweak the Python build script tests slightly so they work.

rdar://106234311
2023-03-06 11:28:16 +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
eac93f9d2a [Backtracing][Tests] Apparently we don't see the dyld frame in CI.
For some reason we don't see the dyld frames in CI.  That's fine, don't
check for them.

Also turn NotImportedByDefault off for Windows as it needs a better
shell than the support provided there.
2023-03-04 08:00:09 +00:00