Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra-debug-info does not appear to work on OSX with lldb #11352

Closed
alexcrichton opened this issue Jan 6, 2014 · 12 comments · Fixed by #11864
Closed

extra-debug-info does not appear to work on OSX with lldb #11352

alexcrichton opened this issue Jan 6, 2014 · 12 comments · Fixed by #11864
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) O-macos Operating system: macOS

Comments

@alexcrichton
Copy link
Member

Here's a recent session of mine

$ cat foo.rs                     
fn main() {
    let x = 3;
}
$ rustc -Z extra-debug-info foo.rs                
foo.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
foo.rs:2     let x = 3;
                 ^
$ lldb ./foo                   
2014-01-06 11:28:25.244 lldb[88932:212f] Metadata.framework [Error]: couldn't get the client port
Current executable set to './foo' (x86_64).
(lldb) b main
Breakpoint 1: where = foo`main, address = 0x0000000100001170
(lldb) c
error: invalid process
(lldb) r
Process 88933 launched: './foo' (x86_64)
Process 88933 stopped
* thread #1: tid = 0x76a58e, 0x0000000100001170 foo`main, queue = 'com.apple.main-thread, stop reason = breakpoint 1.1
    frame #0: 0x0000000100001170 foo`main
foo`main:
-> 0x100001170:  cmpq   %gs:816, %rsp
   0x100001179:  ja     0x100001195               ; main + 37
   0x10000117b:  movabsq $24, %r10
   0x100001185:  movabsq $0, %r11

Even if I continue into my own main function (actually the symbol main::largehashher), I'm not getting any source level debugging.

Is there an extra option that I should be passing or should this be "just working"?

I compiled a C executable with gcc -g and I got nice debug-info without doing anything extra in lldb.

cc @michaelwoerister

@jdm
Copy link
Contributor

jdm commented Jan 6, 2014

This is a known issue with the Servo team, fwiw.

@jdm
Copy link
Contributor

jdm commented Jan 6, 2014

Does clang give you usable debug symbols?

@alexcrichton
Copy link
Member Author

I do indeed get nice debugging with clang:

$ cat foo.c
#include <sys/filio.h>
#include <stdio.h>

int main() {
    int x = 3;
}
$ clang -g foo.c -o foo
$ lldb ./foo
2014-01-06 11:40:04.437 lldb[89479:212f] Metadata.framework [Error]: couldn't get the client port
Current executable set to './foo' (x86_64).
(lldb) b main
Breakpoint 1: where = foo`main + 9 at foo.c:5, address = 0x0000000100000f89
(lldb) r
Process 89484 launched: './foo' (x86_64)
Process 89484 stopped
* thread #1: tid = 0x76b78b, 0x0000000100000f89 foo`main + 9 at foo.c:5, queue = 'com.apple.main-thread, stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f89 foo`main + 9 at foo.c:5
   2    #include <stdio.h>
   3   
   4    int main() {
-> 5        int x = 3;
   6    }

@jdm
Copy link
Contributor

jdm commented Jan 6, 2014

Could you dump the IR from clang and rustc for similar programs?

@jdm
Copy link
Contributor

jdm commented Jan 6, 2014

I'd also be interested in seeing if clang produces dSYM bundles and whether there are any observable differences between them and the ones that rustc produces. Relevant literature at http://lldb.llvm.org/symbols.html .

@alexcrichton
Copy link
Member Author

This has the two IR outputs: https://gist.github.com/alexcrichton/8288727

@jdm
Copy link
Contributor

jdm commented Jan 6, 2014

Clang:

!0 = metadata !{i32 786449, i32 0, i32 12, metadata !"foo.c", metadata !"/Users/alex/code/rust2", metadata !"Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)", i1 true, i1 false, metadata !"", i32 0, metadata !1, metadata !1, metadata !3, metadata !1} ; [ DW_TAG_compile_unit ] [/Users/alex/code/rust2/foo.c] [DW_LANG_C99]

rustc:

!0 = metadata !{i32 786449, metadata !1, i32 36864, metadata !"rustc version 0.9 (a6d3e57 2014-01-05 20:56:53 -0800)", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [/Users/alex/code/rust2/foo.rc] [lang 0x9000]

That's some strong difference there.

@comex
Copy link
Contributor

comex commented Jan 26, 2014

I spent a while tracking this down due to a red herring, but the actual issue is simple: the DWARF version is too high.

As of OS X 10.9, 'dwarfdump' and 'dsymutil', the latter of which is required to aggregate DWARF info from .o files into the final executable, appear to ignore DWARF information with version > 3. Rust uses LLVM's default of DWARF 4. clang defaults to DWARF 2 on OS X; in fact, the version of clang distributed with Xcode (but not the version I have installed through MacPorts? too tired to investigate this properly) seems to ignore -gdwarf-3 and above, so probably better to go with 2 than 3.

Workaround: --llvm-args -dwarf-version,2.

I believe the correct way to solve this is for rustc to set the LLVM module flag "Dwarf Version", as clang does. It should also set "Debug Info Version", which, as far as I can tell, causes a separate issue where anything reading bitcode files using a new version of LLVM (e.g. the versions of llvm-dis or llc compiled by rust) will magically discard all the debug metadata.

@alexcrichton
Copy link
Member Author

@comex, you are my new favorite person in the world, thank you for figuring this out!!!

I would be more than ok accepting a patch to pass these arguments by default! Pull requests are always welcome :)

@jdm
Copy link
Contributor

jdm commented Jan 26, 2014

Ship it, shipt it! 🌵

@michaelwoerister
Copy link
Member

This is a great find indeed! For anyone interested, here is another source of information on DWARF on Mac OS X:
http://wiki.dwarfstd.org/index.php?title=Apple%27s_%22Lazy%22_DWARF_Scheme

The DWARF standard says that namespaces are not supported yet in version 2. I'd be interested in what the consequences of this are. Other than that I don't think we use anything that needs a newer version than 2.

I'd be happy to turn this information into a fix and a pull request but I don't have a Mac to test it (yet).
Thanks again @comex 👍

@pnkfelix
Copy link
Member

cc me

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 27, 2014
OSX apparently doesn't have tooling which understands higher versions of dwarf
by default right now.

Closes rust-lang#11352
bors added a commit that referenced this issue Jan 28, 2014
Set "Dwarf Version" to 2 on OS X to avoid toolchain incompatibility, and
set "Debug Info Version" to prevent debug info from being stripped from
bitcode.

Fixes #11352.
@bors bors closed this as completed in ea7b20d Jan 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) O-macos Operating system: macOS
Projects
None yet
5 participants