Commit Graph

30 Commits

Author SHA1 Message Date
DianQK
017d31fc31 [Backtracing][Linux] Support the DW_AT_specification attribute.
Support parsing the following format:
```
0x0000104b: DW_TAG_subprogram
              DW_AT_specification (0x00000d23 "$s8CrashOpt6level1yyF")
              DW_AT_inline (DW_INL_inlined)
```
2023-08-01 06:59:56 +08:00
Alastair Houghton
c3b925cd1f [Linux][Backtracing] Fix incorrect line number generation.
The code that looks up line numbers wasn't respecting the end-sequence
flag, so it could "find" a line number between the end of one sequence
and the beginning of another.  That was wrong.

rdar://112595022
2023-07-20 15:33:24 +01:00
Alastair Houghton
a73e98c660 [Linux][Backtracing] Fix unwinder so it stops properly.
On Linux specifically, it was possible for it to return `nil` to signal
the end of the unwind, then subsequently return non-`nil` again.  That
violates the expectations of the code layered above it, and can cause
an "Index out of range" error to occur.

rdar://112534548
2023-07-20 15:32:57 +01:00
Alastair Houghton
0b09af1f2f [Backtracing] Fix crash in CrashAsync test on Ubuntu 18.04.
This seems to be happening because we're hitting an invalid frame
on the stack where the program counter value is read back as zero.

If we find one of those, treat it as the end of our stack walk.

rdar://110846253
2023-06-21 11:09:31 +01:00
Alastair Houghton
d396656400 [Backtracing][Linux] Replace regex with ProcMapsScanner.
We were using a regular expression to scan `/proc/<pid>/maps`, but we
shouldn't really do that because it breaks non-bootstrapped builds.

rdar://110452324
2023-06-08 15:53:49 +01:00
Alastair Houghton
8cf570cd76 Revert "[Backtracing][Linux] Temporarily add a default addressWidth."
This reverts commit 0d7c45d9dac68ca820baec816b8857070168136a.
2023-06-07 09:06:34 +01:00
Alastair Houghton
d4b8828e32 [Backtracing][Linux] Also remove the status argument from Runtime module.
There's a separate declaration here because we can't include the `Backtrace.h`
header from inside `modules/Runtime/Runtime.h`.

rdar://110261712
2023-06-07 09:02:12 +01:00
Alastair Houghton
582946b3ee [Backtracing][Linux] Remove status argument.
The `status` argument to the `_swift_backtrace_demangle()` function
isn't especially useful, won't match behaviour on Windows, and we
actually don't use it in the Swift code that calls this SPI.

Remove it.

rdar://110261712
2023-06-07 08:19:13 +01:00
Alastair Houghton
8d9138412d [Backtracing][Linux] Work correctly in the presence of partial reads.
There's a chance that pipes might perform a partial read; we should
handle that case.

rdar://110261712
2023-06-06 18:22:32 +01:00
Alastair Houghton
6ad9720751 [Backtracing][Linux] Temporarily add a default addressWidth.
This is for compatibility, so that I can split up the PRs.
We'll remove it in the next PR.

rdar://110261712
2023-06-06 16:16:20 +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
43ed01f08f [Backtracing][Linux] Reorganise modules for _Backtracing.
Using `SwiftShims` is undesirable - it creates all kinds of build issues,
and means shipping the `_SwiftBacktracing.h` header in the SDK, which is
not necessary.

While we're doing this, add the necessary definitions for reading ELF
and DWARF information.

rdar://110261712
2023-06-06 16:16:20 +01: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
d6cef2c0b5 Merge pull request #64170 from al45tair/eng/PR-106276227
[Backtracing] Mark withCurrentContext() as @_transparent.
2023-03-08 08:37:59 +00:00
Alastair Houghton
7ed869e868 [Backtracing] Mark withCurrentContext() as @_transparent.
The `withCurrentContext()` methods on the `Context` structs need to be
inlined, even in debug builds, otherwise we would need to skip an extra
frame at the top of the backtrace.

This fixes test failures in debug stdlib builds.

rdar://106276227
2023-03-07 18:20:29 +00:00
Alastair Houghton
b9800fda43 Merge pull request #64102 from al45tair/backtracing/full-extra-shims
[Backtracing] Build work.
2023-03-06 20:54:27 +00:00
Alastair Houghton
4ad0a40a73 [Backtracing] Disable assembly language on ARM Windows.
On ARM Windows, we need MARMASM to assemble the context capture code,
but CMake doesn't support MARMASM until version 3.26, which isn't yet
released.

(Confusingly it appears to have partial but non-working support in the
present versions.)

rdar://106284325
2023-03-06 15:47:04 +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
aeb0323b0e [Backtracing] Fix i386 typo.
There was a missing "e" in "movl (%esp), %edx".
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
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
f15011f4d0 [Backtracing] Tweak output slightly.
Fixed the colours so that they work with all of the default Terminal
presets.  Also changed things so that when colour is off, we only use
ASCII characters in our source code displays.

rdar://105452194
2023-03-04 08:00:09 +00:00
Alastair Houghton
af57b2c26d [Backtracing] Tweaks after Mike's remarks.
Just use `UInt` for `Address`.  This is still the subject of some discussion
on the forums, but I haven't decided precisely what to do about it and `UInt`
makes sense for now.  This also necessitated some casts elsewhere.

Improve some comments.

Made `limit` robust against silly negative values.

A couple of formatting fixes.

Don't bother supporting the macOS 10.12.2 SDK as Xcode now supports a minimum
of 10.13.
2023-03-04 07:56:03 +00:00
Alastair Houghton
1c3b8b53c5 [Backtracing] Various improvements following Johannes' remarks.
Removed some unnecessary memory rebinding.

Made `CFString` conversion slightly more efficient.

Provide the `SharedCacheInfo` fields everywhere, but make it optional all
over as well.

rdar://104336548
2023-03-04 07:56:03 +00:00
Alastair Houghton
36c2e4c694 [Backtracing] Fix OS conditionals so iOS builds work.
Some of the `TARGET` and `os()` conditionals needed to be updated.

rdar://104336548
2023-03-04 07:56:03 +00:00
Alastair Houghton
fb830e0505 [Backtracing][Windows] Use CRT, not MSVCRT.
The correct name for the runtime library appears to be CRT, not MSVCRT.

rdar://104336548
2023-03-04 07:56:03 +00:00
Alastair Houghton
55104aae54 [Backtracing] Fix Windows assembler related problem.
We need to enable MASM/MARMASM and we need to add a get-cpu-context.asm
file for it to build.

rdar://104336548
2023-03-04 07:56:03 +00:00
Alastair Houghton
6caea5386b [Backtracing] Add _Backtracing library to the build.
Adds a new swift_Backtracing library, with a corresponding _Backtracing
module, to the build.  Also add some tests.

This is not public API at this point, but will be used by the external
backtracing program, `swift-backtrace`.

rdar://104336548
2023-03-04 07:56:03 +00:00