From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7862) id 5075F3858D38; Mon, 3 Oct 2022 08:09:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5075F3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664784596; bh=lAZnckRZ1KXPWh8Q5gwNA2LBWI76sSX72MbfMV0mSHE=; h=From:To:Subject:Date:From; b=xR1sYL/sZ481GvdTVH7IyhGthYTQmBwcMfBy2SwTGyHb0GVWkr26ZObeInR3dyoGg WL+In3NuV37+tLHB12sgLVsH2Vw0eRbk1Xa/P7KBXz0ihUfluF4p5xuZAgUts5hlF+ AAlzIp8HQNsCENUt9i5Ul+wIG1JjlSqwhf30ijx0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Bruno Larsen To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Improve GDB's baseclass detection with typedefs X-Act-Checkin: binutils-gdb X-Git-Author: Bruno Larsen X-Git-Refname: refs/heads/master X-Git-Oldrev: 7b4f240762ffa03e65e17cb7dee807bc1628c24a X-Git-Newrev: 2820f08f2331820808ac2f54d8e3619f36ea258b Message-Id: <20221003080956.5075F3858D38@sourceware.org> Date: Mon, 3 Oct 2022 08:09:56 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2820f08f2331= 820808ac2f54d8e3619f36ea258b commit 2820f08f2331820808ac2f54d8e3619f36ea258b Author: Bruno Larsen Date: Fri Sep 23 11:36:02 2022 +0200 Improve GDB's baseclass detection with typedefs =20 When a class inherits from a typedef'd baseclass, GDB may be unable to find the baseclass if the user is not using the typedef'd name, as is tested on gdb.cp/virtbase2.exp; the reason that test case is working under gcc is that the dwarf generated by gcc links the class to the original definition of the baseclass, not to the typedef. If the inheritance is linked to the typedef, such as how clang does it, gdb.cp/virtbase2.exp starts failing. =20 This can also be seen in gdb.cp/impl-this.exp, when attempting to print D::Bint::i, and GDB not being able to find the baseclass Bint. =20 This happens because searching for baseclasses only uses the macro TYPE_BASECLASS_NAME, which returns the typedef'd name. However, we can't switch that macro to checking for typedefs, otherwise we wouldn't be able to find the typedef'd name anymore. This is fixed by searching for members or baseclasses by name, we check both the saved name and the name after checking for typedefs. =20 This also fixes said long-standing bug in gdb.cp/impl-this.exp when the compiler adds information about typedefs in the debuginfo. Diff: --- gdb/cp-namespace.c | 5 +++-- gdb/testsuite/gdb.cp/impl-this.exp | 45 ++++++++++++++++++++++++++++------= ---- gdb/valops.c | 4 +--- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 837eafc52f1..1d7759a7669 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -780,12 +780,13 @@ cp_find_type_baseclass_by_name (struct type *parent_t= ype, const char *name) for (i =3D 0; i < TYPE_N_BASECLASSES (parent_type); ++i) { struct type *type =3D check_typedef (TYPE_BASECLASS (parent_type, i)= ); - const char *base_name =3D TYPE_BASECLASS_NAME (parent_type, i); + const char *tdef_name =3D TYPE_BASECLASS_NAME (parent_type, i); + const char *base_name =3D type->name (); =20 if (base_name =3D=3D NULL) continue; =20 - if (streq (base_name, name)) + if (streq (tdef_name, name) || streq (base_name, name)) return type; =20 type =3D cp_find_type_baseclass_by_name (type, name); diff --git a/gdb/testsuite/gdb.cp/impl-this.exp b/gdb/testsuite/gdb.cp/impl= -this.exp index 2910bf7d79d..4a11fb21823 100644 --- a/gdb/testsuite/gdb.cp/impl-this.exp +++ b/gdb/testsuite/gdb.cp/impl-this.exp @@ -26,6 +26,8 @@ if {[prepare_for_testing "failed to prepare" $testfile $s= rcfile {debug c++}]} { return -1 } =20 +set gcc_used [test_compiler_info gcc-*-*] + # First test expressions when there is no context. with_test_prefix "before run" { gdb_test "print i" "No symbol \"i\" in current context." @@ -63,15 +65,23 @@ with_test_prefix "at D::f (valid expressions)" { gdb_test "print D::i" "=3D 4" gdb_test "print D::B::i" "=3D 2" gdb_test "print B::i" "=3D 2" - gdb_test "print D::Bint::i" \ - "No type \"Bint\" within class or namespace \"D\"." + + if {$gcc_used} { + setup_xfail *-*-* gcc/60833 + } + gdb_test "print D::Bint::i" "=3D 2" + gdb_test "print Bint::i" "=3D 2" gdb_test "print D::C::i" "=3D 3" gdb_test "print C::i" "=3D 3" gdb_test "print D::B::A::i" "=3D 1" gdb_test "print B::A::i" "=3D 1" - gdb_test "print D::Bint::A::i" \ - "No type \"Bint\" within class or namespace \"D\"." + + if {$gcc_used} { + setup_xfail *-*-* gcc/60833 + } + gdb_test "print D::Bint::A::i" "=3D 1" + gdb_test "print Bint::A::i" "=3D 1" gdb_test "print A::i" "=3D 1" gdb_test "print D::C::A::i" "=3D 1" @@ -88,11 +98,16 @@ with_test_prefix "at D::f (valid expressions)" { with_test_prefix "at D::f (invalid expressions)" { gdb_test "print D::B::c" "There is no field named c" gdb_test "print D::B::A::c" "There is no field named c" - gdb_test "print D::Bint::c" \ - "No type \"Bint\" within class or namespace \"D\"." =20 - gdb_test "print D::Bint::A::c" \ - "No type \"Bint\" within class or namespace \"D\"." + if {$gcc_used} { + setup_xfail *-*-* gcc/60833 + } + gdb_test "print D::Bint::c" "There is no field named c" + if {$gcc_used} { + setup_xfail *-*-* gcc/60833 + } + gdb_test "print D::Bint::A::c" "There is no field named c" + gdb_test "print D::C::A::c" "There is no field named c" gdb_test "print B::c" "There is no field named c" gdb_test "print B::A::c" "There is no field named c" @@ -101,10 +116,16 @@ with_test_prefix "at D::f (invalid expressions)" { gdb_test "print C::A::c" "There is no field named c" gdb_test "print D::B::x" "There is no field named x" gdb_test "print D::B::A::x" "There is no field named x" - gdb_test "print D::Bint::x" \ - "No type \"Bint\" within class or namespace \"D\"." - gdb_test "print D::Bint::A::x" \ - "No type \"Bint\" within class or namespace \"D\"." + + if {$gcc_used} { + setup_xfail *-*-* gcc/60833 + } + gdb_test "print D::Bint::x" "There is no field named x" + if {$gcc_used} { + setup_xfail *-*-* gcc/60833 + } + gdb_test "print D::Bint::A::x" "There is no field named x" + gdb_test "print B::x" "There is no field named x" gdb_test "print B::A::x" "There is no field named x" gdb_test "print Bint::x" "There is no field named x" diff --git a/gdb/valops.c b/gdb/valops.c index 0a215d699a1..de8a68888e4 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -2066,9 +2066,7 @@ struct_field_searcher::search (struct value *arg1, LO= NGEST offset, name is not yet filled in. */ int found_baseclass =3D (m_looking_for_baseclass && TYPE_BASECLASS_NAME (type, i) !=3D NULL - && (strcmp_iw (m_name, - TYPE_BASECLASS_NAME (type, - i)) =3D=3D 0)); + && (strcmp_iw (m_name, basetype->name ()) =3D=3D 0)); LONGEST boffset =3D value_embedded_offset (arg1) + offset; =20 if (BASETYPE_VIA_VIRTUAL (type, i))