This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC, testsuite/guality] Use relative line numbers in gdb-test


Tom de Vries <tdevries@suse.de> writes:
> [ was: [PATCH, testsuite/guality] Use line number vars in gdb-test ]
> On Thu, Jun 28, 2018 at 07:49:30PM +0200, Tom de Vries wrote:
>> Hi,
>> 
>> I played around with pr45882.c and ran into FAILs.  It took me a while to
>> realize that the FAILs where due to the gdb-test (a dg-final action) using
>> absolute line numbers, and me adding lines before the gdb-test lines.
>> 
>> I've written this patch, which factors out the handling of relative line
>> numbers as well as line number variables from process-message, and reuses the
>> functionality in gdb-test.
>> 
>> This enables the line number variables functionality in gdb-test.  [ There's
>> one quirk: line number variables have a define-before-use semantics (with
>> matching used-before-defined error) but in the test-case the use in gdb-test
>> preceeds the definition in gdb-line.  This doesn't cause errors, because
>> the dg-final actions are executed after the definition has taken effect. ]
>> 
>> [ Relative line numbers still don't work in gdb-test, but that's due to an
>> orthogonal issue: gdb-test is a dg-final action, and while dg-final receives
>> the line number on which it occurred as it's first argument, it doesn't pass
>> on this line number to the argument list of the action. I'll submit a
>> follow-on rfc patch for this. ]
>>
>
> This patch adds a dg-final override that passes it's first argument to the
> gdb-test action.  This allows us to use relative line numbers in gdb-test.
>
> Tested pr45882.c.
>
> Any comments?
>  
> Thanks,
> - Tom
>
> [testsuite/guality] Use relative line numbers in gdb-test
>
> 2018-06-28  Tom de Vries  <tdevries@suse.de>
>
> 	* gcc.dg/guality/pr45882.c (foo): Use relative line numbers.
> 	* lib/gcc-dg.exp (dg-final): New proc.
> 	* lib/gcc-gdb-test.exp (gdb-test): Add and handle additional line number
> 	argument.
>
> ---
>  gcc/testsuite/gcc.dg/guality/pr45882.c | 10 +++++-----
>  gcc/testsuite/lib/gcc-dg.exp           | 20 ++++++++++++++++++++
>  gcc/testsuite/lib/gcc-gdb-test.exp     |  4 ++--
>  3 files changed, 27 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.dg/guality/pr45882.c b/gcc/testsuite/gcc.dg/guality/pr45882.c
> index da9e2755590..02d74389ea0 100644
> --- a/gcc/testsuite/gcc.dg/guality/pr45882.c
> +++ b/gcc/testsuite/gcc.dg/guality/pr45882.c
> @@ -9,11 +9,11 @@ volatile short int v;
>  __attribute__((noinline,noclone,used)) int
>  foo (int i, int j)
>  {
> -  int b = i;		/* { dg-final { gdb-test bpline "b" "7" } } */
> -  int c = i + 4;	/* { dg-final { gdb-test bpline "c" "11" } } */
> -  int d = a[i];		/* { dg-final { gdb-test bpline "d" "112" } } */
> -  int e = a[i + 6];	/* { dg-final { gdb-test bpline "e" "142" } } */
> -  ++v;			/* { dg-line bpline } */
> +  int b = i;		/* { dg-final { gdb-test .+4 "b" "7" } } */
> +  int c = i + 4;	/* { dg-final { gdb-test .+3 "c" "11" } } */
> +  int d = a[i];		/* { dg-final { gdb-test .+2 "d" "112" } } */
> +  int e = a[i + 6];	/* { dg-final { gdb-test .+1 "e" "142" } } */
> +  ++v;
>    return ++j;
>  }
>  
> diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
> index 22065c7e3fe..6f88ce2213e 100644
> --- a/gcc/testsuite/lib/gcc-dg.exp
> +++ b/gcc/testsuite/lib/gcc-dg.exp
> @@ -114,6 +114,26 @@ if [info exists ADDITIONAL_TORTURE_OPTIONS] {
>  	[concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
>  }
>  
> +proc dg-final { args } {
> +    upvar dg-final-code final-code
> +
> +    if { [llength $args] > 2 } {
> +	error "[lindex $args 0]: too many arguments"
> +    }
> +    set line [lindex $args 0]
> +    set code [lindex $args 1]
> +    set directive [lindex $code 0]
> +    set withline \
> +	[switch $directive {
> +	    gdb-test {expr {1}}
> +	    default  {expr {0}}
> +	}]
> +    if { $withline == 1 } {
> +	set code [linsert $code 1 $line]
> +    }
> +    append final-code "$code\n"
> +}

Like the idea, but I think:

    set withline \
	[switch $directive {
	    gdb-test {expr {1}}
	    default  {expr {0}}
	}]
    if { $withline == 1 } {
	set code [linsert $code 1 $line]
    }

would be clearer as:

    switch $directive {
	gdb-test {
	    set code [linsert $code 1 $line]
	}
    }

Thanks,
Richard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]