* [PATCH 0/3] Improve Ada test coverage
@ 2026-05-08 17:34 Tom Tromey
2026-05-08 17:34 ` [PATCH 1/3] Combine ada_unop_atr and ada_unop_atr_operation::evaluate Tom Tromey
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Tom Tromey @ 2026-05-08 17:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I recently looked at code coverage of gdb's test suite. This found a
few holes in the Ada test coverage. This short series fixes a few of
these. (There's at least one more hole to cover.)
Regression tested on x86-64 Fedora 43.
Signed-off-by: Tom Tromey <tromey@adacore.com>
---
Tom Tromey (3):
Combine ada_unop_atr and ada_unop_atr_operation::evaluate
Test attributes with array types
Add test for Ada abs operator
gdb/ada-lang.c | 263 ++++++++++-----------
gdb/testsuite/gdb.ada/abs.exp | 29 +++
gdb/testsuite/gdb.ada/array_bounds.exp | 8 +
.../gdb.ada/tick_length_array_enum_idx.exp | 3 +
4 files changed, 168 insertions(+), 135 deletions(-)
---
base-commit: c7c8e5bf414b7512fb19df8bf153372d56cb7fc1
change-id: 20260508-ada-unop-atr-ed6f2b234c4e
Best regards,
--
Tom Tromey <tromey@adacore.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] Combine ada_unop_atr and ada_unop_atr_operation::evaluate
2026-05-08 17:34 [PATCH 0/3] Improve Ada test coverage Tom Tromey
@ 2026-05-08 17:34 ` Tom Tromey
2026-05-08 17:34 ` [PATCH 2/3] Test attributes with array types Tom Tromey
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2026-05-08 17:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This inlines ada_unop_atr into its sole caller. This split was an
artifact of the expression type conversion.
---
gdb/ada-lang.c | 263 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 128 insertions(+), 135 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0600394361c..0ecc6712677 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10364,139 +10364,6 @@ ada_binop_in_bounds_operation::evaluate (struct type *expect_type,
} /* namespace expr */
-/* A helper function for some attribute operations. */
-
-static value *
-ada_unop_atr (struct expression *exp, enum noside noside, enum exp_opcode op,
- struct value *arg1, struct type *type_arg, int tem)
-{
- const char *attr_name = nullptr;
- if (op == OP_ATR_FIRST)
- attr_name = "first";
- else if (op == OP_ATR_LAST)
- attr_name = "last";
-
- if (noside == EVAL_AVOID_SIDE_EFFECTS)
- {
- if (type_arg == NULL)
- type_arg = arg1->type ();
-
- if (ada_is_constrained_packed_array_type (type_arg))
- type_arg = decode_constrained_packed_array_type (type_arg);
-
- if (!discrete_type_p (type_arg))
- {
- switch (op)
- {
- default: /* Should never happen. */
- error (_("unexpected attribute encountered"));
- case OP_ATR_FIRST:
- case OP_ATR_LAST:
- type_arg = ada_index_type (type_arg, tem,
- attr_name);
- break;
- case OP_ATR_LENGTH:
- type_arg = builtin_type (exp->gdbarch)->builtin_int;
- break;
- }
- }
-
- return value::zero (type_arg, not_lval);
- }
- else if (type_arg == NULL)
- {
- arg1 = ada_coerce_ref (arg1);
-
- if (ada_is_constrained_packed_array_type (arg1->type ()))
- arg1 = ada_coerce_to_simple_array (arg1);
-
- struct type *type;
- if (op == OP_ATR_LENGTH)
- type = builtin_type (exp->gdbarch)->builtin_int;
- else
- {
- type = ada_index_type (arg1->type (), tem,
- attr_name);
- if (type == NULL)
- type = builtin_type (exp->gdbarch)->builtin_int;
- }
-
- switch (op)
- {
- default: /* Should never happen. */
- error (_("unexpected attribute encountered"));
- case OP_ATR_FIRST:
- return value_from_longest
- (type, ada_array_bound (arg1, tem, 0));
- case OP_ATR_LAST:
- return value_from_longest
- (type, ada_array_bound (arg1, tem, 1));
- case OP_ATR_LENGTH:
- return value_from_longest
- (type, ada_array_length (arg1, tem));
- }
- }
- else if (discrete_type_p (type_arg))
- {
- struct type *range_type;
- const char *name = ada_type_name (type_arg);
-
- range_type = NULL;
- if (name != NULL && type_arg->code () != TYPE_CODE_ENUM)
- range_type = to_fixed_range_type (type_arg, NULL);
- if (range_type == NULL)
- range_type = type_arg;
- switch (op)
- {
- default:
- error (_("unexpected attribute encountered"));
- case OP_ATR_FIRST:
- return value_from_longest
- (range_type, ada_discrete_type_low_bound (range_type));
- case OP_ATR_LAST:
- return value_from_longest
- (range_type, ada_discrete_type_high_bound (range_type));
- case OP_ATR_LENGTH:
- error (_("the 'length attribute applies only to array types"));
- }
- }
- else if (type_arg->code () == TYPE_CODE_FLT)
- error (_("unimplemented type attribute"));
- else
- {
- LONGEST low, high;
-
- if (ada_is_constrained_packed_array_type (type_arg))
- type_arg = decode_constrained_packed_array_type (type_arg);
-
- struct type *type;
- if (op == OP_ATR_LENGTH)
- type = builtin_type (exp->gdbarch)->builtin_int;
- else
- {
- type = ada_index_type (type_arg, tem, attr_name);
- if (type == NULL)
- type = builtin_type (exp->gdbarch)->builtin_int;
- }
-
- switch (op)
- {
- default:
- error (_("unexpected attribute encountered"));
- case OP_ATR_FIRST:
- low = ada_array_bound_from_type (type_arg, tem, 0);
- return value_from_longest (type, low);
- case OP_ATR_LAST:
- high = ada_array_bound_from_type (type_arg, tem, 1);
- return value_from_longest (type, high);
- case OP_ATR_LENGTH:
- low = ada_array_bound_from_type (type_arg, tem, 0);
- high = ada_array_bound_from_type (type_arg, tem, 1);
- return value_from_longest (type, high - low + 1);
- }
- }
-}
-
/* A helper function for OP_ATR_MIN and OP_ATR_MAX. */
struct value *
@@ -10855,8 +10722,134 @@ ada_unop_atr_operation::evaluate (struct type *expect_type,
else
val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
- return ada_unop_atr (exp, noside, std::get<1> (m_storage),
- val, type_arg, std::get<2> (m_storage));
+ exp_opcode op = std::get<1> (m_storage);
+ const char *attr_name = nullptr;
+ if (op == OP_ATR_FIRST)
+ attr_name = "first";
+ else if (op == OP_ATR_LAST)
+ attr_name = "last";
+
+ int tem = std::get<2> (m_storage);
+
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ {
+ if (type_arg == NULL)
+ type_arg = val->type ();
+
+ if (ada_is_constrained_packed_array_type (type_arg))
+ type_arg = decode_constrained_packed_array_type (type_arg);
+
+ if (!discrete_type_p (type_arg))
+ {
+ switch (op)
+ {
+ default: /* Should never happen. */
+ error (_("unexpected attribute encountered"));
+ case OP_ATR_FIRST:
+ case OP_ATR_LAST:
+ type_arg = ada_index_type (type_arg, tem,
+ attr_name);
+ break;
+ case OP_ATR_LENGTH:
+ type_arg = builtin_type (exp->gdbarch)->builtin_int;
+ break;
+ }
+ }
+
+ return value::zero (type_arg, not_lval);
+ }
+ else if (type_arg == NULL)
+ {
+ val = ada_coerce_ref (val);
+
+ if (ada_is_constrained_packed_array_type (val->type ()))
+ val = ada_coerce_to_simple_array (val);
+
+ struct type *type;
+ if (op == OP_ATR_LENGTH)
+ type = builtin_type (exp->gdbarch)->builtin_int;
+ else
+ {
+ type = ada_index_type (val->type (), tem,
+ attr_name);
+ if (type == NULL)
+ type = builtin_type (exp->gdbarch)->builtin_int;
+ }
+
+ switch (op)
+ {
+ default: /* Should never happen. */
+ error (_("unexpected attribute encountered"));
+ case OP_ATR_FIRST:
+ return value_from_longest
+ (type, ada_array_bound (val, tem, 0));
+ case OP_ATR_LAST:
+ return value_from_longest
+ (type, ada_array_bound (val, tem, 1));
+ case OP_ATR_LENGTH:
+ return value_from_longest
+ (type, ada_array_length (val, tem));
+ }
+ }
+ else if (discrete_type_p (type_arg))
+ {
+ struct type *range_type;
+ const char *name = ada_type_name (type_arg);
+
+ range_type = NULL;
+ if (name != NULL && type_arg->code () != TYPE_CODE_ENUM)
+ range_type = to_fixed_range_type (type_arg, NULL);
+ if (range_type == NULL)
+ range_type = type_arg;
+ switch (op)
+ {
+ default:
+ error (_("unexpected attribute encountered"));
+ case OP_ATR_FIRST:
+ return value_from_longest
+ (range_type, ada_discrete_type_low_bound (range_type));
+ case OP_ATR_LAST:
+ return value_from_longest
+ (range_type, ada_discrete_type_high_bound (range_type));
+ case OP_ATR_LENGTH:
+ error (_("the 'length attribute applies only to array types"));
+ }
+ }
+ else if (type_arg->code () == TYPE_CODE_FLT)
+ error (_("unimplemented type attribute"));
+ else
+ {
+ LONGEST low, high;
+
+ if (ada_is_constrained_packed_array_type (type_arg))
+ type_arg = decode_constrained_packed_array_type (type_arg);
+
+ struct type *type;
+ if (op == OP_ATR_LENGTH)
+ type = builtin_type (exp->gdbarch)->builtin_int;
+ else
+ {
+ type = ada_index_type (type_arg, tem, attr_name);
+ if (type == NULL)
+ type = builtin_type (exp->gdbarch)->builtin_int;
+ }
+
+ switch (op)
+ {
+ default:
+ error (_("unexpected attribute encountered"));
+ case OP_ATR_FIRST:
+ low = ada_array_bound_from_type (type_arg, tem, 0);
+ return value_from_longest (type, low);
+ case OP_ATR_LAST:
+ high = ada_array_bound_from_type (type_arg, tem, 1);
+ return value_from_longest (type, high);
+ case OP_ATR_LENGTH:
+ low = ada_array_bound_from_type (type_arg, tem, 0);
+ high = ada_array_bound_from_type (type_arg, tem, 1);
+ return value_from_longest (type, high - low + 1);
+ }
+ }
}
value *
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] Test attributes with array types
2026-05-08 17:34 [PATCH 0/3] Improve Ada test coverage Tom Tromey
2026-05-08 17:34 ` [PATCH 1/3] Combine ada_unop_atr and ada_unop_atr_operation::evaluate Tom Tromey
@ 2026-05-08 17:34 ` Tom Tromey
2026-05-08 17:34 ` [PATCH 3/3] Add test for Ada abs operator Tom Tromey
2026-05-21 17:31 ` [PATCH 0/3] Improve Ada test coverage Tom Tromey
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2026-05-08 17:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
While looking at code coverage, I noticed that gdb was not testing the
case where certain attributes were applied to an Ada array type. This
patch adds some new tests, improving the coverage.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34043
---
gdb/testsuite/gdb.ada/array_bounds.exp | 8 ++++++++
gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp | 3 +++
2 files changed, 11 insertions(+)
diff --git a/gdb/testsuite/gdb.ada/array_bounds.exp b/gdb/testsuite/gdb.ada/array_bounds.exp
index f9b4fb48cc3..6b9e79ffd00 100644
--- a/gdb/testsuite/gdb.ada/array_bounds.exp
+++ b/gdb/testsuite/gdb.ada/array_bounds.exp
@@ -32,12 +32,20 @@ if {![runto "bar.adb:$bp_location"]} {
gdb_test "print itable'first" \
"= 2"
+gdb_test "print ivector'first" \
+ "= 2"
gdb_test "print itable'last" \
"= 5"
+gdb_test "print ivector'last" \
+ "= 5"
gdb_test "print table'first" \
"= zero"
+gdb_test "print vector'first" \
+ "= zero"
gdb_test "print table'last" \
"= two"
+gdb_test "print vector'last" \
+ "= two"
diff --git a/gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp
index f90f1d7acc9..8e359d7bb56 100644
--- a/gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp
+++ b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp
@@ -39,6 +39,9 @@ gdb_test "ptype cold'length" "type = <$decimal-byte integer>"
gdb_test "ptype vars'length" "type = <$decimal-byte integer>"
gdb_test "ptype full_table'length" "type = <$decimal-byte integer>"
+gdb_test "print full_table'length" "= 5"
gdb_test "ptype primary_table'length" "type = <$decimal-byte integer>"
+gdb_test "print primary_table'length" " = 3"
gdb_test "ptype variable_table'length" "type = <$decimal-byte integer>"
gdb_test "ptype full_pt'length" "type = <$decimal-byte integer>"
+gdb_test "print full_pt'length" "= 5"
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] Add test for Ada abs operator
2026-05-08 17:34 [PATCH 0/3] Improve Ada test coverage Tom Tromey
2026-05-08 17:34 ` [PATCH 1/3] Combine ada_unop_atr and ada_unop_atr_operation::evaluate Tom Tromey
2026-05-08 17:34 ` [PATCH 2/3] Test attributes with array types Tom Tromey
@ 2026-05-08 17:34 ` Tom Tromey
2026-05-21 17:31 ` [PATCH 0/3] Improve Ada test coverage Tom Tromey
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2026-05-08 17:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
There were no tests in the tree for the Ada abs operator, meaning that
ada_abs was never invoked during a test. This patch adds a new basic
test for this.
Note that operator overloading of 'abs' does seem to be tested.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34042
---
gdb/testsuite/gdb.ada/abs.exp | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/gdb/testsuite/gdb.ada/abs.exp b/gdb/testsuite/gdb.ada/abs.exp
new file mode 100644
index 00000000000..5035604fa86
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/abs.exp
@@ -0,0 +1,29 @@
+# Copyright 2026 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/>.
+
+# Simple tests of the 'abs' operator.
+
+load_lib "ada.exp"
+
+require allow_ada_tests
+
+clean_restart
+
+gdb_test_no_output "set language ada"
+
+gdb_test "print abs -5" [quotemeta {@DECIMAL = 5}]
+gdb_test "print abs 5" [quotemeta {@DECIMAL = 5}]
+gdb_test "print abs(-5)" [quotemeta {@DECIMAL = 5}]
+gdb_test "print abs(5)" [quotemeta {@DECIMAL = 5}]
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] Improve Ada test coverage
2026-05-08 17:34 [PATCH 0/3] Improve Ada test coverage Tom Tromey
` (2 preceding siblings ...)
2026-05-08 17:34 ` [PATCH 3/3] Add test for Ada abs operator Tom Tromey
@ 2026-05-21 17:31 ` Tom Tromey
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2026-05-21 17:31 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:
Tom> I recently looked at code coverage of gdb's test suite. This found a
Tom> few holes in the Ada test coverage. This short series fixes a few of
Tom> these. (There's at least one more hole to cover.)
I'm checking these in.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-05-21 17:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-08 17:34 [PATCH 0/3] Improve Ada test coverage Tom Tromey
2026-05-08 17:34 ` [PATCH 1/3] Combine ada_unop_atr and ada_unop_atr_operation::evaluate Tom Tromey
2026-05-08 17:34 ` [PATCH 2/3] Test attributes with array types Tom Tromey
2026-05-08 17:34 ` [PATCH 3/3] Add test for Ada abs operator Tom Tromey
2026-05-21 17:31 ` [PATCH 0/3] Improve Ada test coverage Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox