From: hex <heixia108@gmail.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb@sourceware.org
Subject: Re: Could GDB get offset of a field in virtual base class through NULL pointer
Date: Sun, 29 Sep 2013 01:59:00 -0000 [thread overview]
Message-ID: <CAB_AMN5ngrKWwwVwUBFQ1wS5fLiDCyDRO+qe9bOjPBJAMo-05Q@mail.gmail.com> (raw)
In-Reply-To: <20130928183852.GA12891@host2.jankratochvil.net>
>> 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
>
Sorry, a mistake, I meant "GDB could print &(((B *)0)->b), but it could not
print &(((B *)0)->a)."
> 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;
> }
>
If we use &(((B *)0)->a), we are likely to get offset of 'a' in class
B. If GDB could
support this specific case, we do not need a real object to get the offset.
next prev parent reply other threads:[~2013-09-29 1:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-28 16:23 hex
2013-09-28 18:39 ` Jan Kratochvil
2013-09-29 1:59 ` hex [this message]
2013-09-30 8:16 ` Jan Kratochvil
2013-09-30 14:29 ` hex
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAB_AMN5ngrKWwwVwUBFQ1wS5fLiDCyDRO+qe9bOjPBJAMo-05Q@mail.gmail.com \
--to=heixia108@gmail.com \
--cc=gdb@sourceware.org \
--cc=jan.kratochvil@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox