Update copyright year in most headers.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / formatted-ref.exp
CommitLineData
4c38e0a4 1# Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
8d04f9f0
JB
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# Author: P. N. Hilfinger, AdaCore, Inc.
17
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
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
22# the reference's address value itself when doing a formatted print,
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&,
25# yields an appropriate value.
c332165e
JG
26# This also tests that some other arithmetic operations on references
27# work properly: condition expression using a reference object as one of its
28# operand.
8d04f9f0
JB
29
30if $tracelevel then {
31 strace $tracelevel
32}
33
34set prms_id 0
35set bug_id 0
36
37if { [skip_cplus_tests] } { continue }
38
39set testfile "formatted-ref"
40set srcfile ${testfile}.cc
41set binfile ${objdir}/${subdir}/${testfile}
42
43if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
44 untested formatted-ref.exp
45 return -1
46}
47
48proc get_address { var } {
49 global expect_out
50 global gdb_prompt
51
52 send_gdb "print &$var\n"
53 gdb_expect {
54 -re "\\$\[0-9\]+ = \\(.*\\) (0x\[0-9a-f\]+).*$gdb_prompt $" {
55 return $expect_out(1,string)
56 }
57 timeout {
58 perror "couldn't find address of $var"
59 return ""
60 }
61 }
62}
63
64proc test_p_x { var type val addr } {
65 global gdb_prompt
66
67 set test "print/x $var"
68 gdb_test_multiple $test $test {
69 -re "\\$\[0-9\]+ = \\([string_to_regexp $type]\\) @0x\[a-f0-9\]+: [string_to_regexp $val].*$gdb_prompt $" {
70 pass $test
71 }
72 -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" {
73 fail "$test (prints just address)"
74 }
75 -re "\\$\[0-9\]+ = 0x\[a-f0-9\]+.*$gdb_prompt $" {
76 fail "$test (prints unexpected address)"
77 }
78 }
79 return 0
80}
81
82proc test_p_x_addr { var addr } {
83 global gdb_prompt
84
85 set test "print/x &$var"
86 gdb_test_multiple $test $test {
87 -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" {
88 pass $test
89 }
90 -re "\\$\[0-9\]+ = 0x\[a-f0-9+\]+.*$gdb_prompt $" {
91 fail "$test (prints unexpected address)"
92 }
93 }
94 return 0
95}
96
97proc test_p_x_ref_addr { var addr } {
98 global gdb_prompt
99
100 set test "print/x *(&(&$var))"
101 gdb_test_multiple $test $test {
102 -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" {
103 pass $test
7cbcbded
DJ
104 }
105 -re "Attempt to take address of value not located in memory.*$gdb_prompt $" {
106 # The reference might be in a register. At least we parsed
107 # correctly...
108 pass $test
109 }
8d04f9f0
JB
110 -re "\\$\[0-9\]+ = 0x\[a-f0-9+\]+.*$gdb_prompt $" {
111 fail "$test (prints unexpected address)"
112 }
113 }
114 return 0
115}
116
c332165e
JG
117proc test_p_op1_equals_op2 {op1 op2} {
118 set test "print $op1 == $op2"
119 gdb_test $test "\\$\[0-9\]+ = true"
120}
121
8d04f9f0
JB
122gdb_exit
123gdb_start
124gdb_reinitialize_dir $srcdir/$subdir
125gdb_load ${binfile}
126
127runto ${srcfile}:[gdb_get_line_number "marker here"]
128
129set s1_address [get_address "s1"]
130set e1_address [get_address "e1"]
131set i1_address [get_address "i1"]
132
133test_p_x "s" "Struct1 &" "{x = 0xd, y = 0x13}" $s1_address
134test_p_x "e" "Enum1 &" "0xb" $e1_address
135test_p_x "i" "int &" "0x17" $i1_address
136
137test_p_x_addr "s" $s1_address
138test_p_x_addr "e" $e1_address
139test_p_x_addr "i" $i1_address
140
141test_p_x_ref_addr "s" $s1_address
142test_p_x_ref_addr "i" $i1_address
143test_p_x_ref_addr "e" $e1_address
c332165e
JG
144
145test_p_op1_equals_op2 "s.x" "13"
This page took 0.21647 seconds and 4 git commands to generate.