* [PATCH] Fix crash with C++ qualified names
@ 2022-12-23 19:58 Tom Tromey
2023-01-09 10:12 ` Bruno Larsen
2023-01-09 11:50 ` Andrew Burgess
0 siblings, 2 replies; 3+ messages in thread
From: Tom Tromey @ 2022-12-23 19:58 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix crash with C++ qualified names
2022-12-23 19:58 [PATCH] Fix crash with C++ qualified names Tom Tromey
@ 2023-01-09 10:12 ` Bruno Larsen
2023-01-09 11:50 ` Andrew Burgess
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Larsen @ 2023-01-09 10:12 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 23/12/2022 20:58, Tom Tromey wrote:
> 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
I can confirm that this fixes the issue, and seems like a simple enough
change.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
--
Cheers,
Bruno
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix crash with C++ qualified names
2022-12-23 19:58 [PATCH] Fix crash with C++ qualified names Tom Tromey
2023-01-09 10:12 ` Bruno Larsen
@ 2023-01-09 11:50 ` Andrew Burgess
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2023-01-09 11:50 UTC (permalink / raw)
To: Tom Tromey, gdb-patches; +Cc: Tom Tromey
Tom Tromey <tom@tromey.com> writes:
> 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"
LGTM.
Thanks,
Andrew
> --
> 2.38.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-09 11:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-23 19:58 [PATCH] Fix crash with C++ qualified names Tom Tromey
2023-01-09 10:12 ` Bruno Larsen
2023-01-09 11:50 ` Andrew Burgess
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).