public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fortran: Extra comparison operator parsing, and OP_BOOL expression dumping
@ 2021-01-11 15:44 Andrew Burgess
  2021-01-11 15:44 ` [PATCH 1/2] gdb/fortran: add symbol base comparison operators Andrew Burgess
  2021-01-11 15:44 ` [PATCH 2/2] gdb: fix debug dump of OP_BOOL expressions Andrew Burgess
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Burgess @ 2021-01-11 15:44 UTC (permalink / raw)
  To: gdb-patches

The first patch adds support for additional comparison operators (just
aliases for the existing operators).  And the second patch is
something I spotted while checking the first patch, expression dumping
for OP_BOOL is broken.

--

Andrew Burgess (2):
  gdb/fortran: add symbol base comparison operators
  gdb: fix debug dump of OP_BOOL expressions

 gdb/ChangeLog                            | 13 +++++++++
 gdb/expprint.c                           |  9 +++++-
 gdb/f-exp.y                              | 36 ++++++++++++------------
 gdb/testsuite/ChangeLog                  |  8 ++++++
 gdb/testsuite/gdb.fortran/debug-expr.exp |  8 ++++++
 gdb/testsuite/gdb.fortran/dot-ops.exp    | 30 ++++++++++++++++++++
 6 files changed, 85 insertions(+), 19 deletions(-)

-- 
2.25.4


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

* [PATCH 1/2] gdb/fortran: add symbol base comparison operators
  2021-01-11 15:44 [PATCH 0/2] Fortran: Extra comparison operator parsing, and OP_BOOL expression dumping Andrew Burgess
@ 2021-01-11 15:44 ` Andrew Burgess
  2021-01-11 21:06   ` Tom Tromey
  2021-01-11 15:44 ` [PATCH 2/2] gdb: fix debug dump of OP_BOOL expressions Andrew Burgess
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2021-01-11 15:44 UTC (permalink / raw)
  To: gdb-patches

Fortran supports symbol based comparison operators as well as the
classic text based comparison operators, so we have:

   Text     | Symbol
   Operator | Operator
   ---------|---------
   .eq.     | ==
   .ne.     | /=
   .le.     | <=
   .ge.     | >=
   .gt.     | >
   .lt.     | <

This commit adds the symbol based operators as well as some tests.

gdb/ChangeLog:

	* f-exp.y (dot_ops): Rename to...
	(fortran_operators): ...this.  Add a header comment.  Add symbol
	based operators.
	(yylex): Update to use fortran_operators not dot_ops.  Remove
	special handling for '**', this is now included in
	fortran_operators.

gdb/testsuite/ChangeLog:

	* gdb.fortran/dot-ops.exp: Add new tests.
---
 gdb/ChangeLog                         |  9 +++++++
 gdb/f-exp.y                           | 36 +++++++++++++--------------
 gdb/testsuite/ChangeLog               |  4 +++
 gdb/testsuite/gdb.fortran/dot-ops.exp | 30 ++++++++++++++++++++++
 4 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index e0f1b1ffe15..3b0f23d5d73 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -979,7 +979,9 @@ struct token
   bool case_sensitive;
 };
 
-static const struct token dot_ops[] =
+/* List of Fortran operators.  */
+
+static const struct token fortran_operators[] =
 {
   { ".and.", BOOL_AND, BINOP_END, false },
   { ".or.", BOOL_OR, BINOP_END, false },
@@ -987,11 +989,18 @@ static const struct token dot_ops[] =
   { ".eq.", EQUAL, BINOP_END, false },
   { ".eqv.", EQUAL, BINOP_END, false },
   { ".neqv.", NOTEQUAL, BINOP_END, false },
+  { "==", EQUAL, BINOP_END, false },
   { ".ne.", NOTEQUAL, BINOP_END, false },
+  { "/=", NOTEQUAL, BINOP_END, false },
   { ".le.", LEQ, BINOP_END, false },
+  { "<=", LEQ, BINOP_END, false },
   { ".ge.", GEQ, BINOP_END, false },
+  { ">=", GEQ, BINOP_END, false },
   { ".gt.", GREATERTHAN, BINOP_END, false },
+  { ">", GREATERTHAN, BINOP_END, false },
   { ".lt.", LESSTHAN, BINOP_END, false },
+  { "<", LESSTHAN, BINOP_END, false },
+  { "**", STARSTAR, BINOP_EXP, false },
 };
 
 /* Holds the Fortran representation of a boolean, and the integer value we
@@ -1163,26 +1172,17 @@ yylex (void)
 	}
     }
 
-  /* See if it is a special .foo. operator.  */
-  for (int i = 0; i < ARRAY_SIZE (dot_ops); i++)
-    if (strncasecmp (tokstart, dot_ops[i].oper,
-		     strlen (dot_ops[i].oper)) == 0)
+  /* See if it is a Fortran operator.  */
+  for (int i = 0; i < ARRAY_SIZE (fortran_operators); i++)
+    if (strncasecmp (tokstart, fortran_operators[i].oper,
+		     strlen (fortran_operators[i].oper)) == 0)
       {
-	gdb_assert (!dot_ops[i].case_sensitive);
-	pstate->lexptr += strlen (dot_ops[i].oper);
-	yylval.opcode = dot_ops[i].opcode;
-	return dot_ops[i].token;
+	gdb_assert (!fortran_operators[i].case_sensitive);
+	pstate->lexptr += strlen (fortran_operators[i].oper);
+	yylval.opcode = fortran_operators[i].opcode;
+	return fortran_operators[i].token;
       }
 
-  /* See if it is an exponentiation operator.  */
-
-  if (strncmp (tokstart, "**", 2) == 0)
-    {
-      pstate->lexptr += 2;
-      yylval.opcode = BINOP_EXP;
-      return STARSTAR;
-    }
-
   switch (c = *tokstart)
     {
     case 0:
diff --git a/gdb/testsuite/gdb.fortran/dot-ops.exp b/gdb/testsuite/gdb.fortran/dot-ops.exp
index 8454f7e298c..cc9adf37aa4 100644
--- a/gdb/testsuite/gdb.fortran/dot-ops.exp
+++ b/gdb/testsuite/gdb.fortran/dot-ops.exp
@@ -109,6 +109,36 @@ proc test_dot_operations {} {
 	gdb_test "p 4 $gt 4" " = .FALSE."
 	gdb_test "p 3 $gt 4" " = .FALSE."
     }
+
+    # Now test the symbol based comparison operators.
+
+    # Arithmetic EQ
+    gdb_test "p 5 == 4" " = .FALSE."
+    gdb_test "p 4 == 4" " = .TRUE."
+
+    # Arithmetic NE
+    gdb_test "p 5 /= 4" " = .TRUE."
+    gdb_test "p 4 /= 4" " = .FALSE."
+
+    # Arithmetic LE
+    gdb_test "p 5 <= 4" " = .FALSE."
+    gdb_test "p 4 <= 4" " = .TRUE."
+    gdb_test "p 3 <= 4" " = .TRUE."
+
+    # Arithmetic LT
+    gdb_test "p 5 < 4" " = .FALSE."
+    gdb_test "p 4 < 4" " = .FALSE."
+    gdb_test "p 3 < 4" " = .TRUE."
+
+    # Arithmetic GE
+    gdb_test "p 5 >= 4" " = .TRUE."
+    gdb_test "p 4 >= 4" " = .TRUE."
+    gdb_test "p 3 >= 4" " = .FALSE."
+
+    # Arithmetic GT
+    gdb_test "p 5 > 4" " = .TRUE."
+    gdb_test "p 4 > 4" " = .FALSE."
+    gdb_test "p 3 > 4" " = .FALSE."
 }
 
 # Start of test script.
-- 
2.25.4


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

* [PATCH 2/2] gdb: fix debug dump of OP_BOOL expressions
  2021-01-11 15:44 [PATCH 0/2] Fortran: Extra comparison operator parsing, and OP_BOOL expression dumping Andrew Burgess
  2021-01-11 15:44 ` [PATCH 1/2] gdb/fortran: add symbol base comparison operators Andrew Burgess
@ 2021-01-11 15:44 ` Andrew Burgess
  2021-01-11 21:13   ` Tom Tromey
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2021-01-11 15:44 UTC (permalink / raw)
  To: gdb-patches

Consider this GDB session:

  (gdb) set language fortran
  (gdb) set debug expression 1
  (gdb) p .TRUE.
  Dump of expression @ 0x4055d90, before conversion to prefix form:
  	Language fortran, 3 elements, 16 bytes each.
  	Index                Opcode         Hex Value  String Value
  	    0               OP_BOOL  79  O...............
  	    1             BINOP_ADD  1  ................
  	    2               OP_BOOL  79  O...............
  Dump of expression @ 0x4055d90, after conversion to prefix form:
  Expression: `TRUE'
  	Language fortran, 3 elements, 16 bytes each.

  	    0  OP_BOOL               Unknown format
  	    1  BINOP_ADD
  	    2    OP_BOOL               Unknown format
  	    3    OP_NULL               Unknown format
  $1 = .TRUE.

The final dump of the OP_BOOL is completely wrong.  After this patch
we now get:

  (gdb) set language fortran
  (gdb) set debug expression 1
  (gdb) p .TRUE.
  Dump of expression @ 0x2d07470, before conversion to prefix form:
  	Language fortran, 3 elements, 16 bytes each.
  	Index                Opcode         Hex Value  String Value
  	    0               OP_BOOL  79  O...............
  	    1             BINOP_ADD  1  ................
  	    2               OP_BOOL  79  O...............
  Dump of expression @ 0x2d07470, after conversion to prefix form:
  Expression: `TRUE'
  	Language fortran, 3 elements, 16 bytes each.

  	    0  OP_BOOL               TRUE
  $1 = .TRUE.

Much better.  I added a test for this into the Fortran testsuite.

gdb/ChangeLog:

	* expprint.c (dump_subexp_body_standard): Handle OP_BOOL.

gdb/testsuite/ChangeLog:

	* gdb.fortran/debug-expr.exp: Add new tests.
---
 gdb/ChangeLog                            | 4 ++++
 gdb/expprint.c                           | 9 ++++++++-
 gdb/testsuite/ChangeLog                  | 4 ++++
 gdb/testsuite/gdb.fortran/debug-expr.exp | 8 ++++++++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gdb/expprint.c b/gdb/expprint.c
index f75874b77df..d95835fc47d 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -1121,11 +1121,18 @@ dump_subexp_body_standard (struct expression *exp,
       }
       break;
 
+    case OP_BOOL:
+      {
+	bool val = (bool) (exp->elts[elt].longconst);
+	fputs_filtered (val ? "TRUE" : "FALSE", stream);
+	elt += 2;
+      }
+      break;
+
     default:
     case OP_NULL:
     case MULTI_SUBSCRIPT:
     case OP_COMPLEX:
-    case OP_BOOL:
     case OP_M2_STRING:
     case OP_THIS:
     case OP_NAME:
diff --git a/gdb/testsuite/gdb.fortran/debug-expr.exp b/gdb/testsuite/gdb.fortran/debug-expr.exp
index 4111d8daa36..07fbf1400a9 100644
--- a/gdb/testsuite/gdb.fortran/debug-expr.exp
+++ b/gdb/testsuite/gdb.fortran/debug-expr.exp
@@ -41,3 +41,11 @@ gdb_continue_to_breakpoint "Break Here"
 
 gdb_test_no_output "set debug expression 1"
 gdb_test_debug_expr "print obj%three(1)%two(1)%one(1)%i" "\\\$$decimal = 1"
+gdb_test_debug_expr "print .TRUE."  [ multi_line \
+					  "" \
+					  "\\s+0\\s+OP_BOOL\\s+TRUE" \
+					  "\\\$$decimal = \.TRUE\." ]
+gdb_test_debug_expr "print .FALSE."  [ multi_line \
+					   "" \
+					   "\\s+0\\s+OP_BOOL\\s+FALSE" \
+					   "\\\$$decimal = \.FALSE\." ]
-- 
2.25.4


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

* Re: [PATCH 1/2] gdb/fortran: add symbol base comparison operators
  2021-01-11 15:44 ` [PATCH 1/2] gdb/fortran: add symbol base comparison operators Andrew Burgess
@ 2021-01-11 21:06   ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2021-01-11 21:06 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> gdb/ChangeLog:

Andrew> 	* f-exp.y (dot_ops): Rename to...
Andrew> 	(fortran_operators): ...this.  Add a header comment.  Add symbol
Andrew> 	based operators.
Andrew> 	(yylex): Update to use fortran_operators not dot_ops.  Remove
Andrew> 	special handling for '**', this is now included in
Andrew> 	fortran_operators.

Looks good to me.

Tom

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

* Re: [PATCH 2/2] gdb: fix debug dump of OP_BOOL expressions
  2021-01-11 15:44 ` [PATCH 2/2] gdb: fix debug dump of OP_BOOL expressions Andrew Burgess
@ 2021-01-11 21:13   ` Tom Tromey
  2021-01-12  9:33     ` Andrew Burgess
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2021-01-11 21:13 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> gdb/ChangeLog:

Andrew> 	* expprint.c (dump_subexp_body_standard): Handle OP_BOOL.

Thanks.

Of course I am hoping to delete all of this :)
FWIW the rewrite handles this dumping already:

    (gdb) print .TRUE.
    Operation: OP_BOOL
     Address: 0x0000000000000001
    $1 = .TRUE.

Though it does print "Address" where maybe it should just say "Integer"
or something along those lines.

Andrew> +gdb_test_debug_expr "print .TRUE."  [ multi_line \
Andrew> +					  "" \
Andrew> +					  "\\s+0\\s+OP_BOOL\\s+TRUE" \
Andrew> +					  "\\\$$decimal = \.TRUE\." ]

Classic Tcl style doesn't put a space after '[' or before ']'

Tom

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

* Re: [PATCH 2/2] gdb: fix debug dump of OP_BOOL expressions
  2021-01-11 21:13   ` Tom Tromey
@ 2021-01-12  9:33     ` Andrew Burgess
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Burgess @ 2021-01-12  9:33 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2021-01-11 14:13:56 -0700]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
> 
> Andrew> gdb/ChangeLog:
> 
> Andrew> 	* expprint.c (dump_subexp_body_standard): Handle OP_BOOL.
> 
> Thanks.
> 
> Of course I am hoping to delete all of this :)
> FWIW the rewrite handles this dumping already:

Absolutely, and the sooner your series lands the better I think.  But
until then....

> 
>     (gdb) print .TRUE.
>     Operation: OP_BOOL
>      Address: 0x0000000000000001
>     $1 = .TRUE.
> 
> Though it does print "Address" where maybe it should just say "Integer"
> or something along those lines.
> 
> Andrew> +gdb_test_debug_expr "print .TRUE."  [ multi_line \
> Andrew> +					  "" \
> Andrew> +					  "\\s+0\\s+OP_BOOL\\s+TRUE" \
> Andrew> +					  "\\\$$decimal = \.TRUE\." ]
> 
> Classic Tcl style doesn't put a space after '[' or before ']'

Thanks, I'll correct this and try to remember for future patches.

Andrew

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

end of thread, other threads:[~2021-01-12  9:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 15:44 [PATCH 0/2] Fortran: Extra comparison operator parsing, and OP_BOOL expression dumping Andrew Burgess
2021-01-11 15:44 ` [PATCH 1/2] gdb/fortran: add symbol base comparison operators Andrew Burgess
2021-01-11 21:06   ` Tom Tromey
2021-01-11 15:44 ` [PATCH 2/2] gdb: fix debug dump of OP_BOOL expressions Andrew Burgess
2021-01-11 21:13   ` Tom Tromey
2021-01-12  9:33     ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).