This is the mail archive of the gdb@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: Could GDB get offset of a field in virtual base class through NULL pointer


On Sat, 28 Sep 2013 18:23:22 +0200, hex wrote:
> I defined two classes as following:
> // test.cpp
> class A{
> public:
>      int a;
> };
> class B: public virtual A{
> public:
>      int b;
> };
> 
> GDB could print &(((B *)0)->a), but it could not print &(((B *)0)->a).
                  ^^^^^^^^^^^^^^                         ^^^^^^^^^^^^^^
Those two expressions are the same and they really od not work:

(gdb) p &(((B *)0)->a)
Cannot access memory at address 0x0


> it could just regard the NULL pointer as a special
> case: it could get offset using TYPE_BASECLASS_BITPOS().

I do not see what it should do.  In the following case &(((B *)&OBJECT)->a)
prints once 12 and once 16 for different OBJECT so what it should print for 0?

class X:public virtual A,public B {};
class C {
public:
        int c;
};
class Y:public virtual A,public C,public B {};
#include <iostream>
int main() {
        X x;
        Y y;
        std::cout << (char *)&(((B *)&x)->a)-(char *)&x << std::endl;
        std::cout << (char *)&(((B *)&y)->a)-(char *)&y << std::endl;
}


Jan Kratochvil


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