1 # Copyright 2022-2023 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 # 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
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
29 standard_testfile .c .S
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"]
36 set asm_file [standard_output_file $srcfile2]
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
54 {name dw2-prologue-end.c}
55 {stmt_list ${lines_label} DW_FORM_sec_offset}
56 {producer "clang version 17.0.1"}
58 declare_labels char_label
60 char_label: base_type {
62 {encoding @DW_ATE_signed}
63 {byte_size 1 DW_FORM_sdata}
69 {low_pc $trivial_start addr}
70 {high_pc "$trivial_start + $trivial_len" addr}
75 {low_pc $watch_start addr}
76 {high_pc "$watch_start + $watch_len" addr}
81 {DW_AT_location {DW_OP_reg0} SPECIAL_expr}
87 {low_pc $main_start addr}
88 {high_pc "$main_start + $main_len" addr}
93 lines {version 5} lines_label {
94 set diridx [include_dir "${srcdir}/${subdir}"]
95 file_name "$srcfile" $diridx
98 DW_LNS_set_file $diridx
99 DW_LNE_set_address $trivial_start
101 DW_LNS_set_prologue_end
102 DW_LNS_set_epilogue_begin
105 DW_LNE_set_address watch
106 line $watch_start_line
109 DW_LNE_set_address watch_start
110 line [gdb_get_line_number "watch assign"]
111 DW_LNS_set_prologue_end
114 DW_LNE_set_address watch_reassign
115 line [gdb_get_line_number "watch reassign"]
116 DW_LNS_set_epilogue_begin
119 DW_LNE_set_address watch_end
120 line [gdb_get_line_number "watch end"]
123 DW_LNE_set_address $main_start
125 DW_LNS_set_prologue_end
128 DW_LNE_set_address main_fun_call
129 line [gdb_get_line_number "main function call"]
132 DW_LNE_set_address main_epilogue
134 DW_LNS_set_epilogue_begin
142 if { [prepare_for_testing "failed to prepare" ${testfile} \
143 [list $srcfile $asm_file] {nodebug}] } {
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"
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"
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"
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
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" {