]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Handle unsupported catch syscall
authorTom de Vries <tdevries@suse.de>
Sat, 31 Aug 2024 05:56:48 +0000 (07:56 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 31 Aug 2024 05:56:48 +0000 (07:56 +0200)
On riscv64-linux, I run into:
...
Expecting: ^(catch syscall[^M
]+)?((&.*)*.*~"Catchpoint 5 .*\\n".*=breakpoint-created,bkpt=\{number="5",type="catchpoint".*\}.*\n\^done[^M
]+[(]gdb[)] ^M
[ ]*)
catch syscall^M
&"catch syscall\n"^M
&"The feature 'catch syscall' is not supported on this architecture yet.\n"^M
^error,msg="The feature 'catch syscall' is not supported on this architecture yet."^M
(gdb) ^M
FAIL: gdb.mi/mi-breakpoint-changed.exp: test_insert_delete_modify: catch syscall (unexpected output)
...

Fix this by:
- factoring out proc supports_catch_syscall out of gdb.base/catch-syscall.exp,
  and
- using it in gdb.mi/mi-breakpoint-changed.exp.

Tested on x86_64-linux and riscv64-linux.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/testsuite/gdb.base/catch-syscall.exp
gdb/testsuite/gdb.mi/mi-breakpoint-changed.exp
gdb/testsuite/lib/gdb.exp

index 431bfd5bb148b941544c055413a8ca1f78497386..2e20b8f81837106bbab238b73b598f15df7522ea 100644 (file)
 # It was written by Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com>
 # on September/2008.
 
+require supports_catch_syscall
+
 standard_testfile
 
 if  { [prepare_for_testing "failed to prepare" $testfile ${testfile}.c] } {
      return -1
 }
 
-# Check target supports catch syscall or not.
 if {![runto_main]} {
     return
 }
 
-set test "catch syscall"
-gdb_test_multiple $test $test {
-    -re "The feature \'catch syscall\' is not supported.*\r\n$gdb_prompt $" {
-       unsupported "catch syscall isn't supported"
-       return -1
-    }
-    -re ".*$gdb_prompt $" {
-       pass $test
-    }
-}
-
-set test "check catch syscall"
-gdb_test_multiple "continue" $test {
-    -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
-       unsupported "catch syscall isn't supported"
-       return -1
-    }
-    -re ".*Catchpoint.*$gdb_prompt $" {
-      pass $test
-    }
-}
-
 # Test-case for PR27313.  Verify that negative syscall numbers are refused.
 gdb_test "catch syscall -1" "Unknown syscall number '-1'\\."
 
index d7f81322d8db4fc4b3d640c532c97b07e2c179ff..18e19a27be3ff220e8d69a132e3d3e4a1891691b 100644 (file)
@@ -15,6 +15,8 @@
 
 require allow_shlib_tests
 
+set supports_catch_syscall [supports_catch_syscall]
+
 load_lib mi-support.exp
 
 standard_testfile pending.c
@@ -85,17 +87,34 @@ proc test_insert_delete_modify { } {
     mi_gdb_test ${test} \
        {(&.*)*.*~".*atchpoint 3: .*\\n".*=breakpoint-created,bkpt=\{number="3",type="(hw |)watchpoint".*\}.*\n\^done} \
        $test
+
     set test "trace marker"
     mi_gdb_test $test \
        {(&.*)*.*~"Tracepoint 4 at .*\\n".*=breakpoint-created,bkpt=\{number="4",type="tracepoint".*\}.*\n\^done} \
        $test
+
     set test "catch syscall"
-    mi_gdb_test $test \
-       {(&.*)*.*~"Catchpoint 5 .*\\n".*=breakpoint-created,bkpt=\{number="5",type="catchpoint".*\}.*\n\^done} \
-       $test
+    if { $::supports_catch_syscall } {
+       mi_gdb_test $test \
+           {(&.*)*.*~"Catchpoint 5 .*\\n".*=breakpoint-created,bkpt=\{number="5",type="catchpoint".*\}.*\n\^done} \
+           $test
+       set bp_nr 6
+    } else {
+       unsupported $test
+       set bp_nr 5
+    }
+
     set test "dprintf marker, \"arg\" \""
+    set bp_re [mi_make_breakpoint \
+                  -number $bp_nr \
+                  -type dprintf \
+                  -func marker \
+                  -script [string_to_regexp {["printf \"arg\" \""]}]]
     mi_gdb_test $test \
-       {.*=breakpoint-created,bkpt=\{number="6",type="dprintf".*,script=\[\"printf \\\"arg\\\" \\\"\"\].*\}\r\n\^done} \
+       [multi_line \
+            ".*" \
+            "=breakpoint-created,${bp_re}" \
+            "\\^done"] \
        $test
 
     # 2. when modifying condition
@@ -143,7 +162,7 @@ proc test_insert_delete_modify { } {
 
     # Delete some breakpoints and verify that '=breakpoint-deleted
     # notification is correctly emitted.
-    for {set i 3} {$i < 7} {incr i} {
+    for {set i 3} {$i <= $bp_nr} {incr i} {
        mi_gdb_test "delete ${i}" ".*=breakpoint-deleted,id=\"${i}\".*\\^done" \
            "delete ${i}"
     }
index 2d33470b0ea1c4598f51c4e4476de7dd7ace4c4f..d4d4acb2313c12b36fb16ef4d2fe4064f3c69e21 100644 (file)
@@ -3568,6 +3568,55 @@ gdb_caching_proc supports_memtag {} {
     return 0
 }
 
+# Return 1 if catch syscall is supported, otherwise return 0.
+
+gdb_caching_proc supports_catch_syscall {} {
+    set me "supports_catch_syscall"
+
+    # Compile a test program.
+    set src {
+       int main() {
+           return 0;
+       }
+    }
+    if {![gdb_simple_compile $me $src executable]} {
+       verbose -log "$me: failed to compile"
+       return 0
+    }
+
+    # No error message, compilation succeeded so now run it via gdb.
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $::srcdir/$::subdir
+    gdb_load $obj
+    if { ![runto_main] } {
+       verbose -log "$me: failed to run to main"
+       return 0
+    }
+
+    # To make sure we test both setting and inserting the catchpoint.
+    gdb_test_no_output "set breakpoint always-inserted on"
+
+    set res 0
+    set re_yes \
+       [string_to_regexp \
+            "Catchpoint 2 (any syscall)"]
+    gdb_test_multiple "catch syscall" "" {
+       -re -wrap ^$re_yes {
+           set res 1
+       }
+       -re -wrap "" {
+       }
+    }
+
+    gdb_exit
+    remote_file build delete $obj
+
+    verbose "$me: returning $res" 2
+    return $res
+}
+
 # Return 1 if the target supports hardware single stepping.
 
 proc can_hardware_single_step {} {