1 # Copyright 2020-2021 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test printing and subscripting flexible array members.
20 if { [prepare_for_testing "failed to prepare" \
21 ${testfile} ${srcfile}] } {
25 if { ![runto break_here] } {
26 untested "could not run to break_here"
30 # The various cases are:
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
38 # Print the whole structure.
40 gdb_test "print *ns" " = {n = 3, items = $hex}"
41 gdb_test "print *zs" " = {n = 3, items = $hex}"
42 gdb_test "print *zso" " = {items = $hex}"
46 gdb_test "print ns->items\[0\]" " = 101"
47 gdb_test "print ns->items\[1\]" " = 102"
48 gdb_test "print ns->items\[2\]" " = 103"
50 gdb_test "print zs->items\[0\]" " = 201"
51 gdb_test "print zs->items\[1\]" " = 202"
52 gdb_test "print zs->items\[2\]" " = 203"
54 gdb_test "print zso->items\[0\]" " = 301"
55 gdb_test "print zso->items\[1\]" " = 302"
56 gdb_test "print zso->items\[2\]" " = 303"
58 # Check taking the address of array elements (how PR 28675 was originally
61 gdb_test "print ns->items == &ns->items\[0\]" " = 1"
62 gdb_test "print ns->items + 1 == &ns->items\[1\]" " = 1"
63 gdb_test "print zs->items == &zs->items\[0\]" " = 1"
64 gdb_test "print zs->items + 1 == &zs->items\[1\]" " = 1"
65 gdb_test "print zso->items == &zso->items\[0\]" " = 1"
66 gdb_test "print zso->items + 1 == &zso->items\[1\]" " = 1"