1# Copyright 2020-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# Test printing and subscripting flexible array members. 17 18standard_testfile 19 20if { [prepare_for_testing "failed to prepare" \ 21 ${testfile} ${srcfile}] } { 22 return 23} 24 25if { ![runto break_here] } { 26 untested "could not run to break_here" 27 return 28} 29 30# The various cases are: 31# 32# - ns: flexible array member with no size 33# - zs: flexible array member with size 0 (GNU C extension that predates the 34# standardization of the feature, but widely supported) 35# - zso: zero-size only, a corner case where the array is the sole member of 36# the structure 37 38# Print the whole structure. 39 40gdb_test "print *ns" " = {n = 3, items = $hex}" 41gdb_test "print *zs" " = {n = 3, items = $hex}" 42gdb_test "print *zso" " = {items = $hex}" 43 44# Print all items. 45 46gdb_test "print ns->items\[0\]" " = 101" 47gdb_test "print ns->items\[1\]" " = 102" 48gdb_test "print ns->items\[2\]" " = 103" 49 50gdb_test "print zs->items\[0\]" " = 201" 51gdb_test "print zs->items\[1\]" " = 202" 52gdb_test "print zs->items\[2\]" " = 203" 53 54gdb_test "print zso->items\[0\]" " = 301" 55gdb_test "print zso->items\[1\]" " = 302" 56gdb_test "print zso->items\[2\]" " = 303" 57 58# Check taking the address of array elements (how PR 28675 was originally 59# reported). 60 61gdb_test "print ns->items == &ns->items\[0\]" " = 1" 62gdb_test "print ns->items + 1 == &ns->items\[1\]" " = 1" 63gdb_test "print zs->items == &zs->items\[0\]" " = 1" 64gdb_test "print zs->items + 1 == &zs->items\[1\]" " = 1" 65gdb_test "print zso->items == &zso->items\[0\]" " = 1" 66gdb_test "print zso->items + 1 == &zso->items\[1\]" " = 1" 67