| # Copyright 2026 Free Software Foundation, Inc. | |
| # This program is free software; you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation; either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| # Test printing arrays whose stride is larger and smaller than their element | |
| # type. | |
| load_lib dwarf.exp | |
| require dwarf2_support | |
| standard_testfile main.c -dw.S | |
| set asm_file [standard_output_file $srcfile2] | |
| # Array of two shorts with a 128-byte stride. The stride is chosen large | |
| # enough to safely exceed the buffer allocated for a 2-byte short. | |
| set stride 128 | |
| set padding [lrepeat [expr {$stride - 1}] 0x00] | |
| set contents [list 0x01 {*}$padding 0x02 {*}$padding] | |
| # Array of two shorts with a 1-byte stride. Each element is read w.r.t. the | |
| # stride, not the element type. | |
| set packed_stride 1 | |
| set packed_contents {0x01 0x02} | |
| Dwarf::assemble $asm_file { | |
| cu {} { | |
| DW_TAG_compile_unit { | |
| DW_AT_language @DW_LANG_C99 | |
| } { | |
| declare_labels short_label strided_label packed_label | |
| short_label: DW_TAG_base_type { | |
| DW_AT_byte_size 2 DW_FORM_sdata | |
| DW_AT_encoding @DW_ATE_signed | |
| DW_AT_name short | |
| } | |
| strided_label: DW_TAG_array_type { | |
| DW_AT_type :$short_label | |
| DW_AT_byte_stride $::stride DW_FORM_udata | |
| } { | |
| DW_TAG_subrange_type { | |
| DW_AT_upper_bound 1 DW_FORM_data1 | |
| } | |
| } | |
| DW_TAG_variable { | |
| DW_AT_name strided | |
| DW_AT_type :$strided_label | |
| DW_AT_location { | |
| DW_OP_implicit_value {*}$::contents | |
| } SPECIAL_expr | |
| } | |
| packed_label: DW_TAG_array_type { | |
| DW_AT_type :$short_label | |
| DW_AT_byte_stride $::packed_stride DW_FORM_udata | |
| } { | |
| DW_TAG_subrange_type { | |
| DW_AT_upper_bound 1 DW_FORM_data1 | |
| } | |
| } | |
| DW_TAG_variable { | |
| DW_AT_name packed | |
| DW_AT_type :$packed_label | |
| DW_AT_location { | |
| DW_OP_implicit_value {*}$::packed_contents | |
| } SPECIAL_expr | |
| } | |
| } | |
| } | |
| } | |
| if {[prepare_for_testing "failed to prepare" $testfile \ | |
| [list $srcfile $asm_file] {nodebug}]} { | |
| return | |
| } | |
| # Check that "print VAR" shows EXPECTED. A crash of GDB is converted into | |
| # "unresolved". Report it as a failure instead. | |
| proc test_print { var expected } { | |
| gdb_test_multiple "print $var" "" { | |
| -re -wrap " = $expected" { | |
| pass $gdb_test_name | |
| } | |
| -re "A fatal error internal to GDB has been detected" { | |
| fail "$gdb_test_name (GDB crashed)" | |
| } | |
| } | |
| } | |
| test_print strided "\\{1, 2\\}" | |
| test_print packed "\\{1, 2\\}" |