Commit | Line | Data |
---|---|---|
0fb0cc75 | 1 | # Copyright 2003, 2004, 2007, 2008, 2009 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 MC |
15 | |
16 | if $tracelevel then { | |
17 | strace $tracelevel | |
18 | } | |
19 | ||
20 | if { [skip_cplus_tests] } { continue } | |
21 | ||
22 | set prms_id 0 | |
23 | set bug_id 0 | |
24 | ||
25 | set testfile "class2" | |
26 | set srcfile ${testfile}.cc | |
27 | set binfile ${objdir}/${subdir}/${testfile} | |
28 | ||
29 | # Create and source the file that provides information about the compiler | |
30 | # used to compile the test case. | |
31 | if [get_compiler_info ${binfile} "c++"] { | |
32 | return -1 | |
33 | } | |
34 | ||
35 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
b60f0898 JB |
36 | untested class2.exp |
37 | return -1 | |
f4e8b6f3 MC |
38 | } |
39 | ||
40 | gdb_exit | |
41 | gdb_start | |
42 | gdb_reinitialize_dir $srcdir/$subdir | |
43 | gdb_load ${binfile} | |
44 | ||
45 | # Start with "set print object off". | |
46 | ||
47 | gdb_test "set print object off" "" | |
48 | ||
49 | if ![runto_main] then { | |
50 | perror "couldn't run to main" | |
51 | continue | |
52 | } | |
53 | ||
54 | get_debug_format | |
55 | ||
56 | gdb_test "break [gdb_get_line_number "marker return 0"]" \ | |
57 | "Breakpoint.*at.* file .*" "" | |
58 | ||
59 | gdb_test "continue" "Breakpoint .* at .*" "" | |
60 | ||
61 | # Access the "A" object. | |
62 | ||
63 | gdb_test "print alpha" \ | |
64 | "= {.*a1 = 100.*}" \ | |
65 | "print alpha at marker return 0" | |
66 | ||
67 | # Access the "B" object. | |
68 | ||
69 | gdb_test "print beta" \ | |
70 | "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \ | |
71 | "print beta at marker return 0" | |
72 | ||
73 | # Access the "A" object through an "A *" pointer. | |
74 | ||
75 | gdb_test_multiple "print * aap" "print * aap at marker return 0" { | |
76 | -re "= {.*a1 = 100.*}\r\n$gdb_prompt $" { | |
77 | # gcc 2.95.3 -gstabs+ | |
78 | # gcc 3.3.2 -gdwarf-2 | |
79 | # gcc 3.3.2 -gstabs+ | |
80 | pass "print * aap at marker return 0" | |
81 | } | |
82 | -re "= {.*a1 = .*}\r\n$gdb_prompt $" { | |
83 | if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } { | |
84 | # gcc 2.95.3 -gdwarf-2 | |
85 | setup_kfail "gdb/1465" "*-*-*" | |
86 | } | |
87 | fail "print * aap at marker return 0" | |
88 | } | |
89 | } | |
90 | ||
91 | # Access the "B" object through a "B *" pointer. | |
92 | ||
93 | gdb_test "print * bbp" \ | |
94 | "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \ | |
95 | "print * bbp at marker return 0" | |
96 | ||
97 | # Access the "B" object through an "A *" pointer. | |
98 | # This should print using the "A" type. | |
99 | ||
100 | gdb_test_multiple "print * abp" "print * abp at marker return 0, s-p-o off" { | |
101 | -re "= {.*a1 = 200.*b1 = .*b2 = .*}\r\n$gdb_prompt $" { | |
102 | # This would violate the documentation for "set print object off". | |
103 | fail "print * abp at marker return 0, s-p-o off" | |
104 | } | |
105 | -re "= {.*a1 = 200.*}\r\n$gdb_prompt $" { | |
106 | pass "print * abp at marker return 0, s-p-o off" | |
107 | } | |
108 | } | |
109 | ||
110 | # Access the "B" object through a "B *" pointer expression. | |
111 | # This should print using the "B" type. | |
112 | ||
113 | gdb_test "print * (B *) abp" \ | |
114 | "= {.*a1 = 200.*b1 = 201.*b2 = 202}" \ | |
115 | "print * (B *) abp at marker return 0" | |
98f9cd2d JB |
116 | |
117 | # Printing the value of an object containing no data fields: | |
118 | ||
119 | gdb_test "p e" "= \{<No data fields>\}" "print object with no data fields" | |
7093c834 PP |
120 | |
121 | # Printing NULL pointers with "set print object on" | |
122 | ||
123 | gdb_test "set print object on" "" | |
0709f7d3 | 124 | gdb_test "p acp" "= \\(C \\*\\) ${hex}" |
7093c834 | 125 | gdb_test "p acp->c1" "\\(A \\*\\) 0x0" |
0709f7d3 | 126 | gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f" |