summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.ada
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2019-05-13 13:21:48 -0600
committerTom Tromey <tromey@adacore.com>2019-09-03 10:20:40 -0600
commit4e962e74e45f2b0365e5b21504f33480c468ff00 (patch)
tree7f20b55fbf46c379db243e1bcbf8a84ccd55c028 /gdb/testsuite/gdb.ada
parentf44b758d3133ef0a7f3131c1e12ed20feb33ee61 (diff)
downloadbinutils-gdb-4e962e74e45f2b0365e5b21504f33480c468ff00.tar.gz
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.
Diffstat (limited to 'gdb/testsuite/gdb.ada')
-rw-r--r--gdb/testsuite/gdb.ada/bias.exp56
-rw-r--r--gdb/testsuite/gdb.ada/bias/bias.adb52
-rw-r--r--gdb/testsuite/gdb.ada/bias/pck.adb23
-rw-r--r--gdb/testsuite/gdb.ada/bias/pck.ads20
-rw-r--r--gdb/testsuite/gdb.ada/print_chars.exp2
-rw-r--r--gdb/testsuite/gdb.ada/print_chars/foo.adb3
6 files changed, 155 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.ada/bias.exp b/gdb/testsuite/gdb.ada/bias.exp
new file mode 100644
index 00000000000..76ca6c08c63
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/bias.exp
@@ -0,0 +1,56 @@
+# 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/>.
+
+load_lib "ada.exp"
+
+standard_ada_testfile bias
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \
+ {debug additional_flags=-fgnat-encodings=minimal}] != "" } {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/bias.adb]
+runto "bias.adb:$bp_location"
+
+gdb_test "print x" " = 64"
+gdb_test "print y" " = -5"
+
+gdb_test "print cval" " = 65"
+gdb_test "print/c cval" " = 65 'A'"
+
+# Some binary arithmetic checks.
+gdb_test "print y < y1" " = false"
+gdb_test "print y <= y1" " = false"
+gdb_test "print y > y1" " = true"
+gdb_test "print y >= y1" " = true"
+gdb_test "print y = y" " = true"
+gdb_test "print y /= y" " = false"
+gdb_test "print y /= y1" " = true"
+
+gdb_test "print x + x1" " = 65"
+gdb_test "ptype x + x1" "type = range 1 \\.\\. 64"
+gdb_test "print x / x1" " = 64"
+gdb_test "print x * x1" " = 64"
+gdb_test "print x - x1" " = 63"
+
+# Test that storing un-biases.
+gdb_test "print x := 5" " = 5"
+gdb_test "print x" " = 5" "re-read x after storing"
+
+gdb_test "print spr" " = \\(r => -4, s => -5\\)"
+gdb_test "print a" " = \\(-7, -5, -4\\)"
diff --git a/gdb/testsuite/gdb.ada/bias/bias.adb b/gdb/testsuite/gdb.ada/bias/bias.adb
new file mode 100644
index 00000000000..ad46d20dd20
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/bias/bias.adb
@@ -0,0 +1,52 @@
+-- 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;
diff --git a/gdb/testsuite/gdb.ada/bias/pck.adb b/gdb/testsuite/gdb.ada/bias/pck.adb
new file mode 100644
index 00000000000..fb433861df0
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/bias/pck.adb
@@ -0,0 +1,23 @@
+-- Copyright 2012-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 System;
+
+package body Pck is
+ procedure Do_Nothing (A : System.Address) is
+ begin
+ null;
+ end Do_Nothing;
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/bias/pck.ads b/gdb/testsuite/gdb.ada/bias/pck.ads
new file mode 100644
index 00000000000..a40fa62c8eb
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/bias/pck.ads
@@ -0,0 +1,20 @@
+-- Copyright 2012-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 System;
+
+package Pck is
+ procedure Do_Nothing (A : System.Address);
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/print_chars.exp b/gdb/testsuite/gdb.ada/print_chars.exp
index 992b1347641..9a0e2157844 100644
--- a/gdb/testsuite/gdb.ada/print_chars.exp
+++ b/gdb/testsuite/gdb.ada/print_chars.exp
@@ -39,4 +39,4 @@ gdb_test "print WWC" \
"= 99 'c'" \
"print WWC"
-
+gdb_test "print MC" " = 77 'M'"
diff --git a/gdb/testsuite/gdb.ada/print_chars/foo.adb b/gdb/testsuite/gdb.ada/print_chars/foo.adb
index 40d0c060942..c89c0d3cef9 100644
--- a/gdb/testsuite/gdb.ada/print_chars/foo.adb
+++ b/gdb/testsuite/gdb.ada/print_chars/foo.adb
@@ -19,6 +19,9 @@ procedure Foo is
C : Character := 'a';
WC : Wide_Character := 'b';
WWC : Wide_Wide_Character := 'c';
+
+ type My_Character is new Character;
+ MC : My_Character := 'M';
begin
Do_Nothing (C'Address); -- START
Do_Nothing (WC'Address);