3739c9a9e5c0d49f2b17d2452b42686abeacefc1
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / flexible-array-member.exp
1 # Copyright 2020-2021 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 getting the range of flexible array members in Python.
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 gdb_test "python ns = gdb.parse_and_eval('ns').dereference()"
39 gdb_test "python zs = gdb.parse_and_eval('zs').dereference()"
40 gdb_test "python zso = gdb.parse_and_eval('zso').dereference()"
41
42 # Print the whole structure.
43
44 gdb_test "python print(ns)" "{n = 3, items = $hex}"
45 gdb_test "python print(zs)" "{n = 3, items = $hex}"
46 gdb_test "python print(zso)" "{items = $hex}"
47
48 # Print all items.
49
50 gdb_test "python print(ns\['items'\])" "$hex"
51 gdb_test "python print(ns\['items'\]\[0\])" "101"
52 gdb_test "python print(ns\['items'\]\[1\])" "102"
53 gdb_test "python print(ns\['items'\]\[2\])" "103"
54
55 gdb_test "python print(zs\['items'\])" "$hex"
56 gdb_test "python print(zs\['items'\]\[0\])" "201"
57 gdb_test "python print(zs\['items'\]\[1\])" "202"
58 gdb_test "python print(zs\['items'\]\[2\])" "203"
59
60 gdb_test "python print(zso\['items'\])" "$hex"
61 gdb_test "python print(zso\['items'\]\[0\])" "301"
62 gdb_test "python print(zso\['items'\]\[1\])" "302"
63 gdb_test "python print(zso\['items'\]\[2\])" "303"
64
65 # Check taking the address of array elements (how PR 28675 was originally
66 # reported).
67
68 gdb_test "python print(ns\['items'\] == ns\['items'\]\[0\].address)" "True"
69 gdb_test "python print(ns\['items'\]\[0\].address + 1 == ns\['items'\]\[1\].address)" "True"
70 gdb_test "python print(zs\['items'\] == zs\['items'\]\[0\].address)" "True"
71 gdb_test "python print(zs\['items'\]\[0\].address + 1 == zs\['items'\]\[1\].address)" "True"
72 gdb_test "python print(zso\['items'\] == zso\['items'\]\[0\].address)" "True"
73 gdb_test "python print(zso\['items'\]\[0\].address + 1 == zso\['items'\]\[1\].address)" "True"
74
75 # Verify the range attribute. It looks a bit inconsistent that the high bound
76 # is sometimes 0, sometimes -1, but that's what GDB produces today, so that's
77 # what we test.
78
79 gdb_test "python print(ns\['items'\].type.range())" "\\(0, 0\\)"
80 gdb_test "python print(zs\['items'\].type.range())" "\\(0, -1\\)"
81 gdb_test "python print(zso\['items'\].type.range())" "\\(0, -1\\)"
This page took 0.031171 seconds and 3 git commands to generate.