From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Fix crash with C++ qualified names
Date: Fri, 23 Dec 2022 12:58:09 -0700 [thread overview]
Message-ID: <20221223195809.602699-1-tom@tromey.com> (raw)
PR c++/29503 points out that something like "b->Base::member" will
crash when 'b' does not have pointer type. This seems to be a simple
oversight in eval_op_member.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29503
---
gdb/eval.c | 2 ++
gdb/testsuite/gdb.cp/ambiguous.exp | 1 +
2 files changed, 3 insertions(+)
diff --git a/gdb/eval.c b/gdb/eval.c
index d0a4a16ceb5..3757028b4a3 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1300,6 +1300,8 @@ eval_op_member (struct type *expect_type, struct expression *exp,
case TYPE_CODE_MEMBERPTR:
/* Now, convert these values to an address. */
+ if (check_typedef (value_type (arg1))->code () != TYPE_CODE_PTR)
+ arg1 = value_addr (arg1);
arg1 = value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type)),
arg1, 1);
diff --git a/gdb/testsuite/gdb.cp/ambiguous.exp b/gdb/testsuite/gdb.cp/ambiguous.exp
index 5d0d2f88b6e..65b33e89a79 100644
--- a/gdb/testsuite/gdb.cp/ambiguous.exp
+++ b/gdb/testsuite/gdb.cp/ambiguous.exp
@@ -123,6 +123,7 @@ with_test_prefix "all fields" {
gdb_test "print n.A1::y" " = 2"
gdb_test "print n.A2::x" " = 3"
gdb_test "print n.A2::y" " = 4"
+ gdb_test "print n->A2::y" " = 4"
gdb_test "print n.w" " = 5"
gdb_test "print n.r" " = 6"
gdb_test "print n.z" " = 7"
--
2.38.1
next reply other threads:[~2022-12-23 19:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-23 19:58 Tom Tromey [this message]
2023-01-09 10:12 ` Bruno Larsen
2023-01-09 11:50 ` Andrew Burgess
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=20221223195809.602699-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).