Description
Hi! I'm trying to get pretty printing to work smoothly for rust in gdb. For a long time I was pretty sure nothing was working at all, but after liberal amounts of print(...) debugging in the associated python scripts, it appears that the pretty printing only kicks in when directly printing out one of the special structs, and not when they appear as members of something else.
For example, if I have a Vec and print that directly from gdb, I see the result of the pretty printers. But if I have a struct TrivialNewtype(Vec) and try to print that from gdb, I see all the guts of the Vec (the pretty printer is not active).
I made a small repro: https://github.com/mullr/gdb-pretty-test
For convenience, the code is:
struct TrivialNewtype(Vec<u8>);
fn test() {
let bare_vec = vec![1u8, 2, 3];
let newtype_vec = TrivialNewtype(vec![1u8, 2, 3]);
let placeholder = 12;
}
fn main() {
test()
}
I am building and debugging like this:
cargo build
rust-gdb target/debug/gdb-pretty-test -ex 'b test' -ex 'r' -ex 'n' -ex 'n' -ex 'p bare_vec' -ex 'p newtype_vec'
I expected that when I print newtype_vec
, the pretty printer for Vec would be used in a nested way.
Instead, this was printed:
Breakpoint 1, gdb_pretty_test::test () at src/main.rs:5
5 let bare_vec = vec![1u8, 2, 3];
6 let newtype_vec = TrivialNewtype(vec![1u8, 2, 3]);
7 let placeholder = 12;
$1 = Vec(size=3) = {1, 2, 3}
$2 = gdb_pretty_test::TrivialNewtype (alloc::vec::Vec<u8, alloc::alloc::Global> {buf: alloc::raw_vec::RawVec<u8, alloc::alloc::Global> {ptr: core::ptr::unique::Unique<u8> {pointer: 0x55555559abc0, _marker: core::marker::PhantomData<u8>}, cap: 3, alloc: alloc::alloc::Global}, len: 3})
Meta
rustc --version --verbose
:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-unknown-linux-gnu
release: 1.52.1
LLVM version: 12.0.0
This happens for nightly as well (rustc 1.54.0-nightly (5c02926 2021-05-11) (from rustc 1.54.0-nightly (ca82264 2021-05-09))
gdb --version
:
GNU gdb (Ubuntu 10.1-2ubuntu2) 10.1.90.20210411-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.