Bug 21763 - gdb.lookup_type fails for rust
Summary: gdb.lookup_type fails for rust
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: rust (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 8.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-12 20:09 UTC by Tom Tromey
Modified: 2017-07-14 16:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Tromey 2017-07-12 20:09:00 UTC
The Python API gdb.lookup_type fails for Rust.
From jrmuizel:

    struct Foo {
        g: u32,
           h: u32
    }
     
    fn main() {
        let f = Foo{ g: 8, h: 9 };
        println!("Hello, world!");
    }
     
    gives:
     
    (gdb) python print(gdb.lookup_type(str(gdb.parse_and_eval("f").type)))
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    gdb.error: No type named tmp::Foo.
    Error while executing Python code.
    (gdb)
Comment 1 Tom Tromey 2017-07-12 22:59:23 UTC
The issue seems to be that lookup_typename looks in VAR_DOMAIN,
but the symbol in question is in STRUCT_DOMAIN.

Two possible fixes come to mind.

One is to attempt to put all Rust types into VAR_DOMAIN.
This arguably even makes sense because VAR_DOMAIN is defined
as holding typedefs (which seems weird -- having a real
"types" domain might be preferable, but much harder).
This change could probably be done just in dwarf2read.c,
though patching rust_lookup_type would be good to do as well.
It's unclear what other issues this might introduce.

The second possible fix is to have typy_lookup_typename
also search STRUCT_DOMAIN if the VAR_DOMAIN search fails.
Comment 2 Tom Tromey 2017-07-13 02:26:48 UTC
Actually the simplest is just adding to the special case in
symbol_matches_domain.  I sort of hate to do this but...
Comment 3 Tom Tromey 2017-07-13 21:05:19 UTC
Testing a patch.
Comment 4 Sourceware Commits 2017-07-14 16:17:36 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=65547233e04b32e087f74f8f5e9d3ffb6fe2c198

commit 65547233e04b32e087f74f8f5e9d3ffb6fe2c198
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Jul 13 15:03:27 2017 -0600

    Make gdb.lookup_typename work for Rust types
    
    PR rust/21763 points out that gdb.lookup_typename does not work properly
    for (some) Rust types.  I tracked this down to a missing case in
    symbol_matches_domain.
    
    Tested by the buildbot.
    
    2017-07-14  Tom Tromey  <tom@tromey.com>
    
    	PR rust/21763:
    	* symtab.c (symbol_matches_domain): Add language_rust to special
    	case.
    	* rust-exp.y (convert_ast_to_expression) <OP_VAR_VALUE>: Don't
    	treat LOC_TYPEDEF symbols as variables.
    
    2017-07-14  Tom Tromey  <tom@tromey.com>
    
    	* gdb.rust/simple.exp: Add regression test for PR rust/21763.
Comment 5 Tom Tromey 2017-07-14 16:23:59 UTC
Fix checked in.