# Debugging rustc

**URL:** https://internals.rust-lang.org/t/debugging-rustc/12484
**Category:** compiler
**Created:** [June 3, 2020, 1:37pm UTC](https://internals.rust-lang.org/t/debugging-rustc/12484 "2020-06-03T13:37:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![HuStmpHrrr](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hustmphrrr/32/6924_2.png) [@HuStmpHrrr](https://internals.rust-lang.org/u/HuStmpHrrr)
#### Post date: [June 3, 2020, 1:37pm UTC](https://internals.rust-lang.org/t/debugging-rustc/12484/1 "2020-06-03T13:37:38Z")

</div>

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
$ rust-gdb --args ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc ~/projects/test/test.rs

```

and then in gdb, I do

```rust
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?

---

<div class="post-metadata">

### Author: ![HuStmpHrrr](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hustmphrrr/32/6924_2.png) [@HuStmpHrrr](https://internals.rust-lang.org/u/HuStmpHrrr)
#### Post date: [June 3, 2020, 1:57pm UTC](https://internals.rust-lang.org/t/debugging-rustc/12484/2 "2020-06-03T13:57:27Z")

</div>

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

```rust
#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?

---

<div class="post-metadata">

### Author: ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)
#### Post date: [June 3, 2020, 2:01pm UTC](https://internals.rust-lang.org/t/debugging-rustc/12484/3 "2020-06-03T14:01:36Z")

</div>

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

> <https://github.com/rust-lang/rust/blob/ff4aff6ce0f216c8cb8d40f432efaacdaca8095b/config.toml.example#L302>

(don't forget to remove the `#`)

---

<div class="post-metadata">

### Author: ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)
#### Post date: [June 3, 2020, 3:02pm UTC](https://internals.rust-lang.org/t/debugging-rustc/12484/4 "2020-06-03T15:02:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)
#### Post date: [September 1, 2020, 3:02pm UTC](https://internals.rust-lang.org/t/debugging-rustc/12484/5 "2020-09-01T15:02:33Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
