public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26550] New: Object of class with virtual base classes printed incorrectly (gdb.cp/ambiguous.exp)
@ 2020-08-28 20:06 palves at redhat dot com
  2020-10-12 17:12 ` [Bug c++/26550] " cvs-commit at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: palves at redhat dot com @ 2020-08-28 20:06 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 26550
           Summary: Object of class with virtual base classes printed
                    incorrectly (gdb.cp/ambiguous.exp)
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: palves at redhat dot com
  Target Milestone: ---

The gdb.cp/ambiguous.exp testcase ( as soon as these changes land in master:
https://sourceware.org/pipermail/gdb-patches/2020-August/171526.html )
runs into a GDB bug where GDB prints a value with virtual base classes
incorrectly.

The class in question inherits from A1 directly and also inherits
from two other distinct base classes that inherit virtually from A1 in
turn:

class A1 {
public:
  int x;
  int y;
};

class LV : public virtual A1 {
public:
  int z;
};

class KV : public virtual A1 {
public:
  int i;
};

class JVA1 : public KV, public LV, public A1 {
public:
  int jva1;
};

and then is initialized like this:

  JVA1 jva1;
  jva1.KV::x = 1;
  jva1.KV::y = 2;
  jva1.LV::x = 3;
  jva1.LV::y = 4;
  jva1.z = 5;
  jva1.i = 6;
  jva1.jva1 = 7;

The testcase shows:

 print jva1.KV::x
 $51 = 1431665544
 (gdb) FAIL: gdb.cp/ambiguous.exp: all fields: print jva1.KV::x
 print jva1.KV::y
 $52 = 21845
 (gdb) FAIL: gdb.cp/ambiguous.exp: all fields: print jva1.KV::y

 (gdb) print /x (KV)jva1
 $4 = {<A1> = <invalid address>, _vptr.KV = 0x555555557b88 <vtable for
JVA1+24>, i = 0x457}
 (gdb) print /x (A1)(KV)jva1
 Cannot access memory at address 0x0

And with the following we see how GDB is clearly confusing the offset of
_vptr.KV with the offset of A1:

 (gdb) print /x jva1
 $1 = {<KV> = {<A1> = {x = 0x2, y = 0x16}, _vptr.KV = 0x555555557b88 <vtable
for JVA1+24>, i = 0x457}, ......}
                                                      ^^^^^^^^^^^^^^
 (gdb) print /x jva1.KV::x
 $2 = 0x55557b88
      ^^^^^^^^^^
 (gdb) print /x jva1.KV::y
 $3 = 0x5555
      ^^^^^^

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-25 18:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-28 20:06 [Bug c++/26550] New: Object of class with virtual base classes printed incorrectly (gdb.cp/ambiguous.exp) palves at redhat dot com
2020-10-12 17:12 ` [Bug c++/26550] " cvs-commit at gcc dot gnu.org
2021-11-10 16:52 ` blarsen at redhat dot com
2021-11-25 18:28 ` blarsen at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).