From patchwork Thu Jun 12 08:32:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 1463 Received: (qmail 5840 invoked by alias); 12 Jun 2014 08:32:56 -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 5821 invoked by uid 89); 12 Jun 2014 08:32:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Jun 2014 08:32:53 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1Wv0RG-0007Ox-4s from Luis_Gustavo@mentor.com for gdb-patches@sourceware.org; Thu, 12 Jun 2014 01:32:50 -0700 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 12 Jun 2014 01:32:49 -0700 Received: from [172.30.5.216] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Thu, 12 Jun 2014 01:32:49 -0700 Message-ID: <539965AF.9050705@codesourcery.com> Date: Thu, 12 Jun 2014 09:32:47 +0100 From: Luis Machado Reply-To: User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: "'gdb-patches@sourceware.org'" Subject: [PATCH, testsuite] Fix gdb.mi/mi-var-rtti.exp failures X-IsSubscribed: yes Hi, During testing i noticed failures in gdb.mi/mi-var-rtti.exp for various targets. Nios2, arm and even x86. Turns out we are assuming too much in terms of what the compiler should do. In a couple functions (type_update_when_use_rtti_test and skip_type_update_when_not_use_rtti_test) the testcase assumes an uninitialized object has a specific type. In particular, 'ptr' and 's'. In reality the compiler is free to do what it wants with that uninitialized variable, even initialize it beforehand with the future assignment's value. This is exactly what happens on some targets. ptr should have type 'Base *', but it really has type 'Derived *' because it is already initialized (earlier) by the compiler. The same thing happens to 's'. The following patch addresses this by explicitly initializing those variables so the compiler doesn't optimize their assignments and GDB can print their correct values. Tested on Nios2, PowerPC and X86. Ok? Luis 2014-06-12 Luis Machado gdb/testsuite/ * gdb.mi/mi-var-rtti.cc (type_update_when_use_rtti_test): Initialize ptr and S explicitly. (skip_type_update_when_not_use_rtti_test): Likewise. diff --git a/gdb/testsuite/gdb.mi/mi-var-rtti.cc b/gdb/testsuite/gdb.mi/mi-var-rtti.cc index 94098b2..fe19b88 100644 --- a/gdb/testsuite/gdb.mi/mi-var-rtti.cc +++ b/gdb/testsuite/gdb.mi/mi-var-rtti.cc @@ -241,6 +241,12 @@ void use_rtti_with_multiple_inheritence_test () void type_update_when_use_rtti_test () { /*: BEGIN: type_update_when_use_rtti :*/ + Base *ptr = 0; + struct S { + Base* ptr; + S ( Base* v ) : + ptr ( v ) {} + } s ( ptr ); Derived d; /*: set testname type_update_when_use_rtti @@ -260,12 +266,8 @@ void type_update_when_use_rtti_test () check_derived_children_without_rtti S.public.ptr s.ptr $testname :*/ - Base* ptr = &d; - struct S { - Base* ptr; - S ( Base* v ) : - ptr ( v ) {} - } s ( &d ); + ptr = &d; + s.ptr = &d; /*: mi_varobj_update_with_type_change PTR {Derived \*} 2 \ "update ptr to derived in $testname" @@ -295,6 +297,12 @@ void type_update_when_use_rtti_test () void skip_type_update_when_not_use_rtti_test () { /*: BEGIN: skip_type_update_when_not_use_rtti :*/ + Base *ptr = 0; + struct S { + Base* ptr; + S ( Base* v ) : + ptr ( v ) {} + } s ( ptr ); Derived d; /*: set testname skip_type_update_when_not_use_rtti @@ -314,12 +322,8 @@ void skip_type_update_when_not_use_rtti_test () check_derived_children_without_rtti S.public.ptr s.ptr $testname :*/ - Base* ptr = &d; - struct S { - Base* ptr; - S ( Base* v ) : - ptr ( v ) {} - } s ( &d ); + ptr = &d; + s.ptr = &d; /*: mi_varobj_update PTR {PTR PTR.public.A} \ "update ptr to derived type in $testname"