Add support for a new attribute #[debugger_visualizer] to support embedding debugger visualizers into a generated PDB.

Cleanup `DebuggerVisualizerFile` type and other minor cleanup of queries.

Merge the queries for debugger visualizers into a single query.

Revert move of `resolve_path` to `rustc_builtin_macros`. Update dependencies in Cargo.toml for `rustc_passes`.

Respond to PR comments. Load visualizer files into opaque bytes `Vec<u8>`. Debugger visualizers for dynamically linked crates should not be embedded in the current crate.

Update the unstable book with the new feature. Add the tracking issue for the debugger_visualizer feature.

Respond to PR comments and minor cleanups.
This commit is contained in:
ridwanabdillahi 2022-04-25 18:02:43 -07:00
parent e1df625306
commit 175a4eab84
29 changed files with 554 additions and 76 deletions

View file

@ -0,0 +1,25 @@
# `debugger_visualizer`
The tracking issue for this feature is: [#95939]
[#95939]: https://github.com/rust-lang/rust/issues/95939
------------------------
The `debugger_visualizer` attribute can be used to instruct the compiler
to embed a debugger visualizer file into the PDB/ELF generated by `rustc`.
## Examples
``` rust,ignore (partial-example)
#![feature(debugger_visualizer)]
#![debugger_visualizer(natvis_file = "foo.natvis")]
struct Foo {
}
```
## Limitations
Currently, this feature only supports embedding Natvis files on `-windows-msvc`
targets when using the MSVC linker via the `natvis_file` meta item.

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="msvc_embedded_natvis::Point">
<DisplayString>({x}, {y})</DisplayString>
<Expand>
<Item Name="[x]">x</Item>
<Item Name="[y]">y</Item>
</Expand>
</Type>
<Type Name="msvc_embedded_natvis::Line">
<DisplayString>({a}, {b})</DisplayString>
<Expand>
<Item Name="[a]">a</Item>
<Item Name="[b]">b</Item>
</Expand>
</Type>
</AutoVisualizer>

View file

@ -0,0 +1,64 @@
// only-cdb
// compile-flags:-g
// === CDB TESTS ==================================================================================
// cdb-command: g
// cdb-command: .nvlist
// cdb-check: [...].exe (embedded NatVis "[...]msvc_embedded_natvis-0.natvis")
// cdb-command: dx point_a
// cdb-check:point_a : (0, 0) [Type: msvc_embedded_natvis::Point]
// cdb-check: [<Raw View>] [Type: msvc_embedded_natvis::Point]
// cdb-check: [x] : 0 [Type: int]
// cdb-check: [y] : 0 [Type: int]
// cdb-command: dx point_b
// cdb-check:point_b : (5, 8) [Type: msvc_embedded_natvis::Point]
// cdb-check: [<Raw View>] [Type: msvc_embedded_natvis::Point]
// cdb-check: [x] : 5 [Type: int]
// cdb-check: [y] : 8 [Type: int]
// cdb-command: dx line
// cdb-check:line : ((0, 0), (5, 8)) [Type: msvc_embedded_natvis::Line]
// cdb-check: [<Raw View>] [Type: msvc_embedded_natvis::Line]
// cdb-check: [a] : (0, 0) [Type: msvc_embedded_natvis::Point]
// cdb-check: [b] : (5, 8) [Type: msvc_embedded_natvis::Point]
#![feature(debugger_visualizer)]
#![debugger_visualizer(natvis_file = "msvc-embedded-natvis.natvis")]
pub struct Point {
x: i32,
y: i32,
}
impl Point {
pub fn new(x: i32, y: i32) -> Point {
Point { x: x, y: y }
}
}
pub struct Line {
a: Point,
b: Point,
}
impl Line {
pub fn new(a: Point, b: Point) -> Line {
Line { a: a, b: b }
}
}
fn main() {
let point_a = Point::new(0, 0);
let point_b = Point::new(5, 8);
let line = Line::new(point_a, point_b);
zzz(); // #break
}
fn zzz() {
()
}

View file

@ -0,0 +1,3 @@
#![debugger_visualizer(natvis_file = "../foo.natvis")] //~ ERROR the `#[debugger_visualizer]` attribute is an experimental feature
fn main() {}

View file

@ -0,0 +1,12 @@
error[E0658]: the `#[debugger_visualizer]` attribute is an experimental feature
--> $DIR/feature-gate-debugger-visualizer.rs:1:1
|
LL | #![debugger_visualizer(natvis_file = "../foo.natvis")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #95939 <https://github.com/rust-lang/rust/issues/95939> for more information
= help: add `#![feature(debugger_visualizer)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -0,0 +1,4 @@
#![feature(debugger_visualizer)]
#![debugger_visualizer(random_file = "../foo.random")] //~ ERROR invalid argument
fn main() {}

View file

@ -0,0 +1,10 @@
error: invalid argument
--> $DIR/invalid-debugger-visualizer-option.rs:2:1
|
LL | #![debugger_visualizer(random_file = "../foo.random")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected: `natvis_file = "..."`
error: aborting due to previous error

View file

@ -0,0 +1,5 @@
#![feature(debugger_visualizer)]
#[debugger_visualizer(natvis_file = "../foo.natvis")] //~ ERROR attribute should be applied to a module
fn main() {}

View file

@ -0,0 +1,8 @@
error: attribute should be applied to a module
--> $DIR/invalid-debugger-visualizer-target.rs:3:1
|
LL | #[debugger_visualizer(natvis_file = "../foo.natvis")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error