1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
# Copyright 2024 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
load_lib "ada.exp"
require allow_ada_tests
standard_ada_testfile parse
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != "" } {
return -1
}
clean_restart ${testfile}
set bp_location [gdb_get_line_number "START" ${testdir}/parse.adb]
runto "parse.adb:$bp_location"
# Check that we have the expected value for variable y2.
gdb_test "p y2" [string_to_regexp " = (a => false, c => 1.0, d => 2)"]
# Shorthand.
proc set_lang { lang } {
gdb_test_multiple "set language $lang" "" {
-re -wrap "" {
}
}
}
# Calculate the offset of y2.d.
set re_cast [string_to_regexp "(access integer)"]
gdb_test_multiple "print &y2.d - &y2" "" {
-re -wrap " = $re_cast ($hex)" {
set offset_d $expect_out(1,string)
pass $gdb_test_name
}
}
# Try to find a interesting discriminator value, such that at the same time:
# - the d field is part of the variable, and
# - the type size is too small to contain d.
set interesting_discriminator -1
set_lang c
for { set i 0 } { $i < 256 } { incr i } {
with_test_prefix $i {
# Patch in the discriminator value.
gdb_test_multiple "set var *(unsigned char *)(&y2.a)=$i" "" {
-re -wrap "" {
}
}
# Check that we have the variant with fields c+d instead of b.
set have_b 0
gdb_test_multiple "with language ada -- print y2.b" "" {
-re -wrap " = $decimal" {
set have_b 1
}
-re -wrap "" {
}
}
if { $have_b } {
# This is the variant with field b.
continue
}
set size 0
gdb_test_multiple "print sizeof (y2)" "" {
-re -wrap " = (.*)" {
set size $expect_out(1,string)
}
}
if { ! $size } {
continue
}
if { [expr $size > $offset_d] } {
# Field d fits in the size.
continue
}
set interesting_discriminator $i
break
}
}
require {expr $interesting_discriminator != -1}
foreach lang [gdb_supported_languages] {
with_test_prefix $lang {
set_lang $lang
gdb_test_multiple "print y2" "" {
-re -wrap ", d => $decimal.*" {
fail $gdb_test_name
}
-re -wrap ", d = $decimal.*" {
fail $gdb_test_name
}
-re -wrap "" {
pass $gdb_test_name
}
}
}
}
|