Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / class2.exp
CommitLineData
88b9d363 1# Copyright 2003-2022 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 18
f5f3a911 19standard_testfile .cc
f4e8b6f3
MC
20
21# Create and source the file that provides information about the compiler
22# used to compile the test case.
4c93b1db 23if [get_compiler_info "c++"] {
f4e8b6f3
MC
24 return -1
25}
26
5b362f04 27if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
b60f0898 28 return -1
f4e8b6f3
MC
29}
30
775e0f04 31# Start with "set print object off" and "set print symbol off".
f4e8b6f3 32
a8d52276 33gdb_test_no_output "set print object off"
775e0f04 34gdb_test_no_output "set print symbol off"
f4e8b6f3
MC
35
36if ![runto_main] then {
37 perror "couldn't run to main"
38 continue
39}
40
41get_debug_format
42
43gdb_test "break [gdb_get_line_number "marker return 0"]" \
44 "Breakpoint.*at.* file .*" ""
45
46gdb_test "continue" "Breakpoint .* at .*" ""
47
48# Access the "A" object.
49
50gdb_test "print alpha" \
51 "= {.*a1 = 100.*}" \
52 "print alpha at marker return 0"
53
54# Access the "B" object.
55
56gdb_test "print beta" \
57 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
58 "print beta at marker return 0"
59
60# Access the "A" object through an "A *" pointer.
61
62gdb_test_multiple "print * aap" "print * aap at marker return 0" {
63 -re "= {.*a1 = 100.*}\r\n$gdb_prompt $" {
64 # gcc 2.95.3 -gstabs+
65 # gcc 3.3.2 -gdwarf-2
66 # gcc 3.3.2 -gstabs+
67 pass "print * aap at marker return 0"
68 }
69 -re "= {.*a1 = .*}\r\n$gdb_prompt $" {
70 if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } {
71 # gcc 2.95.3 -gdwarf-2
72 setup_kfail "gdb/1465" "*-*-*"
73 }
74 fail "print * aap at marker return 0"
75 }
76}
77
78# Access the "B" object through a "B *" pointer.
79
80gdb_test "print * bbp" \
81 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
82 "print * bbp at marker return 0"
83
84# Access the "B" object through an "A *" pointer.
85# This should print using the "A" type.
86
87gdb_test_multiple "print * abp" "print * abp at marker return 0, s-p-o off" {
88 -re "= {.*a1 = 200.*b1 = .*b2 = .*}\r\n$gdb_prompt $" {
89 # This would violate the documentation for "set print object off".
90 fail "print * abp at marker return 0, s-p-o off"
91 }
92 -re "= {.*a1 = 200.*}\r\n$gdb_prompt $" {
93 pass "print * abp at marker return 0, s-p-o off"
94 }
95}
96
97# Access the "B" object through a "B *" pointer expression.
98# This should print using the "B" type.
99
100gdb_test "print * (B *) abp" \
101 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
102 "print * (B *) abp at marker return 0"
98f9cd2d 103
0def5aaa
DE
104# Print the "D" object.
105
106gdb_test "print delta" \
107 "= {.*d1 = 400}" \
108 "print delta with \"print object\" off"
109
98f9cd2d
JB
110# Printing the value of an object containing no data fields:
111
112gdb_test "p e" "= \{<No data fields>\}" "print object with no data fields"
7093c834 113
0def5aaa 114# Printing NULL pointers with "set print object on".
7093c834 115
a8d52276 116gdb_test_no_output "set print object on"
0709f7d3 117gdb_test "p acp" "= \\(C \\*\\) ${hex}"
7093c834 118gdb_test "p acp->c1" "\\(A \\*\\) 0x0"
0709f7d3 119gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f"
5f2e6b00 120
0def5aaa
DE
121# Print the "D" object with "set print object on".
122# There's no difference in output, but this exercises vtable lookup
123# with a typedef'd baseclass.
124
125gdb_test "print delta" \
126 "= {.*d1 = 400}" \
127 "print delta with \"print object\" on"
128
5f2e6b00
TT
129# Regression test for PR c++/15401.
130# Check that the type printed is a reference.
131gdb_test "p aref" " = \\(A \\&\\) .*"
This page took 2.138831 seconds and 4 git commands to generate.