Commit Graph

91 Commits

Author SHA1 Message Date
Alastair Houghton 97ad7f4910 [Backtracing] Fix processing of DWARF 5 unit headers.
We were processing the header correctly, but remembering the wrong
offset for the DIE.  This was causing missing abbrev errors because
we were then interpreting the wrong bytes.

rdar://178774635
2026-06-10 10:25:34 +01:00
Carl Peto 8b87e3db49 [Backtracing] [Windows] Bugfixes for windows image crash logs (#89218)
- Fix issue with no build id showing up as `000000`... (e.g. no debug
info), now shows as `<no build id>` as intended.
- Try to avoid loading PE file unless it's necessary on Windows
symbolicating backtraces.
- DefaultSymbolLocator: PDB file finding now respects the overridable
path for use in the offline symbolicator (no effect on standard
backtracing).
- Record timestamp/size in Image Info on windows for possible future use
in offline symbolicator

---------

Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
2026-05-19 16:35:38 +01:00
Alastair Houghton a512fc22ee Merge pull request #88488 from al45tair/eng/PR-171438432
[Windows][Backtracing] Don't use `DebugActiveProcess()`.
2026-05-12 11:41:07 +01:00
Alastair Houghton c27e93fc8e [Backtracing][Win32] Scan the global symbol stream and deduplicate.
While for Swift symbols, they always exist in the module streams, the
PDBs that Microsoft serves from its symbol servers don't work that
way, and contain symbols that don't show up in the module streams.

Thus we need to add function data for each of those.

That then creates a problem where the symbol is in both places, so we
need to de-duplicate as well.

rdar://176547291
2026-05-08 16:37:22 +01:00
Carl Peto c3fb29a291 [Backtracing] [Static SDK] Attempt to fix CI build failures
Attempt to fix the static linux build; the target flag isn't being
passed to clang when compiling the `cpu-get-context.S` file. This is
happening because of our abuse of CMake, and only affects the old build
system. (The new build system would do the right thing automatically.)

rdar://175202251
2026-04-30 07:29:07 -07:00
Doug Gregor 1ff4b1a079 Merge pull request #88518 from DougGregor/stdlib-safe-with-functions
Mark the various with* functions as @safe
2026-04-21 22:33:22 -07:00
Carl Peto 550364fadd [Backtracing] Extra SPI for offline symbolicator (#88481)
- **Explanation**:
Add extra SPI to be able to override find methods (for offline
symbolication fetch).

- **Scope**:
No functional change to existing SPI, adds new SPI (and two methods
changed from `public` to `open`).

- **Issues**:
rdar://136978398

- **Original PRs**:
n/a

- **Risk**:
none

- **Testing**:
tested in a local build on Darwin and Linux

- **Reviewers**:
@al45tair

Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
2026-04-20 15:46:48 +01:00
Doug Gregor 453277eb74 Mark the various with* functions as @safe
Functions like withUnsafeBufferPointer are, by themselves, safe to
call. It's only the operations on the unsafe pointers passed into the
closure that are the safety issue.

This was the intent spelled out in SE-0458 but was not fully realized
in the library.

Fixes rdar://174519372.
2026-04-16 22:37:54 -07:00
Alastair Houghton 29a63e572a [Windows][Backtracing] Don't use DebugActiveProcess().
`DebugActiveProcess()` can fail under certain circumstances, which results
in us not seeing the crashing thread, hence you don't get a backtrace (in
fact, the backtracer used to crash, since we never expected to be in that
situation).

Instead, use `NtQuerySystemInformation()` to get the thread list, then
`OpenProcess()` and `OpenThread()` to get process/thread handles.  This
should be more robust.

rdar://171438432
2026-04-16 11:52:07 +01:00
Allan Shortlidge ec6bb44c74 stdlib: Adopt #if os(anyAppleOS).
Replace error prone and verbose compilation conditionals like

```
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
```

with

```
#if os(anyAppleOS)
```
2026-03-26 10:19:00 -07:00
Alastair Houghton 5ea6cf2bc0 [Backtracing] Fix a type error and a warning.
For some reason `DWORD` is `UInt` rather than `UInt32`, which seems wrong.
Anyway, be explicit and use `UInt32` instead.

Also, ignore the image path result from `findElf`, to get rid of a warning.

rdar://172911008
2026-03-20 13:44:37 +00:00
Alastair Houghton 6cb7480a69 [Backtracing] Fix function entry table processing during unwind.
The Win32 unwinder has to locate function entry records for the
`StackWalk64()` API to use; the code that was doing this was
incorrect and sometimes found the wrong record, which would result
in a corrupted stack walk.

rdar://172911008
2026-03-19 12:12:48 +00:00
Alastair Houghton c432e9df61 [Backtracing] Decrease minimum availability version.
We need a minimum target of 15.7 or below because of CI, so add a new
`BacktracingDT 6.2` define.  This is a bit of a hack for now to
unblock CI upgrades; we can go and clean things up and perhaps
generalise this mechanism later.

rdar://172129091
2026-03-12 11:32:22 +00:00
Konrad `ktoso` Malawski ae8922417e [Runtime] Adjust demangle API availability to SwiftStdlib 6.4 (#87820)
The demangle API (`demangle()`) didn't make it into release/6.3, so its
availability should be 6.4.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 03:57:26 -07:00
Carl Peto 4cc9c7638a [Backtracing] Fix cross platform symbolication. (#87490)
Refactoring to allow override on the hard coded image
paths in crash logs. To allow cross platform
offline symbolication.

Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
Co-authored-by: Alastair Houghton <alastair@alastairs-place.net>
2026-03-04 12:18:56 -08:00
Alastair Houghton d8eacdb14b Merge pull request #87676 from al45tair/eng/PR-171711254
[Backtracing] Fix struct packing for PE-COFF definitions.
2026-03-04 17:15:03 +00:00
Nate Cook 856b205170 De-underscore the BorrowingSequence protocols (#87483)
This replaces #87114, aligning the `BorrowingSequence` protocols and
related types to the Swift Evolution proposal, and without included
reparenting of `Sequence`.
2026-03-04 07:13:20 -06:00
Alastair Houghton 78702e64cb [Backtracing] Fix struct packing for PE-COFF definitions.
Due to unfortunate structure packing rules in C, `struct pe_symbol` ends up
being 20 bytes instead of 18. The upshot is that when presented with a PE-COFF
binary that contains symbols (noting that this is actually a spec violation),
the backtracer will crash.

Unfortunately we often generate such binaries. We shouldn’t crash, though, and
the fix is to get the correct size for `struct pe_symbol`.

rdar://171711254
2026-03-04 12:18:56 +00:00
Alastair Houghton 81f477e4a7 [Backtracing] Reorganise thread locals.
Reorganise the thread locals for the backtracing code in the `Runtime` module so
that there’s only one set of them, with everything else hanging off that. This
also reduces code duplication and consumption of thread local variable space.

Fix the `DefaultSymbolLocator`’s shared instance to be thread local.

rdar://171432566
2026-02-28 16:56:05 +00:00
Saleem Abdulrasool cbe4715b9a Merge pull request #87430 from hjyamauchi/armasm
Fix an ARMASM build error
2026-02-23 17:54:31 -08:00
Hiroshi Yamauchi 2354c7ceb7 Fix an ARMASM build error
PUBLIC is a MASM directive and causes a build error in a certain version of MSVC

```
Microsoft (R) ARM Macro Assembler Version 14.44.35217.0 for 64 bits
Copyright (C) Microsoft Corporation.  All rights reserved.

D:\r\_work\swift-build\swift-build\SourceCache\swift\stdlib\public\RuntimeModule\get-cpu-context-aarch64.asm(21) : error A2003: improper line syntax: PUBLIC
```
EXPORT is an ARMASM equivalent, which is already there.
2026-02-23 13:00:39 -08:00
Allan Shortlidge d4547ec74c stdlib: Fix compiler warnings in Concurrency, Cxx, and RuntimeModule
- Remove spurious `unsafe` on non-unsafe calls in TaskCancellation.swift
  and UnsafeCxxIterators.swift
- Change `var fd` to `let fd` in ImageSource.swift since it is never mutated
2026-02-23 09:35:18 -08:00
Alastair Houghton 0c32b10ee6 [Backtracing] baseAddress is Optional, so we need a ! here.
I don't understand how this passed PR testing (or built) previously,
but it did both, then started failing.

rdar://170887396
2026-02-23 10:24:45 +00:00
Carl Peto 70dfbf87b5 [Runtime] Move source code doc comments to DocC (#87311)
rdar://126273038

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
2026-02-20 12:15:42 -08:00
Alastair Houghton 245b5e0766 [Backtracing] Add the ability for a SymbolLocator to find images.
This is better than the `alternativePaths` mechanism because it means that
a client of the `Runtime` module can do its own thing, which might even
mean fetching things from a remote server or decompressing files or any
other thing we might find useful.

rdar://170642627
2026-02-18 16:59:52 +00:00
Alastair Houghton 19b823c9db [Backtracing][PDB] Fix 32-bit Intel build. (#87304) 2026-02-18 07:14:00 -08:00
Alastair Houghton 042861d752 [Backtracing][PDB] Fix a couple of tests.
We can't test the alternate image support for ELF, because that's been
removed in favour of `SymbolLocator`/`SymbolSource`.

Also we must pass `/opt:icf` in the symbolicated backtrace test when
using PDB, otherwise we corrupt the metadata.

Finally fix a mistake in `Utils.swift` where we were crashing if the
environment variable in question wasn't set.

rdar://168454023
2026-02-17 18:51:17 +00:00
Alastair Houghton e7f603fd25 [Backtracing][PDB] For ELF, always return the image file.
ELF images typically do contain symbols, unlike PE-COFF images.

rdar://168454023
2026-02-17 12:24:51 +00:00
Alastair Houghton 2d6d395f75 [Backtracing] Fix Linux build.
The fix for the previous Linux build problem introduced a new one.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton af322cf942 [Backtracing][PDB] Remove ELF-specific lookupSymbol().
We don't need the ELF-specific function any more, so get rid of it.

Also fix a typo.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton d380cde01a [Backtracing][PDB] Remove debugging things.
I'd told the RuntimeModule to build with debug information while
working on debugging it.  We don't want that in the build.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton b89b5e13bd [Backtracing][PDB] Fix-ups after rebasing.
A few tweaks required after rebasing on top of Carl's work on
cross-platform symbolication.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton 487e173a26 [Backtracing][PDB] Scan the main symbol stream as well.
Without scanning the main symbol stream, we get weird names for the
Swift functions in the backtrace, because the compiler generates C++-style
names for them.  We actually want the mangled names, if possible, which
only seem to be in the symbol stream, so scan that as well and use it
to find mangled names.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton acdaeef626 [Backtracing][PDB] Add PDB code and SymbolLocator.
Added the PDB reading code and also a `SymbolLocator` type that
allows us to locate symbols for a given image.

rdar://168454023
2026-02-17 10:50:55 +00:00
Carl Peto 42ea2a5f7f [Backtracing] Allow symbolication across platforms (#86750)
Instead of the symbolication method being decided by what platform the symbolication code is running on, use a parameter passed to the symbolication function, defaulted to the current platform for backward compatibility.

Useful for the upcoming offline symbolicator.

rdar://168769519

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

---------

Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
2026-02-13 13:38:50 +00:00
Jesse Zamora e73c16a330 Support reading DWARFv2 format in DwarfReader
- It is essentially the same as DWARFv3 minus a few missing fields.
2026-02-06 18:13:40 -05:00
Alastair Houghton 3e7647de2c [Backtracing] Fix silly mistake.
I really did mean `ret`.

rdar://101623384
2026-02-06 08:53:16 +00:00
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 ae71bd8d65 [Backtracing] Fix tests up for Windows.
We can't use `|| true` on Windows, so use `not` instead.

Also, on Windows, program names get downcased because `lit` uses
`os.path.normcase()`, so if we have program names in the output,
make sure the programs are already lower-case.

Fix up the stack overflow test to match the expected output.

Plus fix the macOS build to always build for macOS 26.0 or above.

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 58a6470ac3 [Backtracing] Fix build failures for places Runtime doesn't build.
We should only add the assembly files if we're actually going
to build the `Runtime` module.  This was tripping up iOS/tvOS/
watchOS builds.

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 38c4848b12 [Backtracing] Remember to emit end instruction.
We were omitting the `end` instruction, the upshot of which was
that the compact backtrace was always being decoded as truncated.

rdar://101623384
2026-02-06 08:53:15 +00:00
Alastair Houghton add83b4d22 [Backtracing] Don't build backtracing code when it's disabled.
Don't even bother building the backtracing code if the backtracing
code is disabled.

rdar://101623384
2026-02-06 08:53:12 +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 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 bf9dd3ac55 [Backtracing] Make line numbers work.
Also fix things so that we use the right path separator, depending
on image type, and add support for `DW_AT_specification` attributes
on `DW_TAG_subprogram` entries.

rdar://101623384
2026-02-03 18:23:29 +00:00