binutils-gdb/gdb/testsuite/gdb.dwarf2/intbits.c
Tom Tromey 20a5fcbd5b 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.
2020-09-23 09:39:24 -06:00

48 lines
1.7 KiB
C

/* Copyright (C) 2020 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* A 16 bit slot holding a 7-bit value of -1. Note that, for all
these values, we explicitly set the endian-ness in the DWARF to
avoid issues. */
unsigned char i16_m1[2] = { 0x7f, 0 };
/* A 16 bit slot holding a 1-bit value of 1 at offset 2. */
unsigned char u16_1[2] = { 0x4, 0 };
/* A 32 bit slot holding a 17-bit value of -2. */
unsigned char u32_m2[4] = { 0xfe, 0xff, 0x01, 0 };
/* A 32 bit slot holding a 31 bit value of 1. The high bit should be
ignored when reading. */
unsigned char u32_1[4] = { 1, 0, 0, 0x80 };
/* A 32 bit slot holding a 31 bit value of 1, offset by 1 bit. */
unsigned char u32_1_off[4] = { 2, 0, 0, 0 };
/* A 32 bit slot holding a 30 bit value of 1, offset by 1 bit.
Big-endian. */
unsigned char be30_1_off[4] = { 0x80, 0, 0, 2 };
/* A 32 bit slot holding a 0 bit value. We don't use 0 in the array
here, to catch any situation where gdb tries to use the memory. */
unsigned char u32_0[4] = { 0xff, 0xff, 0xff, 0xff };
int
main (void)
{
return 0;
}