]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/flexible-array-member.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / flexible-array-member.exp
CommitLineData
213516ef 1# Copyright 2020-2023 Free Software Foundation, Inc.
e25d6d93
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 getting the range of flexible array members in Python.
17
18standard_testfile
19
20if { [prepare_for_testing "failed to prepare" \
21 ${testfile} ${srcfile}] } {
22 return
23}
24
a87caa6d
SM
25# Skip all tests if Python scripting is not enabled.
26if { [skip_python_tests] } { continue }
27
e25d6d93
SM
28if { ![runto break_here] } {
29 untested "could not run to break_here"
30 return
31}
32
33# The various cases are:
34#
35# - ns: flexible array member with no size
36# - zs: flexible array member with size 0 (GNU C extension that predates the
37# standardization of the feature, but widely supported)
38# - zso: zero-size only, a corner case where the array is the sole member of
39# the structure
40
41gdb_test "python ns = gdb.parse_and_eval('ns').dereference()"
42gdb_test "python zs = gdb.parse_and_eval('zs').dereference()"
43gdb_test "python zso = gdb.parse_and_eval('zso').dereference()"
44
45# Print the whole structure.
46
47gdb_test "python print(ns)" "{n = 3, items = $hex}"
48gdb_test "python print(zs)" "{n = 3, items = $hex}"
49gdb_test "python print(zso)" "{items = $hex}"
50
51# Print all items.
52
53gdb_test "python print(ns\['items'\])" "$hex"
54gdb_test "python print(ns\['items'\]\[0\])" "101"
55gdb_test "python print(ns\['items'\]\[1\])" "102"
56gdb_test "python print(ns\['items'\]\[2\])" "103"
57
58gdb_test "python print(zs\['items'\])" "$hex"
59gdb_test "python print(zs\['items'\]\[0\])" "201"
60gdb_test "python print(zs\['items'\]\[1\])" "202"
61gdb_test "python print(zs\['items'\]\[2\])" "203"
62
63gdb_test "python print(zso\['items'\])" "$hex"
64gdb_test "python print(zso\['items'\]\[0\])" "301"
65gdb_test "python print(zso\['items'\]\[1\])" "302"
66gdb_test "python print(zso\['items'\]\[2\])" "303"
67
68# Check taking the address of array elements (how PR 28675 was originally
69# reported).
70
71gdb_test "python print(ns\['items'\] == ns\['items'\]\[0\].address)" "True"
72gdb_test "python print(ns\['items'\]\[0\].address + 1 == ns\['items'\]\[1\].address)" "True"
73gdb_test "python print(zs\['items'\] == zs\['items'\]\[0\].address)" "True"
74gdb_test "python print(zs\['items'\]\[0\].address + 1 == zs\['items'\]\[1\].address)" "True"
75gdb_test "python print(zso\['items'\] == zso\['items'\]\[0\].address)" "True"
76gdb_test "python print(zso\['items'\]\[0\].address + 1 == zso\['items'\]\[1\].address)" "True"
77
78# Verify the range attribute. It looks a bit inconsistent that the high bound
858c8f2c
SM
79# is sometimes 0, sometimes -1. It depends on the way the flexible array
80# member is specified and on the compiler version (the debug info is
81# different). But that's what GDB produces today, so that's what we test.
e25d6d93
SM
82
83gdb_test "python print(ns\['items'\].type.range())" "\\(0, 0\\)"
858c8f2c
SM
84gdb_test "python print(zs\['items'\].type.range())" "\\(0, (0|-1)\\)"
85gdb_test "python print(zso\['items'\].type.range())" "\\(0, (0|-1)\\)"
86
87# Test the same thing, but going explicitly through the array index's range
88# type.
89
90gdb_test "python print(ns\['items'\].type.fields()\[0\].type.range())" "\\(0, 0\\)"
91gdb_test "python print(zs\['items'\].type.fields()\[0\].type.range())" "\\(0, (0|-1)\\)"
92gdb_test "python print(zso\['items'\].type.fields()\[0\].type.range())" "\\(0, (0|-1)\\)"