Home | History | Annotate | Line # | Download | only in gdb.base
      1 # Copyright 2014-2024 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 standard_testfile
     17 
     18 # Clang says it will never support variable length arrays in structures.
     19 require {!test_compiler_info clang*}
     20 
     21 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
     22     return -1
     23 }
     24 
     25 if ![runto_main] {
     26     return -1
     27 }
     28 
     29 gdb_breakpoint [gdb_get_line_number "vlas_filled"]
     30 gdb_continue_to_breakpoint "vlas_filled"
     31 
     32 # Check the values of VLA's.
     33 gdb_test "print vla_struct_object" \
     34     "\\\{something = 5, vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
     35 gdb_test "print vla_union_object" \
     36     "\\\{vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
     37 gdb_test "print vla_struct_typedef_struct_member_object" \
     38     "\\\{something = 10, vla_object = \\\{something = 15, vla_field = \\\{0, 3, 6, 9, 12\\\}\\\}\\\}"
     39 gdb_test "print vla_struct_typedef_union_member_object" \
     40     "\\\{something = 6, vla_object = \\\{something = 6, vla_field = \\\{-1, 2, 5, 8, 11\\\}\\\}\\\}"
     41 
     42 # Check whatis of VLA's.
     43 gdb_test "whatis vla_struct_object" "type = vla_struct_typedef"
     44 gdb_test "whatis vla_union_object" "type = union vla_union"
     45 
     46 # Check ptype of VLA's.
     47 gdb_test "ptype vla_struct_object" \
     48     "type = struct vla_struct {\r\n\\s+int something;\r\n\\s+int vla_field\\\[5\\\];\r\n}"
     49 gdb_test "ptype vla_union_object" \
     50     "type = union vla_union {\r\n\\s+int vla_field\\\[5\\\];\r\n}"
     51 
     52 # Check the size of the VLA's.
     53 gdb_breakpoint [gdb_get_line_number "break_end_of_vla_factory"]
     54 gdb_continue_to_breakpoint "break_end_of_vla_factory"
     55 gdb_test "print vla_struct_object_size == sizeof(vla_struct_object)" \
     56     " = 1" "size of vla_struct_object"
     57 gdb_test "print vla_union_object_size == sizeof(vla_union_object)" \
     58     " = 1" "size of vla_union_object"
     59 
     60 set a -1
     61 gdb_test_multiple "print inner_vla_struct_object_size" "" {
     62     -re -wrap " = ($decimal)" {
     63 	set a $expect_out(1,string)
     64     }
     65 }
     66 set b -1
     67 gdb_test_multiple "print sizeof(inner_vla_struct_object)" "" {
     68     -re -wrap " = ($decimal)" {
     69 	set b $expect_out(1,string)
     70     }
     71 }
     72 if { [test_compiler_info "gcc-*"] && [gcc_major_version] <= 11 } {
     73     # Fails due to incorrect debugging information generated by GCC.
     74     setup_xfail "*-*-*"
     75 }
     76 gdb_assert {$a == $b} "size of inner_vla_struct_object"
     77