1 # Copyright 2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if { [skip_cplus_tests] } { continue }
24 set srcfile ${testfile}.cc
25 set binfile ${objdir}/${subdir}/${testfile}
27 # Create and source the file that provides information about the compiler
28 # used to compile the test case.
29 if [get_compiler_info ${binfile} "c++"] {
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
40 gdb_reinitialize_dir $srcdir/$subdir
43 # Start with "set print object off".
45 gdb_test_no_output "set print object off"
47 if ![runto_main] then {
48 perror "couldn't run to main"
54 gdb_test "break [gdb_get_line_number "marker return 0"]" \
55 "Breakpoint.*at.* file .*" ""
57 gdb_test "continue" "Breakpoint .* at .*" ""
59 # Access the "A" object.
61 gdb_test "print alpha" \
63 "print alpha at marker return 0"
65 # Access the "B" object.
67 gdb_test "print beta" \
68 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
69 "print beta at marker return 0"
71 # Access the "A" object through an "A *" pointer.
73 gdb_test_multiple "print * aap" "print * aap at marker return 0" {
74 -re "= {.*a1 = 100.*}\r\n$gdb_prompt $" {
78 pass "print * aap at marker return 0"
80 -re "= {.*a1 = .*}\r\n$gdb_prompt $" {
81 if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } {
82 # gcc 2.95.3 -gdwarf-2
83 setup_kfail "gdb/1465" "*-*-*"
85 fail "print * aap at marker return 0"
89 # Access the "B" object through a "B *" pointer.
91 gdb_test "print * bbp" \
92 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
93 "print * bbp at marker return 0"
95 # Access the "B" object through an "A *" pointer.
96 # This should print using the "A" type.
98 gdb_test_multiple "print * abp" "print * abp at marker return 0, s-p-o off" {
99 -re "= {.*a1 = 200.*b1 = .*b2 = .*}\r\n$gdb_prompt $" {
100 # This would violate the documentation for "set print object off".
101 fail "print * abp at marker return 0, s-p-o off"
103 -re "= {.*a1 = 200.*}\r\n$gdb_prompt $" {
104 pass "print * abp at marker return 0, s-p-o off"
108 # Access the "B" object through a "B *" pointer expression.
109 # This should print using the "B" type.
111 gdb_test "print * (B *) abp" \
112 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
113 "print * (B *) abp at marker return 0"
115 # Printing the value of an object containing no data fields:
117 gdb_test "p e" "= \{<No data fields>\}" "print object with no data fields"
119 # Printing NULL pointers with "set print object on"
121 gdb_test_no_output "set print object on"
122 gdb_test "p acp" "= \\(C \\*\\) ${hex}"
123 gdb_test "p acp->c1" "\\(A \\*\\) 0x0"
124 gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f"