1# Copyright 2014-2020 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# Tests to cover DW_AT_count attribute in subranges.
17
18load_lib dwarf.exp
19
20# Only run on targets which support dwarf and gas.
21if { ![dwarf2_support] } {
22    return 0
23}
24
25standard_testfile main.c count.S
26
27set asm_file [standard_output_file $srcfile2]
28Dwarf::assemble $asm_file {
29    cu {} {
30	compile_unit {{language @DW_LANG_C99}} {
31	    declare_labels char_label array_label array_label2 static_array_label
32
33	    char_label: base_type {
34		{name char}
35		{encoding @DW_ATE_signed}
36		{byte_size 1 DW_FORM_sdata}
37	    }
38
39	    array_label: array_type {
40		{type :$char_label}
41	    } {
42		subrange_type {
43		    {count {DW_OP_lit5} SPECIAL_expr}
44		    {type :$char_label}
45		}
46	    }
47
48	    array_label2: array_type {
49		{type :$char_label}
50	    } {
51		subrange_type {
52		    {count {DW_OP_lit1} SPECIAL_expr}
53		    {type :$char_label}
54		}
55	    }
56
57	    static_array_label: array_type {
58		{type :$char_label}
59	    } {
60		subrange_type {
61		    {count 5 DW_FORM_sdata}
62		    {type :$char_label}
63		}
64	    }
65
66	    DW_TAG_variable {
67		{name array2}
68		{type :$array_label2}
69		{const_value 65 DW_FORM_udata}
70	    }
71
72	    DW_TAG_variable {
73		{name array}
74		{type :$array_label}
75		{const_value hello DW_FORM_block1}
76	    }
77
78	    DW_TAG_variable {
79		{name static_array}
80		{type :$static_array_label}
81		{const_value world DW_FORM_block1}
82	    }
83	}
84    }
85}
86
87if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
88	  object {nodebug}] != "" } {
89    return -1
90}
91
92if { [gdb_compile $asm_file ${binfile}2.o object {nodebug}] != "" } {
93    return -1
94}
95
96if { [gdb_compile [list ${binfile}1.o ${binfile}2.o] \
97	  "${binfile}" executable {}] != "" } {
98    return -1
99}
100
101global GDBFLAGS
102set saved_gdbflags $GDBFLAGS
103set GDBFLAGS [concat $GDBFLAGS " -readnow"]
104clean_restart ${testfile}
105set GDBFLAGS $saved_gdbflags
106
107if ![runto_main] {
108    perror "couldn't run to main"
109    return -1
110}
111
112gdb_test "ptype array" "type = char \\\[5\\\]"
113gdb_test "whatis array" "type = char \\\[5\\\]"
114gdb_test "print array" " = \"hello\""
115gdb_test "print sizeof array" " = 5"
116
117gdb_test "ptype array2" "type = char \\\[1\\\]"
118gdb_test "whatis array2" "type = char \\\[1\\\]"
119gdb_test "print array2" " = \"A\""
120gdb_test "print sizeof array2" " = 1"
121
122gdb_test "ptype static_array" "type = char \\\[5\\\]"
123gdb_test "whatis static_array" "type = char \\\[5\\\]"
124gdb_test "print static_array" " = \"world\""
125gdb_test "print sizeof static_array" " = 5"
126