[binutils-gdb] Issue error on erroneous expression
Tom Tromey
tromey@sourceware.org
Tue Feb 21 19:45:28 GMT 2023
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3592bebbbf6b27732effc49bd6a73b0bd5af4df4
commit 3592bebbbf6b27732effc49bd6a73b0bd5af4df4
Author: Tom Tromey <tom@tromey.com>
Date: Fri Feb 17 19:55:50 2023 -0500
Issue error on erroneous expression
A while back I discovered that this does not issue an error:
(gdb) p $x = (void * ) 57
$3 = (void *) 0x39
(gdb) p $x + 7 = 3
$6 = (void *) 0x3
This patch fixes the bug.
Regression tested on x86-64 Fedora 36.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19312
Diff:
---
gdb/testsuite/gdb.base/gdbvars.exp | 8 ++++++++
gdb/valarith.c | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/gdbvars.exp b/gdb/testsuite/gdb.base/gdbvars.exp
index ced77aa15c4..cb6656c176f 100644
--- a/gdb/testsuite/gdb.base/gdbvars.exp
+++ b/gdb/testsuite/gdb.base/gdbvars.exp
@@ -66,6 +66,14 @@ proc test_convenience_variables {} {
gdb_test "print \$arr = {0, 1, 2, 3}" \
" = \\{0, 1, 2, 3\\}" \
"Set convenience variable to different array value"
+
+ gdb_test "print \$ptr = (void *) 7" \
+ " = \\(void \\*\\) 0x7" \
+ "set convenience variable to pointer value"
+ # This used to "succeed".
+ gdb_test "print \$ptr + 23 = 97" \
+ "Left operand of assignment is not an lvalue." \
+ "reject invalid assignment"
}
proc test_convenience_functions {} {
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 0ab684aa05b..a6a5f5102a2 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -93,7 +93,7 @@ value_ptradd (struct value *arg1, LONGEST arg2)
result = value_from_pointer (valptrtype,
value_as_address (arg1) + sz * arg2);
- if (result->lval () != lval_internalvar)
+ if (arg1->lval () != lval_internalvar)
result->set_component_location (arg1);
return result;
}
More information about the Gdb-cvs
mailing list