# Copyright 2003 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # This file was written by Jim Ingham <jingham@apple.com> # This file tests some aspects of the APPLE LOCAL var-path-expression # commands, particularly with classes & base classes. # This file is part of the gdb testsuite load_lib mi-support.exp set MIFLAGS "-i=mi1" if $tracelevel then { strace $tracelevel } gdb_exit if [mi_gdb_start] { continue } set notQuote {\[^"\]*} proc compare_var_and_expression {varObj value {type {}} {typecode {}}} { global expect_out hex notQuote if {[string equal $type ""]} { set type $notQuote } if {[string equal $typecode ""]} { set typecode $notQuote } mi_gdb_test "-var-evaluate-expression $varObj" \ "\\^done,value=(\"$value\")" \ "get the value of $varObj" set originalValue $expect_out(2,string) mi_gdb_test "-var-info-path-expression $varObj" \ {\^done,path_expr=("[^"]*")} \ "get path expression for $varObj" set expression $expect_out(2,string) mi_gdb_test "-var-create - * $expression" \ "\\^done,name=\"(\[^\"\]*)\",numchild=\"0\",type=\"$type\",typecode=\"$typecode\",dynamic_type=\"\[^\"\]*\",resolved_type=\"$type\",in_scope=\"true\",block_start_addr=\"$hex\",block_end_addr=\"$hex\"" \ "Create varobj for $varObj expression" set exprVar $expect_out(2,string) mi_gdb_test "-var-evaluate-expression $exprVar" \ "\\^done,value=(\"$value\")" \ "Get value for $varObj expression" set exprValue $expect_out(2,string) if {[string equal $originalValue $exprValue]} { pass "varobj and expression have same value for $varObj" } else { fail "varobj and expression have same value for $varObj" } } set testfile "var-path-expr" set srcfile ${testfile}.cpp set binfile ${objdir}/${subdir}/${testfile} if { [gdb_compile "$srcdir/$subdir/$srcfile" "${binfile}" executable {debug c++}] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." } mi_delete_breakpoints mi_gdb_reinitialize_dir $srcdir/$subdir mi_gdb_load ${binfile} mi_run_to_main set lineNum 99 mi_gdb_test "-break-insert $lineNum" \ "\\^done,bkpt=\{number=\"$decimal\",.*func=\"main\",.*file=\".*$srcfile\".*\}" \ "breakpoint in main after all the work's done" mi_continue_to 2 main {} var-path-expr.cpp $lineNum {run to break in main} # In this section we drill down to a class member that is a polymorphic object, and make sure # we can print a member from the real dynamic type of the object. mi_gdb_test {-var-create fooVar * myFoo} \ {\^done,name="fooVar",.*numchild="1",.*type="Foo".*} \ "create varobj for fooVar" mi_gdb_test {-var-list-children fooVar} \ {\^done,numchild="1",children=\[child={name="fooVar.private",.*exp="private",.*type="",typecode="FAKE_CHILD",.*dynamic_type="",resolved_type=""}\]} \ "list children of fooVar" mi_gdb_test {-var-list-children fooVar.private} \ {\^done,numchild="1",children=\[child={name="fooVar.private.contents",exp="contents",numchild="2",type="Container \*",typecode="PTR",dynamic_type="FancyIntContainer \*",resolved_type="Container \*"}\]} \ "list children of fooVar.private" mi_gdb_test {-var-list-children fooVar.private.contents} \ {\^done,numchild="2",children=\[child={name="fooVar.private.contents.IntContainer",exp="IntContainer",numchild="3",type="IntContainer \*",typecode="PTR",dynamic_type="",resolved_type="IntContainer \*"},child={name="fooVar.private.contents.private",exp="private",numchild="1",type="",typecode="FAKE_CHILD",dynamic_type="",resolved_type=""}\]} \ "list children of fooVar.private.contents" mi_gdb_test {-var-list-children fooVar.private.contents.private} \ {\^done,numchild="1",children=\[child={name="fooVar.private.contents.private.multiplier",exp="multiplier",numchild="0",type="int",typecode="INT",dynamic_type="",resolved_type="int"}\]} \ "list children of fooVar.private.contents.private" compare_var_and_expression fooVar.private.contents.private.multiplier 10 int INT # Now we'll look at the base classes of this polymorphic object, and make sure we get the expressions # for them right as well. mi_gdb_test {-var-list-children fooVar.private.contents.IntContainer} \ {\^done,numchild="3",children=\[child={name="fooVar.private.contents.IntContainer.Container",exp="Container",numchild="1",type="Container \*",typecode="PTR",dynamic_type="",resolved_type="Container \*"},child={name="fooVar.private.contents.IntContainer.SomeOtherStuff",exp="SomeOtherStuff",numchild="1",type="SomeOtherStuff \*",typecode="PTR",dynamic_type="",resolved_type="SomeOtherStuff \*"},child={name="fooVar.private.contents.IntContainer.private",exp="private",numchild="1",type="",typecode="FAKE_CHILD",dynamic_type="",resolved_type=""}\]} \ "Create varobj for IntContainerfooVar.private.contents.IntContainer" mi_gdb_test {-var-list-children fooVar.private.contents.IntContainer.SomeOtherStuff} \ {\^done,numchild="1",children=\[child={name="fooVar.private.contents.IntContainer.SomeOtherStuff.private",exp="private",numchild="2",type="",typecode="FAKE_CHILD",dynamic_type="",resolved_type=""}\]} \ "Create varobj for fooVar.private.contents.IntContainer.SomeOtherStuff" mi_gdb_test {-var-list-children fooVar.private.contents.IntContainer.SomeOtherStuff.private} \ {\^done,numchild="2",children=\[child={name="fooVar.private.contents.IntContainer.SomeOtherStuff.private.myInt",exp="myInt",numchild="0",type="int",typecode="INT",dynamic_type="",resolved_type="int"},child={name="fooVar.private.contents.IntContainer.SomeOtherStuff.private.myDouble",exp="myDouble",numchild="0",type="double",typecode="FLT",dynamic_type="",resolved_type="double"}\]} \ "Create varobj for fooVar.private.contents.IntContainer.SomeOtherStuff.private" compare_var_and_expression fooVar.private.contents.IntContainer.SomeOtherStuff.private.myDouble 5 double FLT # Now chase through the class heirarchy where we have an object, not a pointer to an object. mi_gdb_test {-var-create contVar * myContainer} \ "\\^done,name=\"contVar\",numchild=\"2\",type=\"FancyIntContainer\",typecode=\"STRUCT\",dynamic_type=\"\",resolved_type=\"FancyIntContainer\",in_scope=\"true\",block_start_addr=\"$hex\",block_end_addr=\"$hex\"" \ "Create myContainer varobj" mi_gdb_test {-var-list-children contVar} \ {\^done,numchild="2",children=\[child={name="contVar.IntContainer",exp="IntContainer",numchild="3",type="IntContainer",typecode="STRUCT",dynamic_type="",resolved_type="IntContainer"},child={name="contVar.private",exp="private",numchild="1",type="",typecode="FAKE_CHILD",dynamic_type="",resolved_type=""}\]} \ "List children of contVar" mi_gdb_test {-var-list-children contVar.IntContainer} \ {\^done,numchild="3",children=\[child={name="contVar.IntContainer.Container",exp="Container",numchild="1",type="Container",typecode="STRUCT",dynamic_type="",resolved_type="Container"},child={name="contVar.IntContainer.SomeOtherStuff",exp="SomeOtherStuff",numchild="1",type="SomeOtherStuff",typecode="STRUCT",dynamic_type="",resolved_type="SomeOtherStuff"},child={name="contVar.IntContainer.private",exp="private",numchild="1",type="",typecode="FAKE_CHILD",dynamic_type="",resolved_type=""}\]} \ "List children of contVar.intContainer" mi_gdb_test {-var-list-children contVar.IntContainer.private} \ {\^done,numchild="1",children=\[child={name="contVar.IntContainer.private.intValue",exp="intValue",numchild="0",type="int",typecode="INT",dynamic_type="",resolved_type="int"}\]} \ "List children of contVar.IntContainer.private" compare_var_and_expression contVar.IntContainer.private.intValue 5 int INT mi_gdb_test {-var-list-children contVar.IntContainer.Container} \ {\^done,numchild="1",children=\[child={name="contVar.IntContainer.Container.private",exp="private",numchild="1",type="",typecode="FAKE_CHILD",dynamic_type="",resolved_type=""}\]} \ "List children of contVar.IntContainer.Container" mi_gdb_test {-var-list-children contVar.IntContainer.Container.private} \ {\^done,numchild="1",children=\[child={name="contVar.IntContainer.Container.private.errorNo",exp="errorNo",numchild="0",type="int",typecode="INT",dynamic_type="",resolved_type="int"}\]} \ "List children of contVar.IntContainer.Container.private" compare_var_and_expression contVar.IntContainer.Container.private.errorNo -1 int INT