Trying to cast memory address as rust HashMap in gdb

Hi,
I am trying to cast a memory address as a rust HashMap in gdb, but it's failing. I must be missing something. Any help is appreciated. Thanks in advance.

Regards,
Sri

(gdb) p contacts
$21 = HashMap(size=4) = {["Daniel"] = "798-1364", ["Katie"] = "435-8291", ["Ashley"] = "645-7689", ["Robert"] = "956-1745"}
(gdb) p *&contacts
$22 = HashMap(size=4) = {["Daniel"] = "798-1364", ["Katie"] = "435-8291", ["Ashley"] = "645-7689", ["Robert"] = "956-1745"}
(gdb) disable pretty-printer
2 printers disabled
0 of 2 printers enabled
(gdb) p &contacts
$23 = (*mut std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState>) 0x7ffc0070d9d8
(gdb) p contacts
$24 = std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState> {base: hashbrown::map::HashMap<&str, &str, std::collections::hash::map::RandomState, alloc::alloc::Global> {hash_builder: std::collections::hash::map::RandomState {k0: 823948624412032795, k1: 3834388228342331852}, table: hashbrown::raw::RawTable<(&str, &str), alloc::alloc::Global> {table: hashbrown::raw::RawTableInner<alloc::alloc::Global> {bucket_mask: 7, ctrl: core::ptr::non_null::NonNull<u8> {pointer: 0x55d67e52aca0}, growth_left: 3, items: 4, alloc: alloc::alloc::Global}, marker: core::marker::PhantomData<(&str, &str)>}}}
(gdb) p (0x7ffc0070d9d8 as *mut std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState>)
No type name 'str' in current context
(gdb)

Sample code from the web:
fn main() {
    let mut contacts = HashMap::new();

    contacts.insert("Daniel", "798-1364");
    contacts.insert("Ashley", "645-7689");
    contacts.insert("Katie", "435-8291");
    contacts.insert("Robert", "956-1745");
.....
}

It sounds like this will be fixed in GDB 14:

https://sourceware.org/bugzilla/show_bug.cgi?id=22251

Thank you cuviper. gdb post patching with the fix is not complaining.

(gdb) info locals
number = "798-1364"
contacts = std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState> {base: hashbrown::map::HashMap<&str, &str, std::collections::hash::map::RandomState, alloc::alloc::Global> {hash_builder: std::collections::hash::map::RandomState {k0: 3798795517194214021, k1: 12864853773798609550}, table: hashbrown::raw::RawTable<(&str, &str), alloc::alloc::Global> {table: hashbrown::raw::RawTableInner<alloc::alloc::Global> {bucket_mask: 7, ctrl: core::ptr::non_null::NonNull<u8> {pointer: 0x55d9df2c3ca0}, growth_left: 3, items: 4, alloc: alloc::alloc::Global}, marker: core::marker::PhantomData<(&str, &str)>}}}
(gdb) p &contacts
$1 = (*mut std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState>) 0x7ffea3cef468
(gdb) p (0x7ffea3cef468 as *mut std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState>)
$2 = (*mut std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState>) 0x7ffea3cef468
(gdb) p *(0x7ffea3cef468 as *mut std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState>)
$3 = std::collections::hash::map::HashMap<&str, &str, std::collections::hash::map::RandomState> {base: hashbrown::map::HashMap<&str, &str, std::collections::hash::map::RandomState, alloc::alloc::Global> {hash_builder: std::collections::hash::map::RandomState {k0: 3798795517194214021, k1: 12864853773798609550}, table: hashbrown::raw::RawTable<(&str, &str), alloc::alloc::Global> {table: hashbrown::raw::RawTableInner<alloc::alloc::Global> {bucket_mask: 7, ctrl: core::ptr::non_null::NonNull<u8> {pointer: 0x55d9df2c3ca0}, growth_left: 3, items: 4, alloc: alloc::alloc::Global}, marker: core::marker::PhantomData<(&str, &str)>}}}
(gdb)

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.