]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Allow value repeat operator on references
authorHannes Domani <ssbssa@yahoo.de>
Fri, 9 Feb 2024 19:25:29 +0000 (20:25 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Fri, 9 Feb 2024 19:26:15 +0000 (20:26 +0100)
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>
gdb/testsuite/gdb.base/exprs.exp
gdb/valops.c

index 239cdce8dc2514a2f503268bf5b748bd4ad8294a..0f8c53bc7164b878e4cdbe6bd78b4d447d133fb9 100644 (file)
@@ -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"
index e2694f0c32b2fa59c158d02fdfe0bb71fb2045be..399d0f109e145acf297b5260c0df409e193e5c80 100644 (file)
@@ -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)