OLD | NEW |
1 # Copyright 2007-2012 Free Software Foundation, Inc. | 1 # Copyright 2007-2012 Free Software Foundation, Inc. |
2 # | 2 # |
3 # This program is free software; you can redistribute it and/or modify | 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 | 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 | 5 # the Free Software Foundation; either version 3 of the License, or |
6 # (at your option) any later version. | 6 # (at your option) any later version. |
7 # | 7 # |
8 # This program is distributed in the hope that it will be useful, | 8 # This program is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
12 # | 12 # |
13 # You should have received a copy of the GNU General Public License | 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/>. | 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
16 # Author: P. N. Hilfinger, AdaCore, Inc. | 16 # Author: P. N. Hilfinger, AdaCore, Inc. |
17 | 17 |
18 # This test checks the behavior of formatted print when applied to a | 18 # This test checks the behavior of formatted print when applied to a |
19 # reference value. The intended behavior is that a formatted print of | 19 # reference value. The intended behavior is that a formatted print of |
20 # such a value should display the same value as a plain print, | 20 # such a value should display the same value as a plain print, |
21 # modulo format, of course. Older versions of GDB would instead print | 21 # modulo format, of course. Older versions of GDB would instead print |
22 # the reference's address value itself when doing a formatted print, | 22 # the reference's address value itself when doing a formatted print, |
23 # rather than printing both that and the dereferenced value. We also | 23 # rather than printing both that and the dereferenced value. We also |
24 # check that the (non-standard) expression &(&x), where x is of type T&, | 24 # check that the (non-standard) expression &(&x), where x is of type T&, |
25 # yields an appropriate value. | 25 # yields an appropriate value. |
26 # This also tests that some other arithmetic operations on references | 26 # This also tests that some other arithmetic operations on references |
27 # work properly: condition expression using a reference object as one of its | 27 # work properly: condition expression using a reference object as one of its |
28 # operand. | 28 # operand. |
29 | 29 |
30 if $tracelevel then { | |
31 strace $tracelevel | |
32 } | |
33 | |
34 | 30 |
35 if { [skip_cplus_tests] } { continue } | 31 if { [skip_cplus_tests] } { continue } |
36 | 32 |
37 set testfile "formatted-ref" | 33 standard_testfile .cc |
38 set srcfile ${testfile}.cc | |
39 set binfile ${objdir}/${subdir}/${testfile} | |
40 | 34 |
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
ug c++}] != "" } { | 35 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { |
42 untested formatted-ref.exp | 36 return -1 |
43 return -1 | |
44 } | 37 } |
45 | 38 |
46 proc get_address { var } { | 39 proc get_address { var } { |
47 global expect_out | 40 global expect_out |
48 global gdb_prompt | 41 global gdb_prompt |
49 | 42 |
50 gdb_test_multiple "print &$var" "find address of $var" { | 43 gdb_test_multiple "print &$var" "find address of $var" { |
51 -re "\\$\[0-9\]+ = \\(.*\\) (0x\[0-9a-f\]+).*$gdb_prompt $" { | 44 -re "\\$\[0-9\]+ = \\(.*\\) (0x\[0-9a-f\]+).*$gdb_prompt $" { |
52 return $expect_out(1,string) | 45 return $expect_out(1,string) |
53 } | 46 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 103 } |
111 } | 104 } |
112 return 0 | 105 return 0 |
113 } | 106 } |
114 | 107 |
115 proc test_p_op1_equals_op2 {op1 op2} { | 108 proc test_p_op1_equals_op2 {op1 op2} { |
116 set test "print $op1 == $op2" | 109 set test "print $op1 == $op2" |
117 gdb_test $test "\\$\[0-9\]+ = true" | 110 gdb_test $test "\\$\[0-9\]+ = true" |
118 } | 111 } |
119 | 112 |
120 gdb_exit | |
121 gdb_start | |
122 gdb_reinitialize_dir $srcdir/$subdir | |
123 gdb_load ${binfile} | |
124 | |
125 runto ${srcfile}:[gdb_get_line_number "marker here"] | 113 runto ${srcfile}:[gdb_get_line_number "marker here"] |
126 | 114 |
127 set s1_address [get_address "s1"] | 115 set s1_address [get_address "s1"] |
128 set e1_address [get_address "e1"] | 116 set e1_address [get_address "e1"] |
129 set i1_address [get_address "i1"] | 117 set i1_address [get_address "i1"] |
130 | 118 |
131 test_p_x "s" "Struct1 &" "{x = 0xd, y = 0x13}" $s1_address | 119 test_p_x "s" "Struct1 &" "{x = 0xd, y = 0x13}" $s1_address |
132 test_p_x "e" "Enum1 &" "0xb" $e1_address | 120 test_p_x "e" "Enum1 &" "0xb" $e1_address |
133 test_p_x "i" "int &" "0x17" $i1_address | 121 test_p_x "i" "int &" "0x17" $i1_address |
134 | 122 |
135 test_p_x_addr "s" $s1_address | 123 test_p_x_addr "s" $s1_address |
136 test_p_x_addr "e" $e1_address | 124 test_p_x_addr "e" $e1_address |
137 test_p_x_addr "i" $i1_address | 125 test_p_x_addr "i" $i1_address |
138 | 126 |
139 test_p_x_ref_addr "s" $s1_address | 127 test_p_x_ref_addr "s" $s1_address |
140 test_p_x_ref_addr "i" $i1_address | 128 test_p_x_ref_addr "i" $i1_address |
141 test_p_x_ref_addr "e" $e1_address | 129 test_p_x_ref_addr "e" $e1_address |
142 | 130 |
143 test_p_op1_equals_op2 "s.x" "13" | 131 test_p_op1_equals_op2 "s.x" "13" |
OLD | NEW |