* [PATCH] Allow value repeat operator on references
[not found] <20240209130451.31442-1-ssbssa.ref@yahoo.de>
@ 2024-02-09 13:04 ` Hannes Domani
2024-02-09 19:14 ` Kevin Buettner
0 siblings, 1 reply; 3+ messages in thread
From: Hannes Domani @ 2024-02-09 13:04 UTC (permalink / raw)
To: gdb-patches
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}
```
---
gdb/testsuite/gdb.base/exprs.exp | 1 +
gdb/valops.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
index 239cdce8dc2..0f8c53bc716 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 e2694f0c32b..399d0f109e1 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)
--
2.35.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Allow value repeat operator on references
2024-02-09 13:04 ` [PATCH] Allow value repeat operator on references Hannes Domani
@ 2024-02-09 19:14 ` Kevin Buettner
2024-02-09 19:27 ` Hannes Domani
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2024-02-09 19:14 UTC (permalink / raw)
To: Hannes Domani; +Cc: gdb-patches
On Fri, 9 Feb 2024 14:04:51 +0100
Hannes Domani <ssbssa@yahoo.de> wrote:
> 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}
> ```
> ---
> gdb/testsuite/gdb.base/exprs.exp | 1 +
> gdb/valops.c | 2 ++
> 2 files changed, 3 insertions(+)
LGTM.
Approved-by: Kevin Buettner <kevinb@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Allow value repeat operator on references
2024-02-09 19:14 ` Kevin Buettner
@ 2024-02-09 19:27 ` Hannes Domani
0 siblings, 0 replies; 3+ messages in thread
From: Hannes Domani @ 2024-02-09 19:27 UTC (permalink / raw)
To: Kevin Buettner; +Cc: gdb-patches
Am Freitag, 9. Februar 2024 um 20:14:41 MEZ hat Kevin Buettner <kevinb@redhat.com> Folgendes geschrieben:
> On Fri, 9 Feb 2024 14:04:51 +0100
>
> Hannes Domani <ssbssa@yahoo.de> wrote:
>
> > 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}
> > ```
> > ---
> > gdb/testsuite/gdb.base/exprs.exp | 1 +
> > gdb/valops.c | 2 ++
> > 2 files changed, 3 insertions(+)
>
>
> LGTM.
>
> Approved-by: Kevin Buettner <kevinb@redhat.com>
Pushed, thanks.
Hannes
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-09 19:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20240209130451.31442-1-ssbssa.ref@yahoo.de>
2024-02-09 13:04 ` [PATCH] Allow value repeat operator on references Hannes Domani
2024-02-09 19:14 ` Kevin Buettner
2024-02-09 19:27 ` Hannes Domani
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).