Skip to content

Commit 80c858f

Browse files
authored
Merge pull request #72031 from ahoppen/ahoppen/lsan-documentation
Improve documentation on how to debug LSAN failures
2 parents 71651b0 + eac6405 commit 80c858f

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

docs/LSANFailureSymbolication.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
1. Clone (or pull) swift-docker: https://github.com/apple/swift-docker
66
2. Build the Ubuntu 18.04 container: `cd swift-ci/master/ubuntu/18.04; docker build .`
7-
3. `docker run -it cpus <CPUs> memory <Memory> -v ~/<path to your local sources>:/src-on-host:cached name lsan-reproducer cap-add=SYS_PTRACE security-opt seccomp=unconfined <hash that docker build outputs> bash`
7+
3. `docker run -it --cpus <CPUs> --memory <Memory> -v ~/<path to your local sources>:/src-on-host:cached --name lsan-reproducer --cap-add=SYS_PTRACE --security-opt seccomp=unconfined <hash that docker build outputs> bash`
88
- The `-cap-add` and `-security-opt` arguments are needed to run LLDB inside the Docker container
9-
4. Copy the sources to inside the Docker container: `cp /src-on-host/* ~`
9+
4. Copy the sources to inside the Docker container: `cp -r /src-on-host/* ~`
1010
- We need to to this because the build needs a case-sensitive file system and your host machine probably has a case-insensitive file system
1111

1212
Build inside the Container
@@ -36,36 +36,25 @@ Direct leak of 120 byte(s) in 3 object(s) allocated from:
3636
SUMMARY: LeakSanitizer: 120 byte(s) leaked in 3 allocation(s).
3737
```
3838
2. `lldb -- <your swiftc invocation above>`
39-
3. Set a breakpoint somewhere in swiftc, eg. at the start of main: `br s -f driver.cpp -l 19`. This should output something like
40-
41-
```
42-
Breakpoint 1: where = swiftc`main + 4 at driver.cpp:20:10, address = 0x00000000014d25d4
43-
```
44-
45-
4. Run swiftc to the breakpoint
46-
5. This should stop you with something like
47-
39+
3. Start running swiftc inside lldb by executing `r`
40+
4. Find the loaded offset of swift-frontend by running `image list`
41+
For example, this might output
4842
```
49-
* thread #1, name = 'swiftc', stop reason = breakpoint 1.1
50-
frame #0: 0x0000555556a265d4 swiftc`main(argc_=168, argv_=0x00007fffffffced8) at driver.cpp:20:10
51-
17 #include "swift/DriverTool/DriverTool.h"
52-
18
53-
19 int main(int argc_, const char **argv_) {
54-
→ 20 return swift::mainEntry(argc_, argv_);
55-
21 }
43+
[ 0] 0AEA10C1 0x0000555555554000 /home/build-user/build/buildbot_incremental_lsan/swift-linux-x86_64/bin/swift-frontend
44+
[ 1] D52BB67A-BBBB-E429-6E87-FC16144CA7CE-55276DD6 0x00007ffff7ffb000 [vdso] (0x00007ffff7ffb000)
45+
[ 2] 9EA8014C-F020-21A2-9E57-AA3E0512E9BB-6E30541D 0x00007ffff7dd3000 /lib/x86_64-linux-gnu/ld-2.27.so
5646
```
57-
58-
6. Find the loaded offset of swift-frontend by subtracting the breakpoint address from the frame address. With the example above, that’s `0x0000555556a265d4 - 0x00000000014d25d4 = 0x555555554000`.
59-
7. For the frame that you want to symbolicate,, add the offset you computed above to the stack frame in the LSAN report, eg. to symbolicate frame 1 `0x555555554000 + 0x292d81c = 0x555557E8181C`
60-
8. Look up the address using `image lookup -a <address you computed>`. This should output something like
47+
The loaded offset is `0x0000555555554000`
48+
5. For the frame that you want to symbolicate,, add the offset you computed above to the stack frame in the LSAN report, eg. to symbolicate frame 1 `0x555555554000 + 0x292d81c = 0x555557E8181C`
49+
6. Look up the address using `image lookup -a <address you computed>`. This should output something like
6150

6251
```
6352
(lldb) image lookup -a 0x555557E8181C
6453
Address: swiftc[0x000000000292d81c] (swiftc.PT_LOAD[0]..text + 22056284)
6554
Summary: swiftc`registerFunctionTest(BridgedStringRef, void*) + 28 at SILBridging.cpp:148:3
6655
```
6756

68-
9. Hoorray, you know which function is leaking.
57+
7. Hoorray, you know which function is leaking.
6958

7059
### Making Local Changes Inside the Container
7160

0 commit comments

Comments
 (0)