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.
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]] } {
27 set linespec ${srcfile}:[gdb_get_line_number "Break here"]
28 if ![runto ${linespec}] {
32 gdb_test "watch -location a\[28\]" \
33 "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \
35 gdb_test "watch -location b\[28\]" \
36 "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \
38 gdb_test "watch -location c\[28\]" \
39 "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \
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
50 set message "continue until memset watchpoint hits"
55 "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \
57 "Old value = 104 'h'" \
58 "New value = 0 '\\\\000'"]
59 gdb_test_multiple "continue" $message {
61 set saw_watch_trigger 1
64 -re ".*memset.* \\(\\) at .*:$decimal\r\n" {
68 -re ".*memset.* \\(\\) from .*libc\[^\r\n\]+\r\n" {
72 -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
74 unsupported "symbol for memset not found"
78 if { $is_supported } {
79 setup_kfail breakpoints/31665 arm*-*-linux*
80 gdb_assert { $saw_watch_trigger && $saw_function } $message
85 # Note: Some architectures use memmove for memcpy.
86 set saw_watch_trigger 0
89 set message "continue until memcpy watchpoint hits"
94 "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \
96 "Old value = 101 'e'" \
97 "New value = 114 'r'"]
98 gdb_test_multiple "continue" $message {
100 set saw_watch_trigger 1
103 -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" {
107 -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" {
111 -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
113 unsupported "symbol for memcpy not found"
116 -re "$gdb_prompt $" {
117 if { $is_supported } {
118 setup_kfail breakpoints/31665 arm*-*-linux*
119 gdb_assert { $saw_watch_trigger && $saw_function } $message
124 # Note: Some architectures use memcpy for memmove.
125 set saw_watch_trigger 0
128 set message "continue until memmove watchpoint hits"
133 "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \
135 "Old value = 100 'd'" \
136 "New value = 114 'r'"]
137 gdb_test_multiple "continue" $message {
139 set saw_watch_trigger 1
142 -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" {
146 -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" {
150 -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
152 unsupported "symbol for memmove not found"
155 -re "$gdb_prompt $" {
156 if { $is_supported } {
157 setup_kfail breakpoints/31665 arm*-*-linux*
158 gdb_assert { $saw_watch_trigger && $saw_function } $message