| 1 | # Copyright 2007-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 | # Author: P. N. Hilfinger, AdaCore Inc. |
| 17 | |
| 18 | # Note: This test is essentially a transcription of gdb.cp/formatted-ref.exp, |
| 19 | # and is thus much more wordy than it needs to be. There are fewer |
| 20 | # tests because only a few parameter types in Ada are required to be |
| 21 | # passed by reference, and there is no equivalent of &(&x) for reference |
| 22 | # values. |
| 23 | # This also tests that some other arithmetic operations on references |
| 24 | # work properly: condition expression using a reference object as one of its |
| 25 | # operand. |
| 26 | |
| 27 | load_lib "ada.exp" |
| 28 | |
| 29 | standard_ada_testfile formatted_ref |
| 30 | |
| 31 | if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { |
| 32 | untested formatted-ref.exp |
| 33 | return -1 |
| 34 | } |
| 35 | |
| 36 | proc get_address { var } { |
| 37 | global expect_out |
| 38 | global gdb_prompt |
| 39 | |
| 40 | gdb_test_multiple "print $var'access" "address of $var" { |
| 41 | -re "\\$\[0-9\]+ = \\(.*\\) (0x\[0-9a-f\]+).*$gdb_prompt $" { |
| 42 | return $expect_out(1,string) |
| 43 | } |
| 44 | } |
| 45 | perror "couldn't find address of $var" |
| 46 | return "" |
| 47 | } |
| 48 | |
| 49 | proc test_p_x { var val addr } { |
| 50 | global gdb_prompt |
| 51 | |
| 52 | set test "print/x $var" |
| 53 | gdb_test_multiple "$test" $test { |
| 54 | -re "\\$\[0-9\]+ = [string_to_regexp $val].*$gdb_prompt $" { |
| 55 | pass $test |
| 56 | } |
| 57 | -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" { |
| 58 | fail "$test (prints just address)" |
| 59 | } |
| 60 | -re "\\$\[0-9\]+ = 0x\[a-f0-9\]+.*$gdb_prompt $" { |
| 61 | fail "$test (prints unexpected address)" |
| 62 | } |
| 63 | } |
| 64 | return 0 |
| 65 | } |
| 66 | |
| 67 | proc test_p_x_addr { var addr } { |
| 68 | global gdb_prompt |
| 69 | |
| 70 | set test "print/x $var'access" |
| 71 | gdb_test_multiple $test $test { |
| 72 | -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" { |
| 73 | pass $test |
| 74 | } |
| 75 | -re "\\$\[0-9\]+ = 0x\[a-f0-9+\]+.*$gdb_prompt $" { |
| 76 | fail "$test (prints unexpected address)" |
| 77 | } |
| 78 | } |
| 79 | return 0 |
| 80 | } |
| 81 | |
| 82 | proc test_p_op1_equals_op2 {op1 op2} { |
| 83 | set test "print $op1 = $op2" |
| 84 | gdb_test $test "\\$\[0-9\]+ = true" |
| 85 | } |
| 86 | |
| 87 | clean_restart ${testfile} |
| 88 | |
| 89 | runto defs.adb:[gdb_get_line_number "marker here" ${testdir}/defs.adb ] |
| 90 | |
| 91 | set s1_address [get_address "s1"] |
| 92 | |
| 93 | test_p_x "s" "(x => 0xd, y => 0x13)" $s1_address |
| 94 | |
| 95 | test_p_x_addr "s" $s1_address |
| 96 | |
| 97 | test_p_op1_equals_op2 "s.x" "13" |