update copyright year range in GDB files
[external/binutils.git] / gdb / testsuite / gdb.dwarf2 / dw2-ranges-base.exp
1 # Copyright 2015-2017 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 load_lib dwarf.exp
16
17 # Test DW_TAG_compile_unit with no children and with neither DW_AT_low_pc nor
18 # DW_AT_high_pc but with DW_AT_ranges instead.
19
20 # This test can only be run on targets which support DWARF-2 and use gas.
21 if {![dwarf2_support]} {
22     verbose "Skipping DW_AT_ranges test."
23     return 0
24 }
25
26 # The .c files use __attribute__.
27 if [get_compiler_info] {
28     return -1
29 }
30 if !$gcc_compiled {
31     verbose "Skipping DW_AT_ranges test."
32     return 0
33 }
34
35 standard_testfile dw2-ranges-base.c dw2-ranges-base-dw.S
36
37 set asm_file [standard_output_file $srcfile2]
38 Dwarf::assemble $asm_file {
39     global srcdir subdir srcfile srcfile2
40     declare_labels ranges_label
41     declare_labels L
42
43     # Find start address and length for our functions.
44     set main_func \
45         [function_range main [list ${srcdir}/${subdir}/$srcfile]]
46     set frame2_func \
47         [function_range frame2 [list ${srcdir}/${subdir}/$srcfile]]
48     set frame3_func \
49         [function_range frame3 [list ${srcdir}/${subdir}/$srcfile]]
50
51     # Very simple info for this test program.  We don't care about
52     # this information being correct (w.r.t. funtion / argument types)
53     # just so long as the compilation using makes use of the
54     # .debug_ranges data then the test achieves its objective.
55     cu {} {
56         compile_unit {
57             {language @DW_LANG_C}
58             {name dw-ranges-base.c}
59             {stmt_list $L DW_FORM_sec_offset}
60             {ranges ${ranges_label} DW_FORM_sec_offset}
61         } {
62             subprogram {
63                 {external 1 flag}
64                 {name main}
65             }
66             subprogram {
67                 {external 1 flag}
68                 {name frame2}
69             }
70             subprogram {
71                 {external 1 flag}
72                 {name frame3}
73             }
74         }
75     }
76
77     lines {version 2} L {
78         include_dir "${srcdir}/${subdir}"
79         file_name "$srcfile" 1
80
81         # Generate simple line table program.  The line table
82         # information contained here is not correct, and we really
83         # don't care, just so long as each function has some line
84         # table data associated with it.  We do make use of the fake
85         # line numbers that we pick here in the tests below.
86         program {
87             {DW_LNE_set_address [lindex $main_func 0]}
88             {DW_LNS_advance_line 10}
89             {DW_LNS_copy}
90             {DW_LNS_advance_pc [lindex $main_func 1]}
91             {DW_LNS_advance_line 19}
92             {DW_LNS_copy}
93             {DW_LNE_end_sequence}
94
95             {DW_LNE_set_address [lindex $frame2_func 0]}
96             {DW_LNS_advance_line 20}
97             {DW_LNS_copy}
98             {DW_LNS_advance_pc [lindex $frame2_func 1]}
99             {DW_LNS_advance_line 29}
100             {DW_LNS_copy}
101             {DW_LNE_end_sequence}
102
103             {DW_LNE_set_address [lindex $frame3_func 0]}
104             {DW_LNS_advance_line 30}
105             {DW_LNS_copy}
106             {DW_LNS_advance_pc [lindex $frame3_func 1]}
107             {DW_LNS_advance_line 39}
108             {DW_LNS_copy}
109             {DW_LNE_end_sequence}
110         }
111     }
112
113     # Generate ranges data.  This is the point of this whole test
114     # file, we must have multiple bases specified, so we use a new
115     # base for each function.
116     ranges {is_64 [is_64_target]} {
117         ranges_label: sequence {
118             {base [lindex $main_func 0]}
119             {range 0 [lindex $main_func 1]}
120             {base [lindex $frame2_func 0]}
121             {range 0 [lindex $frame2_func 1]}
122             {base [lindex $frame3_func 0]}
123             {range 0 [lindex $frame3_func 1]}
124         }
125     }
126 }
127
128 if { [prepare_for_testing "failed to prepare" ${testfile} \
129           [list $srcfile $asm_file] {nodebug}] } {
130     return -1
131 }
132
133 if ![runto_main] {
134     return -1
135 }
136
137 # Make use of the line numbers we faked in the .debug_line table above.
138 gdb_test "info line main" \
139     "Line 11 of .* starts at address .* and ends at .*"
140 gdb_test "info line frame2" \
141     "Line 21 of .* starts at address .* and ends at .*"
142 gdb_test "info line frame3" \
143     "Line 31 of .* starts at address .* and ends at .*"