about summary refs log tree commit diff
path: root/src/test/debuginfo/embedded-visualizer.rs
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2022-05-29 01:12:30 +0200
committerGitHub <noreply@github.com>2022-05-29 01:12:30 +0200
commit239287f013b21d18c8ddd5bf5419629d43dca484 (patch)
tree8370d6dac6dfdae06b82d23e097b46472e026673 /src/test/debuginfo/embedded-visualizer.rs
parent376163a77cda823c4e1bdedd48039609069e6b58 (diff)
parent7ac62ce75cef963017245287f0a7b140e09589d7 (diff)
downloadrust-239287f013b21d18c8ddd5bf5419629d43dca484.tar.gz
rust-239287f013b21d18c8ddd5bf5419629d43dca484.zip
Rollup merge of #97028 - ridwanabdillahi:pretty-printer, r=michaelwoerister
Add support for embedding pretty printers via `#[debugger_visualizer]` attribute

Initial support for [RFC 3191](https://github.com/rust-lang/rfcs/pull/3191) in PR https://github.com/rust-lang/rust/pull/91779 was scoped to supporting embedding NatVis files using a new attribute. This PR implements the pretty printer support as stated in the RFC mentioned above.

This change includes embedding pretty printers in the `.debug_gdb_scripts` just as the pretty printers for rustc are embedded today. Also added additional tests for embedded pretty printers. Additionally cleaned up error checking so all error checking is done up front regardless of the current target.

RFC: https://github.com/rust-lang/rfcs/pull/3191
Diffstat (limited to 'src/test/debuginfo/embedded-visualizer.rs')
-rw-r--r--src/test/debuginfo/embedded-visualizer.rs112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/test/debuginfo/embedded-visualizer.rs b/src/test/debuginfo/embedded-visualizer.rs
new file mode 100644
index 00000000000..0269015b466
--- /dev/null
+++ b/src/test/debuginfo/embedded-visualizer.rs
@@ -0,0 +1,112 @@
+// compile-flags:-g
+// min-gdb-version: 8.1
+// ignore-lldb
+
+// === CDB TESTS ==================================================================================
+
+// cdb-command: g
+
+// The .nvlist command in cdb does not always have a deterministic output
+// for the order that NatVis files are displayed.
+
+// cdb-command: .nvlist
+// cdb-check:    [...].exe (embedded NatVis "[...]embedded_visualizer-0.natvis")
+
+// cdb-command: .nvlist
+// cdb-check:    [...].exe (embedded NatVis "[...]embedded_visualizer-1.natvis")
+
+// cdb-command: .nvlist
+// cdb-check:    [...].exe (embedded NatVis "[...]embedded_visualizer-2.natvis")
+
+// cdb-command: dx point_a
+// cdb-check:point_a          : (0, 0) [Type: embedded_visualizer::point::Point]
+// cdb-check:    [<Raw View>]     [Type: embedded_visualizer::point::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: embedded_visualizer::point::Point]
+// cdb-check:    [<Raw View>]     [Type: embedded_visualizer::point::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: embedded_visualizer::Line]
+// cdb-check:    [<Raw View>]     [Type: embedded_visualizer::Line]
+// cdb-check:    [a]              : (0, 0) [Type: embedded_visualizer::point::Point]
+// cdb-check:    [b]              : (5, 8) [Type: embedded_visualizer::point::Point]
+
+// cdb-command: dx person
+// cdb-check:person           : "Person A" is 10 years old. [Type: dependency_with_embedded_visualizers::Person]
+// cdb-check:    [<Raw View>]     [Type: dependency_with_embedded_visualizers::Person]
+// cdb-check:    [name]           : "Person A" [Type: alloc::string::String]
+// cdb-check:    [age]            : 10 [Type: int]
+
+// === GDB TESTS ===================================================================================
+
+// gdb-command: run
+
+// gdb-command: info auto-load python-scripts
+// gdb-check:Yes     pretty-printer-embedded_visualizer-0
+// gdb-check:Yes     pretty-printer-embedded_visualizer-1
+// gdb-command: print point_a
+// gdb-check:$1 = (0, 0)
+// gdb-command: print point_b
+// gdb-check:$2 = (5, 8)
+// gdb-command: print line
+// gdb-check:$3 = ((0, 0), (5, 8))
+// gdb-command: print person
+// gdb-check:$4 = "Person A" is 10 years old.
+
+#![allow(unused_variables)]
+#![feature(debugger_visualizer)]
+#![debugger_visualizer(natvis_file = "embedded-visualizer.natvis")]
+#![debugger_visualizer(gdb_script_file = "embedded-visualizer.py")]
+
+// aux-build: dependency-with-embedded-visualizers.rs
+extern crate dependency_with_embedded_visualizers;
+
+use dependency_with_embedded_visualizers::Person;
+
+#[debugger_visualizer(natvis_file = "embedded-visualizer-point.natvis")]
+#[debugger_visualizer(gdb_script_file = "embedded-visualizer-point.py")]
+mod point {
+    pub struct Point {
+        x: i32,
+        y: i32,
+    }
+
+    impl Point {
+        pub fn new(x: i32, y: i32) -> Point {
+            Point { x: x, y: y }
+        }
+    }
+}
+
+use point::Point;
+
+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);
+
+    let name = String::from("Person A");
+    let person = Person::new(name, 10);
+
+    zzz(); // #break
+}
+
+fn zzz() {
+    ()
+}