]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/m2: add builtin procedure function ADR
authorGaius Mulley <gaiusmod2@gmail.com>
Sun, 6 Oct 2024 19:40:59 +0000 (20:40 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Sun, 6 Oct 2024 19:40:59 +0000 (20:40 +0100)
This patch introduces ADR to the Modula-2 language interface.
It return the address of the parameter supplied.
The patch also contains a dejagnu test for ADR.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
gdb/doc/gdb.texinfo
gdb/m2-exp.y
gdb/testsuite/gdb.modula2/builtin-procedure-adr.exp [new file with mode: 0644]

index 65a88c8ce10aae6f21d26cc7787ce8301e555c93..46ca62ec0c3ad012c3be3b291c5c089ffe2bb945 100644 (file)
@@ -18298,6 +18298,9 @@ All Modula-2 built-in procedures also return a result, described below.
 @item ABS(@var{n})
 Returns the absolute value of @var{n}.
 
+@item ADR(@var{n})
+Returns the memory address of @var{n}.
+
 @item CAP(@var{c})
 If @var{c} is a lower case letter, it returns its upper case
 equivalent, otherwise it returns its argument.
index c12767533a83aba15a54ff2ded3aa7d8b5d709ab..2887ad2be21a01f0bc54f385c19fa790ff9e729b 100644 (file)
@@ -117,7 +117,7 @@ using namespace expr;
 %token <sval> TYPENAME
 
 %token SIZE CAP ORD HIGH ABS MIN_FUNC MAX_FUNC FLOAT_FUNC VAL CHR ODD TRUNC
-%token TSIZE
+%token TSIZE ADR
 %token INC DEC INCL EXCL
 
 /* The GDB scope operator */
@@ -191,6 +191,10 @@ exp        :       ABS '(' exp ')'
                        { error (_("ABS function is not implemented")); }
        ;
 
+exp    :       ADR '(' exp ')'
+                       { pstate->wrap<unop_addr_operation> (); }
+       ;
+
 exp    :       HIGH '(' exp ')'
                        { pstate->wrap<m2_unop_high_operation> (); }
        ;
@@ -699,6 +703,7 @@ static struct keyword keytab[] =
     {"IN",    IN         },/* Note space after IN */
     {"AND",   LOGICAL_AND},
     {"ABS",   ABS       },
+    {"ADR",   ADR       },
     {"CHR",   CHR       },
     {"DEC",   DEC       },
     {"NOT",   NOT       },
diff --git a/gdb/testsuite/gdb.modula2/builtin-procedure-adr.exp b/gdb/testsuite/gdb.modula2/builtin-procedure-adr.exp
new file mode 100644 (file)
index 0000000..6588020
--- /dev/null
@@ -0,0 +1,32 @@
+# 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/>.
+
+# This file is part of the gdb testsuite.  It contains tests for printing
+# the elements of an unbounded array using the Modula-2 language mode of
+# gdb.
+
+standard_testfile unbounded1.c
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug quiet}]} {
+    return -1
+}
+
+if {![runto main]} {
+    return
+}
+
+gdb_test "set lang modula-2" ".*does not match.*" "switch to modula-2"
+
+gdb_test "print ADR(i)" ".*0x.*" "print the address of local variable i"