testsuite: Exclude end-of-line characters from get_valueof result

Message ID 1502185238-6275-1-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi Aug. 8, 2017, 9:40 a.m. UTC
  The get_valueof procedure allows tests to conveniently make gdb evaluate
an expression an return the value as a string.  However, it includes an
end-of-line character in its result.  I stumbled on this when trying to
use that result as part of a regex further in a test.

You can see this for example by adding a puts in
gdb.dwarf2/implref-struct.exp:get_members:

    set members [get_valueof "" ${var} ""]
    puts "<$members>"

The output is

    <{a = 0, b = 1, c = 2}
    >

This is because the regex in get_valueof is too greedy, the captured
portion matches anything up to the gdb_prompt, including the end of line
characters.  This patch changes it to capture everything but end of line
characters.

The output of the puts becomes:

    <{a = 0, b = 1, c = 2}>

I tested this by running gdb.dwarf2/implref-array.exp and
gdb.dwarf2/implref-struct.exp, the two only current users of that
procedure.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (get_valueof): Don't capture end-of-line
	characters.
---
 gdb/testsuite/lib/gdb.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Simon Marchi Aug. 12, 2017, 8:35 a.m. UTC | #1
On 2017-08-08 11:40 AM, Simon Marchi wrote:
> The get_valueof procedure allows tests to conveniently make gdb evaluate
> an expression an return the value as a string.  However, it includes an
> end-of-line character in its result.  I stumbled on this when trying to
> use that result as part of a regex further in a test.
> 
> You can see this for example by adding a puts in
> gdb.dwarf2/implref-struct.exp:get_members:
> 
>     set members [get_valueof "" ${var} ""]
>     puts "<$members>"
> 
> The output is
> 
>     <{a = 0, b = 1, c = 2}
>     >
> 
> This is because the regex in get_valueof is too greedy, the captured
> portion matches anything up to the gdb_prompt, including the end of line
> characters.  This patch changes it to capture everything but end of line
> characters.
> 
> The output of the puts becomes:
> 
>     <{a = 0, b = 1, c = 2}>
> 
> I tested this by running gdb.dwarf2/implref-array.exp and
> gdb.dwarf2/implref-struct.exp, the two only current users of that
> procedure.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* lib/gdb.exp (get_valueof): Don't capture end-of-line
> 	characters.
> ---
>  gdb/testsuite/lib/gdb.exp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 3d3eaab..d0265fc 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -5537,7 +5537,7 @@ proc get_valueof { fmt exp default {test ""} } {
>  
>      set val ${default}
>      gdb_test_multiple "print${fmt} ${exp}" "$test" {
> -	-re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
> +	-re "\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
>  	    set val $expect_out(1,string)
>  	    pass "$test ($val)"
>  	}
> 

I pushed this.

Simon
  

Patch

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3d3eaab..d0265fc 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5537,7 +5537,7 @@  proc get_valueof { fmt exp default {test ""} } {
 
     set val ${default}
     gdb_test_multiple "print${fmt} ${exp}" "$test" {
-	-re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
+	-re "\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
 	    set val $expect_out(1,string)
 	    pass "$test ($val)"
 	}