[1/2] gdb/testsuite: add gcore_cmd_available predicate proc

Message ID acc0347c1871045f0c70327a794e2d8681c367e8.1741776651.git.aburgess@redhat.com
State New
Headers
Series include shared memory with id zero in core NT_FILE note |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Andrew Burgess March 12, 2025, 10:52 a.m. UTC
  Add a new gcore_cmd_available predicate proc that can be used in a
'requires' line, and make use of it in a few tests.

All of the tests I have modified call gdb_gcore_cmd as one of their
first actions and exit if the gcore command is not available, so it
makes sense (I think) to move the gcore command check into a requires
call.

There should be no change in what is actually run after this commit.
---
 gdb/testsuite/gdb.ada/task_switch_in_core.exp  |  2 +-
 .../gdb.base/coredump-filter-build-id.exp      |  2 +-
 gdb/testsuite/gdb.base/gcore.exp               |  1 +
 .../gdb.base/print-symbol-loading.exp          |  2 +-
 gdb/testsuite/gdb.base/solib-search.exp        |  2 +-
 gdb/testsuite/gdb.tui/corefile-run.exp         |  2 ++
 gdb/testsuite/lib/gdb.exp                      | 18 ++++++++++++++++++
 7 files changed, 25 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gdb/testsuite/gdb.ada/task_switch_in_core.exp b/gdb/testsuite/gdb.ada/task_switch_in_core.exp
index dd63bb87599..5afe8cc3885 100644
--- a/gdb/testsuite/gdb.ada/task_switch_in_core.exp
+++ b/gdb/testsuite/gdb.ada/task_switch_in_core.exp
@@ -15,7 +15,7 @@ 
 
 load_lib "ada.exp"
 
-require allow_ada_tests
+require allow_ada_tests gcore_cmd_available
 
 standard_ada_testfile crash
 
diff --git a/gdb/testsuite/gdb.base/coredump-filter-build-id.exp b/gdb/testsuite/gdb.base/coredump-filter-build-id.exp
index cddacce20c4..7fa0b6a2f5d 100644
--- a/gdb/testsuite/gdb.base/coredump-filter-build-id.exp
+++ b/gdb/testsuite/gdb.base/coredump-filter-build-id.exp
@@ -28,7 +28,7 @@  if { ![istarget *-*-linux*] } {
     untested "$testfile.exp"
     return -1
 }
-require is_x86_64_m64_target
+require is_x86_64_m64_target gcore_cmd_available
 
 if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug build-id}] } {
     return -1
diff --git a/gdb/testsuite/gdb.base/gcore.exp b/gdb/testsuite/gdb.base/gcore.exp
index ff4e94c4df9..6ecfcc34dc3 100644
--- a/gdb/testsuite/gdb.base/gcore.exp
+++ b/gdb/testsuite/gdb.base/gcore.exp
@@ -16,6 +16,7 @@ 
 # This file was written by Michael Snyder (msnyder@redhat.com)
 # This is a test for the gdb command "generate-core-file".
 
+require gcore_cmd_available
 
 standard_testfile
 
diff --git a/gdb/testsuite/gdb.base/print-symbol-loading.exp b/gdb/testsuite/gdb.base/print-symbol-loading.exp
index b3520f1e032..45168c8f233 100644
--- a/gdb/testsuite/gdb.base/print-symbol-loading.exp
+++ b/gdb/testsuite/gdb.base/print-symbol-loading.exp
@@ -15,7 +15,7 @@ 
 
 # Test the "print symbol-loading" option.
 
-require allow_shlib_tests
+require allow_shlib_tests gcore_cmd_available
 
 standard_testfile print-symbol-loading-main.c
 set libfile print-symbol-loading-lib
diff --git a/gdb/testsuite/gdb.base/solib-search.exp b/gdb/testsuite/gdb.base/solib-search.exp
index bf021c8a8d2..eb1aeb112eb 100644
--- a/gdb/testsuite/gdb.base/solib-search.exp
+++ b/gdb/testsuite/gdb.base/solib-search.exp
@@ -16,7 +16,7 @@ 
 # Test solib-search-path, and in the case of solib-svr4.c whether l_addr_p
 # is properly reset when the path is changed.
 
-require allow_shlib_tests
+require allow_shlib_tests gcore_cmd_available
 require {!is_remote target}
 
 # Build "wrong" and "right" versions of the libraries in separate directories.
diff --git a/gdb/testsuite/gdb.tui/corefile-run.exp b/gdb/testsuite/gdb.tui/corefile-run.exp
index f96ead91864..eb58e066711 100644
--- a/gdb/testsuite/gdb.tui/corefile-run.exp
+++ b/gdb/testsuite/gdb.tui/corefile-run.exp
@@ -18,6 +18,8 @@ 
 #
 # Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1765117
 
+require gcore_cmd_available
+
 tuiterm_env
 
 standard_testfile tui-layout.c
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 435a6f8404f..a8ba9193593 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6957,6 +6957,24 @@  proc gdb_load_cmd { args } {
     return -1
 }
 
+# Return non-zero if 'gcore' command is available.
+gdb_caching_proc gcore_cmd_available { } {
+    gdb_exit
+    gdb_start
+
+    # Does this gdb support gcore?
+    gdb_test_multiple "help gcore" "" {
+	-re -wrap "Undefined command: .*" {
+	    return 0
+	}
+	-re -wrap "Save a core file .*" {
+	    return 1
+	}
+    }
+
+    return 0
+}
+
 # Invoke "gcore".  CORE is the name of the core file to write.  TEST
 # is the name of the test case.  This will return 1 if the core file
 # was created, 0 otherwise.  If this fails to make a core file because