]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright 2020-2023 Free Software Foundation, Inc. |
5b56203a SM |
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 | ||
18 | standard_testfile | |
19 | ||
20 | if { [prepare_for_testing "failed to prepare" \ | |
21 | ${testfile} ${srcfile}] } { | |
22 | return | |
23 | } | |
24 | ||
25 | if { ![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 | ||
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}" | |
43 | ||
44 | # Print all items. | |
45 | ||
46 | gdb_test "print ns->items\[0\]" " = 101" | |
47 | gdb_test "print ns->items\[1\]" " = 102" | |
48 | gdb_test "print ns->items\[2\]" " = 103" | |
49 | ||
50 | gdb_test "print zs->items\[0\]" " = 201" | |
51 | gdb_test "print zs->items\[1\]" " = 202" | |
52 | gdb_test "print zs->items\[2\]" " = 203" | |
53 | ||
54 | gdb_test "print zso->items\[0\]" " = 301" | |
55 | gdb_test "print zso->items\[1\]" " = 302" | |
56 | gdb_test "print zso->items\[2\]" " = 303" | |
57 | ||
58 | # Check taking the address of array elements (how PR 28675 was originally | |
59 | # reported). | |
60 | ||
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" |