]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Simplify gdb.base/memops-watchpoint.exp
authorPedro Alves <pedro@palves.net>
Thu, 30 Jan 2025 20:38:29 +0000 (20:38 +0000)
committerPedro Alves <pedro@palves.net>
Mon, 9 Jun 2025 17:09:20 +0000 (18:09 +0100)
gdb.base/memops-watchpoint.exp has the same code basically repeated
three times.  Simplify by refactoring the common code to a procedure.

Modernize the gdb_test_multiple call a little bit while at it: use
-wrap and $gdb_test_name.

Change-Id: I42d9cbccf32760a2bc3dab2aa60412ad5a2ae291

gdb/testsuite/gdb.base/memops-watchpoint.exp

index eba54c1348fee03942bba4ae4363b614b0f70688..cabc306887c7a6bb318d7ba8637e23d0449b74e2 100644 (file)
@@ -44,118 +44,60 @@ gdb_test "watch -location c\[28\]" \
 # This is to allow the tests to work if there's a properly named symbol for
 # the function, even if there's no libc debug info.
 
-set saw_watch_trigger 0
-set saw_function 0
-set is_supported 1
-set message "continue until memset watchpoint hits"
-set watch_trigger \
+# ARRAY_RE is the array whose modification is caught by the
+# watchpoint.  SOURCE_FUNCTION is the function that modifies the
+# array, as written in the source of the test program.  FUNCTION_RE
+# matches the name of the symbol that actually implements
+# SOURCE_FUNCTION (e.g., memcpy may be implemented with memmove, so we
+# may want to expect both).  OLD_VALUE_RE and NEW_VALUE_RE match the
+# old/new values when the watchpoint triggers.
+
+proc continue_to_watchpoint {array_re source_function function_re
+                            old_value_re new_value_re} {
+    set saw_watch_trigger 0
+    set saw_function 0
+    set is_supported 1
+    set watch_trigger_re \
        [multi_line \
             "Continuing\\." \
             "" \
-            "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \
+            "(Hardware w|W)atchpoint ${::decimal}: -location ${array_re}\\\[28\\\]" \
             "" \
-            "Old value = 104 'h'" \
-            "New value = 0 '\\\\000'"]
-gdb_test_multiple "continue" $message {
-    -re $watch_trigger {
-       set saw_watch_trigger 1
-       exp_continue
-    }
-    -re ".*memset.* \\(\\) at .*:$decimal\r\n" {
-       set saw_function 1
-       exp_continue
-    }
-    -re ".*memset.* \\(\\) from .*libc\[^\r\n\]+\r\n" {
-       set saw_function 1
-       exp_continue
-    }
-    -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
-       set is_supported 0
-       unsupported "symbol for memset not found"
-       exp_continue
-    }
-    -re "$gdb_prompt $" {
-       if { $is_supported } {
-           setup_kfail breakpoints/31665 arm*-*-linux*
-           gdb_assert { $saw_watch_trigger && $saw_function } $message
+            "Old value = ${old_value_re}" \
+            "New value = ${new_value_re}"]
+    gdb_test_multiple "continue" \
+       "continue until $source_function watchpoint hits" {
+       -re $watch_trigger_re {
+           set saw_watch_trigger 1
+           exp_continue
+       }
+       -re ".*${function_re}.* \\(\\) at .*:$::decimal\r\n" {
+           set saw_function 1
+           exp_continue
+       }
+       -re ".*${function_re}.* \\(\\) from .*libc\[^\r\n\]+\r\n" {
+           set saw_function 1
+           exp_continue
+       }
+       -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
+           set is_supported 0
+           unsupported "symbol for ${source_function} not found"
+           exp_continue
+       }
+       -re -wrap "" {
+           if { $is_supported } {
+               setup_kfail breakpoints/31665 arm*-*-linux*
+               gdb_assert { $saw_watch_trigger && $saw_function } \
+                   $gdb_test_name
+           }
        }
     }
 }
 
+continue_to_watchpoint "a" "memset" "memset" "104 'h'" "0 '\\\\000'"
+
 # Note: Some architectures use memmove for memcpy.
-set saw_watch_trigger 0
-set saw_function 0
-set is_supported 1
-set message "continue until memcpy watchpoint hits"
-set watch_trigger \
-       [multi_line \
-            "Continuing\\." \
-            "" \
-            "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \
-            "" \
-            "Old value = 101 'e'" \
-            "New value = 114 'r'"]
-gdb_test_multiple "continue" $message {
-    -re $watch_trigger {
-       set saw_watch_trigger 1
-       exp_continue
-    }
-    -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" {
-       set saw_function 1
-       exp_continue
-    }
-    -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" {
-       set saw_function 1
-       exp_continue
-    }
-    -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
-       set is_supported 0
-       unsupported "symbol for memcpy not found"
-       exp_continue
-    }
-    -re "$gdb_prompt $" {
-       if { $is_supported } {
-           setup_kfail breakpoints/31665 arm*-*-linux*
-           gdb_assert { $saw_watch_trigger && $saw_function } $message
-       }
-    }
-}
+continue_to_watchpoint "b" "memcpy" "(memcpy|memmove)" "101 'e'" "114 'r'"
 
 # Note: Some architectures use memcpy for memmove.
-set saw_watch_trigger 0
-set saw_function 0
-set is_supported 1
-set message "continue until memmove watchpoint hits"
-set watch_trigger \
-       [multi_line \
-            "Continuing\\." \
-            "" \
-            "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \
-            "" \
-            "Old value = 100 'd'" \
-            "New value = 114 'r'"]
-gdb_test_multiple "continue" $message {
-    -re $watch_trigger {
-       set saw_watch_trigger 1
-       exp_continue
-    }
-    -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" {
-       set saw_function 1
-       exp_continue
-    }
-    -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" {
-       set saw_function 1
-       exp_continue
-    }
-    -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" {
-       set is_supported 0
-       unsupported "symbol for memmove not found"
-       exp_continue
-    }
-    -re "$gdb_prompt $" {
-       if { $is_supported } {
-           setup_kfail breakpoints/31665 arm*-*-linux*
-           gdb_assert { $saw_watch_trigger && $saw_function } $message
-       }
-    }
-}
+continue_to_watchpoint "c" "memmove" "(memcpy|memmove)" "100 'd'" "114 'r'"