aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2024-02-09 20:25:29 +0100
committerHannes Domani <ssbssa@yahoo.de>2024-02-09 20:26:15 +0100
commit6b991efe7b8c687ab0af64ca6124dbd4a69a6724 (patch)
tree6a21889b78d108517e96d662985caaf2737e923b /gdb
parent4199cf1e152daab0460f08cc7dbd1f727ac3e4cc (diff)
downloadbinutils-6b991efe7b8c687ab0af64ca6124dbd4a69a6724.zip
binutils-6b991efe7b8c687ab0af64ca6124dbd4a69a6724.tar.gz
binutils-6b991efe7b8c687ab0af64ca6124dbd4a69a6724.tar.bz2
Allow value repeat operator on references
Currently it's not possible to use the value repeat operator on references: ``` print ((int &) v_int_array_init[0])@2 Only values in memory can be extended with '@'. ``` This seems like an unnecessary restriction, since it also prevents its use on iterators (which was the original reported problem): ``` (gdb) p *it@2 Only values in memory can be extended with '@'. ``` So this converts any references to the referenced value in value_repeat, making this possible: ``` print ((int &) v_int_array_init[0])@2 $1 = {10, 20} (gdb) p *it@2 $2 = {1, 2} ``` Approved-by: Kevin Buettner <kevinb@redhat.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.base/exprs.exp1
-rw-r--r--gdb/valops.c2
2 files changed, 3 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
index 239cdce..0f8c53b 100644
--- a/gdb/testsuite/gdb.base/exprs.exp
+++ b/gdb/testsuite/gdb.base/exprs.exp
@@ -259,6 +259,7 @@ gdb_test {print *v_int_array_init@2} { = \{10, 20\}}
gdb_test {print v_int_array_init[0]@1} { = \{10\}}
gdb_test {print v_int_array_init[0]@2} { = \{10, 20\}}
gdb_test {print v_int_array_init[1]@1} { = \{20\}}
+gdb_test {print ((int &) v_int_array_init[0])@2} { = \{10, 20\}}
# gdb's {} extension
gdb_test_no_output "set variable v_short_array\[0\] = 42"
diff --git a/gdb/valops.c b/gdb/valops.c
index e2694f0..399d0f1 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1349,6 +1349,8 @@ value_repeat (struct value *arg1, int count)
{
struct value *val;
+ arg1 = coerce_ref (arg1);
+
if (arg1->lval () != lval_memory)
error (_("Only values in memory can be extended with '@'."));
if (count < 1)