diff options
author | Tom Tromey <tom@tromey.com> | 2020-09-23 09:39:24 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2020-09-23 09:39:24 -0600 |
commit | 20a5fcbd5b28cca88511ac5a9ad5e54251e8fa6d (patch) | |
tree | 5443c2824f7d53f50d8d280f64d19f398f523f65 /gdb/dwarf2 | |
parent | bac51ab78d4bee5273c7d6306ff6d41545fd5628 (diff) | |
download | gdb-20a5fcbd5b28cca88511ac5a9ad5e54251e8fa6d.zip gdb-20a5fcbd5b28cca88511ac5a9ad5e54251e8fa6d.tar.gz gdb-20a5fcbd5b28cca88511ac5a9ad5e54251e8fa6d.tar.bz2 |
Handle bit offset and bit size in base types
PR symtab/25470 points out that the Zig programming language allows
integers of various bit sizes (including zero), not just sizes that
are a multiple of 8.
This is supported in DWARF by applying both a byte size and a
DW_AT_bit_size.
This patch adds support for this feature to integer and boolean types.
Other base types are not handled -- for floating-point types, this
didn't seem to make sense, and for character types I didn't see much
need. (These can be added later if desired.)
I've also added support for DW_AT_data_bit_offset at the same time. I
don't know whether the Zig compiler requires this, but it was
described in the same section in the DWARF standard and was easy to
add.
A new test case is supplied, using the DWARF assembler.
gdb/ChangeLog
2020-09-23 Tom Tromey <tom@tromey.com>
PR symtab/25470:
* value.c (unpack_long, pack_long, pack_unsigned_long): Handle bit
offset and bit size.
* printcmd.c (print_scalar_formatted): Handle zero-length
integer.
(print_scalar_formatted): Use bit_size_differs_p.
* gdbtypes.h (enum type_specific_kind) <TYPE_SPECIFIC_INT>: New
constant.
(union type_specific): <int_stuff>: New member.
(struct type) <bit_size_differs_p, bit_size, bit_offset>: New
methods.
* gdbtypes.c (init_integer_type, init_boolean_type): Initialize
TYPE_SPECIFIC_FIELD.
(recursive_dump_type, copy_type_recursive): Update.
* dwarf2/read.c (read_base_type): Handle DW_AT_bit_size and
DW_AT_data_bit_offset.
gdb/testsuite/ChangeLog
2020-09-23 Tom Tromey <tom@tromey.com>
* gdb.dwarf2/intbits.exp: New file.
* gdb.dwarf2/intbits.c: New file.
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/read.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a339141..977bdb8 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18054,6 +18054,26 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) type->set_endianity_is_not_default (gdbarch_byte_order (arch) != byte_order); + if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT) + { + attr = dwarf2_attr (die, DW_AT_bit_size, cu); + if (attr != nullptr && DW_UNSND (attr) <= 8 * TYPE_LENGTH (type)) + { + unsigned real_bit_size = DW_UNSND (attr); + attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); + /* Only use the attributes if they make sense together. */ + if (attr == nullptr + || DW_UNSND (attr) + real_bit_size <= 8 * TYPE_LENGTH (type)) + { + TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size + = real_bit_size; + if (attr != nullptr) + TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset + = DW_UNSND (attr); + } + } + } + return set_die_type (die, type, cu); } |