]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2021-2024 Free Software Foundation, Inc. |
41505c0f TV |
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 | # Test line number information in various configurations. | |
17 | ||
18 | load_lib dwarf.exp | |
19 | ||
20 | # This test can only be run on targets which support DWARF-2 and use gas. | |
793862d2 | 21 | require dwarf2_support |
41505c0f | 22 | |
2a0fa842 | 23 | standard_testfile .c |
41505c0f TV |
24 | |
25 | with_shared_gdb { | |
26 | set func_info_vars \ | |
27 | [concat \ | |
28 | [get_func_info main] \ | |
29 | [get_func_info bar]] | |
30 | } | |
31 | ||
32 | # Helper function. | |
33 | proc line_for { l } { | |
34 | global srcfile | |
35 | set line [gdb_get_line_number "$l:" $srcfile] | |
36 | return [expr $line + 1] | |
37 | } | |
38 | ||
39 | # Execute test. | |
bab31d14 | 40 | proc test_1 { _cv _cdw64 _lv _ldw64 {_string_form ""}} { |
41505c0f | 41 | global srcfile srcfile2 testfile |
bab31d14 | 42 | global cv cdw64 lv ldw64 string_form |
41505c0f TV |
43 | set cv $_cv |
44 | set cdw64 $_cdw64 | |
45 | set lv $_lv | |
46 | set ldw64 $_ldw64 | |
bab31d14 | 47 | set string_form $_string_form |
41505c0f | 48 | |
2a0fa842 TV |
49 | standard_testfile .c [prefix_id]-dw.S |
50 | ||
41505c0f TV |
51 | set asm_file [standard_output_file $srcfile2] |
52 | Dwarf::assemble $asm_file { | |
53 | declare_labels Llines | |
bab31d14 | 54 | global srcdir subdir srcfile cv cdw64 lv ldw64 string_form |
41505c0f TV |
55 | global func_info_vars |
56 | foreach var $func_info_vars { | |
57 | global $var | |
58 | } | |
59 | ||
60 | cu { version $cv is_64 $cdw64 } { | |
61 | compile_unit { | |
62 | {language @DW_LANG_C} | |
63 | {name $srcfile} | |
64 | {stmt_list $Llines DW_FORM_sec_offset} | |
65 | } { | |
66 | subprogram { | |
67 | {external 1 flag} | |
68 | {name main} | |
69 | {low_pc $main_start addr} | |
70 | {high_pc "$main_start + $main_len" addr} | |
71 | } | |
72 | subprogram { | |
73 | {external 1 flag} | |
74 | {name bar} | |
75 | {low_pc $bar_start addr} | |
76 | {high_pc "$bar_start + $bar_len" addr} | |
77 | } | |
78 | } | |
79 | } | |
80 | ||
bab31d14 | 81 | lines [list version $lv is_64 $ldw64 string_form $string_form] Llines { |
9a0de6ab SM |
82 | set diridx [include_dir "${srcdir}/${subdir}"] |
83 | file_name "$srcfile" $diridx | |
41505c0f TV |
84 | |
85 | program { | |
9a0de6ab SM |
86 | # If using DWARF 5, we want to refer to file 0, but the LNP |
87 | # state machine is still initialized with file 1. So we need | |
88 | # to set the current file explicitly. | |
89 | DW_LNS_set_file $diridx | |
90 | ||
d4c4a229 SM |
91 | DW_LNE_set_address bar_label |
92 | line [line_for bar_label] | |
93 | DW_LNS_copy | |
41505c0f | 94 | |
d4c4a229 SM |
95 | DW_LNE_set_address bar_label_2 |
96 | line [line_for bar_label_2] | |
97 | DW_LNS_copy | |
41505c0f | 98 | |
d4c4a229 SM |
99 | DW_LNE_set_address bar_label_3 |
100 | line [line_for bar_label_3] | |
101 | DW_LNS_copy | |
41505c0f | 102 | |
d4c4a229 SM |
103 | DW_LNE_set_address bar_label_4 |
104 | line [line_for bar_label_4] | |
105 | DW_LNS_copy | |
41505c0f | 106 | |
d4c4a229 SM |
107 | DW_LNE_set_address bar_label_5 |
108 | DW_LNE_end_sequence | |
41505c0f TV |
109 | } |
110 | } | |
111 | } | |
112 | ||
2a0fa842 | 113 | if { [prepare_for_testing "failed to prepare" ${testfile}.[prefix_id] \ |
41505c0f TV |
114 | [list $srcfile $asm_file] {nodebug}] } { |
115 | return -1 | |
116 | } | |
117 | ||
118 | if ![runto_main] { | |
119 | return -1 | |
120 | } | |
121 | ||
e7be7292 | 122 | gdb_breakpoint "bar_label" |
41505c0f TV |
123 | gdb_continue_to_breakpoint "foo \\(1\\)" |
124 | ||
125 | gdb_test "next" "foo \\(2\\).*" "next to foo (2)" | |
126 | gdb_test "next" "foo \\(3\\).*" "next to foo (3)" | |
127 | gdb_test "next" "foo \\(4\\).*" "next to foo (4)" | |
128 | } | |
129 | ||
130 | ||
131 | # Add unique test prefix. | |
bab31d14 | 132 | proc test { cv cdw64 lv ldw64 {string_form ""}} { |
41505c0f TV |
133 | with_test_prefix cv=$cv { |
134 | with_test_prefix cdw=[expr $cdw64 ? 64 : 32] { | |
135 | with_test_prefix lv=$lv { | |
136 | with_test_prefix ldw=[expr $ldw64 ? 64 : 32] { | |
bab31d14 TV |
137 | if { $string_form == "" } { |
138 | test_1 $cv $cdw64 $lv $ldw64 | |
139 | } else { | |
140 | with_test_prefix string_form=$string_form { | |
141 | test_1 $cv $cdw64 $lv $ldw64 $string_form | |
142 | } | |
143 | } | |
41505c0f TV |
144 | } |
145 | } | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | set cv_low 2 | |
151 | set cv_high 4 | |
152 | ||
153 | set lv_low 2 | |
6cb22d4a | 154 | set lv_high 4 |
41505c0f TV |
155 | |
156 | for { set cv $cv_low } { $cv <= $cv_high } { incr cv } { | |
157 | for { set lv $lv_low } { $lv <= $lv_high } { incr lv } { | |
158 | # I'm not sure if it makes sense to have a dwarf vx CU with | |
159 | # a dwarf vx+1 line unit. | |
160 | if { $lv > $lv } { | |
161 | continue | |
162 | } | |
163 | ||
164 | foreach cdw64 { 0 1 } { | |
165 | foreach ldw64 { 0 1 } { | |
166 | test $cv $cdw64 $lv $ldw64 | |
167 | } | |
168 | } | |
169 | } | |
170 | } | |
44fda089 TV |
171 | |
172 | foreach cdw64 { 0 1 } { | |
173 | foreach ldw64 { 0 1 } { | |
bab31d14 TV |
174 | test 5 $cdw64 5 $ldw64 string |
175 | test 5 $cdw64 5 $ldw64 line_strp | |
44fda089 TV |
176 | } |
177 | } |