[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / memops-watchpoint.exp
blobcee2d799c67ab8b256191d0e8c146d062a2a7298
1 # Copyright 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 # Test a binary that uses standard libc memory operation functions.  They are
17 # frequently optimized with specialized instructions, so make sure GDB behaves
18 # correctly in their presence.
20 standard_testfile
21 set options "-fno-builtin-memset -fno-builtin-memcpy -fno-builtin-memmove"
22 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
23           [list debug additional_flags=$options]] } {
24     return -1
27 set linespec ${srcfile}:[gdb_get_line_number "Break here"]
28 if ![runto ${linespec}] {
29     return -1
32 gdb_test "watch -location a\[28\]" \
33     "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \
34     "set watch on a"
35 gdb_test "watch -location b\[28\]" \
36     "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \
37     "set watchpoint on b"
38 gdb_test "watch -location c\[28\]" \
39     "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \
40     "set watchpoint on c"
42 # For the tests below, split the pattern matching in two parts: one for the
43 # watchpoint trigger, and another for the line showing the function name.
44 # This is to allow the tests to work if there's a properly named symbol for
45 # the function, even if there's no libc debug info.
47 set saw_watch_trigger 0
48 set saw_function 0
49 set is_supported 1
50 set message "continue until memset watchpoint hits"
51 set watch_trigger \
52         [multi_line \
53              "Continuing\\." \
54              "" \
55              "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \
56              "" \
57              "Old value = 104 'h'" \
58              "New value = 0 '\\\\000'"]
59 gdb_test_multiple "continue" $message {
60     -re $watch_trigger {
61         set saw_watch_trigger 1
62         exp_continue
63     }
64     -re ".*memset.* \\(\\) at .*:$decimal\r\n" {
65         set saw_function 1
66         exp_continue
67     }
68     -re ".*memset.* \\(\\) from .*libc\[^\r\n\]+\r\n" {
69         set saw_function 1
70         exp_continue
71     }
72     -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
73         set is_supported 0
74         unsupported "symbol for memset not found"
75         exp_continue
76     }
77     -re "$gdb_prompt $" {
78         if { $is_supported } {
79             setup_kfail breakpoints/31665 arm*-*-linux*
80             gdb_assert { $saw_watch_trigger && $saw_function } $message
81         }
82     }
85 # Note: Some architectures use memmove for memcpy.
86 set saw_watch_trigger 0
87 set saw_function 0
88 set is_supported 1
89 set message "continue until memcpy watchpoint hits"
90 set watch_trigger \
91         [multi_line \
92              "Continuing\\." \
93              "" \
94              "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \
95              "" \
96              "Old value = 101 'e'" \
97              "New value = 114 'r'"]
98 gdb_test_multiple "continue" $message {
99     -re $watch_trigger {
100         set saw_watch_trigger 1
101         exp_continue
102     }
103     -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" {
104         set saw_function 1
105         exp_continue
106     }
107     -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" {
108         set saw_function 1
109         exp_continue
110     }
111     -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
112         set is_supported 0
113         unsupported "symbol for memcpy not found"
114         exp_continue
115     }
116     -re "$gdb_prompt $" {
117         if { $is_supported } {
118             setup_kfail breakpoints/31665 arm*-*-linux*
119             gdb_assert { $saw_watch_trigger && $saw_function } $message
120         }
121     }
124 # Note: Some architectures use memcpy for memmove.
125 set saw_watch_trigger 0
126 set saw_function 0
127 set is_supported 1
128 set message "continue until memmove watchpoint hits"
129 set watch_trigger \
130         [multi_line \
131              "Continuing\\." \
132              "" \
133              "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \
134              "" \
135              "Old value = 100 'd'" \
136              "New value = 114 'r'"]
137 gdb_test_multiple "continue" $message {
138     -re $watch_trigger {
139         set saw_watch_trigger 1
140         exp_continue
141     }
142     -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" {
143         set saw_function 1
144         exp_continue
145     }
146     -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" {
147         set saw_function 1
148         exp_continue
149     }
150     -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
151         set is_supported 0
152         unsupported "symbol for memmove not found"
153         exp_continue
154     }
155     -re "$gdb_prompt $" {
156         if { $is_supported } {
157             setup_kfail breakpoints/31665 arm*-*-linux*
158             gdb_assert { $saw_watch_trigger && $saw_function } $message
159         }
160     }