Blame SOURCES/gdb-flexible-array-member-expected-pattern.patch

a8223e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
a8223e
From: Simon Marchi <simon.marchi@efficios.com>
a8223e
Date: Tue, 4 May 2021 11:20:09 -0400
a8223e
Subject: gdb-flexible-array-member-expected-pattern.patch
a8223e
a8223e
;; Backport "adjust gdb.python/flexible-array-member.exp expected pattern"
a8223e
;; (Simon Marchi)
a8223e
a8223e
The `Type.range ()` tests in gdb.python/flexible-array-member.exp pass
a8223e
when the test is compiled with gcc 9 or later, but not with gcc 8 or
a8223e
earlier:
a8223e
a8223e
    $ make check TESTS="gdb.python/flexible-array-member.exp" RUNTESTFLAGS="CC_FOR_TARGET='gcc-8'"
a8223e
a8223e
    python print(zs['items'].type.range())^M
a8223e
    (0, 0)^M
a8223e
    (gdb) FAIL: gdb.python/flexible-array-member.exp: python print(zs['items'].type.range())
a8223e
    python print(zso['items'].type.range())^M
a8223e
    (0, 0)^M
a8223e
    (gdb) FAIL: gdb.python/flexible-array-member.exp: python print(zso['items'].type.range())
a8223e
a8223e
The value that we get for the upper bound of a flexible array member
a8223e
declared with a "0" size is 0 with gcc <= 8 and is -1 for gcc >= 9.
a8223e
This is due to different debug info.  For this member, gcc 8 does:
a8223e
a8223e
    0x000000d5:   DW_TAG_array_type
a8223e
                    DW_AT_type [DW_FORM_ref4]       (0x00000034 "int")
a8223e
                    DW_AT_sibling [DW_FORM_ref4]    (0x000000e4)
a8223e
a8223e
    0x000000de:     DW_TAG_subrange_type
a8223e
                      DW_AT_type [DW_FORM_ref4]     (0x0000002d "long unsigned int")
a8223e
a8223e
For the same type, gcc 9 does:
a8223e
a8223e
    0x000000d5:   DW_TAG_array_type
a8223e
                    DW_AT_type [DW_FORM_ref4]       (0x00000034 "int")
a8223e
                    DW_AT_sibling [DW_FORM_ref4]    (0x000000e5)
a8223e
a8223e
    0x000000de:     DW_TAG_subrange_type
a8223e
                      DW_AT_type [DW_FORM_ref4]     (0x0000002d "long unsigned int")
a8223e
                      DW_AT_count [DW_FORM_data1]   (0x00)
a8223e
a8223e
Ideally, GDB would present a consistent and documented value for an
a8223e
array member declared with size 0, regardless of how the debug info
a8223e
looks like.  But for now, just change the test to accept the two
a8223e
values, to get rid of the failure and make the test in sync
a8223e
a8223e
I also realized (by looking at the py-type.exp test) that calling the
a8223e
fields method on an array type yields one field representing the "index"
a8223e
of the array.  The type of that field is of type range
a8223e
(gdb.TYPE_CODE_RANGE).  When calling `.range()` on that range type, it
a8223e
yields the same range tuple as when calling `.range()` on the array type
a8223e
itself.  For completeness, add some tests to access the range tuple
a8223e
through that range type as well.
a8223e
a8223e
gdb/testsuite/ChangeLog:
a8223e
a8223e
	* gdb.python/flexible-array-member.exp: Adjust expected range
a8223e
	value for member declared with 0 size.  Test accessing range
a8223e
	tuple through range type.
a8223e
a8223e
Change-Id: Ie4e06d99fe9315527f04577888f48284d649ca4c
a8223e
a8223e
diff --git a/gdb/testsuite/gdb.python/flexible-array-member.exp b/gdb/testsuite/gdb.python/flexible-array-member.exp
a8223e
--- a/gdb/testsuite/gdb.python/flexible-array-member.exp
a8223e
+++ b/gdb/testsuite/gdb.python/flexible-array-member.exp
a8223e
@@ -76,9 +76,17 @@ gdb_test "python print(zso\['items'\] == zso\['items'\]\[0\].address)" "True"
a8223e
 gdb_test "python print(zso\['items'\]\[0\].address + 1 == zso\['items'\]\[1\].address)" "True"
a8223e
 
a8223e
 # Verify the range attribute.  It looks a bit inconsistent that the high bound
a8223e
-# is sometimes 0, sometimes -1, but that's what GDB produces today, so that's
a8223e
-# what we test.
a8223e
+# is sometimes 0, sometimes -1.  It depends on the way the flexible array
a8223e
+# member is specified and on the compiler version (the debug info is
a8223e
+# different).  But that's what GDB produces today, so that's what we test.
a8223e
 
a8223e
 gdb_test "python print(ns\['items'\].type.range())" "\\(0, 0\\)"
a8223e
-gdb_test "python print(zs\['items'\].type.range())" "\\(0, -1\\)"
a8223e
-gdb_test "python print(zso\['items'\].type.range())" "\\(0, -1\\)"
a8223e
+gdb_test "python print(zs\['items'\].type.range())" "\\(0, (0|-1)\\)"
a8223e
+gdb_test "python print(zso\['items'\].type.range())" "\\(0, (0|-1)\\)"
a8223e
+
a8223e
+# Test the same thing, but going explicitly through the array index's range
a8223e
+# type.
a8223e
+
a8223e
+gdb_test "python print(ns\['items'\].type.fields()\[0\].type.range())" "\\(0, 0\\)"
a8223e
+gdb_test "python print(zs\['items'\].type.fields()\[0\].type.range())" "\\(0, (0|-1)\\)"
a8223e
+gdb_test "python print(zso\['items'\].type.fields()\[0\].type.range())" "\\(0, (0|-1)\\)"