]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2022-2024 Free Software Foundation, Inc. |
528b729b GL |
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 | # Check that GDB can honor the epilogue_begin flag the compiler can place | |
17 | # in the line-table data. | |
18 | # We test 2 things: 1. that a software watchpoint triggered in an epilogue | |
19 | # is correctly ignored | |
20 | # 2. that GDB can mark the same line as both prologue and epilogue | |
21 | ||
22 | load_lib dwarf.exp | |
23 | ||
24 | # This test can only be run on targets which support DWARF-2 and use gas. | |
25 | require dwarf2_support | |
26 | # restricted to x86 to make it simpler to follow a variable | |
27 | require is_x86_64_m64_target | |
28 | ||
29 | standard_testfile .c .S | |
30 | ||
31 | set trivial_line [gdb_get_line_number "trivial function"] | |
32 | set main_prologue [gdb_get_line_number "main prologue"] | |
33 | set main_epilogue [gdb_get_line_number "main end"] | |
34 | set watch_start_line [gdb_get_line_number "watch start"] | |
35 | ||
36 | set asm_file [standard_output_file $srcfile2] | |
37 | ||
38 | # The producer will be set to clang because at the time of writing | |
39 | # we only care about epilogues if the producer is clang. When the | |
40 | # producer is GCC, variables use CFA locations, so watchpoints can | |
41 | # continue working even on epilogues. | |
42 | Dwarf::assemble $asm_file { | |
43 | global srcdir subdir srcfile srcfile2 | |
44 | global trivial_line main_prologue main_epilogue watch_start_line | |
45 | declare_labels lines_label | |
46 | ||
47 | get_func_info main | |
48 | get_func_info trivial | |
49 | get_func_info watch | |
50 | ||
51 | cu {} { | |
52 | compile_unit { | |
53 | {language @DW_LANG_C} | |
54 | {name dw2-prologue-end.c} | |
55 | {stmt_list ${lines_label} DW_FORM_sec_offset} | |
56 | {producer "clang version 17.0.1"} | |
57 | } { | |
58 | declare_labels char_label | |
59 | ||
60 | char_label: base_type { | |
61 | {name char} | |
62 | {encoding @DW_ATE_signed} | |
63 | {byte_size 1 DW_FORM_sdata} | |
64 | } | |
65 | ||
66 | subprogram { | |
67 | {external 1 flag} | |
68 | {name trivial} | |
69 | {low_pc $trivial_start addr} | |
70 | {high_pc "$trivial_start + $trivial_len" addr} | |
71 | } | |
72 | subprogram { | |
73 | {external 1 flag} | |
74 | {name watch} | |
75 | {low_pc $watch_start addr} | |
76 | {high_pc "$watch_start + $watch_len" addr} | |
77 | } { | |
78 | DW_TAG_variable { | |
79 | {name local} | |
80 | {type :$char_label} | |
81 | {DW_AT_location {DW_OP_reg0} SPECIAL_expr} | |
82 | } | |
83 | } | |
84 | subprogram { | |
85 | {external 1 flag} | |
86 | {name main} | |
87 | {low_pc $main_start addr} | |
88 | {high_pc "$main_start + $main_len" addr} | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | lines {version 5} lines_label { | |
94 | set diridx [include_dir "${srcdir}/${subdir}"] | |
95 | file_name "$srcfile" $diridx | |
96 | ||
97 | program { | |
98 | DW_LNS_set_file $diridx | |
99 | DW_LNE_set_address $trivial_start | |
100 | line $trivial_line | |
101 | DW_LNS_set_prologue_end | |
102 | DW_LNS_set_epilogue_begin | |
103 | DW_LNS_copy | |
104 | ||
105 | DW_LNE_set_address watch | |
106 | line $watch_start_line | |
107 | DW_LNS_copy | |
108 | ||
109 | DW_LNE_set_address watch_start | |
110 | line [gdb_get_line_number "watch assign"] | |
111 | DW_LNS_set_prologue_end | |
112 | DW_LNS_copy | |
113 | ||
114 | DW_LNE_set_address watch_reassign | |
115 | line [gdb_get_line_number "watch reassign"] | |
116 | DW_LNS_set_epilogue_begin | |
117 | DW_LNS_copy | |
118 | ||
119 | DW_LNE_set_address watch_end | |
120 | line [gdb_get_line_number "watch end"] | |
121 | DW_LNS_copy | |
122 | ||
123 | DW_LNE_set_address $main_start | |
124 | line $main_prologue | |
125 | DW_LNS_set_prologue_end | |
126 | DW_LNS_copy | |
127 | ||
128 | DW_LNE_set_address main_fun_call | |
129 | line [gdb_get_line_number "main function call"] | |
130 | DW_LNS_copy | |
131 | ||
132 | DW_LNE_set_address main_epilogue | |
133 | line $main_epilogue | |
134 | DW_LNS_set_epilogue_begin | |
135 | DW_LNS_copy | |
136 | ||
137 | DW_LNE_end_sequence | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | if { [prepare_for_testing "failed to prepare" ${testfile} \ | |
143 | [list $srcfile $asm_file] {nodebug}] } { | |
144 | return -1 | |
145 | } | |
146 | ||
147 | if ![runto_main] { | |
148 | return -1 | |
149 | } | |
150 | ||
151 | # Moving to the scope with a local variable. | |
152 | gdb_breakpoint $watch_start_line | |
153 | gdb_continue_to_breakpoint "continuing to function" ".*" | |
154 | gdb_test "next" "local = 2.*" "stepping to epilogue" | |
155 | ||
156 | # Forcing software watchpoints because hardware ones don't care if we | |
157 | # are in the epilogue or not. | |
158 | gdb_test_no_output "set can-use-hw-watchpoints 0" | |
159 | ||
160 | # Test that the software watchpoint will not trigger in this case | |
161 | gdb_test "watch local" "\[W|w\]atchpoint .: local" "set watchpoint" | |
162 | gdb_test "continue" ".*\[W|w\]atchpoint . deleted.*" \ | |
163 | "confirm watchpoint doesn't trigger" | |
164 | ||
165 | # First we test that the trivial function has a line with both a prologue | |
166 | # and an epilogue. Do this by finding a line that has 3 Y columns | |
167 | set sep "\[ \t\]" | |
168 | set hex_number "0x\[0-9a-f\]+" | |
169 | gdb_test_multiple "maint info line-table" "test epilogue in linetable" -lbl { | |
170 | -re "\[0-9\]$sep+$trivial_line$sep+$hex_number$sep+$hex_number$sep+Y$sep+Y$sep+Y" { | |
171 | pass $gdb_test_name | |
172 | } | |
173 | } |