PR gold/14309
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / class2.exp
CommitLineData
0b302171 1# Copyright 2003-2004, 2007-2012 Free Software Foundation, Inc.
f4e8b6f3
MC
2
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
f4e8b6f3 6# (at your option) any later version.
e22f8b7c 7#
f4e8b6f3
MC
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.
e22f8b7c 12#
f4e8b6f3 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
f4e8b6f3 15
f4e8b6f3
MC
16if { [skip_cplus_tests] } { continue }
17
f4e8b6f3
MC
18
19set testfile "class2"
20set srcfile ${testfile}.cc
21set binfile ${objdir}/${subdir}/${testfile}
22
23# Create and source the file that provides information about the compiler
24# used to compile the test case.
4c93b1db 25if [get_compiler_info "c++"] {
f4e8b6f3
MC
26 return -1
27}
28
29if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
30 untested class2.exp
31 return -1
f4e8b6f3
MC
32}
33
34gdb_exit
35gdb_start
36gdb_reinitialize_dir $srcdir/$subdir
37gdb_load ${binfile}
38
39# Start with "set print object off".
40
a8d52276 41gdb_test_no_output "set print object off"
f4e8b6f3
MC
42
43if ![runto_main] then {
44 perror "couldn't run to main"
45 continue
46}
47
48get_debug_format
49
50gdb_test "break [gdb_get_line_number "marker return 0"]" \
51 "Breakpoint.*at.* file .*" ""
52
53gdb_test "continue" "Breakpoint .* at .*" ""
54
55# Access the "A" object.
56
57gdb_test "print alpha" \
58 "= {.*a1 = 100.*}" \
59 "print alpha at marker return 0"
60
61# Access the "B" object.
62
63gdb_test "print beta" \
64 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
65 "print beta at marker return 0"
66
67# Access the "A" object through an "A *" pointer.
68
69gdb_test_multiple "print * aap" "print * aap at marker return 0" {
70 -re "= {.*a1 = 100.*}\r\n$gdb_prompt $" {
71 # gcc 2.95.3 -gstabs+
72 # gcc 3.3.2 -gdwarf-2
73 # gcc 3.3.2 -gstabs+
74 pass "print * aap at marker return 0"
75 }
76 -re "= {.*a1 = .*}\r\n$gdb_prompt $" {
77 if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } {
78 # gcc 2.95.3 -gdwarf-2
79 setup_kfail "gdb/1465" "*-*-*"
80 }
81 fail "print * aap at marker return 0"
82 }
83}
84
85# Access the "B" object through a "B *" pointer.
86
87gdb_test "print * bbp" \
88 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
89 "print * bbp at marker return 0"
90
91# Access the "B" object through an "A *" pointer.
92# This should print using the "A" type.
93
94gdb_test_multiple "print * abp" "print * abp at marker return 0, s-p-o off" {
95 -re "= {.*a1 = 200.*b1 = .*b2 = .*}\r\n$gdb_prompt $" {
96 # This would violate the documentation for "set print object off".
97 fail "print * abp at marker return 0, s-p-o off"
98 }
99 -re "= {.*a1 = 200.*}\r\n$gdb_prompt $" {
100 pass "print * abp at marker return 0, s-p-o off"
101 }
102}
103
104# Access the "B" object through a "B *" pointer expression.
105# This should print using the "B" type.
106
107gdb_test "print * (B *) abp" \
108 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
109 "print * (B *) abp at marker return 0"
98f9cd2d
JB
110
111# Printing the value of an object containing no data fields:
112
113gdb_test "p e" "= \{<No data fields>\}" "print object with no data fields"
7093c834
PP
114
115# Printing NULL pointers with "set print object on"
116
a8d52276 117gdb_test_no_output "set print object on"
0709f7d3 118gdb_test "p acp" "= \\(C \\*\\) ${hex}"
7093c834 119gdb_test "p acp->c1" "\\(A \\*\\) 0x0"
0709f7d3 120gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f"
This page took 0.827878 seconds and 4 git commands to generate.