Skip to content

Consider having special debugger pretty printers/handling for Unique/Shared/NonZero #29392

Open
@huonw

Description

@huonw

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions