public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix crash with C++ qualified names
@ 2023-01-09 19:27 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-01-09 19:27 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bf716a53bd8f725975979397b3c6b9d4bd4434ef

commit bf716a53bd8f725975979397b3c6b9d4bd4434ef
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Dec 23 12:55:10 2022 -0700

    Fix crash with C++ qualified names
    
    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
    Reviewed-By: Bruno Larsen <blarsen@redhat.com>

Diff:
---
 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 05e35941101..bb42e693b17 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1309,6 +1309,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 b430b039887..966d99ae595 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"

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-09 19:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 19:27 [binutils-gdb] Fix crash with C++ qualified names Tom Tromey

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).