$ cat test.cpp struct Base1 { int b1 = 0x1111; }; struct Base2 { int b2 = 0x2222; }; struct Derived : public Base1, Base2 { int d = 0x3333; }; int main() { Derived d; return 0; } $ g++ test.cpp -g3 -O0 $ DEBUGINFOD_URLS= ./gdb -nx -q --data-directory=data-directory a.out -ex "b 15" -ex r Reading symbols from a.out... Breakpoint 1 at 0x1165: file test.cpp, line 15. Starting program: /home/simark/build/binutils-gdb/gdb/a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1". Breakpoint 1, main () at test.cpp:15 15 return 0; (gdb) p &d $1 = (Derived *) 0x7fffffffdcfc (gdb) p (Base2 *) &d $2 = (Base2 *) 0x7fffffffdd00 (gdb) p (Derived *) (Base2 *) &d $3 = (Derived *) 0x7fffffffdcf8 Pretty sure that $1 and $3 should be equal. Might be related to https://sourceware.org/bugzilla/show_bug.cgi?id=20285. Not quite the same, but it might be the same root cause.
Sending a patch.
The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2390419d1cb72882110538e01e5586372df19657 commit 2390419d1cb72882110538e01e5586372df19657 Author: Tom Tromey <tom@tromey.com> Date: Sat Apr 2 09:54:40 2022 -0600 Fix C++ cast of derived class to base class PR c++/28907 points out that casting from a derived class to a base class fails in some situations. The problem turned out to be a missing use of value_embedded_offset. One peculiarity here is that, if you managed to construct a pointer-to-derived with an embedded offset of 0, the cast would work -- for example, one of the two new tests here passes without the patch. This embedded offset stuff is an endless source of bugs. I wonder if it's possible to get rid of it somehow. Regression tested on x86-64 Fedora 34. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28907
Fixed.