(lldb) r
Process 40246 resuming
Process 40246 stopped
* thread #1: tid = 0x14dfdf, 0x0000000100000e7c Factorial`Factorial.factorial (n=4) -> Swift.Int + 12 at Factorial.swift:2, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1frame #0: 0x0000000100000e7c Factorial`Factorial.factorial (n=4) -> Swift.Int + 12 at Factorial.swift:21 func factorial(n: Int) -> Int {-> 2if n <=1{return n }3return n * factorial(n: n - 1)4}56letnumber=47 print("\(number)! is equal to \(factorial(n: number))")
Use the print (p) command to inspect the value of the n parameter.
1
2
(lldb) p n
(Int)$R0=4
The print command can evaluate Swift expressions as well.
1
2
(lldb) p n * n
(Int)$R1=16
Use the backtrace (bt) command to show the frames leading to factorial(n:) being called.
Use the continue (c) command to resume the process until the breakpoint is hit again.
1
2
3
4
5
6
7
8
9
10
11
12
(lldb) c
Process 40246 resuming
Process 40246 stopped
* thread #1: tid = 0x14e393, 0x0000000100000e7c Factorial`Factorial.factorial (n=3) -> Swift.Int + 12 at Factorial.swift:2, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1frame #0: 0x0000000100000e7c Factorial`Factorial.factorial (n=3) -> Swift.Int + 12 at Factorial.swift:21 func factorial(n: Int) -> Int {-> 2if n <=1{return n }3return n * factorial(n: n - 1)4}56letnumber=47 print("\(number)! is equal to \(factorial(n: number))")
Use the print (p) command again to inspect the value of the n parameter for the second call to factorial(n:).
1
2
(lldb) p n
(Int)$R2=3
取消断点
Use the breakpoint disable (br di) command to disable all breakpoints and the continue (c) command to have the process run until it exits.
1
2
3
4
5
6
(lldb) br di
All breakpoints disabled. (1 breakpoints)(lldb) c
Process 40246 resuming
4! is equal to 24Process 40246 exited with status=0(0x00000000)