|
| 1 | +# Copyright 2024 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 | +load_lib "ada.exp" |
| 17 | + |
| 18 | +require allow_ada_tests |
| 19 | + |
| 20 | +standard_ada_testfile parse |
| 21 | + |
| 22 | +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != "" } { |
| 23 | + return -1 |
| 24 | +} |
| 25 | + |
| 26 | +clean_restart ${testfile} |
| 27 | + |
| 28 | +set bp_location [gdb_get_line_number "START" ${testdir}/parse.adb] |
| 29 | +runto "parse.adb:$bp_location" |
| 30 | + |
| 31 | +# Check that we have the expected value for variable y2. |
| 32 | + |
| 33 | +gdb_test "p y2" [string_to_regexp " = (a => false, c => 1.0, d => 2)"] |
| 34 | + |
| 35 | +# Shorthand. |
| 36 | + |
| 37 | +proc set_lang { lang } { |
| 38 | + gdb_test_multiple "set language $lang" "" { |
| 39 | + -re -wrap "" { |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +# Calculate the offset of y2.d. |
| 45 | + |
| 46 | +set re_cast [string_to_regexp "(access integer)"] |
| 47 | +gdb_test_multiple "print &y2.d - &y2" "" { |
| 48 | + -re -wrap " = $re_cast ($hex)" { |
| 49 | + set offset_d $expect_out(1,string) |
| 50 | + pass $gdb_test_name |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +# Try to find a interesting discriminator value, such that at the same time: |
| 55 | +# - the d field is part of the variable, and |
| 56 | +# - the type size is too small to contain d. |
| 57 | + |
| 58 | +set interesting_discriminator -1 |
| 59 | +set_lang c |
| 60 | +for { set i 0 } { $i < 256 } { incr i } { |
| 61 | + with_test_prefix $i { |
| 62 | + |
| 63 | + # Patch in the discriminator value. |
| 64 | + gdb_test_multiple "set var *(unsigned char *)(&y2.a)=$i" "" { |
| 65 | + -re -wrap "" { |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + # Check that we have the variant with fields c+d instead of b. |
| 70 | + set have_b 0 |
| 71 | + gdb_test_multiple "with language ada -- print y2.b" "" { |
| 72 | + -re -wrap " = $decimal" { |
| 73 | + set have_b 1 |
| 74 | + } |
| 75 | + -re -wrap "" { |
| 76 | + } |
| 77 | + } |
| 78 | + if { $have_b } { |
| 79 | + # This is the variant with field b. |
| 80 | + continue |
| 81 | + } |
| 82 | + |
| 83 | + set size 0 |
| 84 | + gdb_test_multiple "print sizeof (y2)" "" { |
| 85 | + -re -wrap " = (.*)" { |
| 86 | + set size $expect_out(1,string) |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + if { ! $size } { |
| 91 | + continue |
| 92 | + } |
| 93 | + |
| 94 | + if { [expr $size > $offset_d] } { |
| 95 | + # Field d fits in the size. |
| 96 | + continue |
| 97 | + } |
| 98 | + |
| 99 | + set interesting_discriminator $i |
| 100 | + break |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +require {expr $interesting_discriminator != -1} |
| 105 | + |
| 106 | +foreach lang [gdb_supported_languages] { |
| 107 | + with_test_prefix $lang { |
| 108 | + set_lang $lang |
| 109 | + |
| 110 | + gdb_test_multiple "print y2" "" { |
| 111 | + -re -wrap ", d => $decimal.*" { |
| 112 | + fail $gdb_test_name |
| 113 | + } |
| 114 | + -re -wrap ", d = $decimal.*" { |
| 115 | + fail $gdb_test_name |
| 116 | + } |
| 117 | + -re -wrap "" { |
| 118 | + pass $gdb_test_name |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | +} |
0 commit comments