Bug 14870 - Missing source information for binaries compiled with clang on Linux and OS X
Summary: Missing source information for binaries compiled with clang on Linux and OS X
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-22 03:15 UTC by David Albert
Modified: 2015-06-09 17:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Albert 2012-11-22 03:15:21 UTC
When debugging programs compiled with clang, GDB is missing source information. I've verified this on Linux with Clang 3.1 and GDB 7.5, and Darwin with Apple Clang 4.1 (based on Clang 3.1) and GDB trunk and 7.5.

I've included a transcript of my debugging session on OS X. The results for Linux were the same (I can provide them if necessary).

A few things to notice:

1) Setting a breakpoint should print line and file information, but instead prints only the address.

2) If I were to run `next` or `step` after the breakpoint is hit, GDB responds with "Single stepping until exit from function main, which has no line number information." Advancing with `nexti` works fine (as do all operations that don't deal directly with source info). After advancing five instructions, GDB suddenly has source info and `next` and `step` start working again, however if you re-start the program being debugged, source info is lost again.

$ clang --version
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix

$ gdb --version
GNU gdb (GDB) 7.5.50.20121121-cvs
[snip]

$ cat hello.c
#include <stdio.h>

int main(int argc, const char *argv[])
{
        printf("Hello, world\n");
        return 0;
}

$ clang -g -O0 hello.c -o hello

$ gdb -q hello
Reading symbols from /private/tmp/gdbtest/hello...Reading symbols from /private/tmp/gdbtest/hello.dSYM/Contents/Resources/DWARF/hello...done.
done.
(gdb) break main
Breakpoint 1 at 0x100000f14
(gdb) run
Starting program: /private/tmp/gdbtest/hello 

Breakpoint 1, 0x0000000100000f14 in main (argc=1606422622, argv=0x7fff5fbff7b0)
(gdb) nexti
0x0000000100000f18 in main (argc=1606422622, argv=0x7fff5fbff7b0)
(gdb) nexti
0x0000000100000f1f in main (argc=1606422622, argv=0x7fff5fbff7b0)
(gdb) nexti
0x0000000100000f26 in main (argc=1606422622, argv=0x7fff5fbff7b0)
(gdb) nexti
0x0000000100000f29 in main (argc=1, argv=0x7fff5fbff7b0)
(gdb) nexti
5	        printf("Hello, world\n");
(gdb) next
Hello, world
6	        return 0;
Comment 1 Ben Longbons 2013-07-30 06:30:22 UTC
Sounds like this clang bug: http://llvm.org/bugs/show_bug.cgi?id=13211
Comment 2 David Albert 2015-06-09 17:23:22 UTC
I believe this bug is now fixed. I just tested this on OS X 10.10.3 with Apple Clang 6.1.0 (based on LLVM 3.6.0) and GDB 7.9.1 as well as an Ubuntu 15.04 VM with Clang 3.6.0 and GDB 7.9 and was unable to reproduce in either instance. I'm going to close this ticket. I've included my shell sessions below for reference.


# OS X 10.10.3

$ clang --version
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

$ gdb --version
GNU gdb (GDB) 7.9.1
[snip]

$ cat hello.c 
#include <stdio.h>

int main(int argc, const char *argv[])
{
        printf("Hello, world\n");
        return 0;
}

$ clang -g -O0 hello.c -o hello

$ gdb -q hello
Reading symbols from hello...Reading symbols from /private/tmp/hello/hello.dSYM/Contents/Resources/DWARF/hello...done.
done.
(gdb) break main
Breakpoint 1 at 0x100000f4d: file hello.c, line 5.
(gdb) run
Starting program: /private/tmp/hello/hello 

[snip some unrelated warnings]

Breakpoint 1, main (argc=1, argv=0x7fff5fbff368) at hello.c:5
5	        printf("Hello, world\n");
(gdb) next
Hello, world
6	        return 0;
(gdb) next
0x00007fff8f5b45c9 in start () from /usr/lib/system/libdyld.dylib
(gdb) next
Single stepping until exit from function start,
which has no line number information.
[Inferior 1 (process 68284) exited normally]
(gdb) 




# Ubuntu 15.04

$ clang --version
Ubuntu clang version 3.6.0-2ubuntu1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)
Target: x86_64-pc-linux-gnu
Thread model: posix

$ gdb --version
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
[snip]

$ cat hello.c
#include <stdio.h>

int main(int argc, const char *argv[])
{
        printf("Hello, world\n");
        return 0;
}

$ clang -g -O0 hello.c -o hello

$ gdb -q hello
Reading symbols from hello...done.
(gdb) break main
Breakpoint 1 at 0x400510: file hello.c, line 5.
(gdb) run
Starting program: /home/vagrant/hello 

Breakpoint 1, main (argc=1, argv=0x7fffffffe618) at hello.c:5
5	        printf("Hello, world\n");
(gdb) next
Hello, world
6	        return 0;
(gdb) next
__libc_start_main (main=0x4004f0 <main>, argc=1, argv=0x7fffffffe618, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffe608) at libc-start.c:323
323	libc-start.c: No such file or directory.
(gdb) next
[Inferior 1 (process 5001) exited normally]
(gdb)