This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH, testsuite] Fix gdb.mi/mi-var-rtti.exp failures
- From: Luis Machado <lgustavo at codesourcery dot com>
- To: "'gdb-patches at sourceware dot org'" <gdb-patches at sourceware dot org>
- Date: Thu, 12 Jun 2014 09:32:47 +0100
- Subject: [PATCH, testsuite] Fix gdb.mi/mi-var-rtti.exp failures
- Authentication-results: sourceware.org; auth=none
- Reply-to: <lgustavo at codesourcery dot com>
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 <lgustavo@codesourcery.com>
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"