From patchwork Tue Feb 24 22:21:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 5271 Received: (qmail 118588 invoked by alias); 24 Feb 2015 22:21:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 118577 invoked by uid 89); 24 Feb 2015 22:21:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ie0-f202.google.com Received: from mail-ie0-f202.google.com (HELO mail-ie0-f202.google.com) (209.85.223.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 24 Feb 2015 22:21:05 +0000 Received: by iecrd18 with SMTP id rd18so12745iec.1 for ; Tue, 24 Feb 2015 14:21:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=gvpqaXsRe+k+/LqyBf0kQyXckRZgBhBPHWFztQ72Z3E=; b=mujmUi24K+RML1kRy1kIBa8q4EAMTCDqCDPGBErcBRjKocTk2NkuzoSlPjHox5TSIo BhlvQLS1oPtIMhFaRf36IYzY0+YnpDcL81qEsddpLF4YDAMOwhKgTHXj/36B/bt7VgJi OjEfKiS2TzUIs3I0i3/YKdCijDBuVVzfOk6Y22WBzszAhMvfXNEwQ6L17QEnSUzHed/j 9FTaCjhxuApn6aZosTQ0h1ySLO+vgQ3W4SVkX4e6UbX0p+F18QAFUKw5QtzaYXAaHxGo v9eMNT2jRWyhXgP82Dv4321zSxvNX1VGJlqlFF0dVkcWfGz0YEknvf0VhacNpoxOcDSX 4TTQ== X-Gm-Message-State: ALoCoQmksjzWX5ojg6jznkFb5e4cEvuc+K4Luq269gq/KMtCHu/KecYFdASvyJqyuhsBvlXfFXr55iR8eOXiiWUtRwaCsYa8z2msmAp98Pvcn63QUn57EaCH3QFV/xRuDILTtn81TxHz7XnmXxbF24pgndqEL/jxnXJD/WlW33jWZprhomsqAuU= X-Received: by 10.42.62.19 with SMTP id w19mr485815ich.30.1424816463408; Tue, 24 Feb 2015 14:21:03 -0800 (PST) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id 3si1429924yhe.0.2015.02.24.14.21.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Feb 2015 14:21:03 -0800 (PST) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTPS id BpMCje8T.1; Tue, 24 Feb 2015 14:21:03 -0800 From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH] Fix internal errors due to missing check_typedef calls Date: Tue, 24 Feb 2015 14:21:02 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. Silly me forgot to add in the requisite check_typedef calls. I tripped over this bug with a program that had a typedef'd unnamed baseclass with virtual methods. The patch includes testcases to exercise this case now. I added tests in a couple of files because I wanted to exercise both ptype and print, and these files looked like the best place to put them. Regression tested on amd64-linux. 2015-02-24 Doug Evans * gdbtypes.c (internal_type_vptr_fieldno): Add missing call to CHECK_TYPEDEF. (set_type_vptr_fieldno): Ditto. (internal_type_vptr_basetype, set_type_vptr_basetype): Ditto. * gnu-v3-abi.c (gnuv3_dynamic_class): Ditto. testsuite/ * class2.cc (Dbase, D): New classes. (main): New local delta. * class2.exp: Test printing delta. * classes.cc (DynamicBase2, DynamicBar): New classes. (dynbar): New global. * classes.exp (test_ptype_class_objects): Test ptype DynamicBar. diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index a80151c..ebb047f 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1636,6 +1636,7 @@ get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max) int internal_type_vptr_fieldno (struct type *type) { + CHECK_TYPEDEF (type); gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION); if (!HAVE_CPLUS_STRUCT (type)) @@ -1648,6 +1649,7 @@ internal_type_vptr_fieldno (struct type *type) void set_type_vptr_fieldno (struct type *type, int fieldno) { + CHECK_TYPEDEF (type); gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION); if (!HAVE_CPLUS_STRUCT (type)) @@ -1661,6 +1663,7 @@ set_type_vptr_fieldno (struct type *type, int fieldno) struct type * internal_type_vptr_basetype (struct type *type) { + CHECK_TYPEDEF (type); gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION); gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF); @@ -1672,6 +1675,7 @@ internal_type_vptr_basetype (struct type *type) void set_type_vptr_basetype (struct type *type, struct type *basetype) { + CHECK_TYPEDEF (type); gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION); if (!HAVE_CPLUS_STRUCT (type)) diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index cdcb354..1dfb37b 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -202,6 +202,7 @@ gnuv3_dynamic_class (struct type *type) { int fieldnum, fieldelem; + CHECK_TYPEDEF (type); gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION); diff --git a/gdb/testsuite/gdb.cp/class2.cc b/gdb/testsuite/gdb.cp/class2.cc index 617a8fa..409fb29 100644 --- a/gdb/testsuite/gdb.cp/class2.cc +++ b/gdb/testsuite/gdb.cp/class2.cc @@ -46,6 +46,23 @@ struct C : public B A *c2; }; +/* Use a typedef for the baseclass, with a virtual method, to exercise + gnu-v3-abi.c:gnuv3_dynamic_class recursion. It's important that the + class itself have no name to make sure the typedef makes it through + to the recursive call. */ +typedef class { + public: + /* This class has no members as gcc 4.9.x doesn't emit the debug info + for them. */ + virtual int get () { return 42; } +} Dbase; + +class D : public Dbase +{ + public: + int d1; +}; + // Stop the compiler from optimizing away data. void refer (A *) { @@ -65,12 +82,14 @@ int main (void) A alpha, *aap, *abp, *acp; B beta, *bbp; C gamma; + D delta; empty e; A &aref (alpha); alpha.a1 = 100; beta.a1 = 200; beta.b1 = 201; beta.b2 = 202; gamma.c1 = 0; gamma.c2 = (A *) ~0UL; + delta.d1 = 400; aap = α refer (aap); abp = β refer (abp); diff --git a/gdb/testsuite/gdb.cp/class2.exp b/gdb/testsuite/gdb.cp/class2.exp index 7fedc58..81b3561 100644 --- a/gdb/testsuite/gdb.cp/class2.exp +++ b/gdb/testsuite/gdb.cp/class2.exp @@ -101,17 +101,31 @@ gdb_test "print * (B *) abp" \ "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \ "print * (B *) abp at marker return 0" +# Print the "D" object. + +gdb_test "print delta" \ + "= {.*d1 = 400}" \ + "print delta with \"print object\" off" + # Printing the value of an object containing no data fields: gdb_test "p e" "= \{\}" "print object with no data fields" -# Printing NULL pointers with "set print object on" +# Printing NULL pointers with "set print object on". gdb_test_no_output "set print object on" gdb_test "p acp" "= \\(C \\*\\) ${hex}" gdb_test "p acp->c1" "\\(A \\*\\) 0x0" gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f" +# Print the "D" object with "set print object on". +# There's no difference in output, but this exercises vtable lookup +# with a typedef'd baseclass. + +gdb_test "print delta" \ + "= {.*d1 = 400}" \ + "print delta with \"print object\" on" + # Regression test for PR c++/15401. # Check that the type printed is a reference. gdb_test "p aref" " = \\(A \\&\\) .*" diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc index e7b7c14..648452c 100644 --- a/gdb/testsuite/gdb.cp/classes.cc +++ b/gdb/testsuite/gdb.cp/classes.cc @@ -434,6 +434,24 @@ Foo::operator int() { return x; } ByAnyOtherName foo(10, 11); Bar bar(20, 21, 22); +/* Use a typedef for the baseclass to exercise gnu-v3-abi.c:gnuv3_dynamic_class + recursion. It's important that the class itself have no name to make sure + the typedef makes it through to the recursive call. */ +typedef class { + public: + int x; + virtual int get_x () { return x; } +} DynamicBase2; + +class DynamicBar : public DynamicBase2 +{ + public: + DynamicBar (int i, int j) { x = i; y = j; } + int y; +}; + +DynamicBar dynbar (23, 24); + class ClassWithEnum { public: enum PrivEnum { red, green, blue, yellow = 42 }; diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp index 7b658d5..1d714d3 100644 --- a/gdb/testsuite/gdb.cp/classes.exp +++ b/gdb/testsuite/gdb.cp/classes.exp @@ -307,6 +307,15 @@ proc test_ptype_class_objects {} { { method public "Bar(int, int, int);" } } + # Derived class with typedef'd baseclass with virtual methods. + + cp_test_ptype_class \ + "class DynamicBar" "" "class" "DynamicBar" \ + { + { base "public DynamicBase2" } + { field public "int y;" } + { method public "DynamicBar(int, int);" } + } } # Test simple access to class members.