public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4] gdb/fortran: Add 'LOC' intrinsic support.
@ 2021-03-09  8:42 Felix Willgerodt
  2021-03-09 10:00 ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Willgerodt @ 2021-03-09  8:42 UTC (permalink / raw)
  To: gdb-patches, felix.willgerodt

LOC(X) returns the address of X as an integer:
https://gcc.gnu.org/onlinedocs/gfortran/LOC.html

Before:
(gdb) p LOC(r)
No symbol "LOC" in current context.

After:
(gdb) p LOC(r)
$1 = 0xffffdf48

gdb/ChangeLog:
2021-03-04  Felix Willgerodt  <felix.willgerodt@intel.com>

	* f-exp.y (f77_keywords): Add LOC.
	* f-lang.c (evaluate_subexp_f): Handle UNOP_FORTRAN_LOC.
	(operator_length_f): Likewise.
	(print_subexp_f): Likewise.
	(dump_subexp_body_f): Likewise.
	(operator_check_f): Likewise.
	* std-operator.def (UNOP_FORTRAN_LOC): New operator.

gdb/testsuite/ChangeLog:
2020-03-04  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.fortran/intrinsics.exp: Add LOC test.
---
 gdb/f-exp.h                              |  7 +++++++
 gdb/f-exp.y                              |  4 ++++
 gdb/f-lang.c                             | 19 +++++++++++++++++++
 gdb/std-operator.def                     |  1 +
 gdb/testsuite/gdb.fortran/intrinsics.exp |  5 +++++
 5 files changed, 36 insertions(+)

diff --git a/gdb/f-exp.h b/gdb/f-exp.h
index 81cf3412ee2..a2e5b332b40 100644
--- a/gdb/f-exp.h
+++ b/gdb/f-exp.h
@@ -73,6 +73,11 @@ extern struct value * eval_op_f_allocated (struct type *expect_type,
 					   enum noside noside,
 					   enum exp_opcode op,
 					   struct value *arg1);
+extern struct value * eval_op_f_loc (struct type *expect_type,
+				     struct expression *exp,
+				     enum noside noside,
+				     enum exp_opcode op,
+				     struct value *arg1);
 
 namespace expr
 {
@@ -86,6 +91,8 @@ using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND,
 					      eval_op_f_kind>;
 using fortran_allocated_operation = unop_operation<UNOP_FORTRAN_ALLOCATED,
 						   eval_op_f_allocated>;
+using fortran_loc_operation = unop_operation<UNOP_FORTRAN_LOC,
+						   eval_op_f_loc>;
 
 using fortran_mod_operation = binop_operation<BINOP_MOD, eval_op_f_mod>;
 using fortran_modulo_operation = binop_operation<BINOP_FORTRAN_MODULO,
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index c33b5079158..0c2a5be7a06 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -319,6 +319,9 @@ exp	:	UNOP_INTRINSIC '(' exp ')'
 			      break;
 			    case UNOP_FORTRAN_ALLOCATED:
 			      pstate->wrap<fortran_allocated_operation> ();
+			      break;
+				case UNOP_FORTRAN_LOC:
+			      pstate->wrap<fortran_loc_operation> ();
 			      break;
 			    default:
 			      gdb_assert_not_reached ("unhandled intrinsic");
@@ -1139,6 +1142,7 @@ static const struct token f77_keywords[] =
   { "ubound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_UBOUND, false },
   { "allocated", UNOP_INTRINSIC, UNOP_FORTRAN_ALLOCATED, false },
   { "associated", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ASSOCIATED, false },
+  { "loc", UNOP_INTRINSIC, UNOP_FORTRAN_LOC, false },
 };
 
 /* Implementation of a dynamically expandable buffer for processing input
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 1b66ae34159..833b151449a 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -773,6 +773,25 @@ eval_op_f_allocated (struct type *expect_type, struct expression *exp,
   return value_from_longest (result_type, result_value);
 }
 
+/* A helper function for UNOP_FORTRAN_LOC.  */
+
+struct value *
+eval_op_f_loc (struct type *expect_type, struct expression *exp,
+		     enum noside noside, enum exp_opcode op,
+		     struct value *arg1)
+{
+  struct type *result_type;
+  if (gdbarch_ptr_bit (exp->gdbarch) == 16)
+    result_type = builtin_f_type (exp->gdbarch)->builtin_integer_s2;
+  else if (gdbarch_ptr_bit (exp->gdbarch) == 32)
+    result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
+  else
+    result_type = builtin_f_type (exp->gdbarch)->builtin_integer_s8;
+
+  LONGEST result_value = value_address (arg1);
+  return value_from_longest (result_type, result_value);
+}
+
 namespace expr
 {
 
diff --git a/gdb/std-operator.def b/gdb/std-operator.def
index b0c6beb4628..5d29305d47b 100644
--- a/gdb/std-operator.def
+++ b/gdb/std-operator.def
@@ -378,6 +378,7 @@ OP (UNOP_FORTRAN_KIND)
 OP (UNOP_FORTRAN_FLOOR)
 OP (UNOP_FORTRAN_CEILING)
 OP (UNOP_FORTRAN_ALLOCATED)
+OP (UNOP_FORTRAN_LOC)
 
 /* Two operand builtins.  */
 OP (BINOP_FORTRAN_CMPLX)
diff --git a/gdb/testsuite/gdb.fortran/intrinsics.exp b/gdb/testsuite/gdb.fortran/intrinsics.exp
index d0ac1944aab..84f486f4d7b 100644
--- a/gdb/testsuite/gdb.fortran/intrinsics.exp
+++ b/gdb/testsuite/gdb.fortran/intrinsics.exp
@@ -84,3 +84,8 @@ gdb_test "ptype MODULO (3.0,2.0)" "type = real\\*8"
 # Test CMPLX
 
 gdb_test "p CMPLX (4.1, 2.0)" " = \\(4.$decimal,2\\)"
+
+# Test LOC
+
+gdb_test "p/x LOC(l)" "= $hex"
+gdb_test "ptype loc(l)" "type = integer(\\*$decimal)?"
-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* Re: [PATCH v4] gdb/fortran: Add 'LOC' intrinsic support.
  2021-03-09  8:42 [PATCH v4] gdb/fortran: Add 'LOC' intrinsic support Felix Willgerodt
@ 2021-03-09 10:00 ` Andrew Burgess
  2021-03-09 10:41   ` Willgerodt, Felix
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2021-03-09 10:00 UTC (permalink / raw)
  To: Felix Willgerodt; +Cc: gdb-patches

* Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org> [2021-03-09 09:42:21 +0100]:

> LOC(X) returns the address of X as an integer:
> https://gcc.gnu.org/onlinedocs/gfortran/LOC.html
> 
> Before:
> (gdb) p LOC(r)
> No symbol "LOC" in current context.
> 
> After:
> (gdb) p LOC(r)
> $1 = 0xffffdf48
> 
> gdb/ChangeLog:
> 2021-03-04  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* f-exp.y (f77_keywords): Add LOC.
> 	* f-lang.c (evaluate_subexp_f): Handle UNOP_FORTRAN_LOC.
> 	(operator_length_f): Likewise.
> 	(print_subexp_f): Likewise.
> 	(dump_subexp_body_f): Likewise.
> 	(operator_check_f): Likewise.
> 	* std-operator.def (UNOP_FORTRAN_LOC): New operator.

Remember to update your ChangeLog.  Otherwise, this looks good.  You
can push this once the ChangeLog has been updated.

Thanks,
Andrew



> 
> gdb/testsuite/ChangeLog:
> 2020-03-04  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* gdb.fortran/intrinsics.exp: Add LOC test.
> ---
>  gdb/f-exp.h                              |  7 +++++++
>  gdb/f-exp.y                              |  4 ++++
>  gdb/f-lang.c                             | 19 +++++++++++++++++++
>  gdb/std-operator.def                     |  1 +
>  gdb/testsuite/gdb.fortran/intrinsics.exp |  5 +++++
>  5 files changed, 36 insertions(+)
> 
> diff --git a/gdb/f-exp.h b/gdb/f-exp.h
> index 81cf3412ee2..a2e5b332b40 100644
> --- a/gdb/f-exp.h
> +++ b/gdb/f-exp.h
> @@ -73,6 +73,11 @@ extern struct value * eval_op_f_allocated (struct type *expect_type,
>  					   enum noside noside,
>  					   enum exp_opcode op,
>  					   struct value *arg1);
> +extern struct value * eval_op_f_loc (struct type *expect_type,
> +				     struct expression *exp,
> +				     enum noside noside,
> +				     enum exp_opcode op,
> +				     struct value *arg1);
>  
>  namespace expr
>  {
> @@ -86,6 +91,8 @@ using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND,
>  					      eval_op_f_kind>;
>  using fortran_allocated_operation = unop_operation<UNOP_FORTRAN_ALLOCATED,
>  						   eval_op_f_allocated>;
> +using fortran_loc_operation = unop_operation<UNOP_FORTRAN_LOC,
> +						   eval_op_f_loc>;
>  
>  using fortran_mod_operation = binop_operation<BINOP_MOD, eval_op_f_mod>;
>  using fortran_modulo_operation = binop_operation<BINOP_FORTRAN_MODULO,
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index c33b5079158..0c2a5be7a06 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -319,6 +319,9 @@ exp	:	UNOP_INTRINSIC '(' exp ')'
>  			      break;
>  			    case UNOP_FORTRAN_ALLOCATED:
>  			      pstate->wrap<fortran_allocated_operation> ();
> +			      break;
> +				case UNOP_FORTRAN_LOC:
> +			      pstate->wrap<fortran_loc_operation> ();
>  			      break;
>  			    default:
>  			      gdb_assert_not_reached ("unhandled intrinsic");
> @@ -1139,6 +1142,7 @@ static const struct token f77_keywords[] =
>    { "ubound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_UBOUND, false },
>    { "allocated", UNOP_INTRINSIC, UNOP_FORTRAN_ALLOCATED, false },
>    { "associated", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ASSOCIATED, false },
> +  { "loc", UNOP_INTRINSIC, UNOP_FORTRAN_LOC, false },
>  };
>  
>  /* Implementation of a dynamically expandable buffer for processing input
> diff --git a/gdb/f-lang.c b/gdb/f-lang.c
> index 1b66ae34159..833b151449a 100644
> --- a/gdb/f-lang.c
> +++ b/gdb/f-lang.c
> @@ -773,6 +773,25 @@ eval_op_f_allocated (struct type *expect_type, struct expression *exp,
>    return value_from_longest (result_type, result_value);
>  }
>  
> +/* A helper function for UNOP_FORTRAN_LOC.  */
> +
> +struct value *
> +eval_op_f_loc (struct type *expect_type, struct expression *exp,
> +		     enum noside noside, enum exp_opcode op,
> +		     struct value *arg1)
> +{
> +  struct type *result_type;
> +  if (gdbarch_ptr_bit (exp->gdbarch) == 16)
> +    result_type = builtin_f_type (exp->gdbarch)->builtin_integer_s2;
> +  else if (gdbarch_ptr_bit (exp->gdbarch) == 32)
> +    result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
> +  else
> +    result_type = builtin_f_type (exp->gdbarch)->builtin_integer_s8;
> +
> +  LONGEST result_value = value_address (arg1);
> +  return value_from_longest (result_type, result_value);
> +}
> +
>  namespace expr
>  {
>  
> diff --git a/gdb/std-operator.def b/gdb/std-operator.def
> index b0c6beb4628..5d29305d47b 100644
> --- a/gdb/std-operator.def
> +++ b/gdb/std-operator.def
> @@ -378,6 +378,7 @@ OP (UNOP_FORTRAN_KIND)
>  OP (UNOP_FORTRAN_FLOOR)
>  OP (UNOP_FORTRAN_CEILING)
>  OP (UNOP_FORTRAN_ALLOCATED)
> +OP (UNOP_FORTRAN_LOC)
>  
>  /* Two operand builtins.  */
>  OP (BINOP_FORTRAN_CMPLX)
> diff --git a/gdb/testsuite/gdb.fortran/intrinsics.exp b/gdb/testsuite/gdb.fortran/intrinsics.exp
> index d0ac1944aab..84f486f4d7b 100644
> --- a/gdb/testsuite/gdb.fortran/intrinsics.exp
> +++ b/gdb/testsuite/gdb.fortran/intrinsics.exp
> @@ -84,3 +84,8 @@ gdb_test "ptype MODULO (3.0,2.0)" "type = real\\*8"
>  # Test CMPLX
>  
>  gdb_test "p CMPLX (4.1, 2.0)" " = \\(4.$decimal,2\\)"
> +
> +# Test LOC
> +
> +gdb_test "p/x LOC(l)" "= $hex"
> +gdb_test "ptype loc(l)" "type = integer(\\*$decimal)?"
> -- 
> 2.25.4
> 
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
> Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928
> 

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

* RE: [PATCH v4] gdb/fortran: Add 'LOC' intrinsic support.
  2021-03-09 10:00 ` Andrew Burgess
@ 2021-03-09 10:41   ` Willgerodt, Felix
  0 siblings, 0 replies; 3+ messages in thread
From: Willgerodt, Felix @ 2021-03-09 10:41 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

Thanks, I updated the changelog and rebased and tested it again.
Everything was ok, so I pushed.

Felix

-----Original Message-----
From: Andrew Burgess <andrew.burgess@embecosm.com> 
Sent: Dienstag, 9. März 2021 11:01
To: Willgerodt, Felix <felix.willgerodt@intel.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v4] gdb/fortran: Add 'LOC' intrinsic support.

* Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org> [2021-03-09 09:42:21 +0100]:

> LOC(X) returns the address of X as an integer:
> https://gcc.gnu.org/onlinedocs/gfortran/LOC.html
> 
> Before:
> (gdb) p LOC(r)
> No symbol "LOC" in current context.
> 
> After:
> (gdb) p LOC(r)
> $1 = 0xffffdf48
> 
> gdb/ChangeLog:
> 2021-03-04  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* f-exp.y (f77_keywords): Add LOC.
> 	* f-lang.c (evaluate_subexp_f): Handle UNOP_FORTRAN_LOC.
> 	(operator_length_f): Likewise.
> 	(print_subexp_f): Likewise.
> 	(dump_subexp_body_f): Likewise.
> 	(operator_check_f): Likewise.
> 	* std-operator.def (UNOP_FORTRAN_LOC): New operator.

Remember to update your ChangeLog.  Otherwise, this looks good.  You can push this once the ChangeLog has been updated.

Thanks,
Andrew



> 
> gdb/testsuite/ChangeLog:
> 2020-03-04  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* gdb.fortran/intrinsics.exp: Add LOC test.
> ---
>  gdb/f-exp.h                              |  7 +++++++
>  gdb/f-exp.y                              |  4 ++++
>  gdb/f-lang.c                             | 19 +++++++++++++++++++
>  gdb/std-operator.def                     |  1 +
>  gdb/testsuite/gdb.fortran/intrinsics.exp |  5 +++++
>  5 files changed, 36 insertions(+)
> 
> diff --git a/gdb/f-exp.h b/gdb/f-exp.h index 81cf3412ee2..a2e5b332b40 
> 100644
> --- a/gdb/f-exp.h
> +++ b/gdb/f-exp.h
> @@ -73,6 +73,11 @@ extern struct value * eval_op_f_allocated (struct type *expect_type,
>  					   enum noside noside,
>  					   enum exp_opcode op,
>  					   struct value *arg1);
> +extern struct value * eval_op_f_loc (struct type *expect_type,
> +				     struct expression *exp,
> +				     enum noside noside,
> +				     enum exp_opcode op,
> +				     struct value *arg1);
>  
>  namespace expr
>  {
> @@ -86,6 +91,8 @@ using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND,
>  					      eval_op_f_kind>;
>  using fortran_allocated_operation = unop_operation<UNOP_FORTRAN_ALLOCATED,
>  						   eval_op_f_allocated>;
> +using fortran_loc_operation = unop_operation<UNOP_FORTRAN_LOC,
> +						   eval_op_f_loc>;
>  
>  using fortran_mod_operation = binop_operation<BINOP_MOD, 
> eval_op_f_mod>;  using fortran_modulo_operation = 
> binop_operation<BINOP_FORTRAN_MODULO,
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y index c33b5079158..0c2a5be7a06 
> 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -319,6 +319,9 @@ exp	:	UNOP_INTRINSIC '(' exp ')'
>  			      break;
>  			    case UNOP_FORTRAN_ALLOCATED:
>  			      pstate->wrap<fortran_allocated_operation> ();
> +			      break;
> +				case UNOP_FORTRAN_LOC:
> +			      pstate->wrap<fortran_loc_operation> ();
>  			      break;
>  			    default:
>  			      gdb_assert_not_reached ("unhandled intrinsic"); @@ -1139,6 
> +1142,7 @@ static const struct token f77_keywords[] =
>    { "ubound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_UBOUND, false },
>    { "allocated", UNOP_INTRINSIC, UNOP_FORTRAN_ALLOCATED, false },
>    { "associated", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ASSOCIATED, false 
> },
> +  { "loc", UNOP_INTRINSIC, UNOP_FORTRAN_LOC, false },
>  };
>  
>  /* Implementation of a dynamically expandable buffer for processing 
> input diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 
> 1b66ae34159..833b151449a 100644
> --- a/gdb/f-lang.c
> +++ b/gdb/f-lang.c
> @@ -773,6 +773,25 @@ eval_op_f_allocated (struct type *expect_type, struct expression *exp,
>    return value_from_longest (result_type, result_value);  }
>  
> +/* A helper function for UNOP_FORTRAN_LOC.  */
> +
> +struct value *
> +eval_op_f_loc (struct type *expect_type, struct expression *exp,
> +		     enum noside noside, enum exp_opcode op,
> +		     struct value *arg1)
> +{
> +  struct type *result_type;
> +  if (gdbarch_ptr_bit (exp->gdbarch) == 16)
> +    result_type = builtin_f_type (exp->gdbarch)->builtin_integer_s2;
> +  else if (gdbarch_ptr_bit (exp->gdbarch) == 32)
> +    result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
> +  else
> +    result_type = builtin_f_type (exp->gdbarch)->builtin_integer_s8;
> +
> +  LONGEST result_value = value_address (arg1);
> +  return value_from_longest (result_type, result_value); }
> +
>  namespace expr
>  {
>  
> diff --git a/gdb/std-operator.def b/gdb/std-operator.def index 
> b0c6beb4628..5d29305d47b 100644
> --- a/gdb/std-operator.def
> +++ b/gdb/std-operator.def
> @@ -378,6 +378,7 @@ OP (UNOP_FORTRAN_KIND)  OP (UNOP_FORTRAN_FLOOR)  
> OP (UNOP_FORTRAN_CEILING)  OP (UNOP_FORTRAN_ALLOCATED)
> +OP (UNOP_FORTRAN_LOC)
>  
>  /* Two operand builtins.  */
>  OP (BINOP_FORTRAN_CMPLX)
> diff --git a/gdb/testsuite/gdb.fortran/intrinsics.exp 
> b/gdb/testsuite/gdb.fortran/intrinsics.exp
> index d0ac1944aab..84f486f4d7b 100644
> --- a/gdb/testsuite/gdb.fortran/intrinsics.exp
> +++ b/gdb/testsuite/gdb.fortran/intrinsics.exp
> @@ -84,3 +84,8 @@ gdb_test "ptype MODULO (3.0,2.0)" "type = real\\*8"
>  # Test CMPLX
>  
>  gdb_test "p CMPLX (4.1, 2.0)" " = \\(4.$decimal,2\\)"
> +
> +# Test LOC
> +
> +gdb_test "p/x LOC(l)" "= $hex"
> +gdb_test "ptype loc(l)" "type = integer(\\*$decimal)?"
> --
> 2.25.4
> 
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de> Managing 
> Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva 
> Chairperson of the Supervisory Board: Nicole Lau Registered Office: 
> Munich Commercial Register: Amtsgericht Muenchen HRB 186928
> 
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

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

end of thread, other threads:[~2021-03-09 10:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09  8:42 [PATCH v4] gdb/fortran: Add 'LOC' intrinsic support Felix Willgerodt
2021-03-09 10:00 ` Andrew Burgess
2021-03-09 10:41   ` Willgerodt, Felix

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).