public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Allow re-assigning to convenience variables
Date: Fri, 14 Jun 2019 14:09:00 -0000	[thread overview]
Message-ID: <20190614140920.74226.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f411722cbc18820e5266ec4c2aadd2269eb15447

commit f411722cbc18820e5266ec4c2aadd2269eb15447
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Jun 5 10:53:16 2019 -0600

    Allow re-assigning to convenience variables
    
    In Ada mode, re-assigning an array of a different size to a
    convenience variable will cause an error:
    
        (gdb) set lang ada
        (gdb) set $v := "abc"
        (gdb) set $v := "abcd"
        cannot assign arrays of different length
    
    However, this does not really make sense -- instead, it should always
    be possible to overwrite a convenience variable.
    
    This patch fixes this bug.
    
    This was reviewed off-list by Joel.  I'm checking it in.
    
    gdb/ChangeLog
    2019-06-14  Tom Tromey  <tromey@adacore.com>
    
    	* ada-lang.c (ada_evaluate_subexp) <case BINOP_ASSIGN>: Always
    	allow assignment to an internalvar.
    
    gdb/testsuite/ChangeLog
    2019-06-14  Tom Tromey  <tromey@adacore.com>
    
    	* gdb.ada/set_wstr.exp: Add reassignment test.

Diff:
---
 gdb/ChangeLog                      | 5 +++++
 gdb/ada-lang.c                     | 6 +++++-
 gdb/testsuite/ChangeLog            | 4 ++++
 gdb/testsuite/gdb.ada/set_wstr.exp | 5 +++++
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9fbfcfa..ee3377c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2019-06-14  Tom Tromey  <tromey@adacore.com>
 
+	* ada-lang.c (ada_evaluate_subexp) <case BINOP_ASSIGN>: Always
+	allow assignment to an internalvar.
+
+2019-06-14  Tom Tromey  <tromey@adacore.com>
+
 	* ada-lex.l: Allow "_" in attribute names.
 
 2019-06-14  Tom Tromey  <tromey@adacore.com>
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1f0ada3..1b5f183 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10486,7 +10486,11 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg2 = evaluate_subexp (type, exp, pos, noside);
       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
         return arg1;
-      if (ada_is_fixed_point_type (value_type (arg1)))
+      if (VALUE_LVAL (arg1) == lval_internalvar)
+	{
+	  /* Nothing.  */
+	}
+      else if (ada_is_fixed_point_type (value_type (arg1)))
         arg2 = cast_to_fixed (value_type (arg1), arg2);
       else if (ada_is_fixed_point_type (value_type (arg2)))
         error
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9bfd570..8219486 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
 2019-06-14  Tom Tromey  <tromey@adacore.com>
 
+	* gdb.ada/set_wstr.exp: Add reassignment test.
+
+2019-06-14  Tom Tromey  <tromey@adacore.com>
+
 	* gdb.ada/formatted_ref.exp (test_p_x_addr): Check
 	'unchecked_access and 'unrestricted_access as well.
 
diff --git a/gdb/testsuite/gdb.ada/set_wstr.exp b/gdb/testsuite/gdb.ada/set_wstr.exp
index 0c5c42c..ac70985 100644
--- a/gdb/testsuite/gdb.ada/set_wstr.exp
+++ b/gdb/testsuite/gdb.ada/set_wstr.exp
@@ -72,3 +72,8 @@ gdb_test "print rws" \
 
 gdb_test "set variable www := \"1#2#3#4#5#\"" \
          "cannot assign arrays of different length"
+
+# However, reassigning an array of a different length should work when
+# the LHS is a convenience variable.
+gdb_test_no_output "set variable \$str := \"1234\""
+gdb_test_no_output "set variable \$str := \"12345\""


             reply	other threads:[~2019-06-14 14:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 14:09 Tom Tromey [this message]
2019-11-14 18:59 Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190614140920.74226.qmail@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).