|
3 | 3 | <!-- toc -->
|
4 | 4 |
|
5 | 5 | This document explains the state of debugging tools support in the Rust compiler (rustc).
|
6 |
| -It gives an overview of GDB, LLDB, |
| 6 | +It gives an overview of GDB, LLDB, WinDbg/CDB, |
7 | 7 | as well as infrastructure around Rust compiler to debug Rust code.
|
8 | 8 | If you want to learn how to debug the Rust compiler itself,
|
9 | 9 | see [Debugging the Compiler].
|
@@ -42,6 +42,15 @@ Debugging Information Entry (DIE) which stores the information as "tags" to deno
|
42 | 42 | variables etc., e.g., `DW_TAG_variable`, `DW_TAG_pointer_type`, `DW_TAG_subprogram` etc.
|
43 | 43 | You can also invent your own tags and attributes.
|
44 | 44 |
|
| 45 | +### CodeView/PDB |
| 46 | + |
| 47 | +[PDB] (Program Database) is a file format created by Microsoft that contains debug information. |
| 48 | +PDBs can be consumed by debuggers such as WinDbg/CDB and other tools to display debug information. |
| 49 | +A PDB contains multiple streams that describe debug information about a specific binary such |
| 50 | +as types, symbols, and source files used to compile the given binary. CodeView is another |
| 51 | +format which defines the structure of [symbol records] and [type records] that appear within |
| 52 | +PDB streams. |
| 53 | + |
45 | 54 | ## Supported debuggers
|
46 | 55 |
|
47 | 56 | ### GDB
|
@@ -104,6 +113,27 @@ LLDB has Rust-like value and type output.
|
104 | 113 | * LLDB has a plugin architecture but that does not work for language support.
|
105 | 114 | * GDB generally works better on Linux.
|
106 | 115 |
|
| 116 | +### WinDbg/CDB |
| 117 | + |
| 118 | +Microsoft provides [Windows Debugging Tools] such as the Windows Debugger (WinDbg) and |
| 119 | +the Console Debugger (CDB) which both support debugging programs written in Rust. These |
| 120 | +debuggers parse the debug info for a binary from the `PDB`, if available, to construct a |
| 121 | +visualization to serve up in the debugger. |
| 122 | + |
| 123 | +#### Natvis |
| 124 | + |
| 125 | +Both WinDbg and CDB support defining and viewing custom visualizations for any given type |
| 126 | +within the debugger using the Natvis framework. The Rust compiler defines a set of Natvis |
| 127 | +files that define custom visualizations for a subset of types in the standard libraries such |
| 128 | +as, `std, core and alloc`. These Natvis files are embedded into `PDBs` generated by the |
| 129 | +`*-pc-windows-msvc` target triples to automatically enable these custom visualizations when |
| 130 | +debugging. This default can be overridden by setting the `strip` rustc flag to either `debuginfo` |
| 131 | +or `symbols`. |
| 132 | + |
| 133 | +Rust has support for embedding Natvis files for crates outside of the standard libraries by |
| 134 | +using the `#[debugger_visualizer]` attribute. For more details on how to embed debugger visualizers |
| 135 | +please refer to the `#[debugger_visualizer]` attribute in [the unstable book](https://doc.rust-lang.org/unstable-book/language-features/debugger-visualizer.html). |
| 136 | + |
107 | 137 | ## DWARF and `rustc`
|
108 | 138 |
|
109 | 139 | [DWARF] is the standard way compilers generate debugging information that debuggers read.
|
@@ -316,3 +346,7 @@ but may have to add some mode to let the compiler understand some extensions.
|
316 | 346 | [Apple developer documentation for System Integrity Protection]: https://developer.apple.com/library/archive/releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_11.html#//apple_ref/doc/uid/TP40016227-SW11
|
317 | 347 | [https://github.com/rust-lang/lldb]: https://github.com/rust-lang/lldb
|
318 | 348 | [https://github.com/rust-lang/llvm-project]: https://github.com/rust-lang/llvm-project
|
| 349 | +[PDB]: https://llvm.org/docs/PDB/index.html |
| 350 | +[symbol records]: https://llvm.org/docs/PDB/CodeViewSymbols.html |
| 351 | +[type records]: https://llvm.org/docs/PDB/CodeViewTypes.html |
| 352 | +[Windows Debugging Tools]: https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/ |
0 commit comments