This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix inherit.exp tests


Andrew Stubbs <ams@codesourcery.com> writes:

> The reason is that the "_vptr" entries in C++ types do not point to
> the head of the vtable, but point to the address following the last
> entry in the table, which mean that when GDB prints the symbol
> associated with the address, it actually prints the name of the value
> that follows the table in memory.

Yes, gcc option -fdump-class-hierarchy is quite useful in this case,

Class vE
   size=72 align=8
   base size=16 base align=8
vE (0x0x7ff4b6000c98) 0
    vptridx=0u vptr=((& vE::vtable for vE) + 48u)
  vD (0x0x7ff4b61970e0) 16 virtual
      subvttidx=32u vptridx=8u vbaseoffset=-24 vptr=((& vE::vtable for vE) + 88u)
    vB (0x0x7ff4b6000d00) 32 virtual
        subvttidx=56u vptridx=16u vbaseoffset=-32 vptr=((& vE::vtable for vE) + 112u)
      vA (0x0x7ff4b618d060) 48 virtual
          vbaseoffset=-40
    vC (0x0x7ff4b6000d68) 56 virtual
        subvttidx=64u vptridx=24u vbaseoffset=-48 vptr=((& vE::vtable for vE) + 136u)  <-- [1]
      vA (0x0x7ff4b618d060) alternative-path


Vtable for vE
vE::vtable for vE: 17u entries
0     56u
8     48u
16    32u
24    16u
32    (int (*)(...))0
40    (int (*)(...))(& typeinfo for vE)
48    40u
56    32u
64    16u
72    (int (*)(...))-16
80    (int (*)(...))(& typeinfo for vE)
88    16u
96    (int (*)(...))-32
104   (int (*)(...))(& typeinfo for vE)
112   18446744073709551608u
120   (int (*)(...))-56
128   (int (*)(...))(& typeinfo for vE)

As we can see vptr in [1] points to 136 bytes after vE::vtable (because
vptr is accessed as an array by negative index), but vE::vtable is only
128 bytes big, so anything can be there.

>
> Index: gdb/testsuite/gdb.cp/inherit.exp
> ===================================================================
> --- gdb/testsuite/gdb.cp/inherit.exp	(revision 455195)
> +++ gdb/testsuite/gdb.cp/inherit.exp	(working copy)
> @@ -524,6 +524,11 @@
>  	    # gcc HEAD 2004-07-31 -gstabs+
>  	    pass $name
>  	}
> +	-re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = ${hex}( <\[^>]*>)?, vb = 5, vx = 6\}$nl$gdb_prompt $" {
> +	    # gcc HEAD 2015?+
> +	    # the vptr is set to the address *after* the vtable, so the symbol shown is unpredictable

This line is too long, multiple instances of this problem.  Otherwise,
that patch is OK.  We can also garbage collect some patterns, but this
change can be done in follow-up patch.

Do you plan to fix fails in virtbase.exp too?

-- 
Yao (éå)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]