xcodelldbmach-o

LLDB can't list function nor set a breakpoint


I'm having some trouble using lldb, I want to set a breakpoint for a macho file at the start label and at a function called Function1. Ideally i'd like to list all the functions like in gdb with the 'info functions' command, but it seems that this is not available in lldb. Anyways, when I try to set a breakpoint I get this:

breakpoint set --name start
Breakpoint 3: 22 locations

Then if I run the binary, the breakpoint doesn't get hit, it just executes and quits, what gives? Also why does it show "22 locations" there should only be one entry point named start.


Solution

  • lldb's breakpoints aren't quite like gdb breakpoints. An lldb breakpoint is a "search query" that stays alive till you delete the breakpoint, and makes "breakpoint locations" for all matches to the query.

    The default breakpoint type (-n) is an eager search, so:

    (lldb) break set -n start
    

    will match start MyClass::start, -[MyClass start] etc. If you want to have an exact match, use break set -f. You might take a look at:

    (lldb) help break set
    

    for more information on how lldb breakpoints work.

    On Darwin, most programs don't actually have a start symbol anymore. You can see that by running:

     $ nm <my_binary> | grep start
    

    After all, only the loader needs that symbol and it can just record the initial address in its data structures in the binary and avoid a symbol lookup.

    If you want the binary to stop at it's entry point, use:

    (lldb) process launch --stop-at-entry
    

    That will work anywhere.

    If you want to list the symbols in a binary, use:

    (lldb) image dump symtab <Image Name>
    

    If you are used to gdb, you might have a look at:

    https://lldb.llvm.org/use/map.html