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
- 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>
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
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
- **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>
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.
`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
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
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
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
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>
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>
This replaces #87114, aligning the `BorrowingSequence` protocols and
related types to the Swift Evolution proposal, and without included
reparenting of `Sequence`.
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
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
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.
- 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
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
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
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
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>
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
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
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
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
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
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