@@ -7,8 +7,8 @@ This document contains some useful information for debugging:
7
7
* Intermediate output of the Swift Compiler.
8
8
* Swift applications at runtime.
9
9
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.
12
12
13
13
** Table of Contents**
14
14
@@ -33,7 +33,7 @@ benefit of all swift developers.
33
33
- [ Bisecting Compiler Errors] ( #bisecting-compiler-errors )
34
34
- [ Bisecting on SIL optimizer pass counts to identify optimizer bugs] ( #bisecting-on-sil-optimizer-pass-counts-to-identify-optimizer-bugs )
35
35
- [ 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 )
37
37
- [ Debugging Swift Executables] ( #debugging-swift-executables )
38
38
- [ Determining the mangled name of a function in LLDB] ( #determining-the-mangled-name-of-a-function-in-lldb )
39
39
- [ 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.
60
60
Here is how to dump the IR after the main phases of the Swift compiler
61
61
(assuming you are compiling with optimizations enabled):
62
62
63
- * ** Parser** To print the AST after parsing::
63
+ * ** Parser** To print the AST after parsing:
64
64
65
65
``` bash
66
66
swiftc -dump-ast -O file.swift
67
67
```
68
68
69
- * ** SILGen** To print the SIL immediately after SILGen::
69
+ * ** SILGen** To print the SIL immediately after SILGen:
70
70
71
71
``` bash
72
72
swiftc -emit-silgen -O file.swift
73
73
```
74
74
75
- * ** Mandatory SIL passes** To print the SIL after the mandatory passes::
75
+ * ** Mandatory SIL passes** To print the SIL after the mandatory passes:
76
76
77
77
``` bash
78
78
swiftc -emit-sil -Onone file.swift
@@ -83,25 +83,25 @@ swiftc -emit-sil -Onone file.swift
83
83
get what you want to see.
84
84
85
85
* ** Performance SIL passes** To print the SIL after the complete SIL
86
- optimization pipeline::
86
+ optimization pipeline:
87
87
88
88
``` bash
89
89
swiftc -emit-sil -O file.swift
90
90
```
91
91
92
- * ** IRGen** To print the LLVM IR after IR generation::
92
+ * ** IRGen** To print the LLVM IR after IR generation:
93
93
94
94
``` bash
95
95
swiftc -emit-ir -Xfrontend -disable-llvm-optzns -O file.swift
96
96
```
97
97
98
- * ** LLVM passes** To print the LLVM IR after LLVM passes::
98
+ * ** LLVM passes** To print the LLVM IR after LLVM passes:
99
99
100
100
``` bash
101
101
swiftc -emit-ir -O file.swift
102
102
```
103
103
104
- * ** Code generation** To print the final generated code::
104
+ * ** Code generation** To print the final generated code:
105
105
106
106
``` bash
107
107
swiftc -S -O file.swift
@@ -380,18 +380,18 @@ and check for the function name in the breakpoint condition:
380
380
381
381
Sometimes you may want to know which optimization inserts, removes or moves a
382
382
certain 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
385
385
` SILInstruction.cpp ` .
386
386
The following command sets a breakpoint which stops if a ` strong_retain `
387
387
instruction is removed:
388
388
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
390
390
391
391
The condition can be made more precise e.g. by also testing in which function
392
392
this happens:
393
393
394
- (lldb) br set -c 'I->getKind() == ValueKind:StrongRetainInst &&
394
+ (lldb) br set -c 'I->getKind() == ValueKind:: StrongRetainInst &&
395
395
I->getFunction()->hasName("_TFC3nix1Xd")'
396
396
-f SILInstruction.cpp -l 63
397
397
@@ -402,7 +402,7 @@ function.
402
402
403
403
To achieve this, set another breakpoint and add breakpoint commands:
404
404
405
- (lldb) br set -n GlobalARCOpts:run
405
+ (lldb) br set -n GlobalARCOpts:: run
406
406
Breakpoint 2
407
407
(lldb) br com add 2
408
408
> p int $n = $n + 1
@@ -419,26 +419,26 @@ Now remove the breakpoint commands from the second breakpoint (or create a new
419
419
one) and set the ignore count to $n minus one:
420
420
421
421
(lldb) br delete 2
422
- (lldb) br set -i 4 -n GlobalARCOpts:run
422
+ (lldb) br set -i 4 -n GlobalARCOpts:: run
423
423
424
424
Run your program again and the breakpoint hits just before the first breakpoint.
425
425
426
426
Another method for accomplishing the same task is to set the ignore count of the
427
427
breakpoint to a large number, i.e.:
428
428
429
- (lldb) br set -i 9999999 -n GlobalARCOpts:run
429
+ (lldb) br set -i 9999999 -n GlobalARCOpts:: run
430
430
431
431
Then whenever the debugger stops next time (due to hitting another
432
432
breakpoint/crash/assert) you can list the current breakpoints:
433
433
434
434
(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
436
436
437
437
which 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
439
439
we know to ignore swift_getGenericMetadata 84 times, i.e.:
440
440
441
- (lldb) br set -i 84 -n GlobalARCOpts:run
441
+ (lldb) br set -i 84 -n GlobalARCOpts:: run
442
442
443
443
A final trick is that one can use the -R option to stop at a relative assembly
444
444
address in lldb. Specifically, lldb resolves the breakpoint normally and then
0 commit comments