aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-09-18 12:44:42 -0600
committerTom Tromey <tromey@adacore.com>2024-10-22 12:04:06 -0600
commit04ce6b03d9e940b6fb2ccd54539357714e7550bd (patch)
tree68c3fc221b0127ac3d1aae149bd7dd7e588f05a2 /gdb/testsuite
parent8483536dea6e36e9f4a0949ecad0fcaafd62cf54 (diff)
downloadbinutils-04ce6b03d9e940b6fb2ccd54539357714e7550bd.zip
binutils-04ce6b03d9e940b6fb2ccd54539357714e7550bd.tar.gz
binutils-04ce6b03d9e940b6fb2ccd54539357714e7550bd.tar.bz2
Implement 'Object_Size
This patch started as an attempt to allow the 'Size attribute to be applied to types, and not just objects. However, that turns out to be difficult due to the Ada semantcs of 'Size. In particular, Ada requires 'Size to denote the size of the representation of the value, so for example Boolean'Size must be 1. Implementing this properly requires information not readily available to gdb... and while we could synthesize this information in many cases, it also seemed to me that this wasn't strictly very useful when debugging. So instead, this patch adds support for the 'Object_Size attribute, which is somewhat closer to 'sizeof'. Note also that while 'Object_Size is defined for some dynamic types, I chose not to implement this here, as again this information is not readily available -- and I think it's preferable to error than to print something that might be incorrect. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.ada/type-tick-size.exp50
-rw-r--r--gdb/testsuite/gdb.ada/type-tick-size/pck.adb21
-rw-r--r--gdb/testsuite/gdb.ada/type-tick-size/pck.ads36
-rw-r--r--gdb/testsuite/gdb.ada/type-tick-size/prog.adb56
-rw-r--r--gdb/testsuite/gdb.ada/type-tick-size/support.adb21
-rw-r--r--gdb/testsuite/gdb.ada/type-tick-size/support.ads18
6 files changed, 202 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.ada/type-tick-size.exp b/gdb/testsuite/gdb.ada/type-tick-size.exp
new file mode 100644
index 0000000..c696a31
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/type-tick-size.exp
@@ -0,0 +1,50 @@
+# Copyright 2024 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"
+
+require allow_ada_tests
+
+standard_ada_testfile prog
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/prog.adb]
+runto "prog.adb:$bp_location"
+
+foreach type {boolean color simple small_int} {
+ # Log all the values for easier debugging.
+ gdb_test "print ${type}_val'object_size" " = $decimal"
+ gdb_test "print ${type}'object_size" " = $decimal"
+ gdb_test "print ${type}_size" " = $decimal"
+ gdb_test "print ${type}_type_size" " = $decimal"
+
+ gdb_test "print ${type}_val'object_size = ${type}_size" " = true"
+ gdb_test "print ${type}'object_size = ${type}_type_size" " = true"
+
+ gdb_test "print ${type}'size" "gdb cannot apply 'Size to a type"
+}
+
+gdb_test "print rec_val'object_size" " = $decimal"
+gdb_test "print rec'object_size" "cannot apply 'Object_Size to dynamic type"
+
+# Check that 'Size can be applied to values, regardless of whether
+# their declared type is dynamic.
+gdb_test "print static_blob'size = static_blob_size" " = true"
+gdb_test "print dynamic_blob'size = dynamic_blob_size" " = true"
diff --git a/gdb/testsuite/gdb.ada/type-tick-size/pck.adb b/gdb/testsuite/gdb.ada/type-tick-size/pck.adb
new file mode 100644
index 0000000..ffff1b6
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/type-tick-size/pck.adb
@@ -0,0 +1,21 @@
+-- Copyright 2024 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/>.
+
+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/type-tick-size/pck.ads b/gdb/testsuite/gdb.ada/type-tick-size/pck.ads
new file mode 100644
index 0000000..a3c3cd1
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/type-tick-size/pck.ads
@@ -0,0 +1,36 @@
+-- Copyright 2024 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;
+with Support; use Support;
+
+package Pck is
+ subtype Length is Natural range 0 .. 10;
+ type Bounded_String (Max_Length : Length := Length'Last) is
+ record
+ Current_Length : Length := 0;
+ Buffer : String (1 .. Max_Length);
+ end record;
+
+ type Blob is array (Integer range <>) of Bounded_String;
+
+ Static_Blob : Blob (1 .. 10);
+ Static_Blob_Size : Integer := Static_Blob'Size;
+
+ Dynamic_Blob : Blob (1 .. Ident (10));
+ Dynamic_Blob_Size : Integer := Dynamic_Blob'Size;
+
+ procedure Do_Nothing (A : System.Address);
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/type-tick-size/prog.adb b/gdb/testsuite/gdb.ada/type-tick-size/prog.adb
new file mode 100644
index 0000000..c911583
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/type-tick-size/prog.adb
@@ -0,0 +1,56 @@
+-- Copyright 2024 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 Prog is
+ type Color is (Red, Orange, Yellow, Green, Blue, Indigo, Violet);
+
+ type Simple is record
+ I : Integer;
+ end record;
+
+ subtype Small_Int is Natural range 0 .. 100;
+ type Rec (L : Small_Int := 0) is record
+ S : String (1 .. L);
+ end record;
+
+ Boolean_Val : Boolean := True;
+ Boolean_Size : Integer := Boolean_Val'Size;
+ Boolean_Type_Size : Integer := Boolean'Object_Size;
+
+ Color_Val : Color := Indigo;
+ Color_Size : Integer := Color_Val'Size;
+ Color_Type_Size : Integer := Color'Object_Size;
+
+ Simple_Val : Simple := (I => 91);
+ Simple_Size : Integer := Simple_Val'Size;
+ Simple_Type_Size : Integer := Simple'Object_Size;
+
+ Small_Int_Val : Small_Int := 31;
+ Small_Int_Size : Integer := Small_Int_Val'Size;
+ Small_Int_Type_Size : Integer := Small_Int'Object_Size;
+
+ Rec_Val : Rec := (L => 2, S => "xy");
+ -- This is implementation defined, so the compiler does provide
+ -- something, but gdb does not.
+ Rec_Size : Integer := Rec_Val'Size;
+ Rec_Type_Size : Integer := Rec'Object_Size;
+
+begin
+ Do_Nothing (Static_Blob'Address);
+ Do_Nothing (Dynamic_Blob'Address);
+ null; -- STOP
+end Prog;
diff --git a/gdb/testsuite/gdb.ada/type-tick-size/support.adb b/gdb/testsuite/gdb.ada/type-tick-size/support.adb
new file mode 100644
index 0000000..b694653
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/type-tick-size/support.adb
@@ -0,0 +1,21 @@
+-- Copyright 2024 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/>.
+
+package body Support is
+ function Ident (I : Integer) return Integer is
+ begin
+ return I;
+ end Ident;
+end Support;
diff --git a/gdb/testsuite/gdb.ada/type-tick-size/support.ads b/gdb/testsuite/gdb.ada/type-tick-size/support.ads
new file mode 100644
index 0000000..b86b14e
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/type-tick-size/support.ads
@@ -0,0 +1,18 @@
+-- Copyright 2024 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/>.
+
+package Support is
+ function Ident (I : Integer) return Integer;
+end Support;