Description
A debugger is particularly useful for diagnosing problems in unsafe code, and these types appear reasonably often there. Currently they're printed in a rather ugly way:
#![feature(unique)]
use std::ptr::Unique;
struct Bar { y: u8 }
struct Foo {
ptr: Unique<Bar>,
}
fn main() {
let mut x = Bar { y: 10 };
unsafe {
let f = Foo { ptr: Unique::new(&mut x) };
drop(f);
}
}
Compiling with rustc -g unique.rs
and using rust-gdb unique
to break on the drop(f)
line allows one to print f
:
(gdb) break unique.rs:13
(gdb) r
...
(gdb) p f
$1 = Foo = {ptr = Unique<unique::Bar> = {pointer = NonZero<*const unique::Bar> = {0x7fffffffdef8}, _marker = PhantomData<unique::Bar>}}
Pretty much the only thing that's even slightly interesting there is the 0x7fffffffdef8
and maybe the unique::Bar
, the layers of NonZero
and PhantomData
are just noise. (And even the raw address is pretty useless, and the type is often obvious from context.)
Also, the only way to examine what the pointer points to is to do a pile of field accesses, like:
(gdb) p *f.ptr.pointer.__0
$2 = Bar = {y = 10 '\n'}
In the best case, it'd be great if *f.ptr
could work. (Also, f.ptr.pointer.__0[x]
being written f.ptr[x]
, for when the Unique
is representing an array.)
(I guess there may be other standard library types to consider in a similar context: making rust-gdb
handle them even more nicely.)