How do I pretty-print Rust structures in GDB?
Asked Answered
M

0

9

How do I pretty-print structures (specifically Vecs) in rust-gdb or plain gdb? Whenever I call p some_vector I get this result:

collections::vec::Vec<usize> = {buf = alloc::raw_vec::RawVec<usize> = {ptr = core::ptr::Unique<usize> = {pointer = core::nonzero::NonZero<*const usize> = {
    0x7ffff640d000}, _marker = core::marker::PhantomData<usize>}, cap = 16}, len = 10}

This is just unreadable. Is there any way to get a result showing the contents of the Vec? I am using Rust 1.12 and GDB 7.12.

Men answered 19/10, 2016 at 18:45 Comment(7)
In rust-gdb I'm getting things like $1 = Vec<i32>(len: 2, cap: 2) = {1, 2}. In gdb on the other hand, I'm getting something closer to what you have. Have you really tried rust-gdb?Schilit
@Schilit do your GDB / Rust versions match?Estancia
Slightly outdated gdb 7.11.1 & rust 1.12. But maybe there's been a regression at some point…Schilit
Well, after upgrading to gdb 7.12, I get exactly the same output as his with gdb, and still the nicer one with rust-gdb.Schilit
Make sure the rust-gdb pretty-printers are in fact installed, using info pretty-printer.Isopleth
> rust-gdb -q (gdb) info pretty-printer global pretty-printers: builtin mpx_bound128Men
Rust 1.12.1 & gdb 7.12 here, getting data ugly-printed in rust-gdb (even though info pretty-printer lists rust_pretty_printer_lookup_function)...Showcase

© 2022 - 2024 — McMap. All rights reserved.