diff options
author | Hannes Domani <ssbssa@yahoo.de> | 2024-03-20 18:23:40 +0100 |
---|---|---|
committer | Hannes Domani <ssbssa@yahoo.de> | 2024-03-20 18:23:50 +0100 |
commit | d391f3721e20d160909a3afae7fee647ea5575a2 (patch) | |
tree | c2a6eb77e8c862ece4511ea9fa7dbfe66d3872e6 /gdb/valops.c | |
parent | 23cdd9431ad424b092c65419d47ef4601168a1c9 (diff) | |
download | binutils-d391f3721e20d160909a3afae7fee647ea5575a2.zip binutils-d391f3721e20d160909a3afae7fee647ea5575a2.tar.gz binutils-d391f3721e20d160909a3afae7fee647ea5575a2.tar.bz2 |
Fix casting in-memory values of primitive types to const reference
It's currently not possible to cast an in-memory value of a primitive
type to const reference:
```
(gdb) p Q.id
$1 = 42
(gdb) p (int&)Q.id
$2 = (int &) @0x22fd0c: 42
(gdb) p (const int&)Q.id
Attempt to take address of value not located in memory.
```
And if in a function call an argument needs the same kind of casting,
it also doesn't work:
```
(gdb) l f3
39 int f3(const int &i)
40 {
41 return i;
42 }
(gdb) p f3(Q.id)
Attempt to take address of value not located in memory.
```
It's because when the constness of the type changes in a call to
value_cast, a new not_lval value is allocated, which doesn't exist
in the target memory.
Fixed by ignoring const/volatile/restrict qualifications in
value_cast when comparing cast type to original type, so the new
value will point to the same location as the original value:
```
(gdb) p (int&)i
$2 = (int &) @0x39f72c: 1
(gdb) p (const int&)i
$3 = (const int &) @0x39f72c: 1
(gdb) p f3(Q.id)
$4 = 42
```
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19423
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/valops.c')
-rw-r--r-- | gdb/valops.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/gdb/valops.c b/gdb/valops.c index 1a943f0..52cce28 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -411,7 +411,8 @@ value_cast (struct type *type, struct value *arg2) In this case we want to preserve the LVAL of ARG2 as this allows the resulting value to be used in more places. We do this by calling VALUE_COPY if appropriate. */ - if (types_deeply_equal (arg2->type (), type)) + if (types_deeply_equal (make_unqualified_type (arg2->type ()), + make_unqualified_type (type))) { /* If the types are exactly equal then we can avoid creating a new value completely. */ |