Skip to content

gdb pretty-printers not working for struct fields with gdb 10.x #85267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mullr opened this issue May 13, 2021 · 7 comments
Closed

gdb pretty-printers not working for struct fields with gdb 10.x #85267

mullr opened this issue May 13, 2021 · 7 comments
Labels
C-bug Category: This is a bug.

Comments

@mullr
Copy link

mullr commented May 13, 2021

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.
@mullr mullr added the C-bug Category: This is a bug. label May 13, 2021
@mullr
Copy link
Author

mullr commented May 13, 2021

I tried this with a fresh ubuntu 20.04 VM, (gdb 9.2) and it's working there:

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 (Vec(size=3) = {1, 2, 3})

Ubuntu 20.10 (gdb 9.2) works as well.

With a fresh Ubuntu 21.04 VM (gdb 10.1), the problem occurs. So it seems possible this is related to the gdb version.

@mullr
Copy link
Author

mullr commented May 13, 2021

gdb 10.2 is broken as well, but the problem goes away on a manual downgrade to gdb 9.2. So this is pretty clearly an issue with gdb 10+.

@mullr
Copy link
Author

mullr commented May 13, 2021

I bisected through gdb's history and found that this is the offending commit:
bminor/binutils-gdb@5f56f7c

@mullr
Copy link
Author

mullr commented May 14, 2021

I've posted a question on this subject to the gdb mailing list; I'll update back here with any progress.

@mullr
Copy link
Author

mullr commented May 14, 2021

Confirmed that this is a bug in gdb.

@tromey
Copy link
Contributor

tromey commented May 15, 2021

I fixed it for gdb 11. There most likely won't be another release of gdb 10. https://sourceware.org/pipermail/gdb-patches/2021-May/178895.html

@mullr mullr changed the title gdb pretty-printers not working for struct fields gdb pretty-printers not working for struct fields with gdb 10.x May 18, 2021
@tromey
Copy link
Contributor

tromey commented Mar 18, 2022

We're working up to the gdb 12 release now. Given that this isn't a bug in rust, and because gdb 11 fixes the problem, I'm going to close this bug.

@tromey tromey closed this as completed Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants