Avoid "text file busy" in dw2-using-debug-str.exp
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-ranges-psym.exp
blobbb0b5dbfc0b0ca0bce27b8cc77143076d429fd39
1 # Copyright 2018-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 load_lib dwarf.exp
18 # Test that psymbols are made when DW_AT_ranges is used.
20 # This test can only be run on targets which support DWARF-2 and use gas.
21 require dwarf2_support
23 require is_c_compiler_gcc
25 standard_testfile main.c .c -dw.S
27 # We need to know the size of integer and address types in order to
28 # write some of the debugging info we'd like to generate.
30 # For that, we ask GDB by debugging our test program.  Any program
31 # would do, but since we already have it specifically for this
32 # testcase, might as well use that.
34 if { [prepare_for_testing "failed to prepare" ${testfile} \
35           [list ${srcfile} ${srcfile2}]] } {
36     return -1
39 set asm_file [standard_output_file $srcfile3]
40 Dwarf::assemble $asm_file {
41     global srcdir subdir srcfile srcfile2
42     declare_labels integer_label volatile_label func_ranges_label cu_ranges_label
43     set int_size [get_sizeof "int" 4]
45     # Find start address and length for our functions.
46     set sources  [list ${srcdir}/${subdir}/$srcfile ${srcdir}/${subdir}/$srcfile2]
48     lassign [function_range foo $sources] \
49         foo_start foo_len
50     set foo_end "$foo_start + $foo_len"
52     lassign [function_range foo_low $sources] \
53         foo_low_start foo_low_len
54     set foo_low_end "$foo_low_start + $foo_low_len"
56     lassign [function_range bar $sources] \
57         bar_start bar_len
58     set bar_end "$bar_start + $bar_len"
60     lassign [function_range baz $sources] \
61         baz_start baz_len
62     set baz_end "$baz_start + $baz_len"
64     cu {} {
65         compile_unit {
66             {language @DW_LANG_C}
67             {name dw-ranges-psym.c}
68             {low_pc 0 addr}
69             {ranges ${cu_ranges_label} DW_FORM_sec_offset}
70         } {
71             integer_label: DW_TAG_base_type {
72                 {DW_AT_byte_size $int_size DW_FORM_sdata}
73                 {DW_AT_encoding  @DW_ATE_signed}
74                 {DW_AT_name      integer}
75             }
76             volatile_label: DW_TAG_volatile_type {
77                 {type :$integer_label}
78             }
79             subprogram {
80                 {external 1 flag}
81                 {name someothername}
82                 {ranges ${func_ranges_label} DW_FORM_sec_offset}
83             }
84             subprogram {
85                 {external 1 flag}
86                 {name bar}
87                 {low_pc $bar_start addr}
88                 {high_pc $bar_len DW_FORM_data4}
89             }
90             subprogram {
91                 {external 1 flag}
92                 {name baz}
93                 {low_pc $baz_start addr}
94                 {high_pc $baz_len DW_FORM_data4}
95             }
96         }
97     }
99     # Generate ranges data.
100     ranges {is_64 [is_64_target]} {
101         func_ranges_label: sequence {
102             range $foo_start $foo_end
103             range $foo_low_start $foo_low_end
104         }
105         cu_ranges_label: sequence {
106             range $foo_start $foo_end
107             range $foo_low_start $foo_low_end
108             range $bar_start $bar_end
109             range $baz_start $baz_end
110         }
111     }
114 if { [build_executable "failed to prepare" ${testfile} \
115           [list $srcfile $srcfile2 $asm_file] {nodebug}] } {
116     return -1
119 clean_restart
120 gdb_load_no_complaints $binfile
122 if ![runto_main] {
123     return -1
126 # "someothername" should be put into the partial symbol table, but
127 # there was a bug causing functions using DW_AT_ranges not to be.
128 # Note we use a name that is very different from the linkage name, in
129 # order to not set the breakpoint via minsyms.
130 gdb_test "break someothername" \
131     "Breakpoint.*at.*"