testsuite: Exclude end-of-line characters from get_valueof result
authorSimon Marchi <simon.marchi@ericsson.com>
Sat, 12 Aug 2017 08:33:00 +0000 (10:33 +0200)
committerSimon Marchi <simon.marchi@ericsson.com>
Sat, 12 Aug 2017 08:33:00 +0000 (10:33 +0200)
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/ChangeLog
gdb/testsuite/lib/gdb.exp

index 31f419faf5d5a81730acb7313095f483150665e3..23658b098e8143431d2238ab6978d662cff31361 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-12  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * lib/gdb.exp (get_valueof): Don't capture end-of-line
+       characters.
+
 2017-08-05  Tom Tromey  <tom@tromey.com>
 
        * gdb.rust/simple.exp: Allow String to appear in a different
index 3d3eaab2583d7bebe0b1d4ed9b790991d3e270a5..d0265fc2117fc53cecd6501d0cd1869a49f92a8a 100644 (file)
@@ -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)"
        }
This page took 0.036072 seconds and 4 git commands to generate.