Skip to content

gdb needs to know what traits a type implements #33014

Open
@tromey

Description

@tromey

I'd like to make operator overloading work for Rust in gdb. That is, I'd like something like print x+y to call the appropriate method on the Add trait. I'd also like to make ordinary method calls work, where the method is defined in some trait that is impl'd for the concrete type of the object.

Right now I think this can't be done. There is no information in the debug info about what traits are implemented by a type.

Consider:

pub trait What {
    fn what(&self);
}

impl What for i32 {
    fn what(&self) {
        println!("{}", self);
    }
}

fn main() {
    let v = 23;
    let x = &v as &What;

    x.what();
    ()
}

Here i32 is described as just a base type:

 <1><5e7>: Abbrev Number: 16 (DW_TAG_base_type)
    <5e8>   DW_AT_name        : (indirect string, offset: 0x46a): i32
    <5ec>   DW_AT_encoding    : 5   (signed)
    <5ed>   DW_AT_byte_size   : 4

I think this might be a good spot to list all the impl'd traits. Perhaps they can be represented as DWARF interfaces; or maybe some Rust extension to DWARF would be preferable.

i32.What is emitted as a namespace:

 <2><2f>: Abbrev Number: 2 (DW_TAG_namespace)
    <30>   DW_AT_name        : (indirect string, offset: 0x48): i32.What

... but this isn't directly useful as it would require an iteration over all the namespace DIEs looking for matches. Maybe I could do this; but I'd rather not as it is very inefficient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)A-trait-systemArea: Trait systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.P-lowLow priorityT-compilerRelevant to the compiler team, 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