@@ -7,8 +7,8 @@ This document contains some useful information for debugging:
77* Intermediate output of the Swift Compiler.
88* Swift applications at runtime.
99
10- Please feel free add any useful tips that one finds to this document for the
11- benefit of all swift developers.
10+ Please feel free to add any useful tips that one finds to this document for the
11+ benefit of all Swift developers.
1212
1313** Table of Contents**
1414
@@ -33,7 +33,7 @@ benefit of all swift developers.
3333 - [ Bisecting Compiler Errors] ( #bisecting-compiler-errors )
3434 - [ Bisecting on SIL optimizer pass counts to identify optimizer bugs] ( #bisecting-on-sil-optimizer-pass-counts-to-identify-optimizer-bugs )
3535 - [ Using git-bisect in the presence of branch forwarding/feature branches] ( #using-git-bisect-in-the-presence-of-branch-forwardingfeature-branches )
36- - [ Reducing SIL test cases using bug_reducer] ( #reducing-sil-test-cases-using-bugreducer )
36+ - [ Reducing SIL test cases using bug_reducer] ( #reducing-sil-test-cases-using-bug_reducer )
3737- [ Debugging Swift Executables] ( #debugging-swift-executables )
3838 - [ Determining the mangled name of a function in LLDB] ( #determining-the-mangled-name-of-a-function-in-lldb )
3939 - [ Manually symbolication using LLDB] ( #manually-symbolication-using-lldb )
@@ -60,19 +60,19 @@ The most important thing when debugging the compiler is to examine the IR.
6060Here is how to dump the IR after the main phases of the Swift compiler
6161(assuming you are compiling with optimizations enabled):
6262
63- * ** Parser** To print the AST after parsing::
63+ * ** Parser** To print the AST after parsing:
6464
6565``` bash
6666swiftc -dump-ast -O file.swift
6767```
6868
69- * ** SILGen** To print the SIL immediately after SILGen::
69+ * ** SILGen** To print the SIL immediately after SILGen:
7070
7171``` bash
7272swiftc -emit-silgen -O file.swift
7373```
7474
75- * ** Mandatory SIL passes** To print the SIL after the mandatory passes::
75+ * ** Mandatory SIL passes** To print the SIL after the mandatory passes:
7676
7777``` bash
7878swiftc -emit-sil -Onone file.swift
@@ -83,25 +83,25 @@ swiftc -emit-sil -Onone file.swift
8383 get what you want to see.
8484
8585* ** Performance SIL passes** To print the SIL after the complete SIL
86- optimization pipeline::
86+ optimization pipeline:
8787
8888``` bash
8989swiftc -emit-sil -O file.swift
9090```
9191
92- * ** IRGen** To print the LLVM IR after IR generation::
92+ * ** IRGen** To print the LLVM IR after IR generation:
9393
9494``` bash
9595swiftc -emit-ir -Xfrontend -disable-llvm-optzns -O file.swift
9696```
9797
98- * ** LLVM passes** To print the LLVM IR after LLVM passes::
98+ * ** LLVM passes** To print the LLVM IR after LLVM passes:
9999
100100``` bash
101101swiftc -emit-ir -O file.swift
102102```
103103
104- * ** Code generation** To print the final generated code::
104+ * ** Code generation** To print the final generated code:
105105
106106``` bash
107107swiftc -S -O file.swift
@@ -380,18 +380,18 @@ and check for the function name in the breakpoint condition:
380380
381381Sometimes you may want to know which optimization inserts, removes or moves a
382382certain instruction. To find out, set a breakpoint in
383- ` ilist_traits<SILInstruction>:addNodeToList ` or
384- ` ilist_traits<SILInstruction>:removeNodeFromList ` , which are defined in
383+ ` ilist_traits<SILInstruction>:: addNodeToList ` or
384+ ` ilist_traits<SILInstruction>:: removeNodeFromList ` , which are defined in
385385` SILInstruction.cpp ` .
386386The following command sets a breakpoint which stops if a ` strong_retain `
387387instruction is removed:
388388
389- (lldb) br set -c 'I->getKind() == ValueKind:StrongRetainInst' -f SILInstruction.cpp -l 63
389+ (lldb) br set -c 'I->getKind() == ValueKind:: StrongRetainInst' -f SILInstruction.cpp -l 63
390390
391391The condition can be made more precise e.g. by also testing in which function
392392this happens:
393393
394- (lldb) br set -c 'I->getKind() == ValueKind:StrongRetainInst &&
394+ (lldb) br set -c 'I->getKind() == ValueKind:: StrongRetainInst &&
395395 I->getFunction()->hasName("_TFC3nix1Xd")'
396396 -f SILInstruction.cpp -l 63
397397
@@ -402,7 +402,7 @@ function.
402402
403403To achieve this, set another breakpoint and add breakpoint commands:
404404
405- (lldb) br set -n GlobalARCOpts:run
405+ (lldb) br set -n GlobalARCOpts:: run
406406 Breakpoint 2
407407 (lldb) br com add 2
408408 > p int $n = $n + 1
@@ -419,26 +419,26 @@ Now remove the breakpoint commands from the second breakpoint (or create a new
419419one) and set the ignore count to $n minus one:
420420
421421 (lldb) br delete 2
422- (lldb) br set -i 4 -n GlobalARCOpts:run
422+ (lldb) br set -i 4 -n GlobalARCOpts:: run
423423
424424Run your program again and the breakpoint hits just before the first breakpoint.
425425
426426Another method for accomplishing the same task is to set the ignore count of the
427427breakpoint to a large number, i.e.:
428428
429- (lldb) br set -i 9999999 -n GlobalARCOpts:run
429+ (lldb) br set -i 9999999 -n GlobalARCOpts:: run
430430
431431Then whenever the debugger stops next time (due to hitting another
432432breakpoint/crash/assert) you can list the current breakpoints:
433433
434434 (lldb) br list
435- 1: name = 'GlobalARCOpts:run', locations = 1, resolved = 1, hit count = 85 Options: ignore: 1 enabled
435+ 1: name = 'GlobalARCOpts:: run', locations = 1, resolved = 1, hit count = 85 Options: ignore: 1 enabled
436436
437437which will then show you the number of times that each breakpoint was hit. In
438- this case, we know that ` GlobalARCOpts:run ` was hit 85 times. So, now
438+ this case, we know that ` GlobalARCOpts:: run ` was hit 85 times. So, now
439439we know to ignore swift_getGenericMetadata 84 times, i.e.:
440440
441- (lldb) br set -i 84 -n GlobalARCOpts:run
441+ (lldb) br set -i 84 -n GlobalARCOpts:: run
442442
443443A final trick is that one can use the -R option to stop at a relative assembly
444444address in lldb. Specifically, lldb resolves the breakpoint normally and then
0 commit comments