如何在 swift 的 lldb 终端中设置断点?
How do you set breakpoints in the lldb terminal for swift?
我正在尝试在终端中使用 lldb 调试我的 swift 程序。我用命令
编译了我的代码
swiftc hello.swift
然后我运行 lldb 使用
lldb hello
在 lldb 程序中,我尝试使用
设置断点
(lldb) breakpoint set --file hello.swift --line 10
但我得到了错误
Breakpoint 2: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
这是 hello.swift 的代码:
func answer()-> Int{
var value = 12
value = value + 9
return 4 * value
}
let arr = [0, 1, 2, 3, 4]
for _ in arr{
print(answer())
}
我做错了什么?
编译程序时应设置-g
选项。来自 swiftc --help
:
-g Emit debug info. This is the preferred setting for debugging with LLDB.
示例会话:
% swiftc -g hello.swift
% lldb hello
(lldb) target create "hello"
Current executable set to '/tmp/x/hello' (x86_64).
(lldb) breakpoint set --file hello.swift --line 10
Breakpoint 1: where = hello`main + 256 at hello.swift:10:11, address = 0x0000000100003bf0
(lldb) run
Process 15967 launched: '/tmp/x/hello' (x86_64)
Process 15967 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100003bf0 hello`main at hello.swift:10:11
7 let arr = [0, 1, 2, 3, 4]
8
9 for _ in arr{
-> 10 print(answer())
11 }
Target 0: (hello) stopped.
我正在尝试在终端中使用 lldb 调试我的 swift 程序。我用命令
编译了我的代码swiftc hello.swift
然后我运行 lldb 使用
lldb hello
在 lldb 程序中,我尝试使用
设置断点(lldb) breakpoint set --file hello.swift --line 10
但我得到了错误
Breakpoint 2: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
这是 hello.swift 的代码:
func answer()-> Int{
var value = 12
value = value + 9
return 4 * value
}
let arr = [0, 1, 2, 3, 4]
for _ in arr{
print(answer())
}
我做错了什么?
编译程序时应设置-g
选项。来自 swiftc --help
:
-g Emit debug info. This is the preferred setting for debugging with LLDB.
示例会话:
% swiftc -g hello.swift % lldb hello (lldb) target create "hello" Current executable set to '/tmp/x/hello' (x86_64). (lldb) breakpoint set --file hello.swift --line 10 Breakpoint 1: where = hello`main + 256 at hello.swift:10:11, address = 0x0000000100003bf0 (lldb) run Process 15967 launched: '/tmp/x/hello' (x86_64) Process 15967 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100003bf0 hello`main at hello.swift:10:11 7 let arr = [0, 1, 2, 3, 4] 8 9 for _ in arr{ -> 10 print(answer()) 11 } Target 0: (hello) stopped.