Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

can't set file:line breakpoint in ccache compiled source #20296

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20297
Status NEW
Importance P normal
Reported by Vince Harron (vharron@google.com)
Reported on 2014-07-14 14:19:05 -0700
Last modified on 2014-09-23 15:26:30 -0700
Version 3.4
Hardware Macintosh MacOS X
CC clayborg@gmail.com, emaste@freebsd.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
ccache compiled code has *.i filenames instead of *.c file names so the
breakpoint can't be found.

FWIW, I don't know how it does it, but mingw/gdb can set breakpoints in ccache
compiled files just fine.

vharron-macbookpro:bp vharron$ cat bp.c
#include <stdio.h>

int
main() {
  printf("Hello, World!\n");
  return 0;
}

working case:

vharron-macbookpro:bp vharron$ gcc -c -o bp.o bp.c
vharron-macbookpro:bp vharron$ gcc -o bp bp.o
vharron-macbookpro:bp vharron$ lldb bp
Current executable set to 'bp' (x86_64).
(lldb) b bp.c:5
Breakpoint 1: where = bp`main + 22 at bp.c:5, address = 0x0000000100000f56
(lldb) r
Process 6218 launched: '/Users/vharron/dev/bp/bp' (x86_64)
Process 6218 stopped
* thread #1: tid = 0xa93b9, 0x0000000100000f56 bp`main + 22 at bp.c:5, queue =
'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f56 bp`main + 22 at bp.c:5
   2
   3    int
   4    main() {
-> 5      printf("Hello, World!\n");
   6      return 0;
   7    }
   8
(lldb) quit

vharron-macbookpro:bp vharron$ ccache gcc -g -c -o bp.o bp.c
vharron-macbookpro:bp vharron$ gcc -o bp bp.o
vharron-macbookpro:bp vharron$ lldb bp
Current executable set to 'bp' (x86_64).
(lldb) b bp.c:5
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) quit

(my ccache is from macports)

vharron-macbookpro:bp vharron$ ccache --version
ccache version 3.1.9

Copyright (C) 2002-2007 Andrew Tridgell
Copyright (C) 2009-2011 Joel Rosdahl

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
vharron-macbookpro:bp vharron$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-
gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
Quuxplusone commented 10 years ago
vharron-macbookpro:bp vharron$ lldb --version
lldb-310.2.37

(But I also reproduced this in head of SVN)
Quuxplusone commented 10 years ago
With ccache:
cu_sp->GetPath().c_str() /Users/vharron/.ccache/tmp/bp.tmp.vharron-
macbookpro.roam.corp.google.com.6262.i

Without ccache:
cu_sp->GetPath().c_str() /Users/vharron/dev/bp/bp.c
Quuxplusone commented 10 years ago
(oops, there is a typo in the "working case" it was missing the -g flag.
Corrected here)

working case:

vharron-macbookpro:bp vharron$ gcc -g -c -o bp.o bp.c
vharron-macbookpro:bp vharron$ gcc -o bp bp.o
vharron-macbookpro:bp vharron$ lldb bp
Current executable set to 'bp' (x86_64).
(lldb) b bp.c:5
Breakpoint 1: where = bp`main + 22 at bp.c:5, address = 0x0000000100000f56
(lldb) r
Process 6218 launched: '/Users/vharron/dev/bp/bp' (x86_64)
Process 6218 stopped
* thread #1: tid = 0xa93b9, 0x0000000100000f56 bp`main + 22 at bp.c:5, queue =
'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f56 bp`main + 22 at bp.c:5
   2
   3    int
   4    main() {
-> 5      printf("Hello, World!\n");
   6      return 0;
   7    }
   8
(lldb) quit
Quuxplusone commented 10 years ago

Try adding this to your ~/.lldbinit file:

settings set target.inline-breakpoint-strategy always

Quuxplusone commented 10 years ago
That appears to work around the problem.

vharron-macbookpro:bp vharron$ ./build.sh
+ CCACHE=ccache
+ ccache gcc -g -o bp.o -c bp.c
+ gcc -o bp bp.o
vharron-macbookpro:bp vharron$ cat ~/.lldbinit
settings set target.inline-breakpoint-strategy always
vharron-macbookpro:bp vharron$ lldb bp
Current executable set to 'bp' (x86_64).
(lldb) b bp.c:5
Breakpoint 1: where = bp`main + 22 at bp.c:5, address = 0x0000000100000f56
(lldb) quit
vharron-macbookpro:bp vharron$ rm ~/.lldbinit
vharron-macbookpro:bp vharron$ lldb bp
Current executable set to 'bp' (x86_64).
(lldb) b bp.c:5
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
Quuxplusone commented 10 years ago

Do you have any ideas for how to solve this without the lldbinit setting?

Quuxplusone commented 10 years ago

No, if we set the default value of this setting to "always" we end up with serious breakpoint by file + line performance regressions with large C++ projects (like the clang source base).

Our current notion is that if a breakpoint happens in an implementation file (.c .cpp and many more), we only look in translation units that match the implementation file. If it is in any file that isn't an implementation file, then we auto enable looking for breakpoints anywhere. People #include'ing other source files is pretty rare, so this generally works ok. But in cases where some other tool is going this, like in your case, it ends up not working by default. There is no quick way to detect this without causing the performance regression, so currently this is "behaves correctly".

I would just add this line to your ~/.lldbinit file for now.