MIR Debugging The -Z dump-mir flag can be used to dump a text representation of the MIR. The following optional flags, used in combination with -Z dump-mir, enable additional output formats, including: • -Z dump-mir-graphviz - dumps a .dot...
Constant Evaluation Constant evaluation is the process of computing values at compile time. For a specific item (constant/static/array length) this happens after the MIR for the item is borrow-checked and optimized. In many cases trying to...
Interpreter The interpreter is a virtual machine for executing MIR without compiling to machine code. It is usually invoked via tcx.const_eval_* functions. The interpreter is shared between the compiler (for compile-time function evaluation...
Monomorphization As you probably know, Rust has a very expressive type system that has extensive support for generic types. But of course, assembly is not generic, so we need to figure out the concrete types of all the generics before the c...
Lowering MIR to a Codegen IR Now that we have a list of symbols to generate from the collector, we need to generate some sort of codegen IR. In this chapter, we will assume LLVM IR, since that's what rustc usually uses. The actual monomorph...
Code generation Code generation (or "codegen") is the part of the compiler that actually generates an executable binary. Usually, rustc uses LLVM for code generation, but there is also support for Cranelift and GCC. The key is that rustc do...
Updating LLVM Rust supports building against multiple LLVM versions: • Tip-of-tree for the current LLVM development branch is usually supported within a few days. PRs for such fixes are tagged with llvm-main. • The latest released major ver...
Debugging LLVM NOTE: If you are looking for info about code generation, please see this chapter instead. This section is about debugging compiler bugs in code generation (e.g. why the compiler generated some piece of code or crashed in LLVM...
Backend Agnostic Codegen rustc_codegen_ssa provides an abstract interface for all backends to implement, namely LLVM, Cranelift, and GCC. Below is some background information on the refactoring that created this abstract interface. Refactor...
Implicit caller location Approved in RFC 2091, this feature enables the accurate reporting of caller location during panics initiated from functions like Option::unwrap, Result::expect, and Index::index. This feature adds the #[track_caller...
Debug Info Debug info is a collection of information generated by the compiler that allows debuggers to correctly interpret the state of a program while it is running. That includes things like mapping instruction addresses to lines of code...
Rust Codegen The first phase in debug info generation requires Rust to inspect the MIR of the program and communicate it to LLVM. This is primarily done in rustc_codegen_llvm/debuginfo, though some type-name processing exists in rustc_codeg...
(WIP) LLVM Codegen When Rust calls an LLVM DIBuilder function, LLVM translates the given information to a "debug record" that is format-agnostic. These records can be inspected in the LLVM-IR. It is important to note that tags within the de...
Debugger Internals It is the debugger's job to convert the debug info into an in-memory representation. Both the interpretation of the debug info and the in-memory representation are arbitrary; anything will do so long as meaningful informa...
LLDB Internals LLDB's debug info processing relies on a set of extensible interfaces largely defined in lldb/src/Plugins. These are meant to allow third-party compiler developers to add language support that is loaded at run-time by LLDB, b...
(WIP) GDB Internals GDB's Rust support lives at gdb/rust-lang.h and gdb/rust-lang.c. The expression parsing support can be found in gdb/rust-exp.h and gdb/rust-parse.c
Debugger Visualizers These are typically the last step before the debugger displays the information, but the results may be piped through a debug adapter such as an IDE's debugger API. The term "Visualizer" is a bit of a misnomer. The real...
LLDB - Python Providers NOTE: LLDB's C++<->Python FFI expects a version of Python designated at the time LLDB was compiled. LLDB is careful to correspond this version to the minimum in typical Linux and macOS distributions, but on Windows t...
(WIP) GDB - Python Providers Below are links to relevant parts of the GDB documentation • Overview on writing a pretty printer • Pretty Printer API (equivalent to LLDB's SyntheticProvider) • Value API (equivalent to LLDB's SBValue) • Type A...
(WIP) CDB - Natvis Official documentation for Natvis can be found here and here