]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/class2.exp
00b632208e51a31219bc7f11269e9bc2445c6961
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / class2.exp
1 # Copyright 2003-2013 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
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/>.
15
16 if { [skip_cplus_tests] } { continue }
17
18
19 standard_testfile .cc
20
21 # Create and source the file that provides information about the compiler
22 # used to compile the test case.
23 if [get_compiler_info "c++"] {
24 return -1
25 }
26
27 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
28 return -1
29 }
30
31 # Start with "set print object off".
32
33 gdb_test_no_output "set print object off"
34
35 if ![runto_main] then {
36 perror "couldn't run to main"
37 continue
38 }
39
40 get_debug_format
41
42 gdb_test "break [gdb_get_line_number "marker return 0"]" \
43 "Breakpoint.*at.* file .*" ""
44
45 gdb_test "continue" "Breakpoint .* at .*" ""
46
47 # Access the "A" object.
48
49 gdb_test "print alpha" \
50 "= {.*a1 = 100.*}" \
51 "print alpha at marker return 0"
52
53 # Access the "B" object.
54
55 gdb_test "print beta" \
56 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
57 "print beta at marker return 0"
58
59 # Access the "A" object through an "A *" pointer.
60
61 gdb_test_multiple "print * aap" "print * aap at marker return 0" {
62 -re "= {.*a1 = 100.*}\r\n$gdb_prompt $" {
63 # gcc 2.95.3 -gstabs+
64 # gcc 3.3.2 -gdwarf-2
65 # gcc 3.3.2 -gstabs+
66 pass "print * aap at marker return 0"
67 }
68 -re "= {.*a1 = .*}\r\n$gdb_prompt $" {
69 if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } {
70 # gcc 2.95.3 -gdwarf-2
71 setup_kfail "gdb/1465" "*-*-*"
72 }
73 fail "print * aap at marker return 0"
74 }
75 }
76
77 # Access the "B" object through a "B *" pointer.
78
79 gdb_test "print * bbp" \
80 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
81 "print * bbp at marker return 0"
82
83 # Access the "B" object through an "A *" pointer.
84 # This should print using the "A" type.
85
86 gdb_test_multiple "print * abp" "print * abp at marker return 0, s-p-o off" {
87 -re "= {.*a1 = 200.*b1 = .*b2 = .*}\r\n$gdb_prompt $" {
88 # This would violate the documentation for "set print object off".
89 fail "print * abp at marker return 0, s-p-o off"
90 }
91 -re "= {.*a1 = 200.*}\r\n$gdb_prompt $" {
92 pass "print * abp at marker return 0, s-p-o off"
93 }
94 }
95
96 # Access the "B" object through a "B *" pointer expression.
97 # This should print using the "B" type.
98
99 gdb_test "print * (B *) abp" \
100 "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \
101 "print * (B *) abp at marker return 0"
102
103 # Printing the value of an object containing no data fields:
104
105 gdb_test "p e" "= \{<No data fields>\}" "print object with no data fields"
106
107 # Printing NULL pointers with "set print object on"
108
109 gdb_test_no_output "set print object on"
110 gdb_test "p acp" "= \\(C \\*\\) ${hex}"
111 gdb_test "p acp->c1" "\\(A \\*\\) 0x0"
112 gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f"
113
114 # Regression test for PR c++/15401.
115 # Check that the type printed is a reference.
116 gdb_test "p aref" " = \\(A \\&\\) .*"