diff --git a/gdb/testsuite/gdb.arch/i386-stap-eval-lang-ada.exp b/gdb/testsuite/gdb.arch/i386-stap-eval-lang-ada.exp
index 8449ffa..41530ea 100644
--- a/gdb/testsuite/gdb.arch/i386-stap-eval-lang-ada.exp
+++ b/gdb/testsuite/gdb.arch/i386-stap-eval-lang-ada.exp
@@ -25,7 +25,7 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
     return -1
 }
 
-gdb_test_no_output "set language ada"
+set_language "ada"
 
 if { ![runto "-pstap bar"] } {
     return -1
diff --git a/gdb/testsuite/gdb.base/callfuncs.exp b/gdb/testsuite/gdb.base/callfuncs.exp
index 3651963..ae30fae 100644
--- a/gdb/testsuite/gdb.base/callfuncs.exp
+++ b/gdb/testsuite/gdb.base/callfuncs.exp
@@ -303,7 +303,7 @@ proc rerun_and_prepare {} {
 	gdb_suppress_tests
     }
 
-    gdb_test_no_output "set language c"
+    set_language "c"
 
     get_debug_format
 
diff --git a/gdb/testsuite/gdb.compile/compile-ifunc.exp b/gdb/testsuite/gdb.compile/compile-ifunc.exp
index dc442ff..fc37720 100644
--- a/gdb/testsuite/gdb.compile/compile-ifunc.exp
+++ b/gdb/testsuite/gdb.compile/compile-ifunc.exp
@@ -29,7 +29,7 @@ with_test_prefix "nodebug" {
     # GDB happened to see real asm code when it stopped at the entry point
     # when talking to a remote target, like gdbserver.  This guarantees the
     # feature check below will work.
-    gdb_test_no_output "set language c" ""
+    set_language "c"
 
     if {[skip_compile_feature_tests]} {
 	untested "compile command not supported (could not find libcc1 shared library?)"
diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp
index 256fa68..ef0e515 100644
--- a/gdb/testsuite/gdb.cp/classes.exp
+++ b/gdb/testsuite/gdb.cp/classes.exp
@@ -551,7 +551,7 @@ proc do_tests {} {
     global nl
 
 
-    gdb_test_no_output "set language c++" ""
+    set_language "c++"
     gdb_test_no_output "set width 0" ""
 
     if ![runto_main ] then {
diff --git a/gdb/testsuite/gdb.cp/cmpd-minsyms.exp b/gdb/testsuite/gdb.cp/cmpd-minsyms.exp
index bff6967..9d5c559 100644
--- a/gdb/testsuite/gdb.cp/cmpd-minsyms.exp
+++ b/gdb/testsuite/gdb.cp/cmpd-minsyms.exp
@@ -40,7 +40,7 @@ foreach sym $min_syms {
 }
 
 
-gdb_test_no_output "set language c++"
+set_language "c++"
 
 # A list of minimal symbol names to check.
 # Note that GDB<char>::even_harder<int>(char) is quoted and includes
diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.exp b/gdb/testsuite/gdb.cp/cplusfuncs.exp
index 0b90500..28c5617 100644
--- a/gdb/testsuite/gdb.cp/cplusfuncs.exp
+++ b/gdb/testsuite/gdb.cp/cplusfuncs.exp
@@ -584,7 +584,7 @@ proc do_tests {} {
 
     runto_main
 
-    gdb_test_no_output "set language c++"
+    set_language "c++"
     probe_demangler
     test_paddr_overloaded_functions
     test_paddr_operator_functions
diff --git a/gdb/testsuite/gdb.cp/debug-expr.exp b/gdb/testsuite/gdb.cp/debug-expr.exp
index b20de5b..a941e99 100644
--- a/gdb/testsuite/gdb.cp/debug-expr.exp
+++ b/gdb/testsuite/gdb.cp/debug-expr.exp
@@ -18,7 +18,7 @@
 if { [skip_cplus_tests] } { continue }
 
 gdb_start
-gdb_test_no_output "set language c++"
+set_language "c++"
 gdb_test_no_output "set debug expression 1"
 
 # Test whether the expression debug machinery accepts the expression.
diff --git a/gdb/testsuite/gdb.cp/demangle.exp b/gdb/testsuite/gdb.cp/demangle.exp
index 0ecf95d..c4a9e6e 100644
--- a/gdb/testsuite/gdb.cp/demangle.exp
+++ b/gdb/testsuite/gdb.cp/demangle.exp
@@ -1547,7 +1547,7 @@ proc do_tests {} {
     gdb_exit
     gdb_start
 
-    gdb_test_no_output "set language c++"
+    set_language "c++"
     gdb_test_no_output "set width 0"
 
     # Using catch_demangling_errors this way ensures that, if one of
@@ -1559,7 +1559,7 @@ proc do_tests {} {
     catch_demangling_errors test_hp_style_demangling
 
     # Verify specifying demangle language.
-    gdb_test_no_output "set language unknown"
+    set_language "unknown"
     set_demangling_style "auto"
     gdb_test_exact "demangle -l c++ -- _ZSt4cout" "std::cout"
     gdb_test_exact "demangle -l c++ _ZSt4cout" "std::cout"
diff --git a/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp b/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
index ad2111c..112b717 100644
--- a/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
+++ b/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
@@ -26,7 +26,7 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug c
 
 clean_restart ${executable}
 
-gdb_test_no_output "set language c++"
+set_language "c++"
 
 # FAIL was:
 # $1 = {<text variable, no debug info>} 0
diff --git a/gdb/testsuite/gdb.cp/inherit.exp b/gdb/testsuite/gdb.cp/inherit.exp
index d80caee..9caafc8 100644
--- a/gdb/testsuite/gdb.cp/inherit.exp
+++ b/gdb/testsuite/gdb.cp/inherit.exp
@@ -682,7 +682,7 @@ proc do_tests { } {
 	return
     }
 
-    gdb_test_no_output "set language c++"
+    set_language "c++"
     test_ptype_si
     test_ptype_mi
     test_ptype_vi
diff --git a/gdb/testsuite/gdb.cp/overload-const.exp b/gdb/testsuite/gdb.cp/overload-const.exp
index 0d7b0ae..feb4e96 100644
--- a/gdb/testsuite/gdb.cp/overload-const.exp
+++ b/gdb/testsuite/gdb.cp/overload-const.exp
@@ -23,7 +23,7 @@ if {[prepare_for_testing "failed to prepare" $testfile $testfile.cc {c++ debug}]
     return -1
 }
 
-gdb_test_no_output "set language c++"
+set_language "c++"
 
 if [gdb_breakpoint "myclass::func"] {
     pass "setting breakpoint at myclass::func"
diff --git a/gdb/testsuite/gdb.cp/psymtab-parameter.exp b/gdb/testsuite/gdb.cp/psymtab-parameter.exp
index 3d78de9..0bddd80 100644
--- a/gdb/testsuite/gdb.cp/psymtab-parameter.exp
+++ b/gdb/testsuite/gdb.cp/psymtab-parameter.exp
@@ -25,7 +25,7 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}.x" object {debug
 clean_restart $testfile.x
 
 # As `main' is not present GDB fails to find the proper inferior language.
-gdb_test_no_output "set language c++"
+set_language "c++"
 
 # The goal is to keep the CU (Compilation Unit) unexpanded.  It would be rather
 # XFAIL than FAIL here.  For example -readnow breaks it.
diff --git a/gdb/testsuite/gdb.cp/ptype-flags.exp b/gdb/testsuite/gdb.cp/ptype-flags.exp
index 24c4e31..e82f7d0 100644
--- a/gdb/testsuite/gdb.cp/ptype-flags.exp
+++ b/gdb/testsuite/gdb.cp/ptype-flags.exp
@@ -30,7 +30,7 @@ if ![runto_main] then {
     return
 }
 
-gdb_test_no_output "set language c++" ""
+set_language "c++"
 gdb_test_no_output "set width 0" ""
 
 proc do_check {name {flags ""} {show_typedefs 1} {show_methods 1} {raw 0}} {
diff --git a/gdb/testsuite/gdb.cp/typedef-operator.exp b/gdb/testsuite/gdb.cp/typedef-operator.exp
index 5c5fda6..5180aac 100644
--- a/gdb/testsuite/gdb.cp/typedef-operator.exp
+++ b/gdb/testsuite/gdb.cp/typedef-operator.exp
@@ -23,7 +23,7 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile {c++ debug}]} {
     return -1
 }
 
-gdb_test_no_output "set language c++"
+set_language "c++"
 
 gdb_test "p *u" {You can't do that without a process to debug.} "test crash"
 
diff --git a/gdb/testsuite/gdb.cp/var-tag.exp b/gdb/testsuite/gdb.cp/var-tag.exp
index 5524468..b85055b 100644
--- a/gdb/testsuite/gdb.cp/var-tag.exp
+++ b/gdb/testsuite/gdb.cp/var-tag.exp
@@ -37,7 +37,7 @@ proc do_global_tests {lang} {
     set ptypefmt "type = (class|enum|union|struct) %s $opt_underlying{.*}"
 
     with_test_prefix $lang {
-    gdb_test_no_output "set language $lang"
+    set_language "$lang"
     gdb_test "ptype C" "type = class C {.*}"
     gdb_test "print E" "= a"
     gdb_test "ptype E" "type = enum E $opt_underlying{.*}"
@@ -102,7 +102,7 @@ with_test_prefix "in C::f" {
 # Another hard-to-guess-the-users-intent bug...
 # It would be really nice if we could query the user!
 with_test_prefix "global collision" {
-    gdb_test_no_output "set language c++"
+    set_language "c++"
     setup_kfail "c++/16463" "*-*-*"
     gdb_test "print global" "= 3"
 
diff --git a/gdb/testsuite/gdb.cp/virtfunc.exp b/gdb/testsuite/gdb.cp/virtfunc.exp
index 7b8f672..c0ae27d 100644
--- a/gdb/testsuite/gdb.cp/virtfunc.exp
+++ b/gdb/testsuite/gdb.cp/virtfunc.exp
@@ -270,7 +270,7 @@ proc test_info_vtbl {} {
 }
 
 proc do_tests {} {
-    gdb_test_no_output "set language c++" ""
+    set_language "c++"
     gdb_test_no_output "set width 0" ""
 
     if ![runto_main] then {
diff --git a/gdb/testsuite/gdb.dlang/circular.exp b/gdb/testsuite/gdb.dlang/circular.exp
index 205cde2..09ac534 100644
--- a/gdb/testsuite/gdb.dlang/circular.exp
+++ b/gdb/testsuite/gdb.dlang/circular.exp
@@ -139,7 +139,7 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \
     return -1
 }
 
-gdb_test_no_output "set language d"
+set_language "d"
 
 if {![runto "circular1.found"]} {
     return -1
diff --git a/gdb/testsuite/gdb.dlang/debug-expr.exp b/gdb/testsuite/gdb.dlang/debug-expr.exp
index d62dcc6..bd58421 100644
--- a/gdb/testsuite/gdb.dlang/debug-expr.exp
+++ b/gdb/testsuite/gdb.dlang/debug-expr.exp
@@ -18,7 +18,7 @@
 if { [skip_d_tests] } { return -1 }
 
 gdb_start
-gdb_test_no_output "set language d"
+set_language "d"
 gdb_test_no_output "set debug expression 1"
 
 # Test whether the expression debug machinery accepts the expression.
diff --git a/gdb/testsuite/gdb.dlang/demangle.exp b/gdb/testsuite/gdb.dlang/demangle.exp
index baf6d6f..77b7968 100644
--- a/gdb/testsuite/gdb.dlang/demangle.exp
+++ b/gdb/testsuite/gdb.dlang/demangle.exp
@@ -200,7 +200,7 @@ proc test_d_demangling {} {
 gdb_exit
 gdb_start
 
-if [set_lang_d] {
+if [set_language "d"] {
     gdb_test_no_output "set width 0"
 
     test_d_demangling
diff --git a/gdb/testsuite/gdb.dlang/expression.exp b/gdb/testsuite/gdb.dlang/expression.exp
index 700f59b..9ec95a3 100644
--- a/gdb/testsuite/gdb.dlang/expression.exp
+++ b/gdb/testsuite/gdb.dlang/expression.exp
@@ -128,7 +128,7 @@ proc test_d_expressions {} {
 gdb_exit
 gdb_start
 
-if [set_lang_d] {
+if [set_language "d"] {
     test_d_integer_literals
     test_d_float_literals
     test_d_expressions
diff --git a/gdb/testsuite/gdb.dlang/primitive-types.exp b/gdb/testsuite/gdb.dlang/primitive-types.exp
index eec10ef..241cd6a 100644
--- a/gdb/testsuite/gdb.dlang/primitive-types.exp
+++ b/gdb/testsuite/gdb.dlang/primitive-types.exp
@@ -54,7 +54,7 @@ proc test_builtin_d_types_accepted {} {
 gdb_exit
 gdb_start
 
-if [set_lang_d] {
+if [set_language "d"] {
     test_builtin_d_types_accepted
 } else {
     warning "D type tests suppressed."
diff --git a/gdb/testsuite/gdb.dlang/properties.exp b/gdb/testsuite/gdb.dlang/properties.exp
index de95bd6..1ef8de3 100644
--- a/gdb/testsuite/gdb.dlang/properties.exp
+++ b/gdb/testsuite/gdb.dlang/properties.exp
@@ -85,7 +85,7 @@ proc test_d_typeof {} {
 gdb_exit
 gdb_start
 
-if [set_lang_d] {
+if [set_language "d"] {
     test_d_sizeof
     test_d_typeof
 } else {
diff --git a/gdb/testsuite/gdb.dwarf2/arr-stride.exp b/gdb/testsuite/gdb.dwarf2/arr-stride.exp
index e628d26..201072c 100644
--- a/gdb/testsuite/gdb.dwarf2/arr-stride.exp
+++ b/gdb/testsuite/gdb.dwarf2/arr-stride.exp
@@ -88,7 +88,7 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \
     return -1
 }
 
-gdb_test_no_output "set language ada"
+set_language "ada"
 
 gdb_test "ptype pck.table" \
          "type = array \\(0 \\.\\. 4\\) of pck\\.item <packed: 6-bit elements>"
diff --git a/gdb/testsuite/gdb.dwarf2/arr-subrange.exp b/gdb/testsuite/gdb.dwarf2/arr-subrange.exp
index 1cfffda..8f74448 100644
--- a/gdb/testsuite/gdb.dwarf2/arr-subrange.exp
+++ b/gdb/testsuite/gdb.dwarf2/arr-subrange.exp
@@ -82,7 +82,7 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \
     return -1
 }
 
-gdb_test_no_output "set language ada"
+set_language "ada"
 
 gdb_test "ptype pck.table" \
          "type = array \\(enum_000 \\.\\. enum_128\\) of boolean"
diff --git a/gdb/testsuite/gdb.dwarf2/data-loc.exp b/gdb/testsuite/gdb.dwarf2/data-loc.exp
index 3e4c845..3ef93a8 100644
--- a/gdb/testsuite/gdb.dwarf2/data-loc.exp
+++ b/gdb/testsuite/gdb.dwarf2/data-loc.exp
@@ -129,7 +129,7 @@ if ![runto_main] {
     return -1
 }
 
-gdb_test_no_output "set language ada"
+set_language "ada"
 
 # foo.three
 
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static.exp b/gdb/testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static.exp
index d03d2ab..4fe0964 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static.exp
@@ -37,7 +37,7 @@ if ![runto_main] then {
 }
 
 # main is not provided by DWARF.
-gdb_test_no_output "set language c++"
+set_language "c++"
 
 # There are no mangled names in DWARF to suggest the v3 ABI.
 gdb_test_no_output "set cp-abi gnu-v3"
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp b/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp
index 4275d5d..c339328 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp
@@ -39,7 +39,7 @@ if ![runto_main] then {
 }
 
 # main is not provided by DWARF.
-gdb_test_no_output "set language c++"
+set_language "c++"
 
 # There are no mangled names in DWARF to suggest the v3 ABI.
 gdb_test_no_output "set cp-abi gnu-v3"
diff --git a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
index f7eff69..7567d82 100644
--- a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
+++ b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
@@ -130,7 +130,7 @@ if ![runto_main] {
     return -1
 }
 
-gdb_test_no_output "set language ada"
+set_language "ada"
 
 # foo.three_ptr.all
 
diff --git a/gdb/testsuite/gdb.dwarf2/subrange.exp b/gdb/testsuite/gdb.dwarf2/subrange.exp
index 9c9df7d..3d00bf3 100644
--- a/gdb/testsuite/gdb.dwarf2/subrange.exp
+++ b/gdb/testsuite/gdb.dwarf2/subrange.exp
@@ -65,7 +65,7 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \
     return -1
 }
 
-gdb_test_no_output "set language pascal"
+set_language "pascal"
 
 gdb_test "ptype TByteArray" \
     "type = array \\\[0\\.\\.191\\\] of byte"
diff --git a/gdb/testsuite/gdb.fortran/exprs.exp b/gdb/testsuite/gdb.fortran/exprs.exp
index 1aa7f4c..b9e42ef 100644
--- a/gdb/testsuite/gdb.fortran/exprs.exp
+++ b/gdb/testsuite/gdb.fortran/exprs.exp
@@ -249,7 +249,7 @@ gdb_reinitialize_dir $srcdir/$subdir
 
 gdb_test "set print sevenbit-strings" ""
 
-if [set_lang_fortran] then {
+if [set_language "fortran"] then {
     test_value_history
     test_convenience_variables
     test_integer_literals_accepted
diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp
index 9549515..1c3d677 100644
--- a/gdb/testsuite/gdb.fortran/types.exp
+++ b/gdb/testsuite/gdb.fortran/types.exp
@@ -80,7 +80,7 @@ gdb_reinitialize_dir $srcdir/$subdir
 
 gdb_test "set print sevenbit-strings" ""
 
-if [set_lang_fortran] then {
+if [set_language "fortran"] then {
     test_integer_literal_types_accepted
     test_integer_literal_types_rejected
     test_logical_literal_types_accepted
diff --git a/gdb/testsuite/gdb.go/basic-types.exp b/gdb/testsuite/gdb.go/basic-types.exp
index 453e5e2..85d5849 100644
--- a/gdb/testsuite/gdb.go/basic-types.exp
+++ b/gdb/testsuite/gdb.go/basic-types.exp
@@ -106,7 +106,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
-if [set_lang_go] {
+if [set_language "go"] {
     test_integer_literal_types_accepted
     test_logical_literal_types_accepted
     test_character_literal_types_accepted
diff --git a/gdb/testsuite/gdb.go/print.exp b/gdb/testsuite/gdb.go/print.exp
index c95dc09..01868f6 100644
--- a/gdb/testsuite/gdb.go/print.exp
+++ b/gdb/testsuite/gdb.go/print.exp
@@ -62,7 +62,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
-if [set_lang_go] {
+if [set_language "go"] {
     test_float_accepted
     test_float_rejected
 } else {
diff --git a/gdb/testsuite/gdb.objc/print.exp b/gdb/testsuite/gdb.objc/print.exp
index 9ea4764..17703bb 100644
--- a/gdb/testsuite/gdb.objc/print.exp
+++ b/gdb/testsuite/gdb.objc/print.exp
@@ -21,8 +21,6 @@
 # Test printing of various values.
 # NOTE: The tests here intentionally do not require an objc compiler.
 
-load_lib "objc.exp"
-
 proc test_float_accepted {} {
     global gdb_prompt
 
@@ -63,7 +61,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
-if [set_lang_objc] {
+if [set_language "objective-c"] {
     test_float_accepted
     test_float_rejected
 } else {
diff --git a/gdb/testsuite/gdb.opencl/datatypes.exp b/gdb/testsuite/gdb.opencl/datatypes.exp
index 572e329..baf7be9 100644
--- a/gdb/testsuite/gdb.opencl/datatypes.exp
+++ b/gdb/testsuite/gdb.opencl/datatypes.exp
@@ -36,7 +36,7 @@ gdb_exit
 gdb_start
 
 # Manually switch the language to opencl
-gdb_test_no_output "set language opencl" "no prompt when setting the language to opencl"
+set_language "opencl" "no prompt when setting the language to opencl"
 
 # Check OpenCL data types (GDB)
 gdb_test "whatis bool" "type = bool"
@@ -194,8 +194,8 @@ gdb_test "whatis double16" "type = double16"
 gdb_test "p sizeof(double16)" " = 128"
 
 # Set the language back to the default: "auto; currently c"
-gdb_test_no_output "set language c" "no prompt when setting the language to c"
-gdb_test_no_output "set language auto" "no prompt when setting the language to auto"
+set_language "c" "no prompt when setting the language to c"
+set_language "auto" "no prompt when setting the language to auto"
 
 # Load the OpenCL app
 gdb_reinitialize_dir $srcdir/$subdir
diff --git a/gdb/testsuite/gdb.pascal/print.exp b/gdb/testsuite/gdb.pascal/print.exp
index 458630d..eadbe3a 100644
--- a/gdb/testsuite/gdb.pascal/print.exp
+++ b/gdb/testsuite/gdb.pascal/print.exp
@@ -63,7 +63,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
-if [set_lang_pascal] {
+if [set_language "pascal"] {
     test_float_accepted
     test_float_rejected
 } else {
diff --git a/gdb/testsuite/gdb.pascal/types.exp b/gdb/testsuite/gdb.pascal/types.exp
index 4a2374b..0e31673 100644
--- a/gdb/testsuite/gdb.pascal/types.exp
+++ b/gdb/testsuite/gdb.pascal/types.exp
@@ -74,7 +74,7 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
-if [set_lang_pascal] then {
+if [set_language "pascal"] then {
     test_integer_literal_types_accepted
     test_logical_literal_types_accepted
     test_character_literal_types_accepted
diff --git a/gdb/testsuite/gdb.python/py-lookup-type.exp b/gdb/testsuite/gdb.python/py-lookup-type.exp
index 2f98052..de24bbb 100644
--- a/gdb/testsuite/gdb.python/py-lookup-type.exp
+++ b/gdb/testsuite/gdb.python/py-lookup-type.exp
@@ -31,7 +31,7 @@ gdb_reinitialize_dir $srcdir/$subdir
 if { [skip_python_tests] } { continue }
 
 proc test_lookup_type { lang type_name } {
-    gdb_test_no_output "set language ${lang}"
+    set_language "${lang}"
     gdb_test "python print(gdb.lookup_type('${type_name}').name)" \
         "${type_name}" \
         "lookup type ${type_name} using language ${lang}"
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
index 415680b..4ed84c9 100644
--- a/gdb/testsuite/gdb.rust/expr.exp
+++ b/gdb/testsuite/gdb.rust/expr.exp
@@ -23,7 +23,7 @@ gdb_start
 
 gdb_test_no_output "set var \$something = 27"
 
-if {![set_lang_rust]} {
+if {![set_language "rust"]} {
     warning "Rust expression tests suppressed."
     continue
 }
diff --git a/gdb/testsuite/lib/d-support.exp b/gdb/testsuite/lib/d-support.exp
index ed568d3..3e5b457 100644
--- a/gdb/testsuite/lib/d-support.exp
+++ b/gdb/testsuite/lib/d-support.exp
@@ -13,20 +13,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Auxiliary function to set the language to D.
-# The result is 1 (true) for success, 0 (false) for failure.
-
-proc set_lang_d {} {
-    if [gdb_test_no_output "set language d"] {
-	return 0
-    }
-    if [gdb_test "show language" ".* source language is \"d\"." \
-	   "set language to \"d\""] {
-	return 0
-    }
-    return 1
-}
-
 # D version of runto_main.
 
 proc d_runto_main { } {
diff --git a/gdb/testsuite/lib/fortran.exp b/gdb/testsuite/lib/fortran.exp
index 867e4fc..3e78315 100644
--- a/gdb/testsuite/lib/fortran.exp
+++ b/gdb/testsuite/lib/fortran.exp
@@ -15,20 +15,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Auxiliary function to set the language to fortran.
-# The result is 1 (true) for success, 0 (false) for failure.
-
-proc set_lang_fortran {} {
-    if [gdb_test_no_output "set language fortran"] {
-	return 0
-    }
-    if [gdb_test "show language" ".* source language is \"fortran\"." \
-	   "set language to \"fortran\""] {
-	return 0
-    }
-    return 1
-}
-
 proc fortran_int4 {} {
     if {[test_compiler_info {gcc-4-[012]-*}]} {
 	return "int4"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 48bd7ee..ff076b9 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6018,6 +6018,49 @@ proc multi_line_input { args } {
     return [join $args "\n"]
 }
 
+# Set the language and handle possible warnings output by GDB if
+# we select a language that differs from the current frame's language.
+#
+# The first argument is the language to be set.
+#
+# The second argument is an optional message to be output by the test.  If
+# the message is empty, the command to set the language will be used instead.
+
+proc set_language { language { message "" } } {
+    global gdb_prompt
+
+    set command "set language $language"
+    set lang_pattern [string_to_regexp $language]
+
+    if { $message == "" } {
+	set message $command
+    }
+
+    # Switch to the user-selected language.
+    gdb_test_multiple $command $message {
+	-re "Undefined item: \"$lang_pattern\"\.\[\r\n\]+$gdb_prompt" {
+	  fail $message
+	  return 0
+	}
+	-re "Warning: the current language does not match this frame.\[\r\n\]+$gdb_prompt $" {
+	}
+	-re "$gdb_prompt $" {}
+    }
+
+    # Verify the language has been set correctly.  GDB may output a warning
+    # stating the user-provided language doesn't match the frame's language.
+    # We ignore that warning for testing purposes.
+    if { $language != "auto" } {
+	if [gdb_test "show language" ".* source language is \"$lang_pattern\".*" $message] {
+	    return 0
+	}
+    } else {
+	if [gdb_test "show language" "The current source language is \"auto; currently .*\"\." $message] {
+	    return 0
+	}
+    }
+    return 1
+}
 
 # Always load compatibility stuff.
 load_lib future.exp
diff --git a/gdb/testsuite/lib/go.exp b/gdb/testsuite/lib/go.exp
index c29b7c1..78a4e2c 100644
--- a/gdb/testsuite/lib/go.exp
+++ b/gdb/testsuite/lib/go.exp
@@ -16,20 +16,6 @@
 # FIXME: Presumably skip_go_tests should be defined here,
 # but for consistency with other languages it currently lives in gdb.exp.
 
-# Auxiliary function to set the language to Go.
-# The result is 1 (true) for success, 0 (false) for failure.
-
-proc set_lang_go {} {
-    if [gdb_test_no_output "set language go"] {
-	return 0
-    }
-    if [gdb_test "show language" ".* source language is \"go\"." \
-	   "set language to \"go\""] {
-	return 0
-    }
-    return 1
-}
-
 # Go version of runto_main.
 
 proc go_runto_main { } {
diff --git a/gdb/testsuite/lib/objc.exp b/gdb/testsuite/lib/objc.exp
deleted file mode 100644
index 7189f03..0000000
--- a/gdb/testsuite/lib/objc.exp
+++ /dev/null
@@ -1,30 +0,0 @@
-# This test code is part of GDB, the GNU debugger.
-
-# Copyright 2010-2017 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Auxiliary function to set the language to fortran.
-# The result is 1 (true) for success, 0 (false) for failure.
-
-proc set_lang_objc {} {
-    if [gdb_test_no_output "set language objective-c"] {
-	return 0
-    }
-    if [gdb_test "show language" ".* source language is \"objective-c\"." \
-	   "set language to \"objective-c\""] {
-	return 0
-    }
-    return 1
-}
diff --git a/gdb/testsuite/lib/pascal.exp b/gdb/testsuite/lib/pascal.exp
index a0562c3..f0eb36b 100644
--- a/gdb/testsuite/lib/pascal.exp
+++ b/gdb/testsuite/lib/pascal.exp
@@ -167,17 +167,3 @@ proc gdb_compile_pascal {source destfile type options} {
         return "Pascal compilation failed."
     }
 }
-
-# Auxiliary function to set the language to pascal.
-# The result is 1 (true) for success, 0 (false) for failure.
-
-proc set_lang_pascal {} {
-    if [gdb_test_no_output "set language pascal"] {
-	return 0
-    }
-    if [gdb_test "show language" ".* source language is \"pascal\"." \
-	   "set language to \"pascal\""] {
-	return 0
-    }
-    return 1
-}
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index 2a12cca..e6bda45 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -13,19 +13,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Auxiliary function to set the language to Rust.
-# The result is 1 (true) for success, 0 (false) for failure.
-proc set_lang_rust {} {
-    if [gdb_test_no_output "set language rust"] {
-	return 0
-    }
-    if [gdb_test "show language" ".* source language is \"rust\"." \
-	   "set language to \"rust\""] {
-	return 0
-    }
-    return 1
-}
-
 proc gdb_compile_rust {sources dest options} {
     if {[llength $sources] > 1} {
 	error "gdb rust setup can only compile one source file at a time"
