11# Debugging the compiler
22
3- This chapter contains a few tips to debug the compiler. These tips aim to be
4- useful no matter what you are working on. Some of the other chapters have
3+ This chapter contains a few tips to debug the compiler.
4+ These tips aim to be useful no matter what you are working on.
5+ Some of the other chapters have
56advice about specific parts of the compiler (e.g. the [ Queries Debugging and
67Testing chapter] ( ./incrcomp-debugging.html ) or the [ LLVM Debugging
78chapter] ( ./backend/debugging.md ) ).
89
910## Configuring the compiler
1011
11- By default, rustc is built without most debug information. To enable debug info,
12+ By default, rustc is built without most debug information.
13+ To enable debug info,
1214set ` rust.debug = true ` in your bootstrap.toml.
1315
1416Setting ` rust.debug = true ` turns on many different debug options (e.g., ` debug-assertions ` ,
@@ -45,16 +47,17 @@ You will need to rebuild the compiler after changing any configuration option.
4547## Suppressing the ICE file
4648
4749By default, if rustc encounters an Internal Compiler Error (ICE) it will dump the ICE contents to an
48- ICE file within the current working directory named ` rustc-ice-<timestamp>-<pid>.txt ` . If this is
49- not desirable, you can prevent the ICE file from being created with ` RUSTC_ICE=0 ` .
50+ ICE file within the current working directory named ` rustc-ice-<timestamp>-<pid>.txt ` .
51+ If this is not desirable, you can prevent the ICE file from being created with ` RUSTC_ICE=0 ` .
5052
5153## Getting a backtrace
5254[ getting-a-backtrace ] : #getting-a-backtrace
5355
5456When you have an ICE (panic in the compiler), you can set
55- ` RUST_BACKTRACE=1 ` to get the stack trace of the ` panic! ` like in
56- normal Rust programs. IIRC backtraces ** don't work** on MinGW,
57- sorry. If you have trouble or the backtraces are full of ` unknown ` ,
57+ ` RUST_BACKTRACE=1 ` to get the stack trace of the ` panic! ` like in normal Rust programs.
58+ IIRC backtraces ** don't work** on MinGW,
59+ sorry.
60+ If you have trouble or the backtraces are full of ` unknown ` ,
5861you might want to find some way to use Linux, Mac, or MSVC on Windows.
5962
6063In the default configuration (without ` debug ` set to ` true ` ), you don't have line numbers
@@ -98,9 +101,10 @@ stack backtrace:
98101
99102## ` -Z ` flags
100103
101- The compiler has a bunch of ` -Z * ` flags. These are unstable flags that are only
102- enabled on nightly. Many of them are useful for debugging. To get a full listing
103- of ` -Z ` flags, use ` -Z help ` .
104+ The compiler has a bunch of ` -Z * ` flags.
105+ These are unstable flags that are only enabled on nightly.
106+ Many of them are useful for debugging.
107+ To get a full listing of ` -Z ` flags, use ` -Z help ` .
104108
105109One useful flag is ` -Z verbose-internals ` , which generally enables printing more
106110info that could be useful for debugging.
@@ -112,7 +116,8 @@ Right below you can find elaborate explainers on a selected few.
112116
113117If you want to get a backtrace to the point where the compiler emits an
114118error message, you can pass the ` -Z treat-err-as-bug=n ` , which will make
115- the compiler panic on the ` nth ` error. If you leave off ` =n ` , the compiler will
119+ the compiler panic on the ` nth ` error.
120+ If you leave off ` =n ` , the compiler will
116121assume ` 1 ` for ` n ` and thus panic on the first error it encounters.
117122
118123For example:
@@ -188,13 +193,12 @@ Cool, now I have a backtrace for the error!
188193
189194The ` -Z eagerly-emit-delayed-bugs ` option makes it easy to debug delayed bugs.
190195It turns them into normal errors, i.e. makes them visible. This can be used in
191- combination with ` -Z treat-err-as-bug ` to stop at a particular delayed bug and
192- get a backtrace.
196+ combination with ` -Z treat-err-as-bug ` to stop at a particular delayed bug and get a backtrace.
193197
194198### Getting the error creation location
195199
196- ` -Z track-diagnostics ` can help figure out where errors are emitted. It uses ` #[track_caller] `
197- for this and prints its location alongside the error:
200+ ` -Z track-diagnostics ` can help figure out where errors are emitted.
201+ It uses ` #[track_caller] ` for this and prints its location alongside the error:
198202
199203```
200204$ RUST_BACKTRACE=1 rustc +stage1 error.rs -Z track-diagnostics
@@ -236,11 +240,11 @@ For details see [the guide section on tracing](./tracing.md)
236240## Narrowing (Bisecting) Regressions
237241
238242The [ cargo-bisect-rustc] [ bisect ] tool can be used as a quick and easy way to
239- find exactly which PR caused a change in ` rustc ` behavior. It automatically
240- downloads ` rustc ` PR artifacts and tests them against a project you provide
241- until it finds the regression. You can then look at the PR to get more context
242- on * why * it was changed. See [ this tutorial ] [ bisect-tutorial ] on how to use
243- it.
243+ find exactly which PR caused a change in ` rustc ` behavior.
244+ It automatically downloads ` rustc ` PR artifacts and tests them against a project you provide
245+ until it finds the regression.
246+ You can then look at the PR to get more context on * why * it was changed.
247+ See [ this tutorial ] [ bisect-tutorial ] on how to use it.
244248
245249[ bisect ] : https://github.com/rust-lang/cargo-bisect-rustc
246250[ bisect-tutorial ] : https://rust-lang.github.io/cargo-bisect-rustc/tutorial.html
@@ -250,19 +254,22 @@ it.
250254The [ rustup-toolchain-install-master] [ rtim ] tool by kennytm can be used to
251255download the artifacts produced by Rust's CI for a specific SHA1 -- this
252256basically corresponds to the successful landing of some PR -- and then sets
253- them up for your local use. This also works for artifacts produced by `@bors
254- try`. This is helpful when you want to examine the resulting build of a PR
257+ them up for your local use.
258+ This also works for artifacts produced by ` @bors try ` .
259+ This is helpful when you want to examine the resulting build of a PR
255260without doing the build yourself.
256261
257262[ rtim ] : https://github.com/kennytm/rustup-toolchain-install-master
258263
259264## ` #[rustc_*] ` TEST attributes
260265
261266The compiler defines a whole lot of internal (perma-unstable) attributes some of which are useful
262- for debugging by dumping extra compiler-internal information. These are prefixed with ` rustc_ ` and
267+ for debugging by dumping extra compiler-internal information.
268+ These are prefixed with ` rustc_ ` and
263269are gated behind the internal feature ` rustc_attrs ` (enabled via e.g. ` #![feature(rustc_attrs)] ` ).
264270
265- For a complete and up to date list, see [ ` builtin_attrs ` ] . More specifically, the ones marked ` TEST ` .
271+ For a complete and up to date list, see [ ` builtin_attrs ` ] .
272+ More specifically, the ones marked ` TEST ` .
266273Here are some notable ones:
267274
268275| Attribute | Description |
@@ -311,7 +318,8 @@ $ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
311318### Debugging type layouts
312319
313320The internal attribute ` #[rustc_layout] ` can be used to dump the [ ` Layout ` ] of
314- the type it is attached to. For example:
321+ the type it is attached to.
322+ For example:
315323
316324``` rust
317325#![feature(rustc_attrs)]
0 commit comments