This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v5 2/2] Implement pahole-like 'ptype /o' option
On Wednesday, December 13 2017, I wrote:
> On Wednesday, December 13 2017, Pedro Alves wrote:
>
>> I'm mildly worried about whether the bitfield handling is working
>> correctly on big endian machines. We may want to lift this
>> x86-64-only restriction, by using e.g., alignas(N) or
>> __attribute__((aligned(N)) to take care of most of the differences
>> between architectures and end up with few per-arch code in
>> the .exp. But I'm fine with starting with only x86-64 if you
>> confirm manually on e.g., a big endian PPC64 machine on the
>> compile farm, and we can extend the testcase in that direction
>> after this is merged.
>
> OK, I'll confirm on PPC64BE.
It seems like the algorithm for calculating bitfield offsets is not
working correctly on BE machines. This is not only for "ptype /o", but
also for regular print commands. For example, consider this test:
struct tyu
{
int a1 : 1;
int a2 : 3;
int a3 : 23;
char a4 : 2;
int64_t a5;
int a6 : 5;
int64_t a7 : 3;
};
int
main (int argc, char *argv[])
{
struct tyu e;
e.a1 = e.a2 = e.a3 = e.a4 = e.a6 = e.a7 = -1;
return 0;
}
After stopping GDB at the "return 0;" line, here's what we see when we
print "e" on x86_64:
(gdb) p e
$1 = {a1 = -1, a2 = -1, a3 = -1, a4 = -1 '\377', a5 = 140737488344880, a6 = -1, a7 = -1}
While on PPC64BE:
(gdb) p e
$1 = {a1 = -1, a2 = 3, a3 = 3, a4 = 3 '\003', a5 = 70367536153528, a6 = -1, a7 = -1}
As for "ptype /o", the offsets printed on x86_64 and PPC64BE are the
same:
x86_64:
/* offset | size */ type = struct tyu {
/* 0:31 | 4 */ int a1 : 1;
/* 0:28 | 4 */ int a2 : 3;
/* 0: 5 | 4 */ int a3 : 23;
/* 3: 3 | 1 */ char a4 : 2;
/* XXX 3-bit hole */
/* XXX 4-byte hole */
/* 8 | 8 */ int64_t a5;
/* 16:27 | 4 */ int a6 : 5;
/* 16:56 | 8 */ int64_t a7 : 3;
/* total size (bytes): 24 */
}
PPC64BE:
/* offset | size */ type = struct tyu {
/* 0:31 | 4 */ int a1 : 1;
/* 0:28 | 4 */ int a2 : 3;
/* 0: 5 | 4 */ int a3 : 23;
/* 3: 3 | 1 */ char a4 : 2;
/* XXX 3-bit hole */
/* XXX 4-byte hole */
/* 8 | 8 */ int64_t a5;
/* 16:27 | 4 */ int a6 : 5;
/* 16:56 | 8 */ int64_t a7 : 3;
/* total size (bytes): 24 */
}
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/