Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Luis Machado <lgustavo@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Make language setting tests more robust
Date: Wed, 01 Feb 2017 18:38:00 -0000	[thread overview]
Message-ID: <331062ebcc7352d7731347260b56dee7@polymtl.ca> (raw)
In-Reply-To: <1485962220-31071-1-git-send-email-lgustavo@codesourcery.com>

On 2017-02-01 10:17, Luis Machado wrote:
> 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.

I have just looked at the stuff in lib/, it looks good to me, that's a 
nice cleanup.  A few comments below.

> diff --git a/gdb/testsuite/lib/d-support.exp 
> b/gdb/testsuite/lib/d-support.exp
> index ed568d3..100fb63 100644
> --- a/gdb/testsuite/lib/d-support.exp
> +++ b/gdb/testsuite/lib/d-support.exp
> @@ -16,17 +16,6 @@
>  # Auxiliary function to set the language to D.
>  # The result is 1 (true) for success, 0 (false) for failure.

Remove this comment.

> -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..2f4820b 100644
> --- a/gdb/testsuite/lib/fortran.exp
> +++ b/gdb/testsuite/lib/fortran.exp
> @@ -18,17 +18,6 @@
>  # Auxiliary function to set the language to fortran.
>  # The result is 1 (true) for success, 0 (false) for failure.

Comment.

> -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..327bce8 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -6018,6 +6018,47 @@ 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 set.
> +# The second argument is an optional message to be output by the test.
> +
> +proc set_language { args } {

Instead of "args", it might be clearer to use a default argument for the 
second arg:

   proc set_language { language { message "" } } {

And lower:

   if { $message == "" } {
     set message $command
   }

Not sure about the exact TCL syntax, but I think you get the point :).

> +    global gdb_prompt
> +
> +    set language [lindex $args 0]
> +    set command "set language $language"
> +    set lang_pattern [string_to_regexp $language]
> +
> +    # Do we have an optional user-provided test message?
> +    if {[llength $args] > 1} {
> +	set message [lindex $args 1]
> +    } else {
> +	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 $" {}
> +    }

Do you want to add a "pass" in there somewhere, or we keep it silent if 
it succeeds?

> +
> +    # 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
> +	}
> +    }

In the else, you could verify that it matches 'The current source 
language is "auto; currently .*"'.

> +    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..cb98bdc 100644
> --- a/gdb/testsuite/lib/go.exp
> +++ b/gdb/testsuite/lib/go.exp
> @@ -19,17 +19,6 @@
>  # Auxiliary function to set the language to Go.
>  # The result is 1 (true) for success, 0 (false) for failure.

Comment.

> -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
> index 7189f03..9891758 100644
> --- a/gdb/testsuite/lib/objc.exp
> +++ b/gdb/testsuite/lib/objc.exp
> @@ -17,14 +17,3 @@
> 
>  # Auxiliary function to set the language to fortran.
>  # The result is 1 (true) for success, 0 (false) for failure.

Comment.  Also, note that it mentions fortran :).  Actually, you could 
probably just delete that file.

> -
> -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..a80d60b 100644
> --- a/gdb/testsuite/lib/rust-support.exp
> +++ b/gdb/testsuite/lib/rust-support.exp
> @@ -15,16 +15,6 @@
> 
>  # Auxiliary function to set the language to Rust.
>  # The result is 1 (true) for success, 0 (false) for failure.

Comment.

> -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} {


  reply	other threads:[~2017-02-01 18:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-01 15:17 Luis Machado
2017-02-01 18:38 ` Simon Marchi [this message]
2017-02-01 19:22   ` Luis Machado
2017-02-01 19:25     ` Simon Marchi
2017-02-01 21:50   ` Keith Seitz
2017-02-01 23:29     ` Luis Machado
2017-02-02  1:24     ` Simon Marchi
2017-02-01 20:21 ` [PATCH,v2] " Luis Machado
2017-02-02  1:33   ` Simon Marchi
2017-02-03  0:37   ` Pedro Alves
2017-02-06 14:54     ` Luis Machado
2017-02-06 15:09       ` Luis Machado
2017-02-06 16:51       ` Pedro Alves
2017-02-06 18:04         ` Luis Machado
2017-02-06 18:08           ` Pedro Alves
2017-02-06 18:22             ` Luis Machado
2017-02-06 18:24               ` Pedro Alves
2017-02-06 19:56                 ` Luis Machado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=331062ebcc7352d7731347260b56dee7@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=lgustavo@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox