From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Issue error on erroneous expression
Date: Sat, 18 Feb 2023 08:57:47 -0700 [thread overview]
Message-ID: <20230218155747.3723021-1-tom@tromey.com> (raw)
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.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19312
---
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;
}
--
2.39.1
next reply other threads:[~2023-02-18 15:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-18 15:57 Tom Tromey [this message]
2023-02-20 9:55 ` Bruno Larsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230218155747.3723021-1-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).