Files
binutils-gdb/gdb/testsuite/gdb.ada/bias/bias.adb
Tom Tromey 4e962e74e4 Handle biased types
In Ada, the programmer can request that a range type with a non-zero
base be stored in the minimal number of bits required for the range.
This is done by biasing the values; so, for example, a range of -7..-4
may be stored as two bits with a bias of -7.

This patch implements this for gdb.  It is done by adding a bias to
struct range_bounds and then adjusting a few spots to handle this.

The test case is written to use -fgnat-encodings=minimal, but a future
compiler patch will change the compiler to emit DW_AT_GNU_bias with
-fgnat-encodings=gdb.  It seemed good to get the gdb patch in first.

Tested on x86-64 Fedora 29; plus a variety of targets using AdaCore's
internal test suite.

gdb/ChangeLog
2019-09-03  Tom Tromey  <tromey@adacore.com>

	* ada-valprint.c (ada_val_print_num): Don't recurse for range
	types.
	(has_negatives): Unbias a range type bound.
	* dwarf2read.c (read_subrange_type): Handle DW_AT_GNU_bias.
	* gdbtypes.c (operator==): Handle new field.
	(create_range_type): Add "bias" parameter.
	(create_static_range_type, resolve_dynamic_range): Update.
	* gdbtypes.h (struct range_bounds) <bias>: New member.
	(create_range_type): Add bias parameter.
	* printcmd.c (print_scalar_formatted): Unbias range types.
	* value.c (unpack_long): Unbias range types.
	(pack_long): Bias range types.

gdb/testsuite/ChangeLog
2019-09-03  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/bias.exp: New file.
	* gdb.ada/bias/bias.adb: New file.
	* gdb.ada/print_chars.exp: Add regression test.
	* gdb.ada/print_chars/foo.adb (My_Character): New type.
	(MC): New variable.
2019-09-03 10:20:40 -06:00

53 lines
1.6 KiB
Ada

-- Copyright 2019 Free Software Foundation, Inc.
--
-- 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/>.
with Pck; use Pck;
procedure Bias is
type Small is range -7 .. -4;
for Small'Size use 2;
Y : Small := -5;
Y1 : Small := -7;
type Repeat_Count_T is range 1 .. 2 ** 6;
for Repeat_Count_T'Size use 6;
X : Repeat_Count_T := 64;
X1 : Repeat_Count_T := 1;
type Char_Range is range 65 .. 68;
for Char_Range'Size use 2;
Cval : Char_Range := 65;
type Some_Packed_Record is record
R: Small;
S: Small;
end record;
pragma Pack (Some_Packed_Record);
SPR : Some_Packed_Record := (R => -4, S => -5);
type Packed_Array is array (1 .. 3) of Small;
pragma pack (Packed_Array);
A : Packed_Array := (-7, -5, -4);
begin
Do_Nothing (Y'Address); -- STOP
Do_Nothing (Y1'Address);
Do_Nothing (X'Address);
Do_Nothing (X1'Address);
Do_Nothing (Cval'Address);
Do_Nothing (SPR'Address);
Do_Nothing (A'Address);
end Bias;