1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
//! What the program means: the types a unit describes and the functions it defines.
//!
//! Design: `spec/11-asm-objects-debug.md` section 11.4.
//!
//! The line table answers where an address came from. This answers what the thing at that address
//! is: which function a program counter is inside, what that function takes and gives back, and
//! what the types in its signature are made of. A backtrace needs the first, and printing anything
//! at all needs the rest.
//!
//! # A table of shapes rather than the compiler's own types
//!
//! Nothing here is a C type. A [`Shape`] is a DWARF entry with its attributes already decided, so
//! the questions C answers and DWARF does not, which is most of them, are settled before anything
//! reaches this crate. Whoever builds the table decides what `long` is on this target, which of two
//! spellings of one width to write, whether a record is complete and where a bit-field's bits sit.
//! What is left here is writing entries down, which is the part that has to be right about DWARF
//! and has no opinion about C.
//!
//! It costs one thing, which is that a table can say something C cannot mean, and the answer to
//! that is the same as for the machine IR: the writer is not a checker and the thing that would
//! catch it is a reader. `readelf --debug-dump=info` is that reader and is what the differential
//! runs.
//!
//! Every reference between entries is an index into the unit's [`types`] table, because a table of
//! indices can be built in one pass over a recursive type without the borrow checker having
//! anything to say about it, and because a cycle is ordinary rather than special: `struct node {
//! struct node *next; }` is a pointer whose target is the record that holds it, and an index says
//! that with nothing added.
//!
//! # What is described and what is skipped
//!
//! An [`Option<usize>`] target is DWARF's own convention, where the absence of a `DW_AT_type` means
//! `void`. A type this compiler cannot yet describe is not that: a function that mentions one gets
//! no [`Sig`], and a function with no `Sig` gets no `DW_TAG_subprogram` at all, so a debugger falls
//! back to the symbol table for it the way it does for every function today. The alternative is an
//! entry that says `void` or `void *` where the program said something else, and a debugger showing
//! a wrong type is worse than one showing none.
//!
//! [`types`]: crate::Unit::types
/// How the bits of a base type are read, which is DWARF's `DW_AT_encoding`.
///
/// The set C needs and no more. An enumeration rather than the `DW_ATE_` constants themselves so
/// that whoever builds a table does not have to depend on `gimli` to name one.
/// A qualifier, which DWARF writes as an entry wrapping the type it qualifies.
/// Which bits of a record a bit-field member is.
/// One member of a record.
/// One type, in the terms DWARF describes one.
/// One enumerator of an enumeration.
/// What a function takes and gives back.
/// One parameter of a function.
/// One variable the unit defines at file scope.
///
/// Not the same problem as a local, and that is the whole reason this is here and a local is not.
/// A file-scope variable is at one address for the whole of the program, so its location is the
/// address of its own symbol and the linker fills it in, the same way it fills in a function's. A
/// local's location is wherever the code happens to be keeping it at the program counter the
/// debugger stopped at, which is a list rather than an expression, and that is the rest of
/// tamnd/rucc#9.
/// One local the program declared.
///
/// A parameter is not here even when it has a place. It is already a child of the subprogram, from
/// the signature, and a second entry for it would be a second variable of the same name. What it
/// gets instead is [`Param::spot`].
/// Where a local is over the addresses of the function it is in.
///
/// Which of the two a local gets is decided by what lowering did with it rather than by the
/// optimization level. A local with a frame slot is in that slot from the first instruction of the
/// function to the last, because the frame layout hands the slot out once and nothing moves it
/// afterwards, and one expression says so. A scalar whose address is never taken is put in an SSA
/// value instead, at every optimization level including `-O0`, and where the register allocator put
/// that value changes from one program counter to the next.
/// One stretch of a function's addresses and where a local is over it.
/// A place in the machine something can be.
/// Where in the source something was declared.