Debugging rustc

Hi I am trying to invoke gdb to debug rustc for my general understanding of the compiler, as well as understanding the call stack. but I don't seem to be able to debug as I would like to.

Currently, I am doing

$ rust-gdb --args ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc ~/projects/test/test.rs

and then in gdb, I do

b rustc_driver::main
l

but it doesn't print the surrounding code.

The corresponding section in the developer's guide does not mention debugger. How do you actually do it?

it appears to me that stage 1 compiler doesn't have debugging information:

#0  0x00007ffff4dc8000 in rustc_metadata::locator::CrateLocator::report_errs ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#1  0x00007ffff4dc2c66 in rustc_metadata::creader::LoadError::report ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#2  0x00007ffff4dc3166 in rustc_metadata::creader::CrateLoader::resolve_crate::{{closure}} ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#3  0x00007ffff4dc6d41 in rustc_metadata::creader::CrateLoader::process_extern_crate ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#4  0x00007ffff421adc7 in <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor as rustc_ast::visit::Visitor>::visit_item ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#5  0x00007ffff42a1dcd in rustc_ast::visit::walk_item () from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#6  0x00007ffff421abf0 in <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor as rustc_ast::visit::Visitor>::visit_item ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#7  0x00007ffff426be6a in rustc_expand::expand::AstFragment::visit_with ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so
#8  0x00007ffff41ecdfe in rustc_resolve::macros::<impl rustc_expand::base::Resolver for rustc_resolve::Resolver>::visit_ast_fragment_with_placeholders ()
   from /home/hu/projects/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-6506e3fbaedecf30.so

is this correct? if so, is there a way to make it compile with debugging information?

You can copy config.toml.example to config.toml and then set debug to true:

(don't forget to remove the #)

There are also independent debuginfo-level settings in that file, if you want to keep the compiler optimized.

1 Like