diff mbox

[v2] Make language setting tests more robust

Message ID 1485980466-711-1-git-send-email-lgustavo@codesourcery.com
State New
Headers show

Commit Message

Luis Machado Feb. 1, 2017, 8:21 p.m. UTC
New in v2:

- Remove gdb.objc/objc.exp, since it was empty after the removal of
  set_lang_objc.
- Deleted stale comments from .exp files.
- set_language now has a couple of fixed arguments (language and message) and
  is simplified.

This patch robustifies the setting of the language in gdb.  Right now most of
the tests assume "set language" is a silent command and use gdb_test_no_output
for testing, but it may output a warning stating the language the user wants
to select does not match the frame's language.  When this happens we have a
failure. This is also the case with "show language", where it outputs the
language currently-selected but may also output said warning.

One case of the warning being displayed happens when one has debug information
for glibc, which may cause GDB to identify the frame as having an "asm"
language. Therefore setting it to something else will get GDB's attention.

This patch addresses the problem by creating a function in lib/gdb.exp to
set the language. That function will also handle potential warnings and check
to make sure the language was properly selected.

Also, i noticed most of the languages have their own set_lang_<language> proc,
and they are all the same.  Therefore i've removed those and switched to using
only the new set_language proc.

I tried to confirm why set_lang_<language> was replicated, but my conclusion
was that it was just the way the code worked and people just copy/pasted from
an existing language .exp file.

Overall i see no regressions with Ubuntu 16.04 x86-64, though the number of
tests changed slightly due to the way set_language works.  No additional
failures nonetheless.

2017-02-01  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.arch/i386-stap-eval-lang-ada.exp: Use new set_language proc.
	* gdb.base/callfuncs.exp: Likewise.
	* gdb.compile/compile-ifunc.exp: Likewise.
	* gdb.cp/classes.exp: Likewise.
	* gdb.cp/cmpd-minsyms.exp: Likewise.
	* gdb.cp/cplusfuncs.exp: Likewise.
	* gdb.cp/debug-expr.exp: Likewise.
	* gdb.cp/demangle.exp: Likewise.
	* gdb.cp/expand-psymtabs-cxx.exp: Likewise.
	* gdb.cp/inherit.exp: Likewise.
	* gdb.cp/overload-const.exp: Likewise.
	* gdb.cp/psymtab-parameter.exp: Likewise.
	* gdb.cp/ptype-flags.exp: Likewise.
	* gdb.cp/typedef-operator.exp: Likewise.
	* gdb.cp/var-tag.exp: Likewise.
	* gdb.cp/virtfunc.exp: Likewise.
	* gdb.dlang/circular.exp: Likewise.
	* gdb.dlang/debug-expr.exp: Likewise.
	* gdb.dlang/demangle.exp: Likewise.
	* gdb.dlang/expression.exp: Likewise.
	* gdb.dlang/primitive-types.exp: Likewise.
	* gdb.dlang/properties.exp: Likewise.
	* gdb.dwarf2/arr-stride.exp: Likewise.
	* gdb.dwarf2/arr-subrange.exp: Likewise.
	* gdb.dwarf2/data-loc.exp: Likewise.
	* gdb.dwarf2/dw2-cp-infcall-ref-static.exp: Likewise.
	* gdb.dwarf2/dw2-linkage-name-trust.exp: Likewise.
	* gdb.dwarf2/dynarr-ptr.exp: Likewise.
	* gdb.dwarf2/subrange.exp: Likewise.
	* gdb.fortran/exprs.exp: Likewise.
	* gdb.fortran/types.exp: Likewise.
	* gdb.go/basic-types.exp: Likewise.
	* gdb.go/print.exp: Likewise.
	* gdb.objc/print.exp: Likewise.
	* gdb.opencl/datatypes.exp: Likewise.
	* gdb.pascal/print.exp: Likewise.
	* gdb.pascal/types.exp: Likewise.
	* gdb.python/py-lookup-type.exp: Likewise.
	* gdb.rust/expr.exp: Likewise.
	* lib/d-support.exp (set_lang_d): Remove.
	* lib/fortran.exp (set_lang_fortran): Remove.
	* lib/gdb.exp (set_language): New proc.
	* lib/go.exp (set_lang_go): Remove.
	* lib/objc.exp: Remove file.
	* lib/pascal.exp (set_lang_pascal): Remove.
	* lib/rust-support.exp (set_lang_rust): Remove.
---
 gdb/testsuite/gdb.arch/i386-stap-eval-lang-ada.exp |  2 +-
 gdb/testsuite/gdb.base/callfuncs.exp               |  2 +-
 gdb/testsuite/gdb.compile/compile-ifunc.exp        |  2 +-
 gdb/testsuite/gdb.cp/classes.exp                   |  2 +-
 gdb/testsuite/gdb.cp/cmpd-minsyms.exp              |  2 +-
 gdb/testsuite/gdb.cp/cplusfuncs.exp                |  2 +-
 gdb/testsuite/gdb.cp/debug-expr.exp                |  2 +-
 gdb/testsuite/gdb.cp/demangle.exp                  |  4 +-
 gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp       |  2 +-
 gdb/testsuite/gdb.cp/inherit.exp                   |  2 +-
 gdb/testsuite/gdb.cp/overload-const.exp            |  2 +-
 gdb/testsuite/gdb.cp/psymtab-parameter.exp         |  2 +-
 gdb/testsuite/gdb.cp/ptype-flags.exp               |  2 +-
 gdb/testsuite/gdb.cp/typedef-operator.exp          |  2 +-
 gdb/testsuite/gdb.cp/var-tag.exp                   |  4 +-
 gdb/testsuite/gdb.cp/virtfunc.exp                  |  2 +-
 gdb/testsuite/gdb.dlang/circular.exp               |  2 +-
 gdb/testsuite/gdb.dlang/debug-expr.exp             |  2 +-
 gdb/testsuite/gdb.dlang/demangle.exp               |  2 +-
 gdb/testsuite/gdb.dlang/expression.exp             |  2 +-
 gdb/testsuite/gdb.dlang/primitive-types.exp        |  2 +-
 gdb/testsuite/gdb.dlang/properties.exp             |  2 +-
 gdb/testsuite/gdb.dwarf2/arr-stride.exp            |  2 +-
 gdb/testsuite/gdb.dwarf2/arr-subrange.exp          |  2 +-
 gdb/testsuite/gdb.dwarf2/data-loc.exp              |  2 +-
 .../gdb.dwarf2/dw2-cp-infcall-ref-static.exp       |  2 +-
 .../gdb.dwarf2/dw2-linkage-name-trust.exp          |  2 +-
 gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp            |  2 +-
 gdb/testsuite/gdb.dwarf2/subrange.exp              |  2 +-
 gdb/testsuite/gdb.fortran/exprs.exp                |  2 +-
 gdb/testsuite/gdb.fortran/types.exp                |  2 +-
 gdb/testsuite/gdb.go/basic-types.exp               |  2 +-
 gdb/testsuite/gdb.go/print.exp                     |  2 +-
 gdb/testsuite/gdb.objc/print.exp                   |  4 +-
 gdb/testsuite/gdb.opencl/datatypes.exp             |  6 +--
 gdb/testsuite/gdb.pascal/print.exp                 |  2 +-
 gdb/testsuite/gdb.pascal/types.exp                 |  2 +-
 gdb/testsuite/gdb.python/py-lookup-type.exp        |  2 +-
 gdb/testsuite/gdb.rust/expr.exp                    |  2 +-
 gdb/testsuite/lib/d-support.exp                    | 14 -------
 gdb/testsuite/lib/fortran.exp                      | 14 -------
 gdb/testsuite/lib/gdb.exp                          | 43 ++++++++++++++++++++++
 gdb/testsuite/lib/go.exp                           | 14 -------
 gdb/testsuite/lib/objc.exp                         | 30 ---------------
 gdb/testsuite/lib/pascal.exp                       | 14 -------
 gdb/testsuite/lib/rust-support.exp                 | 13 -------
 46 files changed, 86 insertions(+), 144 deletions(-)
 delete mode 100644 gdb/testsuite/lib/objc.exp

Comments

Simon Marchi Feb. 2, 2017, 1:33 a.m. UTC | #1
On 2017-02-01 15:21, Luis Machado wrote:
> New in v2:
> 
> - Remove gdb.objc/objc.exp, since it was empty after the removal of
>   set_lang_objc.
> - Deleted stale comments from .exp files.
> - set_language now has a couple of fixed arguments (language and 
> message) and
>   is simplified.
> 
> This patch robustifies the setting of the language in gdb.  Right now 
> most of
> the tests assume "set language" is a silent command and use 
> gdb_test_no_output
> for testing, but it may output a warning stating the language the user 
> wants
> to select does not match the frame's language.  When this happens we 
> have a
> failure. This is also the case with "show language", where it outputs 
> the
> language currently-selected but may also output said warning.
> 
> One case of the warning being displayed happens when one has debug 
> information
> for glibc, which may cause GDB to identify the frame as having an "asm"
> language. Therefore setting it to something else will get GDB's 
> attention.
> 
> This patch addresses the problem by creating a function in lib/gdb.exp 
> to
> set the language. That function will also handle potential warnings and 
> check
> to make sure the language was properly selected.
> 
> Also, i noticed most of the languages have their own 
> set_lang_<language> proc,
> and they are all the same.  Therefore i've removed those and switched 
> to using
> only the new set_language proc.
> 
> I tried to confirm why set_lang_<language> was replicated, but my 
> conclusion
> was that it was just the way the code worked and people just 
> copy/pasted from
> an existing language .exp file.
> 
> Overall i see no regressions with Ubuntu 16.04 x86-64, though the 
> number of
> tests changed slightly due to the way set_language works.  No 
> additional
> failures nonetheless.
> 
> 2017-02-01  Luis Machado  <lgustavo@codesourcery.com>
> 
> 	* gdb.arch/i386-stap-eval-lang-ada.exp: Use new set_language proc.
> 	* gdb.base/callfuncs.exp: Likewise.
> 	* gdb.compile/compile-ifunc.exp: Likewise.
> 	* gdb.cp/classes.exp: Likewise.
> 	* gdb.cp/cmpd-minsyms.exp: Likewise.
> 	* gdb.cp/cplusfuncs.exp: Likewise.
> 	* gdb.cp/debug-expr.exp: Likewise.
> 	* gdb.cp/demangle.exp: Likewise.
> 	* gdb.cp/expand-psymtabs-cxx.exp: Likewise.
> 	* gdb.cp/inherit.exp: Likewise.
> 	* gdb.cp/overload-const.exp: Likewise.
> 	* gdb.cp/psymtab-parameter.exp: Likewise.
> 	* gdb.cp/ptype-flags.exp: Likewise.
> 	* gdb.cp/typedef-operator.exp: Likewise.
> 	* gdb.cp/var-tag.exp: Likewise.
> 	* gdb.cp/virtfunc.exp: Likewise.
> 	* gdb.dlang/circular.exp: Likewise.
> 	* gdb.dlang/debug-expr.exp: Likewise.
> 	* gdb.dlang/demangle.exp: Likewise.
> 	* gdb.dlang/expression.exp: Likewise.
> 	* gdb.dlang/primitive-types.exp: Likewise.
> 	* gdb.dlang/properties.exp: Likewise.
> 	* gdb.dwarf2/arr-stride.exp: Likewise.
> 	* gdb.dwarf2/arr-subrange.exp: Likewise.
> 	* gdb.dwarf2/data-loc.exp: Likewise.
> 	* gdb.dwarf2/dw2-cp-infcall-ref-static.exp: Likewise.
> 	* gdb.dwarf2/dw2-linkage-name-trust.exp: Likewise.
> 	* gdb.dwarf2/dynarr-ptr.exp: Likewise.
> 	* gdb.dwarf2/subrange.exp: Likewise.
> 	* gdb.fortran/exprs.exp: Likewise.
> 	* gdb.fortran/types.exp: Likewise.
> 	* gdb.go/basic-types.exp: Likewise.
> 	* gdb.go/print.exp: Likewise.
> 	* gdb.objc/print.exp: Likewise.
> 	* gdb.opencl/datatypes.exp: Likewise.
> 	* gdb.pascal/print.exp: Likewise.
> 	* gdb.pascal/types.exp: Likewise.
> 	* gdb.python/py-lookup-type.exp: Likewise.
> 	* gdb.rust/expr.exp: Likewise.
> 	* lib/d-support.exp (set_lang_d): Remove.
> 	* lib/fortran.exp (set_lang_fortran): Remove.
> 	* lib/gdb.exp (set_language): New proc.
> 	* lib/go.exp (set_lang_go): Remove.
> 	* lib/objc.exp: Remove file.
> 	* lib/pascal.exp (set_lang_pascal): Remove.
> 	* lib/rust-support.exp (set_lang_rust): Remove.
> ---
>  gdb/testsuite/gdb.arch/i386-stap-eval-lang-ada.exp |  2 +-
>  gdb/testsuite/gdb.base/callfuncs.exp               |  2 +-
>  gdb/testsuite/gdb.compile/compile-ifunc.exp        |  2 +-
>  gdb/testsuite/gdb.cp/classes.exp                   |  2 +-
>  gdb/testsuite/gdb.cp/cmpd-minsyms.exp              |  2 +-
>  gdb/testsuite/gdb.cp/cplusfuncs.exp                |  2 +-
>  gdb/testsuite/gdb.cp/debug-expr.exp                |  2 +-
>  gdb/testsuite/gdb.cp/demangle.exp                  |  4 +-
>  gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp       |  2 +-
>  gdb/testsuite/gdb.cp/inherit.exp                   |  2 +-
>  gdb/testsuite/gdb.cp/overload-const.exp            |  2 +-
>  gdb/testsuite/gdb.cp/psymtab-parameter.exp         |  2 +-
>  gdb/testsuite/gdb.cp/ptype-flags.exp               |  2 +-
>  gdb/testsuite/gdb.cp/typedef-operator.exp          |  2 +-
>  gdb/testsuite/gdb.cp/var-tag.exp                   |  4 +-
>  gdb/testsuite/gdb.cp/virtfunc.exp                  |  2 +-
>  gdb/testsuite/gdb.dlang/circular.exp               |  2 +-
>  gdb/testsuite/gdb.dlang/debug-expr.exp             |  2 +-
>  gdb/testsuite/gdb.dlang/demangle.exp               |  2 +-
>  gdb/testsuite/gdb.dlang/expression.exp             |  2 +-
>  gdb/testsuite/gdb.dlang/primitive-types.exp        |  2 +-
>  gdb/testsuite/gdb.dlang/properties.exp             |  2 +-
>  gdb/testsuite/gdb.dwarf2/arr-stride.exp            |  2 +-
>  gdb/testsuite/gdb.dwarf2/arr-subrange.exp          |  2 +-
>  gdb/testsuite/gdb.dwarf2/data-loc.exp              |  2 +-
>  .../gdb.dwarf2/dw2-cp-infcall-ref-static.exp       |  2 +-
>  .../gdb.dwarf2/dw2-linkage-name-trust.exp          |  2 +-
>  gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp            |  2 +-
>  gdb/testsuite/gdb.dwarf2/subrange.exp              |  2 +-
>  gdb/testsuite/gdb.fortran/exprs.exp                |  2 +-
>  gdb/testsuite/gdb.fortran/types.exp                |  2 +-
>  gdb/testsuite/gdb.go/basic-types.exp               |  2 +-
>  gdb/testsuite/gdb.go/print.exp                     |  2 +-
>  gdb/testsuite/gdb.objc/print.exp                   |  4 +-
>  gdb/testsuite/gdb.opencl/datatypes.exp             |  6 +--
>  gdb/testsuite/gdb.pascal/print.exp                 |  2 +-
>  gdb/testsuite/gdb.pascal/types.exp                 |  2 +-
>  gdb/testsuite/gdb.python/py-lookup-type.exp        |  2 +-
>  gdb/testsuite/gdb.rust/expr.exp                    |  2 +-
>  gdb/testsuite/lib/d-support.exp                    | 14 -------
>  gdb/testsuite/lib/fortran.exp                      | 14 -------
>  gdb/testsuite/lib/gdb.exp                          | 43 
> ++++++++++++++++++++++
>  gdb/testsuite/lib/go.exp                           | 14 -------
>  gdb/testsuite/lib/objc.exp                         | 30 
> ---------------
>  gdb/testsuite/lib/pascal.exp                       | 14 -------
>  gdb/testsuite/lib/rust-support.exp                 | 13 -------
>  46 files changed, 86 insertions(+), 144 deletions(-)
>  delete mode 100644 gdb/testsuite/lib/objc.exp
> 
> 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"

LGTM.
Pedro Alves Feb. 3, 2017, 12:36 a.m. UTC | #2
On 02/01/2017 08:21 PM, Luis Machado wrote:

> One case of the warning being displayed happens when one has debug information
> for glibc, which may cause GDB to identify the frame as having an "asm"
> language. Therefore setting it to something else will get GDB's attention.
> 
> This patch addresses the problem by creating a function in lib/gdb.exp to
> set the language. That function will also handle potential warnings and check
> to make sure the language was properly selected.

Sorry to be a naysayer, but I'm not sure about this.  :-(  I recall fixing bugs
related to gdb printing that warning when it really should not, or causing
regressions locally due to breaking that logic, with the testsuite helping
notice them.  I worry that this would be hiding such bugs going forward.
Can you name the tests that where you saw the problem you mention?  Many of the tests
you're touching are changing the language after starting gdb with no binary
loaded, even.  Those definitely should not ever warn.  There are a few even that
have "no prompt when changing language"-like messages.

> Also, i noticed most of the languages have their own set_lang_<language> proc,
> and they are all the same.  Therefore i've removed those and switched to using
> only the new set_language proc.
> 
> I tried to confirm why set_lang_<language> was replicated, but my conclusion
> was that it was just the way the code worked and people just copy/pasted from
> an existing language .exp file.

One small advantage I see is that set_lang_<language> is a tcl symbol, so
if you typo it, you'll get a tcl error.  Kind of like avoiding sprinkling
magic constants in C.  You could keep the wrapper procs but define them
in terms of set_language, like:

proc set_lang_objc {} {
   set_language "objective-c"
}

But I won't insist.

> +# 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 $" {}
> +    }

Writing this as:

    set command_re [string_to_regexp $command]

    # Switch to the user-selected language.
    gdb_test_multiple $command $message {
	-re "Warning: the current language does not match this frame.\[\r\n\]+$gdb_prompt $" {
	}
	-re "^$command_re\r\n$gdb_prompt $" {
        }
	-re "$gdb_prompt" {
	  fail $message
	  return 0
	}
    }

Would be more robust in case the "Undefined item" output ever changes.

Thanks,
Pedro Alves
Luis Machado Feb. 6, 2017, 2:54 p.m. UTC | #3
On 02/02/2017 06:36 PM, Pedro Alves wrote:
> On 02/01/2017 08:21 PM, Luis Machado wrote:
>
>> One case of the warning being displayed happens when one has debug information
>> for glibc, which may cause GDB to identify the frame as having an "asm"
>> language. Therefore setting it to something else will get GDB's attention.
>>
>> This patch addresses the problem by creating a function in lib/gdb.exp to
>> set the language. That function will also handle potential warnings and check
>> to make sure the language was properly selected.
>
> Sorry to be a naysayer, but I'm not sure about this.  :-(  I recall fixing bugs
> related to gdb printing that warning when it really should not, or causing
> regressions locally due to breaking that logic, with the testsuite helping
> notice them.  I worry that this would be hiding such bugs going forward.
> Can you name the tests that where you saw the problem you mention?  Many of the tests
> you're touching are changing the language after starting gdb with no binary
> loaded, even.  Those definitely should not ever warn.  There are a few even that
> have "no prompt when changing language"-like messages.

Sounds reasonable. I think i was slightly surprised that the message is 
not coming from the command that sets the language 
(set_language_command), but from some frame manipulation function that 
gets called as part of determining the current language of the frame.

The story here is that i noticed 3 tests with such a problem:

FAIL: gdb.compile/compile-ifunc.exp: nodebug: set language c
FAIL: gdb.dwarf2/data-loc.exp: set language ada
FAIL: gdb.dwarf2/dynarr-ptr.exp: set language ada

And my build had a glibc with debugging symbols and sources, therefore 
GDB had set the initial language to asm before main.

I decided to expand the change to include an extra cleanup since i saw 
no clear purpose on having functions to set particular languages.

>
>> Also, i noticed most of the languages have their own set_lang_<language> proc,
>> and they are all the same.  Therefore i've removed those and switched to using
>> only the new set_language proc.
>>
>> I tried to confirm why set_lang_<language> was replicated, but my conclusion
>> was that it was just the way the code worked and people just copy/pasted from
>> an existing language .exp file.
>
> One small advantage I see is that set_lang_<language> is a tcl symbol, so
> if you typo it, you'll get a tcl error.  Kind of like avoiding sprinkling
> magic constants in C.  You could keep the wrapper procs but define them
> in terms of set_language, like:
>
> proc set_lang_objc {} {
>    set_language "objective-c"
> }
>
> But I won't insist.
>

I wonder if the benefit from doing that justifies having extra code 
lying around. I can certainly do it if people think it is a good way 
forward. Our set of supported languages is not that big.

Thoughts anyone?

>> +# 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 $" {}
>> +    }
>
> Writing this as:
>
>     set command_re [string_to_regexp $command]
>
>     # Switch to the user-selected language.
>     gdb_test_multiple $command $message {
> 	-re "Warning: the current language does not match this frame.\[\r\n\]+$gdb_prompt $" {
> 	}
> 	-re "^$command_re\r\n$gdb_prompt $" {
>         }
> 	-re "$gdb_prompt" {
> 	  fail $message
> 	  return 0
> 	}
>     }
>
> Would be more robust in case the "Undefined item" output ever changes.

Indeed. I'll address this.

Thanks,
Luis
Luis Machado Feb. 6, 2017, 3:09 p.m. UTC | #4
On 02/06/2017 08:54 AM, Luis Machado wrote:
> On 02/02/2017 06:36 PM, Pedro Alves wrote:
>> On 02/01/2017 08:21 PM, Luis Machado wrote:
>>
>>> One case of the warning being displayed happens when one has debug
>>> information
>>> for glibc, which may cause GDB to identify the frame as having an "asm"
>>> language. Therefore setting it to something else will get GDB's
>>> attention.
>>>
>>> This patch addresses the problem by creating a function in
>>> lib/gdb.exp to
>>> set the language. That function will also handle potential warnings
>>> and check
>>> to make sure the language was properly selected.
>>
>> Sorry to be a naysayer, but I'm not sure about this.  :-(  I recall
>> fixing bugs
>> related to gdb printing that warning when it really should not, or
>> causing
>> regressions locally due to breaking that logic, with the testsuite
>> helping
>> notice them.  I worry that this would be hiding such bugs going forward.
>> Can you name the tests that where you saw the problem you mention?
>> Many of the tests
>> you're touching are changing the language after starting gdb with no
>> binary
>> loaded, even.  Those definitely should not ever warn.  There are a few
>> even that
>> have "no prompt when changing language"-like messages.
>
> Sounds reasonable. I think i was slightly surprised that the message is
> not coming from the command that sets the language
> (set_language_command), but from some frame manipulation function that
> gets called as part of determining the current language of the frame.

Nevermind. I think the message is actually being printed from 
execute_command (), after the "set language" gets executed.
Pedro Alves Feb. 6, 2017, 4:50 p.m. UTC | #5
On 02/06/2017 02:54 PM, Luis Machado wrote:
> 
> The story here is that i noticed 3 tests with such a problem:
> 
> FAIL: gdb.compile/compile-ifunc.exp: nodebug: set language c
> FAIL: gdb.dwarf2/data-loc.exp: set language ada
> FAIL: gdb.dwarf2/dynarr-ptr.exp: set language ada
> 
> And my build had a glibc with debugging symbols and sources, therefore
> GDB had set the initial language to asm before main.

There's a comment about that in gdb.compile/compile-ifunc.exp:

    # This binary has no debug information, so force the language to C in case
    # 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" ""

So the question is, why did the gdb_test_no_output work back then,
and doesn't now?

In top.c:check_frame_language_change()
[...]
  if (has_stack_frames ())
    {
      enum language flang;

      flang = get_frame_language (frame);
      if (!warned
	  && flang != language_unknown
	  && flang != current_language->la_language)
	{
	  printf_filtered ("%s\n", lang_frame_mismatch_warn);
	  warned = 1;
	}

what does get_frame_language return?  Isn't it returning
language_unknown for you?  Why not?

> FAIL: gdb.dwarf2/data-loc.exp: set language ada
> FAIL: gdb.dwarf2/dynarr-ptr.exp: set language ada

Likewise.

Thanks,
Pedro Alves
Luis Machado Feb. 6, 2017, 6:04 p.m. UTC | #6
On 02/06/2017 10:50 AM, Pedro Alves wrote:
> On 02/06/2017 02:54 PM, Luis Machado wrote:
>>
>> The story here is that i noticed 3 tests with such a problem:
>>
>> FAIL: gdb.compile/compile-ifunc.exp: nodebug: set language c
>> FAIL: gdb.dwarf2/data-loc.exp: set language ada
>> FAIL: gdb.dwarf2/dynarr-ptr.exp: set language ada
>>
>> And my build had a glibc with debugging symbols and sources, therefore
>> GDB had set the initial language to asm before main.
>
> There's a comment about that in gdb.compile/compile-ifunc.exp:
>
>     # This binary has no debug information, so force the language to C in case
>     # 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" ""
>
> So the question is, why did the gdb_test_no_output work back then,
> and doesn't now?
>

I can't confirm it worked before since i haven't looked at this 
particular setup then.

> In top.c:check_frame_language_change()
> [...]
>   if (has_stack_frames ())
>     {
>       enum language flang;
>
>       flang = get_frame_language (frame);
>       if (!warned
> 	  && flang != language_unknown
> 	  && flang != current_language->la_language)
> 	{
> 	  printf_filtered ("%s\n", lang_frame_mismatch_warn);
> 	  warned = 1;
> 	}
>
> what does get_frame_language return?  Isn't it returning
> language_unknown for you?  Why not?
>

That returns language_asm for me. Supposedly because gdb has seen asm 
from glibc and then sticked with it when it reached the test program's 
main. And the program has no debug info.

>> FAIL: gdb.dwarf2/data-loc.exp: set language ada
>> FAIL: gdb.dwarf2/dynarr-ptr.exp: set language ada

Same as above, language_asm.

Maybe gdb should've switched to language_unknown when it reached main 
for this/these particular cases?

The logic to complain about a mismatch of language between the frame and 
the user selection seems sane.
Pedro Alves Feb. 6, 2017, 6:08 p.m. UTC | #7
On 02/06/2017 06:04 PM, Luis Machado wrote:

> That returns language_asm for me. Supposedly because gdb has seen asm
> from glibc and then sticked with it when it reached the test program's
> main. And the program has no debug info.

No, I don't think that is why.  What sticks is "current_language", not 
the frame's language.

Thanks,
Pedro Alves
Luis Machado Feb. 6, 2017, 6:22 p.m. UTC | #8
On 02/06/2017 12:08 PM, Pedro Alves wrote:
> On 02/06/2017 06:04 PM, Luis Machado wrote:
>
>> That returns language_asm for me. Supposedly because gdb has seen asm
>> from glibc and then sticked with it when it reached the test program's
>> main. And the program has no debug info.
>
> No, I don't think that is why.  What sticks is "current_language", not
> the frame's language.

True. gdb is still seeing asm for the frame with main though. But that 
sounds like an expected outcome.
Pedro Alves Feb. 6, 2017, 6:24 p.m. UTC | #9
On 02/06/2017 06:22 PM, Luis Machado wrote:
> On 02/06/2017 12:08 PM, Pedro Alves wrote:
>> On 02/06/2017 06:04 PM, Luis Machado wrote:
>>
>>> That returns language_asm for me. Supposedly because gdb has seen asm
>>> from glibc and then sticked with it when it reached the test program's
>>> main. And the program has no debug info.
>>
>> No, I don't think that is why.  What sticks is "current_language", not
>> the frame's language.
> 
> True. gdb is still seeing asm for the frame with main though. But that
> sounds like an expected outcome.

Why?  Where is GDB retrieving that from?  Did you step through
get_frame_language?

Thanks,
Pedro Alves
Luis Machado Feb. 6, 2017, 7:55 p.m. UTC | #10
On 02/06/2017 12:24 PM, Pedro Alves wrote:
> On 02/06/2017 06:22 PM, Luis Machado wrote:
>> On 02/06/2017 12:08 PM, Pedro Alves wrote:
>>> On 02/06/2017 06:04 PM, Luis Machado wrote:
>>>
>>>> That returns language_asm for me. Supposedly because gdb has seen asm
>>>> from glibc and then sticked with it when it reached the test program's
>>>> main. And the program has no debug info.
>>>
>>> No, I don't think that is why.  What sticks is "current_language", not
>>> the frame's language.
>>
>> True. gdb is still seeing asm for the frame with main though. But that
>> sounds like an expected outcome.
>
> Why?  Where is GDB retrieving that from?  Did you step through
> get_frame_language?

Ok, here's what i'm seeing so far. The current language is stuck in 
language_asm, even though the frame (frame of main) is supposed to be 
language_c (points to a C file, start_c.c).

The funny thing is that right after connecting to the remote target, if 
you "show language", it doesn't emit any warnings and it keeps seeing a 
previous .S file (from the entry point), therefore the frame's language 
is language_asm, matching current_language.

Attempting a backtrace shows the language mismatch warning, since the 
frame's language is then resolved to language_c (frame of main).

Maybe current_language is not being updated when it should (from 
language_asm to language_c)?

And there also seems to be a hiccup in the case where i can still see a 
frame pointing to the .S file, even though the current frame is the 
frame of main.

It may be a bug after all.
diff mbox

Patch

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"