1 # Copyright 2003-2024 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/>.
16 require allow_cplus_tests
21 set flags [list debug c++]
22 # When using recent Clangs, this test fails to compile without this warning
23 # being disabled. However, older Clangs fail to recognize the flag.
24 if { [gcc_major_version "clang-*" "c++"] > 10 } {
25 lappend flags additional_flags=-Wno-non-c-typedef-for-linkage
28 if {[prepare_for_testing "failed to prepare" $testfile $srcfile $flags]} {
32 # Start with "set print object off" and "set print symbol off".
34 gdb_test_no_output "set print object off"
35 gdb_test_no_output "set print symbol off"
43 gdb_test "break [gdb_get_line_number "marker return 0"]" \
44 "Breakpoint.*at.* file .*" ""
46 gdb_test "continue" "Breakpoint .* at .*" ""
48 # Access the "A" object.
50 gdb_test "print alpha" \
52 "print alpha at marker return 0"
54 # Access the "B" object.
56 gdb_test "print beta" \
57 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
58 "print beta at marker return 0"
60 # Access the "A" object through an "A *" pointer.
62 gdb_test_multiple "print * aap" "print * aap at marker return 0" {
63 -re "= {.*a1 = 100.*}\r\n$gdb_prompt $" {
67 pass "print * aap at marker return 0"
69 -re "= {.*a1 = .*}\r\n$gdb_prompt $" {
70 if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF \[0-9\]"] } {
71 # gcc 2.95.3 -gdwarf-2
72 setup_kfail "gdb/1465" "*-*-*"
74 fail "print * aap at marker return 0"
78 # Access the "B" object through a "B *" pointer.
80 gdb_test "print * bbp" \
81 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
82 "print * bbp at marker return 0"
84 # Access the "B" object through an "A *" pointer.
85 # This should print using the "A" type.
87 gdb_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"
92 -re "= {.*a1 = 200.*}\r\n$gdb_prompt $" {
93 pass "print * abp at marker return 0, s-p-o off"
97 # Access the "B" object through a "B *" pointer expression.
98 # This should print using the "B" type.
100 gdb_test "print * (B *) abp" \
101 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
102 "print * (B *) abp at marker return 0"
104 # Print the "D" object.
106 gdb_test "print delta" \
108 "print delta with \"print object\" off"
110 # Printing the value of an object containing no data fields:
112 gdb_test "p e" "= \{<No data fields>\}" "print object with no data fields"
114 # Printing NULL pointers with "set print object on".
116 gdb_test_no_output "set print object on"
117 gdb_test "p acp" "= \\(C \\*\\) ${hex}"
118 gdb_test "p acp->c1" "\\(A \\*\\) 0x0"
119 gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f"
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.
125 gdb_test "print delta" \
127 "print delta with \"print object\" on"
129 # Regression test for PR c++/15401.
130 # Check that the type printed is a reference.
131 gdb_test "p aref" " = \\(A \\&\\) .*"