I am trying to debug my swift program using lldb in terminal. I have compiled my code with the command
swiftc hello.swift
then I ran lldb using
lldb hello
in the lldb program I tried to set a break point using
(lldb) breakpoint set --file hello.swift --line 10
but I got the error
Breakpoint 2: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
here is the code for 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())
}
what am I doing wrong?
CodePudding user response:
You should set the -g
option when compiling the program. From swiftc --help
:
-g Emit debug info. This is the preferred setting for debugging with LLDB.
Example session:
% 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.