@@ -20,34 +20,30 @@ you might want to find some way to use Linux or MSVC on Windows.
20
20
In the default configuration, you don't have line numbers enabled, so the
21
21
backtrace looks like this:
22
22
23
- ```
23
+ ``` text
24
24
stack backtrace:
25
25
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
26
26
1: std::sys_common::backtrace::_print
27
27
2: std::panicking::default_hook::{{closure}}
28
28
3: std::panicking::default_hook
29
29
4: std::panicking::rust_panic_with_hook
30
30
5: std::panicking::begin_panic
31
- 6: rustc_typeck::check::cast::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, \
32
- 'tcx>>::pointer_kind
33
31
(~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
34
32
32: rustc_typeck::check_crate
35
33
33: <std::thread::local::LocalKey<T>>::with
36
34
34: <std::thread::local::LocalKey<T>>::with
37
35
35: rustc::ty::context::TyCtxt::create_and_enter
38
36
36: rustc_driver::driver::compile_input
39
37
37: rustc_driver::run_compiler
40
- ```
38
+ ```
41
39
42
40
If you want line numbers for the stack trace, you can enable
43
41
` debuginfo-lines=true ` or ` debuginfo=true ` in your config.toml and rebuild the
44
42
compiler. Then the backtrace will look like this:
45
43
46
- ```
44
+ ``` text
47
45
stack backtrace:
48
46
(~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
49
- 6: rustc_typeck::check::cast::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, \
50
- 'tcx>>::pointer_kind
51
47
at /home/user/rust/src/librustc_typeck/check/cast.rs:110
52
48
7: rustc_typeck::check::cast::CastCheck::check
53
49
at /home/user/rust/src/librustc_typeck/check/cast.rs:572
@@ -72,11 +68,15 @@ This can also help when debugging `delay_span_bug` calls - it will make
72
68
the first ` delay_span_bug ` call panic, which will give you a useful backtrace.
73
69
74
70
For example:
75
- ```
71
+
72
+ ``` rust
76
73
$ cat error . rs
77
74
fn main () {
78
75
1 + ();
79
76
}
77
+ ```
78
+
79
+ ``` bash
80
80
$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc error.rs
81
81
error[E0277]: the trait bound ` {integer}: std::ops::Add< ()> ` is not satisfied
82
82
--> error.rs:2:7
@@ -137,8 +137,8 @@ $ # Cool, now I have a backtrace for the error
137
137
138
138
The compiler has a lot of ` debug! ` calls, which print out logging information
139
139
at many points. These are very useful to at least narrow down the location of
140
- a bug if not to find it entirely, or just to orient yourself to why a compiler
141
- is doing a particular thing.
140
+ a bug if not to find it entirely, or just to orient yourself as to why the
141
+ compiler is doing a particular thing.
142
142
143
143
To see the logs, you need to set the ` RUST_LOG` environment variable to
144
144
your log filter, e.g. to get the logs for a specific module, you can run the
@@ -152,7 +152,8 @@ of output - so it's typically a good idea to pipe standard error to a file
152
152
and look at the log output with a text editor.
153
153
154
154
So to put it together.
155
- ```
155
+
156
+ ```bash
156
157
# This puts the output of all debug calls in `librustc/traits` into
157
158
# standard error, which might fill your console backscroll.
158
159
$ RUST_LOG=rustc::traits rustc +local my-file.rs
@@ -191,10 +192,10 @@ want to call `x.py clean` to force one.
191
192
### Logging etiquette
192
193
193
194
Because calls to `debug!` are removed by default, in most cases, don' t worry
194
- about adding "unnecessary" calls to ` debug! ` and leaving them in in code
195
- you commit - they won't slow
196
- down the performance of what we ship, and if they helped you pinning down
197
- a bug, they will probably help someone else with a different one.
195
+ about adding " unnecessary" calls to ` debug! ` and leaving them in code you
196
+ commit - they won' t slow down the performance of what we ship, and if they
197
+ helped you pinning down a bug, they will probably help someone else with a
198
+ different one.
198
199
199
200
However, there are still a few concerns that you might care about:
200
201
@@ -253,7 +254,7 @@ dumps various borrow-checker dataflow graphs.
253
254
These all produce ` .dot` files. To view these files, install graphviz (e.g.
254
255
` apt-get install graphviz` ) and then run the following commands:
255
256
256
- ```
257
+ ` ` ` bash
257
258
$ dot -T pdf maybe_init_suffix.dot > maybe_init_suffix.pdf
258
259
$ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
259
260
` ` `
@@ -281,12 +282,13 @@ to replicate manually and means that LLVM is called multiple times in parallel.
281
282
If you can get away with it (i.e. if it doesn' t make your bug disappear),
282
283
passing `-C codegen-units=1` to rustc will make debugging easier.
283
284
284
- If you want to play with the optimization pipeline, you can use the ` opt ` from
285
- there on the IR rustc emits with ` --emit=llvm-ir ` . Note
286
- that rustc emits different IR depending on whether ` -O ` is enabled, even without
287
- LLVM's optimizations, so if you want to play with the IR rustc emits,
285
+ If you want to play with the optimization pipeline, you can use the opt tool
286
+ from `./build/<host-triple>/llvm/bin/` with the the LLVM IR emitted by rustc.
287
+ Note that rustc emits different IR depending on whether `-O` is enabled, even
288
+ without LLVM' s optimizations, so if you want to play with the IR rustc emits,
288
289
you should:
289
- ```
290
+
291
+ ` ` ` bash
290
292
$ rustc +local my-file.rs --emit=llvm-ir -O -C no-prepopulate-passes \
291
293
-C codegen-units=1
292
294
$ OPT=./build/$TRIPLE /llvm/bin/opt
@@ -309,7 +311,8 @@ the printouts will mix together and you won't be able to read anything.
309
311
If you want just the IR for a specific function (say, you want to see
310
312
why it causes an assertion or doesn' t optimize correctly), you can use
311
313
` llvm-extract` , e.g.
312
- ```
314
+
315
+ ` ` ` bash
313
316
$ ./build/$TRIPLE /llvm/bin/llvm-extract \
314
317
-func=' _ZN11collections3str21_$LT$impl$u20$str$GT$7replace17hbe10ea2e7c809b0bE' \
315
318
-S \
0 commit comments