Bug 21893 - template_argument(0) gives syntax error
Summary: template_argument(0) gives syntax error
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: rust (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-02 21:20 UTC by Jeff Muizelaar
Modified: 2022-01-25 01:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2018-10-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Muizelaar 2017-08-02 21:20:17 UTC
Given the following program:

use std::collections::HashMap;

fn main() {
    let m : HashMap<u32, Vec<u32>> = HashMap::new();
    println!("Hello, world! {:?}", m);
}

print(gdb.parse_and_eval("m")["table"].type.template_argument(0))

gives a:

RuntimeError: syntax error, near `>>'
Error while executing Python code.
Comment 1 Tom Tromey 2017-08-02 23:34:53 UTC
This happens because rustc doesn't emit DW_AT_template_type_param for
the HashMap type.

Then it interacts with a weird gdb/python thing -- in earlier times gcc
also did not emit this template information, so the first iteration of
this python layer code hacked around the omission by parsing the C++
name and extracting the type names.  This code remains, so it still tries
to do this as a fallback.

I think this is apropos: https://github.com/rust-lang/rust/issues/9224
Comment 2 Jeff Muizelaar 2017-08-04 00:47:21 UTC
https://github.com/rust-lang/rust/issues/9224 seems to suggest that rustc is emitting DW_AT_template_type_param
Comment 3 Tom Tromey 2017-08-05 21:49:17 UTC
(In reply to Jeff Muizelaar from comment #2)
> https://github.com/rust-lang/rust/issues/9224 seems to suggest that rustc is
> emitting DW_AT_template_type_param

Not always.  Consider this test (from that bug):

pub struct Generic<T: Clone>(T);
pub struct Normal(i32);

fn main () {
    let generic = Generic(10);
    let normal = Normal(10);
    generic;
    normal;
}

Here the DWARF for Generic<i32> is just:

 <2><81>: Abbrev Number: 6 (DW_TAG_structure_type)
    <82>   DW_AT_name        : (indirect string, offset: 0x6e): Generic<i32>
    <86>   DW_AT_byte_size   : 4
    <87>   Unknown AT value: 88: 4
 <3><88>: Abbrev Number: 7 (DW_TAG_member)
    <89>   DW_AT_name        : (indirect string, offset: 0x66): __0
    <8d>   DW_AT_type        : <0xa8>
    <91>   Unknown AT value: 88: 4
    <92>   DW_AT_data_member_location: 0
 <3><93>: Abbrev Number: 0
Comment 4 Tom Tromey 2018-10-12 13:37:38 UTC
See https://github.com/rust-lang/rust/pull/55010
Comment 5 Tom Tromey 2022-01-25 01:50:29 UTC
The fix for this has been in rustc for a while now,
so I am going to close this.
If it's still a problem, please comment or reopen.  Thanks.