21

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!

Stone
  • 309
  • 2
  • 3
  • 12

1 Answers1

25

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.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • what does the -O0 option do? – Ultrasaurus Nov 24 '17 at 16:03
  • 1
    @Ultrasaurus: The `-O` is the flag for optimization and the number succeeding it is the level of optimization. Basically `-O0` would optimize the binary to run slightly faster than no optimization while keeping mostly everything needed for debugging purposes. – l'L'l Nov 25 '17 at 00:34
  • 1
    Also, if this still doesn't work, try setting a breakpoint on a function name instead of a file. lldb behavior here seems inconsistent, as I'm able to set breakpoint like `b file:lineno` on some programs, but not others. – Nickolai Oct 01 '18 at 00:44
  • The -O0 solved my problem. -O1 was still optimizing out locals and the ability to set many break points. – natersoz Mar 04 '19 at 15:33