Page MenuHomePhabricator

Debug info: Support DWARF4 bitfields via DW_AT_data_bit_offset.

Authored by aprantl on Apr 27 2016, 2:59 PM.


The DWARF2 specification of DW_AT_bit_offset was written from the perspective of
a big-endian machine with unclear semantics for other systems.  DWARF4
deprecated DW_AT_bit_offset and introduced a new attribute DW_AT_data_bit_offset
that simply counts the number of bits from the beginning of the containing
entity regardless of endianness.

After this patch LLVM emits DW_AT_bit_offset for DWARF 2 or 3 and
DW_AT_data_bit_offset when DWARF 4 or later is requested.

Any caveats from any non-LLDB platform maintainers?

Diff Detail

Event Timeline

aprantl updated this revision to Diff 55332.Apr 27 2016, 2:59 PM
aprantl retitled this revision from to Debug info: Support DWARF4 bitfields via DW_AT_data_bit_offset. .
aprantl updated this object.
aprantl added reviewers: echristo, dblaikie, probinson.
aprantl set the repository for this revision to rL LLVM.
aprantl added subscribers: clayborg, llvm-commits.
aprantl accepted this revision.Apr 27 2016, 5:26 PM
aprantl added a reviewer: aprantl.

echristo kindly tested this with GDB and confirmed that this is working.

This revision is now accepted and ready to land.Apr 27 2016, 5:26 PM
echristo edited edge metadata.Apr 27 2016, 5:29 PM
echristo added a subscriber: echristo.


You can accept your own patch.


But yes, please go ahead :)


probinson edited edge metadata.Apr 27 2016, 6:20 PM

Any caveats from any non-LLDB platform maintainers?

WFM. If our debugger doesn't handle it now, the team will have plenty of time before the release that has this change.

materi added a subscriber: materi.May 16 2016, 9:06 AM


I am debugging an issue with bitfields and debug info and found that this commit is where the problems begin.

The file tmp.c:

struct fields
  unsigned int a : 1;
  unsigned int b : 1;
} f;

int main ()
  f.a = 1;
  return 0;

Built with top-of-tree clang and run in gdb:

gdb a.out
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Reading symbols from a.out...done.
(gdb) break main
Breakpoint 1 at 0x40058d: file tmp.c, line 9.
(gdb) run
Starting program: a.out 

Breakpoint 1, main () at tmp.c:9
9         f.a = 1;
(gdb) display f
1: f = {a = 0, b = 0}
(gdb) n
10        return 0;
1: f = {a = 1, b = 1}                 <<<--- Unexpected value of b!
(gdb) x &f
0x402024 <f>:   0x00000001

Should I write a bug report in bugzilla?

Yes please.



aprantl closed this revision.Aug 17 2016, 8:56 AM

Closing this was committed long ago in 267895 with some follow-up in 269827 and 269731.