macosbreakpointslldbosx-yosemite

LLDB Error: Unable to resolve breakpoint to any actual locations


I'm trying to use LLDB (because I apparently can't use gdb anymore) to debug som of my code and each time I try to...

(lldb) breakpoint set -f file.c -l 65

I get...

Breakpoint 1: no locations (pending)
WARNING: Unable to resolve breakpoint to any actual locations.

I've tried different things like assigning the breakpoint to a function and such but I always get the same error. When running there's no break. Please help!


Solution

  • lldb: resolving breakpoints to locations

    If your out file doesn't have debugging symbols enabled for Code Generation Options then breakpoints likely can't be resolved to locations within your .c source file.

    When you create your out file enable debug information:

    $ clang -g -O0 file.c -o file
    $ lldb file
    (lldb) target create "file"
    Current executable set to 'file' (x86_64).
    (lldb) b file.c:13
    Breakpoint 1: where = file`main + 29 at file.c:13, address = 0x0000000100000f4d
    

    Using the -g option adds the necessary debug information to your file for lldb. It should now resolve when you breakpoint set -f file.c -l n (which can be abbreviated as b file.c:n).

    -g Generate debug information. Note that Clang debug information works best at -O0.

    Code Generation Options

    -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
    

    Specify which optimization level to use:

    -O0 Means “no optimization”: this level compiles the fastest and generates the most debuggable code.

    -O1 Somewhere between -O0 and -O2.

    -O2 Moderate level of optimization which enables most optimizations.

    -O3 Like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster).

    -Ofast Enables all the optimizations from -O3 along with other aggressive optimizations that may violate strict compliance with language standards.

    -Os Like -O2 with extra optimizations to reduce code size.

    -Oz Like -Os (and thus -O2), but reduces code size further.

    -Og Like -O1. In future versions, this option might disable different optimizations in order to improve debuggability.

    -O Equivalent to -O1.

    -O4 and higher currently equivalent to -O3