Change:
Here's a recent session of mine Even if I continue into my own function (actually the symbol ), 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 and I got nice debug-info without doing anything extra in lldb. cc
This is a known issue with the Servo team, fwiw.
Does clang give you usable debug symbols?
I do indeed get nice debugging with clang:
Could you dump the IR from clang and rustc for similar programs?
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 .
This has the two IR outputs:
Clang: rustc: That's some strong difference there.
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: . 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.
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 :)
Ship it, shipt it! :cactus:
This is a great find indeed! For anyone interested, here is another source of information on DWARF on Mac OS X: 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 :+1:
cc me

Discussion:
Dialect: c_uint) -> ValueRef; <ins> pub static LLVMRustDebugMetadataVersion: u32; pub fn LLVMRustAddModuleFlag(M: ModuleRef, name: *c_char, value: u32); </ins> pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;

use std::sync::atomics; use std::vec; use syntax::codemap::{Span, Pos}; <del> use syntax::{ast, codemap, ast_util, ast_map, opt_vec}; </del> <ins> use syntax::{abi, ast, codemap, ast_util, ast_map, opt_vec}; </ins> use syntax::parse::token; use syntax::parse::token::special_idents;

unsafe { llvm::LLVMDIBuilderFinalize(DIB(cx)); llvm::LLVMDIBuilderDispose(DIB(cx)); <ins> // Debuginfo generation in LLVM by default uses a higher // version of dwarf than OS X currently understands. We can // instruct LLVM to emit an older version of dwarf, however, // for OS X to understand. For more info see #11352 // This can be overridden using --llvm-opts -dwarf-version,N. if cx.sess.targ_cfg.os == abi::OsMacos { "Dwarf Version".with_c_str( |s| llvm::LLVMRustAddModuleFlag(cx.llmod, s, 2)); } // Prevent bitcode readers from deleting the debug info. "Debug Info Version".with_c_str( |s| llvm::LLVMRustAddModuleFlag(cx.llmod, s, llvm::LLVMRustDebugMetadataVersion)); </ins> }; }

return DIT(ref ? unwrap<MDNode>(ref) : NULL); } <ins> extern "C" const uint32_t LLVMRustDebugMetadataVersion = DEBUG_METADATA_VERSION; extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *name, uint32_t value) { unwrap(M)->addModuleFlag(Module::Warning, name, value); } </ins> extern "C" DIBuilderRef LLVMDIBuilderCreate(LLVMModuleRef M) { return new DIBuilder(*unwrap(M)); }