Skip to content

Commit 55fa387

Browse files
[docs] Update DebuggingTheCompiler.md
1 parent 98d3a81 commit 55fa387

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

docs/DebuggingTheCompiler.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -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.
6060
Here 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
6666
swiftc -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
7272
swiftc -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
7878
swiftc -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
8989
swiftc -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
9595
swiftc -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
101101
swiftc -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
107107
swiftc -S -O file.swift
@@ -380,18 +380,18 @@ and check for the function name in the breakpoint condition:
380380

381381
Sometimes you may want to know which optimization inserts, removes or moves a
382382
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
385385
`SILInstruction.cpp`.
386386
The following command sets a breakpoint which stops if a `strong_retain`
387387
instruction 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

391391
The condition can be made more precise e.g. by also testing in which function
392392
this 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

403403
To 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
419419
one) 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

424424
Run your program again and the breakpoint hits just before the first breakpoint.
425425

426426
Another method for accomplishing the same task is to set the ignore count of the
427427
breakpoint 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

431431
Then whenever the debugger stops next time (due to hitting another
432432
breakpoint/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

437437
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
439439
we 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

443443
A final trick is that one can use the -R option to stop at a relative assembly
444444
address in lldb. Specifically, lldb resolves the breakpoint normally and then

0 commit comments

Comments
 (0)