Skip to content

Commit 6cc6ef0

Browse files
committed
Restructure chapter on compiler debugging
1. Make sections about specific `-Z` flags subsections of the `-Z` flag overview section 2. Introduce overview section for internal `rustc_*` attributes 3. Make sections about specific `rustc_*` attributes subsections of this new section
1 parent cd7f600 commit 6cc6ef0

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

src/compiler-debugging.md

+44-30
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ By default, if rustc encounters an Internal Compiler Error (ICE) it will dump th
5252
ICE file within the current working directory named `rustc-ice-<timestamp>-<pid>.txt`. If this is
5353
not desirable, you can prevent the ICE file from being created with `RUSTC_ICE=0`.
5454

55-
## `-Z` flags
56-
57-
The compiler has a bunch of `-Z` flags. These are unstable flags that are only
58-
enabled on nightly. Many of them are useful for debugging. To get a full listing
59-
of `-Z` flags, use `-Z help`.
60-
61-
One useful flag is `-Z verbose-internals`, which generally enables printing more
62-
info that could be useful for debugging.
63-
6455
## Getting a backtrace
6556
[getting-a-backtrace]: #getting-a-backtrace
6657

@@ -109,7 +100,18 @@ stack backtrace:
109100
at /home/user/rust/compiler/rustc_driver/src/lib.rs:253
110101
```
111102

112-
## Getting a backtrace for errors
103+
## `-Z` flags
104+
105+
The compiler has a bunch of `-Z *` flags. These are unstable flags that are only
106+
enabled on nightly. Many of them are useful for debugging. To get a full listing
107+
of `-Z` flags, use `-Z help`.
108+
109+
One useful flag is `-Z verbose-internals`, which generally enables printing more
110+
info that could be useful for debugging.
111+
112+
Right below you can find elaborate explainers on a selected few.
113+
114+
### Getting a backtrace for errors
113115
[getting-a-backtrace-for-errors]: #getting-a-backtrace-for-errors
114116

115117
If you want to get a backtrace to the point where the compiler emits an
@@ -186,14 +188,14 @@ stack backtrace:
186188

187189
Cool, now I have a backtrace for the error!
188190

189-
## Debugging delayed bugs
191+
### Debugging delayed bugs
190192

191193
The `-Z eagerly-emit-delayed-bugs` option makes it easy to debug delayed bugs.
192194
It turns them into normal errors, i.e. makes them visible. This can be used in
193195
combination with `-Z treat-err-as-bug` to stop at a particular delayed bug and
194196
get a backtrace.
195197

196-
## Getting the error creation location
198+
### Getting the error creation location
197199

198200
`-Z track-diagnostics` can help figure out where errors are emitted. It uses `#[track_caller]`
199201
for this and prints its location alongside the error:
@@ -235,21 +237,6 @@ The compiler uses the [`tracing`] crate for logging.
235237

236238
For details see [the guide section on tracing](./tracing.md)
237239

238-
## Formatting Graphviz output (.dot files)
239-
[formatting-graphviz-output]: #formatting-graphviz-output
240-
241-
Some compiler options for debugging specific features yield graphviz graphs -
242-
e.g. the `#[rustc_mir(borrowck_graphviz_postflow="suffix.dot")]` attribute
243-
dumps various borrow-checker dataflow graphs.
244-
245-
These all produce `.dot` files. To view these files, install graphviz (e.g.
246-
`apt-get install graphviz`) and then run the following commands:
247-
248-
```bash
249-
$ dot -T pdf maybe_init_suffix.dot > maybe_init_suffix.pdf
250-
$ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
251-
```
252-
253240
## Narrowing (Bisecting) Regressions
254241

255242
The [cargo-bisect-rustc][bisect] tool can be used as a quick and easy way to
@@ -273,10 +260,37 @@ without doing the build yourself.
273260

274261
[rtim]: https://github.com/kennytm/rustup-toolchain-install-master
275262

276-
## Debugging type layouts
263+
## `#[rustc_*]` TEST attributes
264+
265+
The compiler defines a whole lot of internal (perma-unstable) attributes some of which are useful
266+
for debugging by dumping extra compiler-internal information. These are prefixed with `rustc_` and
267+
are gated behind the internal feature `rustc_attrs` (enabled via e.g. `#![feature(rustc_attrs)]`).
268+
269+
For a complete and up to date list, see [`builtin_attrs`]. More specifically, the ones marked `TEST`.
270+
271+
Right below you can find elaborate explainers on a selected few.
272+
273+
[`builtin_attrs`]: https://github.com/rust-lang/rust/blob/master/compiler/rustc_feature/src/builtin_attrs.rs
274+
275+
### Formatting Graphviz output (.dot files)
276+
[formatting-graphviz-output]: #formatting-graphviz-output
277+
278+
Some compiler options for debugging specific features yield graphviz graphs -
279+
e.g. the `#[rustc_mir(borrowck_graphviz_postflow="suffix.dot")]` attribute
280+
dumps various borrow-checker dataflow graphs.
281+
282+
These all produce `.dot` files. To view these files, install graphviz (e.g.
283+
`apt-get install graphviz`) and then run the following commands:
284+
285+
```bash
286+
$ dot -T pdf maybe_init_suffix.dot > maybe_init_suffix.pdf
287+
$ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
288+
```
289+
290+
### Debugging type layouts
277291

278-
The (permanently) unstable `#[rustc_layout]` attribute can be used to dump
279-
the [`Layout`] of the type it is attached to. For example:
292+
The internal attribute `#[rustc_layout]` can be used to dump the [`Layout`] of
293+
the type it is attached to. For example:
280294

281295
```rust
282296
#![feature(rustc_attrs)]

0 commit comments

Comments
 (0)