Skip to content

Commit 426eda6

Browse files
committed
[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
1 parent f7a2a02 commit 426eda6

File tree

78 files changed

+3729
-1783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3729
-1783
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,10 @@ option(SWIFT_ENABLE_SYNCHRONIZATION
727727
"Enable build of the Swift Synchronization module"
728728
FALSE)
729729

730+
option(SWIFT_ENABLE_RUNTIME_MODULE
731+
"Build the Swift Runtime module"
732+
FALSE)
733+
730734
option(SWIFT_ENABLE_VOLATILE
731735
"Enable build of the Swift Volatile module"
732736
FALSE)
@@ -1384,6 +1388,8 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
13841388
message(STATUS "Observation Support: ${SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION}")
13851389
message(STATUS "Synchronization Support: ${SWIFT_ENABLE_SYNCHRONIZATION}")
13861390
message(STATUS "Volatile Support: ${SWIFT_ENABLE_VOLATILE}")
1391+
message(STATUS "Pointer Bounds Support: ${SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS}")
1392+
message(STATUS "Runtime Support: ${SWIFT_ENABLE_RUNTIME_MODULE}")
13871393
message(STATUS "")
13881394
else()
13891395
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")

docs/Backtracing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,11 @@ of the backtracer using
319319

320320
If the runtime is unable to locate the backtracer, it will allow your program to
321321
crash as it would have done anyway.
322+
323+
Backtrace Storage
324+
-----------------
325+
326+
Backtraces are stored internally in a format called :download:`Compact Backtrace
327+
Format <CompactBacktraceFormat.md>`. This provides us with a way to store a
328+
large number of frames in a much smaller space than would otherwise be possible.
329+

docs/CompactBacktraceFormat.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
Compact Backtrace Format
2+
========================
3+
4+
We would like to be able to efficiently store and access backtraces,
5+
but we also wish to minimise the memory used to store them. Since
6+
backtraces typically contain a good deal of redundancy, it should be
7+
possible to compress the data.
8+
9+
Compact Backtrace Format (CBF) is a binary format for holding a
10+
backtrace; this specification addresses only the storage of the actual
11+
stack backtrace, and it does not consider storage of ancillary data
12+
(register contents, image lists and so on). Those will be dealt with
13+
separately elsewhere.
14+
15+
## General Format
16+
17+
Compact Backtrace Format data is byte aligned and starts with an
18+
information byte:
19+
20+
~~~
21+
7 6 5 4 3 2 1 0
22+
┌───────────────────────┬───────┐
23+
│ version │ size │
24+
└───────────────────────┴───────┘
25+
~~~
26+
27+
The `version` field identifies the version of CBF that is in use; this
28+
document describes version `0`. The `size` field is encoded as
29+
follows:
30+
31+
| `size` | Machine word size |
32+
| :----: | :---------------- |
33+
| 00 | 16-bit |
34+
| 01 | 32-bit |
35+
| 10 | 64-bit |
36+
| 11 | Reserved |
37+
38+
This is followed by a series of instructions that tell the reader how
39+
to decode subsequent data.
40+
41+
The first instruction that computes an address _must_ specify an
42+
absolute address (the `a` bit must be set).
43+
44+
## Instructions
45+
46+
The following instructions are currently defined
47+
48+
| `opcode` | Mnemonic | Meaning |
49+
| :--------: | :------- | :---------------------------------------- |
50+
| `00000000` | `end` | Marks the end of the backtrace |
51+
| `00000001` | `trunc` | As above, but the backtrace was truncated |
52+
| `0000xxxx` | reserved | Reserved for future expansion |
53+
| `0001axxx` | `pc` | A program counter value follows |
54+
| `0010axxx` | `ra` | A return address value follows |
55+
| `0011axxx` | `async` | An async resume point follows |
56+
| `01xxxxxx` | `omit` | Indicates frames have been omitted |
57+
| `1xxxxxxx` | reserved | Reserved for future expansion |
58+
59+
### `end`/`trunc`
60+
61+
#### Encoding
62+
63+
~~~
64+
7 6 5 4 3 2 1 0
65+
┌───────────────────────────┬───┐
66+
│ 0 0 0 0 0 0 0 │ t │ end (or trunc if t is 1)
67+
└───────────────────────────┴───┘
68+
~~~
69+
70+
#### Meaning
71+
72+
Marks the end of the backtrace data. If `t` is set, it indicates that
73+
the backtrace was truncated at this point (for instance because we hit
74+
a frame limit while capturing).
75+
76+
It is not strictly necessary to use the `end` instruction if the
77+
CBF data is of a known length.
78+
79+
### `pc`, `ra`, `async`
80+
81+
#### Encoding
82+
83+
~~~
84+
7 6 5 4 3 2 1 0
85+
┌────────────────┬───┬──────────┐
86+
│ 0 0 0 1 │ a │ count │ pc
87+
└────────────────┴───┴──────────┘
88+
┌────────────────┬───┬──────────┐
89+
│ 0 0 1 0 │ a │ count │ ra
90+
└────────────────┴───┴──────────┘
91+
┌────────────────┬───┬──────────┐
92+
│ 0 0 1 1 │ a │ count │ async
93+
└────────────────┴───┴──────────┘
94+
~~~
95+
96+
#### Meaning
97+
98+
Each of these instructions represents a frame on the stack. For `pc`
99+
frames, the computed address is an actual program counter (aka
100+
instruction pointer) value. `ra` instructions instead represent a
101+
_return address_, the difference being that the program has not yet
102+
executed that instruction. `async` instructions point at the entry
103+
point of an async resume function, and are used when walking stacks on
104+
systems that support `async`/`await` primitives that are implemented
105+
by function splitting (typically an `async` instruction will point at
106+
the start of a function containing the code immediately following an
107+
`await`).
108+
109+
The next `count + 1` bytes following the instruction are an address
110+
value. If `a` is set, the computed address is equal to the address
111+
value. If `a` is not set, the computed address is equal to the
112+
preceding computed address *plus* the address value.
113+
114+
Address values are sign-extended to the machine word width before
115+
processing. Thus a single address byte with value `0xff` on a 32-bit
116+
backtrace represents the address value `0xffffffff`.
117+
118+
### `omit`
119+
120+
#### Encoding
121+
122+
~~~
123+
7 6 5 4 3 2 1 0
124+
┌───────┬───┬───────────────────┐
125+
│ 0 1 │ x │ count │ omit
126+
└───────┴───┴───────────────────┘
127+
~~~
128+
129+
#### Meaning
130+
131+
Indicates that a number of frames were skipped when capturing the
132+
backtrace. This is used to allow a backtrace to include both the top
133+
and bottom of the stack, without carrying every intervening frame, and
134+
is useful to prevent the data from exploding where recursion has taken
135+
place.
136+
137+
If `x` is `1`, the instruction is followed by `count + 1` bytes (up to the
138+
machine word length) that are zero-extended to machine word length and
139+
that represent a count of the number of frames that were omitted.
140+
141+
If `x` is `0`, `count + 1` is the number of frames that were omitted.

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -651,22 +651,6 @@ static void recordShadowedDeclsAfterTypeMatch(
651651
}
652652
}
653653

654-
// Next, prefer any other module over the _Backtracing module.
655-
if (auto spModule = ctx.getLoadedModule(ctx.Id_Backtracing)) {
656-
if ((firstModule == spModule) != (secondModule == spModule)) {
657-
// If second module is _StringProcessing, then it is shadowed by
658-
// first.
659-
if (secondModule == spModule) {
660-
shadowed.insert(secondDecl);
661-
continue;
662-
}
663-
664-
// Otherwise, the first declaration is shadowed by the second.
665-
shadowed.insert(firstDecl);
666-
break;
667-
}
668-
}
669-
670654
// Next, prefer any other module over the Observation module.
671655
if (auto obsModule = ctx.getLoadedModule(ctx.Id_Observation)) {
672656
if ((firstModule == obsModule) != (secondModule == obsModule)) {

lib/DriverTool/autolink_extract_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
230230
"-lswift_StringProcessing",
231231
"-lswiftRegexBuilder",
232232
"-lswift_RegexParser",
233-
"-lswift_Backtracing",
234233
"-lswift_Builtin_float",
235234
"-lswift_math",
235+
"-lswiftRuntime",
236236
"-lswiftSynchronization",
237237
"-lswiftGlibc",
238238
"-lswiftAndroid",

stdlib/public/Backtracing/ArrayImageSource.swift

Lines changed: 0 additions & 48 deletions
This file was deleted.

stdlib/public/Backtracing/FileImageSource.swift

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)