Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/m2: add builtin procedure function ADR
@ 2024-10-04 14:00 Gaius Mulley
  2024-10-04 14:05 ` Tom Tromey
  2024-10-04 14:25 ` [PATCH] " Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Gaius Mulley @ 2024-10-04 14:00 UTC (permalink / raw)
  To: gdb-patches


This patch introduces the procedure function ADR to the expression
handling parser for the Modula-2 language interface.
The procedure takes a parameter and returns the address of the
parameter supplied.

Tested on x86_64-linux.

ChangeLog:

	* gdb/m2-exp.y (%token): Add ADR.
	(exp): New rule for ADR.
	(keytab): New entry for ADR.
	* gdb/doc/gdb.texinfo (Built-in Functions and Procedures):
	Add description for procedure function ADR.

---

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index cc1b69c6978..a175cde911a 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -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.
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index c12767533a8..db63aa5eb03 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -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	 },

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb/m2: add builtin procedure function ADR
  2024-10-04 14:00 [PATCH] gdb/m2: add builtin procedure function ADR Gaius Mulley
@ 2024-10-04 14:05 ` Tom Tromey
  2024-10-04 15:21   ` [PATCH v2] " Gaius Mulley
  2024-10-04 14:25 ` [PATCH] " Eli Zaretskii
  1 sibling, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2024-10-04 14:05 UTC (permalink / raw)
  To: Gaius Mulley; +Cc: gdb-patches

>>>>> "Gaius" == Gaius Mulley <gaiusmod2@gmail.com> writes:

Hi.  Thanks for the patch.

Gaius> This patch introduces the procedure function ADR to the expression
Gaius> handling parser for the Modula-2 language interface.
Gaius> The procedure takes a parameter and returns the address of the
Gaius> parameter supplied.

Gaius> Tested on x86_64-linux.

Gaius> ChangeLog:

Gaius> 	* gdb/m2-exp.y (%token): Add ADR.
Gaius> 	(exp): New rule for ADR.
Gaius> 	(keytab): New entry for ADR.
Gaius> 	* gdb/doc/gdb.texinfo (Built-in Functions and Procedures):
Gaius> 	Add description for procedure function ADR.

gdb doesn't use ChangeLog entries any more so you can remove this part
of the commit message.

The code parts of this look good to me, but committing will have to wait
for doc review.

I think a test case -- even just a single line in an existing test --
would probably be good to have.

thanks,
Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb/m2: add builtin procedure function ADR
  2024-10-04 14:00 [PATCH] gdb/m2: add builtin procedure function ADR Gaius Mulley
  2024-10-04 14:05 ` Tom Tromey
@ 2024-10-04 14:25 ` Eli Zaretskii
  2024-10-04 15:45   ` Gaius Mulley
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2024-10-04 14:25 UTC (permalink / raw)
  To: Gaius Mulley; +Cc: gdb-patches

> From: Gaius Mulley <gaiusmod2@gmail.com>
> Date: Fri, 04 Oct 2024 15:00:55 +0100
> 
> 
> This patch introduces the procedure function ADR to the expression
> handling parser for the Modula-2 language interface.
> The procedure takes a parameter and returns the address of the
> parameter supplied.
> 
> Tested on x86_64-linux.
> 
> ChangeLog:
> 
> 	* gdb/m2-exp.y (%token): Add ADR.
> 	(exp): New rule for ADR.
> 	(keytab): New entry for ADR.
> 	* gdb/doc/gdb.texinfo (Built-in Functions and Procedures):
> 	Add description for procedure function ADR.

Thanks, the gdb.texinfo part is okay.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] gdb/m2: add builtin procedure function ADR
  2024-10-04 14:05 ` Tom Tromey
@ 2024-10-04 15:21   ` Gaius Mulley
  2024-10-04 18:14     ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Gaius Mulley @ 2024-10-04 15:21 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom Tromey <tom@tromey.com> writes:

> I think a test case -- even just a single line in an existing test --
> would probably be good to have.

Hi Tom,

Many thanks for the review, here is v2 with a testcase.  In v2 the only
change is the new file gdb/testsuite/gdb.modula2/builtin-procedure-adr.exp.

---

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.

---

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index cc1b69c6978..a175cde911a 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -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.
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index c12767533a8..db63aa5eb03 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -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
index 00000000000..6588020cfc2
--- /dev/null
+++ b/gdb/testsuite/gdb.modula2/builtin-procedure-adr.exp
@@ -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"

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb/m2: add builtin procedure function ADR
  2024-10-04 14:25 ` [PATCH] " Eli Zaretskii
@ 2024-10-04 15:45   ` Gaius Mulley
  0 siblings, 0 replies; 7+ messages in thread
From: Gaius Mulley @ 2024-10-04 15:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii <eliz@gnu.org> writes:

>> 	* gdb/doc/gdb.texinfo (Built-in Functions and Procedures):
>> 	Add description for procedure function ADR.
>
> Thanks, the gdb.texinfo part is okay.
>
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>

Many thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] gdb/m2: add builtin procedure function ADR
  2024-10-04 15:21   ` [PATCH v2] " Gaius Mulley
@ 2024-10-04 18:14     ` Tom Tromey
  2024-10-04 18:52       ` Gaius Mulley
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2024-10-04 18:14 UTC (permalink / raw)
  To: Gaius Mulley; +Cc: Tom Tromey, gdb-patches

>>>>> "Gaius" == Gaius Mulley <gaiusmod2@gmail.com> writes:

Gaius> Many thanks for the review, here is v2 with a testcase.  In v2 the only
Gaius> change is the new file gdb/testsuite/gdb.modula2/builtin-procedure-adr.exp.

Looks good to me.  Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] gdb/m2: add builtin procedure function ADR
  2024-10-04 18:14     ` Tom Tromey
@ 2024-10-04 18:52       ` Gaius Mulley
  0 siblings, 0 replies; 7+ messages in thread
From: Gaius Mulley @ 2024-10-04 18:52 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Gaius" == Gaius Mulley <gaiusmod2@gmail.com> writes:
>
> Gaius> Many thanks for the review, here is v2 with a testcase.  In v2 the only
> Gaius> change is the new file gdb/testsuite/gdb.modula2/builtin-procedure-adr.exp.
>
> Looks good to me.  Thank you.
> Approved-By: Tom Tromey <tom@tromey.com>
>
> Tom

Many thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-10-04 18:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-04 14:00 [PATCH] gdb/m2: add builtin procedure function ADR Gaius Mulley
2024-10-04 14:05 ` Tom Tromey
2024-10-04 15:21   ` [PATCH v2] " Gaius Mulley
2024-10-04 18:14     ` Tom Tromey
2024-10-04 18:52       ` Gaius Mulley
2024-10-04 14:25 ` [PATCH] " Eli Zaretskii
2024-10-04 15:45   ` Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox