@@ -27,13 +27,18 @@ import _Backtracing
2727
2828@_implementationOnly import Runtime
2929
30+ enum SomeBacktrace {
31+ case raw( Backtrace )
32+ case symbolicated( SymbolicatedBacktrace )
33+ }
34+
3035struct TargetThread {
3136 typealias ThreadID = pid_t
3237
3338 var id : ThreadID
3439 var context : HostContext ?
3540 var name : String
36- var backtrace : SymbolicatedBacktrace
41+ var backtrace : SomeBacktrace
3742}
3843
3944class Target {
@@ -105,7 +110,8 @@ class Target {
105110 return trimmed
106111 }
107112
108- init ( crashInfoAddr: UInt64 , limit: Int ? , top: Int , cache: Bool ) {
113+ init ( crashInfoAddr: UInt64 , limit: Int ? , top: Int , cache: Bool ,
114+ symbolicate: SwiftBacktrace . Symbolication ) {
109115 // fd #4 is reserved for the memory server
110116 let memserverFd : CInt = 4
111117
@@ -130,7 +136,8 @@ class Target {
130136
131137 do {
132138 try fetchThreads ( threadListHead: Address ( crashInfo. thread_list) ,
133- limit: limit, top: top, cache: cache)
139+ limit: limit, top: top, cache: cache,
140+ symbolicate: symbolicate)
134141 } catch {
135142 print ( " swift-backtrace: failed to fetch thread information: \( error) " )
136143 exit ( 1 )
@@ -143,7 +150,8 @@ class Target {
143150 /// uninterruptible wait, we won't have a ucontext for it.
144151 func fetchThreads(
145152 threadListHead: Address ,
146- limit: Int ? , top: Int , cache: Bool
153+ limit: Int ? , top: Int , cache: Bool ,
154+ symbolicate: SwiftBacktrace . Symbolication
147155 ) throws {
148156 var next = threadListHead
149157
@@ -164,18 +172,46 @@ class Target {
164172 images: images,
165173 limit: limit,
166174 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
173192 }
174193
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+ }
179215 }
180216
181217 // Sort the threads by thread ID; the main thread always sorts
@@ -193,7 +229,10 @@ class Target {
193229 }
194230 }
195231
196- func redoBacktraces( limit: Int ? , top: Int , cache: Bool ) {
232+ func redoBacktraces(
233+ limit: Int ? , top: Int , cache: Bool ,
234+ symbolicate: SwiftBacktrace . Symbolication
235+ ) {
197236 for (ndx, thread) in threads. enumerated ( ) {
198237 guard let context = thread. context else {
199238 continue
@@ -208,14 +247,39 @@ class Target {
208247 continue
209248 }
210249
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
216266 }
217267
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+ }
219283 }
220284 }
221285
0 commit comments