@@ -27,13 +27,18 @@ import _Backtracing
27
27
28
28
@_implementationOnly import Runtime
29
29
30
+ enum SomeBacktrace {
31
+ case raw( Backtrace )
32
+ case symbolicated( SymbolicatedBacktrace )
33
+ }
34
+
30
35
struct TargetThread {
31
36
typealias ThreadID = pid_t
32
37
33
38
var id : ThreadID
34
39
var context : HostContext ?
35
40
var name : String
36
- var backtrace : SymbolicatedBacktrace
41
+ var backtrace : SomeBacktrace
37
42
}
38
43
39
44
class Target {
@@ -105,7 +110,8 @@ class Target {
105
110
return trimmed
106
111
}
107
112
108
- init ( crashInfoAddr: UInt64 , limit: Int ? , top: Int , cache: Bool ) {
113
+ init ( crashInfoAddr: UInt64 , limit: Int ? , top: Int , cache: Bool ,
114
+ symbolicate: SwiftBacktrace . Symbolication ) {
109
115
// fd #4 is reserved for the memory server
110
116
let memserverFd : CInt = 4
111
117
@@ -130,7 +136,8 @@ class Target {
130
136
131
137
do {
132
138
try fetchThreads ( threadListHead: Address ( crashInfo. thread_list) ,
133
- limit: limit, top: top, cache: cache)
139
+ limit: limit, top: top, cache: cache,
140
+ symbolicate: symbolicate)
134
141
} catch {
135
142
print ( " swift-backtrace: failed to fetch thread information: \( error) " )
136
143
exit ( 1 )
@@ -143,7 +150,8 @@ class Target {
143
150
/// uninterruptible wait, we won't have a ucontext for it.
144
151
func fetchThreads(
145
152
threadListHead: Address ,
146
- limit: Int ? , top: Int , cache: Bool
153
+ limit: Int ? , top: Int , cache: Bool ,
154
+ symbolicate: SwiftBacktrace . Symbolication
147
155
) throws {
148
156
var next = threadListHead
149
157
@@ -164,18 +172,46 @@ class Target {
164
172
images: images,
165
173
limit: limit,
166
174
top: top)
167
- guard let symbolicated
168
- = backtrace. symbolicated ( with: images,
169
- sharedCacheInfo: nil ,
170
- useSymbolCache: cache) else {
171
- print ( " unable to symbolicate backtrace for thread \( t. tid) " )
172
- exit ( 1 )
175
+
176
+ let shouldSymbolicate : Bool
177
+ let showInlineFrames : Bool
178
+ let showSourceLocations : Bool
179
+ switch symbolicate {
180
+ case . off:
181
+ shouldSymbolicate = false
182
+ showInlineFrames = false
183
+ showSourceLocations = false
184
+ case . fast:
185
+ shouldSymbolicate = true
186
+ showInlineFrames = false
187
+ showSourceLocations = false
188
+ case . full:
189
+ shouldSymbolicate = true
190
+ showInlineFrames = true
191
+ showSourceLocations = true
173
192
}
174
193
175
- threads. append ( TargetThread ( id: TargetThread . ThreadID ( t. tid) ,
176
- context: context,
177
- name: getThreadName ( tid: t. tid) ,
178
- backtrace: symbolicated) )
194
+ if shouldSymbolicate {
195
+ guard let symbolicated
196
+ = backtrace. symbolicated ( with: images,
197
+ sharedCacheInfo: nil ,
198
+ showInlineFrames: showInlineFrames,
199
+ showSourceLocations: showSourceLocations,
200
+ useSymbolCache: cache) else {
201
+ print ( " unable to symbolicate backtrace for thread \( t. tid) " )
202
+ exit ( 1 )
203
+ }
204
+
205
+ threads. append ( TargetThread ( id: TargetThread . ThreadID ( t. tid) ,
206
+ context: context,
207
+ name: getThreadName ( tid: t. tid) ,
208
+ backtrace: . symbolicated( symbolicated) ) )
209
+ } else {
210
+ threads. append ( TargetThread ( id: TargetThread . ThreadID ( t. tid) ,
211
+ context: context,
212
+ name: getThreadName ( tid: t. tid) ,
213
+ backtrace: . raw( backtrace) ) )
214
+ }
179
215
}
180
216
181
217
// Sort the threads by thread ID; the main thread always sorts
@@ -193,7 +229,10 @@ class Target {
193
229
}
194
230
}
195
231
196
- func redoBacktraces( limit: Int ? , top: Int , cache: Bool ) {
232
+ func redoBacktraces(
233
+ limit: Int ? , top: Int , cache: Bool ,
234
+ symbolicate: SwiftBacktrace . Symbolication
235
+ ) {
197
236
for (ndx, thread) in threads. enumerated ( ) {
198
237
guard let context = thread. context else {
199
238
continue
@@ -208,14 +247,39 @@ class Target {
208
247
continue
209
248
}
210
249
211
- guard let symbolicated = backtrace. symbolicated ( with: images,
212
- sharedCacheInfo: nil ,
213
- useSymbolCache: cache) else {
214
- print ( " unable to symbolicate backtrace from context for thread \( ndx) " )
215
- continue
250
+ let shouldSymbolicate : Bool
251
+ let showInlineFrames : Bool
252
+ let showSourceLocations : Bool
253
+ switch symbolicate {
254
+ case . off:
255
+ shouldSymbolicate = false
256
+ showInlineFrames = false
257
+ showSourceLocations = false
258
+ case . fast:
259
+ shouldSymbolicate = true
260
+ showInlineFrames = false
261
+ showSourceLocations = false
262
+ case . full:
263
+ shouldSymbolicate = true
264
+ showInlineFrames = true
265
+ showSourceLocations = true
216
266
}
217
267
218
- threads [ ndx] . backtrace = symbolicated
268
+ if shouldSymbolicate {
269
+ guard let symbolicated = backtrace. symbolicated (
270
+ with: images,
271
+ sharedCacheInfo: nil ,
272
+ showInlineFrames: showInlineFrames,
273
+ showSourceLocations: showSourceLocations,
274
+ useSymbolCache: cache) else {
275
+ print ( " unable to symbolicate backtrace from context for thread \( ndx) " )
276
+ continue
277
+ }
278
+
279
+ threads [ ndx] . backtrace = . symbolicated( symbolicated)
280
+ } else {
281
+ threads [ ndx] . backtrace = . raw( backtrace)
282
+ }
219
283
}
220
284
}
221
285
0 commit comments