1*b725ae77Skettenis# Copyright 2003, 2004 Free Software Foundation, Inc. 2*b725ae77Skettenis 3*b725ae77Skettenis# This program is free software; you can redistribute it and/or modify 4*b725ae77Skettenis# it under the terms of the GNU General Public License as published by 5*b725ae77Skettenis# the Free Software Foundation; either version 2 of the License, or 6*b725ae77Skettenis# (at your option) any later version. 7*b725ae77Skettenis# 8*b725ae77Skettenis# This program is distributed in the hope that it will be useful, 9*b725ae77Skettenis# but WITHOUT ANY WARRANTY; without even the implied warranty of 10*b725ae77Skettenis# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11*b725ae77Skettenis# GNU General Public License for more details. 12*b725ae77Skettenis# 13*b725ae77Skettenis# You should have received a copy of the GNU General Public License 14*b725ae77Skettenis# along with this program; if not, write to the Free Software 15*b725ae77Skettenis# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16*b725ae77Skettenis 17*b725ae77Skettenisif $tracelevel then { 18*b725ae77Skettenis strace $tracelevel 19*b725ae77Skettenis } 20*b725ae77Skettenis 21*b725ae77Skettenisif { [skip_cplus_tests] } { continue } 22*b725ae77Skettenis 23*b725ae77Skettenisset prms_id 0 24*b725ae77Skettenisset bug_id 0 25*b725ae77Skettenis 26*b725ae77Skettenisset testfile "class2" 27*b725ae77Skettenisset srcfile ${testfile}.cc 28*b725ae77Skettenisset binfile ${objdir}/${subdir}/${testfile} 29*b725ae77Skettenis 30*b725ae77Skettenis# Create and source the file that provides information about the compiler 31*b725ae77Skettenis# used to compile the test case. 32*b725ae77Skettenisif [get_compiler_info ${binfile} "c++"] { 33*b725ae77Skettenis return -1 34*b725ae77Skettenis} 35*b725ae77Skettenis 36*b725ae77Skettenisif { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { 37*b725ae77Skettenis gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 38*b725ae77Skettenis} 39*b725ae77Skettenis 40*b725ae77Skettenisgdb_exit 41*b725ae77Skettenisgdb_start 42*b725ae77Skettenisgdb_reinitialize_dir $srcdir/$subdir 43*b725ae77Skettenisgdb_load ${binfile} 44*b725ae77Skettenis 45*b725ae77Skettenis# Start with "set print object off". 46*b725ae77Skettenis 47*b725ae77Skettenisgdb_test "set print object off" "" 48*b725ae77Skettenis 49*b725ae77Skettenisif ![runto_main] then { 50*b725ae77Skettenis perror "couldn't run to main" 51*b725ae77Skettenis continue 52*b725ae77Skettenis} 53*b725ae77Skettenis 54*b725ae77Skettenisget_debug_format 55*b725ae77Skettenis 56*b725ae77Skettenisgdb_test "break [gdb_get_line_number "marker return 0"]" \ 57*b725ae77Skettenis "Breakpoint.*at.* file .*" "" 58*b725ae77Skettenis 59*b725ae77Skettenisgdb_test "continue" "Breakpoint .* at .*" "" 60*b725ae77Skettenis 61*b725ae77Skettenis# Access the "A" object. 62*b725ae77Skettenis 63*b725ae77Skettenisgdb_test "print alpha" \ 64*b725ae77Skettenis "= {.*a1 = 100.*}" \ 65*b725ae77Skettenis "print alpha at marker return 0" 66*b725ae77Skettenis 67*b725ae77Skettenis# Access the "B" object. 68*b725ae77Skettenis 69*b725ae77Skettenisgdb_test "print beta" \ 70*b725ae77Skettenis "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \ 71*b725ae77Skettenis "print beta at marker return 0" 72*b725ae77Skettenis 73*b725ae77Skettenis# Access the "A" object through an "A *" pointer. 74*b725ae77Skettenis 75*b725ae77Skettenisgdb_test_multiple "print * aap" "print * aap at marker return 0" { 76*b725ae77Skettenis -re "= {.*a1 = 100.*}\r\n$gdb_prompt $" { 77*b725ae77Skettenis # gcc 2.95.3 -gstabs+ 78*b725ae77Skettenis # gcc 3.3.2 -gdwarf-2 79*b725ae77Skettenis # gcc 3.3.2 -gstabs+ 80*b725ae77Skettenis pass "print * aap at marker return 0" 81*b725ae77Skettenis } 82*b725ae77Skettenis -re "= {.*a1 = .*}\r\n$gdb_prompt $" { 83*b725ae77Skettenis if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } { 84*b725ae77Skettenis # gcc 2.95.3 -gdwarf-2 85*b725ae77Skettenis setup_kfail "gdb/1465" "*-*-*" 86*b725ae77Skettenis } 87*b725ae77Skettenis fail "print * aap at marker return 0" 88*b725ae77Skettenis } 89*b725ae77Skettenis} 90*b725ae77Skettenis 91*b725ae77Skettenis# Access the "B" object through a "B *" pointer. 92*b725ae77Skettenis 93*b725ae77Skettenisgdb_test "print * bbp" \ 94*b725ae77Skettenis "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \ 95*b725ae77Skettenis "print * bbp at marker return 0" 96*b725ae77Skettenis 97*b725ae77Skettenis# Access the "B" object through an "A *" pointer. 98*b725ae77Skettenis# This should print using the "A" type. 99*b725ae77Skettenis 100*b725ae77Skettenisgdb_test_multiple "print * abp" "print * abp at marker return 0, s-p-o off" { 101*b725ae77Skettenis -re "= {.*a1 = 200.*b1 = .*b2 = .*}\r\n$gdb_prompt $" { 102*b725ae77Skettenis # This would violate the documentation for "set print object off". 103*b725ae77Skettenis fail "print * abp at marker return 0, s-p-o off" 104*b725ae77Skettenis } 105*b725ae77Skettenis -re "= {.*a1 = 200.*}\r\n$gdb_prompt $" { 106*b725ae77Skettenis pass "print * abp at marker return 0, s-p-o off" 107*b725ae77Skettenis } 108*b725ae77Skettenis} 109*b725ae77Skettenis 110*b725ae77Skettenis# Access the "B" object through a "B *" pointer expression. 111*b725ae77Skettenis# This should print using the "B" type. 112*b725ae77Skettenis 113*b725ae77Skettenisgdb_test "print * (B *) abp" \ 114*b725ae77Skettenis "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \ 115*b725ae77Skettenis "print * (B *) abp at marker return 0" 116*b725ae77Skettenis 117*b725ae77Skettenis# Printing the value of an object containing no data fields: 118*b725ae77Skettenis 119*b725ae77Skettenisgdb_test "p e" "= \{<No data fields>\}" "print object with no data fields" 120