]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: restructure gdb.base/dlmopen.exp
authorAndrew Burgess <aburgess@redhat.com>
Thu, 19 Dec 2024 10:41:40 +0000 (10:41 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Sun, 9 Feb 2025 17:30:57 +0000 (17:30 +0000)
In the next commit I want to add more tests to the dlmopen.exp script.
Doing this will be easier if the dlmopen.exp script was structured so
that the current tests were contained inside separatate procs.  So
this commit moves all of the current tests within dlmopen into two
procs, and then calls these.

There should be no changes to what is actually being tested in this
commit.

gdb/testsuite/gdb.base/dlmopen.exp

index dee046a8b335f35bcecf90af20d7dc713b331c6a..f1da76a13f6ae6322c18f7e60099938daef894f7 100644 (file)
@@ -77,16 +77,16 @@ if { [build_executable "build shlib" $binfile_lib2 $srcfile_lib \
     return
 }
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
+if { [build_executable "failed to build" $testfile $srcfile \
          [list additional_flags=-DDSO1_NAME=\"$binfile_lib1\" \
               additional_flags=-DDSO2_NAME=\"$binfile_lib2\" \
               shlib_load debug]] } {
-    return -1
+    return
 }
 
-if { ![runto_main] } {
-    return -1
-}
+# Some locations needed by the tests.
+set bp_inc [gdb_get_line_number "bp.inc" $srcfile_lib]
+set bp_main [gdb_get_line_number "bp.main" $srcfile]
 
 # Check that 'info shared' show NUM occurrences of DSO.
 proc check_dso_count { dso num } {
@@ -158,41 +158,58 @@ proc test_dlmopen {} {
     }
 }
 
-# Remove the pause.  We only need it for the attach test.
-gdb_test "print wait_for_gdb = 0" "\\\$1 = 0"
+# Setup for calling 'test_dlmopen', this is the version of the test
+# that doesn't use 'attach'.
+proc test_dlmopen_no_attach {} {
+    clean_restart $::binfile
 
-# Break in the to-be-loaded library and at the end of main.
-set bp_inc [gdb_get_line_number "bp.inc" $srcfile_lib]
-set bp_main [gdb_get_line_number "bp.main" $srcfile]
+    if { ![runto_main] } {
+       return
+    }
 
-delete_breakpoints
-gdb_breakpoint $srcfile_lib:$bp_inc allow-pending
-gdb_breakpoint $srcfile:$bp_main
+    # Remove the pause.  We only need it for the attach test.
+    gdb_test "print wait_for_gdb = 0" "\\\$1 = 0"
 
-test_dlmopen
+    # Break in the to-be-loaded library and at the end of main.
+    delete_breakpoints
+    gdb_breakpoint $::srcfile_lib:$::bp_inc allow-pending
+    gdb_breakpoint $::srcfile:$::bp_main
 
-# Try the same again when attaching after dlmopen().
-require can_spawn_for_attach
+    test_dlmopen
+}
 
-clean_restart $binfile
+# Setup for calling 'test_dlmopen', this is the version of the test
+# that does use 'attach'.
+proc test_dlmopen_with_attach {} {
+    if { ![can_spawn_for_attach] } {
+       unsupported "cannot run attach tests"
+       return
+    }
 
-# Start the test program.
-set test_spawn_id [spawn_wait_for_attach $binfile]
-set testpid [spawn_id_get_pid $test_spawn_id]
+    clean_restart $::binfile
 
-# Attach.
-if { ![gdb_attach $testpid] } {
-    return
-}
+    # Start the test program.
+    set test_spawn_id [spawn_wait_for_attach $::binfile]
+    set testpid [spawn_id_get_pid $test_spawn_id]
 
-with_test_prefix "attach" {
-    # Remove the pause.  We no longer need it.
-    gdb_test "print wait_for_gdb = 0" "\\\$1 = 0"
+    # Attach.
+    if { ![gdb_attach $testpid] } {
+       return
+    }
 
-    # Set the same breakpoints again.  This time, however, we do not allow the
-    # breakpoint to be pending since the library has already been loaded.
-    gdb_breakpoint $srcfile_lib:$bp_inc
-    gdb_breakpoint $srcfile:$bp_main
+    with_test_prefix "attach" {
+       # Remove the pause.  We no longer need it.
+       gdb_test "print wait_for_gdb = 0" "\\\$1 = 0"
 
-    test_dlmopen
+       # Set the same breakpoints again.  This time, however, we do not allow the
+       # breakpoint to be pending since the library has already been loaded.
+       gdb_breakpoint $::srcfile_lib:$::bp_inc
+       gdb_breakpoint $::srcfile:$::bp_main
+
+       test_dlmopen
+    }
 }
+
+# Run the actual tests.
+test_dlmopen_no_attach
+test_dlmopen_with_attach