1# MIR Debugging23The `-Z dump-mir` flag can be used to dump a text representation of the MIR.4The following optional flags, used in combination with `-Z dump-mir`, enable5additional output formats, including:67* `-Z dump-mir-graphviz` - dumps a `.dot` file that represents MIR as a8control-flow graph9* `-Z dump-mir-dataflow` - dumps a `.dot` file showing the [dataflow state] at10 each point in the control-flow graph1112`-Z dump-mir=F` is a handy compiler option that will let you view the MIR for13each function at each stage of compilation. `-Z dump-mir` takes a **filter** `F`14which allows you to control which functions and which passes you are15interested in. For example:1617```bash18> rustc -Z dump-mir=foo ...19```2021This will dump the MIR for any function whose name contains `foo`; it22will dump the MIR both before and after every pass. Those files will23be created in the `mir_dump` directory. There will likely be quite a24lot of them!2526```bash27> cat > foo.rs28fn main() {29 println!("Hello, world!");30}31^D32> rustc -Z dump-mir=main foo.rs33> ls mir_dump/* | wc -l34 16135```3637The files have names like `rustc.main.000-000.CleanEndRegions.after.mir`. These38names have a number of parts:3940```text41rustc.main.000-000.CleanEndRegions.after.mir42 ---- --- --- --------------- ----- either before or after43 | | | name of the pass44 | | index of dump within the pass (usually 0, but some passes dump intermediate states)45 | index of the pass46 def-path to the function etc being dumped47```4849You can also make more selective filters. For example, `main & CleanEndRegions`50will select for things that reference *both* `main` and the pass51`CleanEndRegions`:5253```bash54> rustc -Z dump-mir='main & CleanEndRegions' foo.rs55> ls mir_dump56rustc.main.000-000.CleanEndRegions.after.mir rustc.main.000-000.CleanEndRegions.before.mir57```58<!--- TODO: Change NoLandingPads. [#1232](https://github.com/rust-lang/rustc-dev-guide/issues/1232) -->59Filters can also have `|` parts to combine multiple sets of60`&`-filters. For example `main & CleanEndRegions | main &61NoLandingPads` will select *either* `main` and `CleanEndRegions` *or*62`main` and `NoLandingPads`:6364```bash65> rustc -Z dump-mir='main & CleanEndRegions | main & NoLandingPads' foo.rs66> ls mir_dump67rustc.main-promoted[0].002-000.NoLandingPads.after.mir68rustc.main-promoted[0].002-000.NoLandingPads.before.mir69rustc.main-promoted[0].002-006.NoLandingPads.after.mir70rustc.main-promoted[0].002-006.NoLandingPads.before.mir71rustc.main-promoted[1].002-000.NoLandingPads.after.mir72rustc.main-promoted[1].002-000.NoLandingPads.before.mir73rustc.main-promoted[1].002-006.NoLandingPads.after.mir74rustc.main-promoted[1].002-006.NoLandingPads.before.mir75rustc.main.000-000.CleanEndRegions.after.mir76rustc.main.000-000.CleanEndRegions.before.mir77rustc.main.002-000.NoLandingPads.after.mir78rustc.main.002-000.NoLandingPads.before.mir79rustc.main.002-006.NoLandingPads.after.mir80rustc.main.002-006.NoLandingPads.before.mir81```8283(Here, the `main-promoted[0]` files refer to the MIR for "promoted constants"84that appeared within the `main` function.)8586The `-Z unpretty=mir-cfg` flag can be used to create a graphviz MIR87control-flow diagram for the whole crate:88899091TODO: anything else?9293[dataflow state]: ./dataflow.html#graphviz-diagrams
Findings
✓ No findings reported for this file.