I assembled with these options nasm -O0 -g -f macho64
but lldb complains of "Unable to resolve breakpoint to any actual locations." when i try to set any breakpoints at line numbers in the file.
I've started trying to learn 64 bit assembly for OS X but it's proving a real challenge so far, there seems to be hardly any resources for learning.
Your assembler probably didn't emit any debug information for the binary you created. You can tell by running dwarfdump --debug-line
on your .o
file or on the .dSYM
bundle for your binary if there is one.
Load the binary into lldb and run the disassemble -n function-name
command. That will show you the assembly - then you can set a breakpoint with breakpoint set -a address
. By default lldb will run your binary with address space randomization (ASLR) turned off -- so the binary will run at the same address every time, instead of loading your program at a randomized address.
A simple example:
% echo 'int main () { }' > a.c
% clang a.c
% lldb a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) disass -n main
a.out`main:
a.out[0x100000fb0] <+0>: pushq %rbp
a.out[0x100000fb1] <+1>: movq %rsp, %rbp
a.out[0x100000fb4] <+4>: xorl %eax, %eax
a.out[0x100000fb6] <+6>: popq %rbp
a.out[0x100000fb7] <+7>: retq
(lldb) br s -a 0x100000fb4
Breakpoint 1: address = 0x0000000100000fb4
(lldb) r
Process 32406 launched: '/private/tmp/a.out' (x86_64)
Process 32406 stopped
* thread #1: tid = 0x145576, 0x0000000100000fb4 a.out`main + 4, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000fb4 a.out`main + 4
a.out`main:
-> 0x100000fb4 <+4>: xorl %eax, %eax
0x100000fb6 <+6>: popq %rbp
0x100000fb7 <+7>: retq
0x100000fb8: addl %eax, (%rax)
(lldb)