binutils-gdb/gdb/testsuite/lib
Kevin Buettner 75312ae3ab Use noncapturing subpattern/parens in gdb_test implementation
This is the portion of gdb_test which performs the match against
the RE (regular expression) passed to it:

    return [gdb_test_multiple $command $message {
        -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
            if ![string match "" $message] then {
                pass "$message"
            }
        }

In a test that I've been working on recently, I wanted to use
a backreference - that's the \1 in the the RE below:

gdb_test "info threads"  \
	{.*[\r\n]+\* +([0-9]+) +Thread[^\r\n]* do_something \(n=\1\) at.*}

Put into English, I wanted to make sure that the value of n passed to
do_something() is the same as the thread number shown in the "info
threads" Id column.  (I've structured the test case so that this
*should* be the case.)

It didn't work though.  It turned out that ($pattern) in the RE
noted above is capturing the attempted backreference.  So, in this
case, the backreference does not refer to ([0-9]+) as intended, but
instead refers to ($pattern).  This is wrong because it's not what I
intended, but is also wrong because, if allowed, it could only match a
string of infinite length.

This problem can be fixed by using parens for a "noncapturing
subpattern".  The way that this is done, syntactically, is to use
(?:$pattern) instead of ($pattern).

My research shows that this feature has been present since tcl8.1 which
was released in 1999.

The current tcl version is 8.6 - at least that's what I have on my
machine.  It appears to me that mingw uses some subversion of tcl8.4
which will also have this feature (since 8.4 > 8.1).

So it seems to me that any platform upon which we might wish to test
GDB will have a version of tcl which has this feature.  That being the
case, my hope is that there won't be any objections to its use.

When I looked at the implementation of gdb_test, I wondered whether
the parens were needed at all.  I've concluded that they are.  In the
event that $pattern is an RE which uses alternation at the top level,
e.g. a|b, we need to make $pattern a subpattern (via parens) to limit
the extend of the alternation.  I.e, we don't want the alternation to
extend to the other portions of the RE which gdb_test uses to match
potential blank lines at the beginning of the pattern or the gdb
prompt at the end.

gdb/testsuite/ChangeLog:

	* gdb.exp (gdb_test): Using noncapturing parens for the $pattern
	subpattern.
2017-06-21 14:44:04 -07:00
..
ada.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
append_gdb_boards_dir.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
build-piece.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
cache.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
cell.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
cl_util.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
cl_util.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
compiler.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
compiler.cc update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
cp-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
d-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
dtrace.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
dwarf.exp Big-endian targets: Don't ignore offset into DW_OP_stack_value 2017-03-16 19:50:24 +01:00
fortran.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
future.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb-guile.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb-python.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb-utils.exp Add test for modifiable DWARF locations 2017-06-13 15:20:25 +02:00
gdb.exp Use noncapturing subpattern/parens in gdb_test implementation 2017-06-21 14:44:04 -07:00
gdbserver-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gen-perf-test.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
go.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
memory.exp 2017-01-26 Luis Machado <lgustavo@codesourcery.com> 2017-01-26 14:05:37 -06:00
mi-support.exp Add a better diagnostic message in mi_gdb_test 2017-03-20 14:57:45 -04:00
objc.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
opencl.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
opencl_hostapp.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
opencl_kernel.cl
pascal.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
pdtrace.in update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
perftest.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
prelink-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
prompt.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
range-stepping-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
read1.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
rust-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
selftest-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
set_unbuffered_mode.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
trace-support.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
unbuffer_output.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00