Re: [reverse RFC] test for restored machine state

teawater
2008-09-17T16:14:55Z

OK. Looks good.

On Wed, Sep 17, 2008 at 07:54, Michael Snyder <msnyder@vmware.com> wrote:
> Here's a test for the question we've been discussing,
> about the restored machine state after reverse execution
> stops.
>
> Although it probably would have been sufficient to test
> two cases (register and memory), I went for completeness
> and tested five cases:
> * a register variable
> * an auto variable
> * a function static
> * a module static, and
> * a module global.
>
> In each case, I let the program increment the variable.
> Then I tested whether the pre-increment value was restored
> under two conditions:
> * continue backward to a breakpoint, and
> * step backward.
>
> I checked each value "before" and "after", and the
> Teawater record/replay implementation passes 100 percent.
>
> I would welcome any suggestions for improving or extending
> the test. I've suggested a few possible extensions in the
> comments. I did a little hoop-dancing to make it as likely
> as possible that the compiler would emit a single instruction
> in the register case, so we can see that the side effect of
> the breakpoint instruction (incrementing the register variable)
> is in fact reverted.
>
>
> 2008-09-16 Michael Snyder <msnyder@vmware.com>
>
> * gdb.twreverse/machinestate.exp: New file.
> * gdb.twreverse/machinestate.c: New file.
> * gdb.twreverse/machinestate1.c: New file.
> * gdb.twreverse/Makefile.in: Update for make clean.
>
> Index: machinestate.c
> ===================================================================
> RCS file: machinestate.c
> diff -N machinestate.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ machinestate.c 16 Sep 2008 23:43:04 -0000
> @@ -0,0 +1,101 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> + Copyright 2008 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>.
> */
> +
> +/*
> + * Test restoration of machine state
> + */
> +
> +extern void hide (int);
> +
> +/* Test register variable
> + Requires -- compiler honors 'register'. */
> +
> +void
> +register_state (void)
> +{
> + register int a = 0;
> +
> + hide (a); /* External function to defeat optimization. */
> + a++; /* register_state: set breakpoint here */
> + hide (a); /* register post-change */
> +}
> +
> +/* Test auto variable (whatever that means). */
> +
> +void
> +auto_state (void)
> +{
> + auto int a = 0;
> +
> + hide (a); /* External function to defeat optimization. */
> + a++; /* auto_state: set breakpoint here */
> + hide (a); /* auto post-change */
> +}
> +
> +/* Test function-static variable. */
> +
> +void
> +function_static_state (void)
> +{
> + static int a = 0;
> +
> + hide (a); /* External function to defeat optimization. */
> + a++; /* function_static_state: set breakpoint here */
> + hide (a); /* function static post-change */
> +}
> +
> +/* Test module-static variable. */
> +
> +static int astatic;
> +
> +void
> +module_static_state (void)
> +{
> + astatic = 0;
> +
> + hide (astatic); /* External function to defeat optimization. */
> + astatic++; /* module_static_state: set breakpoint here */
> + hide (astatic); /* module static post-change */
> +}
> +
> +/* Test module-global variable. */
> +
> +int aglobal;
> +
> +void
> +module_global_state (void)
> +{
> + aglobal = 0;
> +
> + hide (aglobal); /* External function to defeat optimization. */
> + aglobal++; /* module_global_state: set breakpoint here */
> + hide (aglobal); /* module global post-change */
> +}
> +
> +/* main test driver */
> +
> +int
> +main (int argc, char **argv)
> +{
> + register_state (); /* begin main */
> + auto_state ();
> + function_static_state ();
> + module_static_state ();
> + module_global_state ();
> +
> + return 0; /* end main */
> +}
> Index: machinestate.exp
> ===================================================================
> RCS file: machinestate.exp
> diff -N machinestate.exp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ machinestate.exp 16 Sep 2008 23:43:04 -0000
> @@ -0,0 +1,142 @@
> +# Copyright 2008 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Please email any bugs, comments, and/or additions to this file to:
> +# bug-gdb@prep.ai.mit.edu
> +
> +#
> +# This test tests the restoration of various kinds of machine state
> +# to their original values by reverse execution. We will execute
> +# the program forward while it changes various types of data, and
> +# then execute it backward to see if their values get restored.
> +#
> +# The types of machine state (data) that are tested are:
> +# register variable
> +# auto variable
> +# function static variable
> +# module static variable
> +# module global variable
> +#
> +# TODO:
> +# various, possibly including...
> +# .bss variable, .data variable, ...
> +# shared library variable
> +# heap variable (pointer)...
> +# overlay variables...
> +#
> +
> +
> +set testfile "machinestate"
> +set srcfile ${testfile}.c
> +set srcfile1 ${testfile}1.c
> +
> +if { [prepare_for_testing machinestate.exp $testfile {machinestate.c
> machinestate1.c} ] } {
> + return -1
> +}
> +
> +set newline "\[\r\n\]+"
> +
> +set beginmain [gdb_get_line_number " begin main " $srcfile]
> +set endmain [gdb_get_line_number " end main " $srcfile]
> +
> +# Test begins
> +
> +runto main
> +
> +# FIXME 'record' command should say something so we know it's working.
> +gdb_test "record" "" "start recording"
> +
> +# Proceed to end of main
> +
> +gdb_test "break $endmain" \
> + "Breakpoint.* file .*/$srcfile, line $endmain.*" ""
> +gdb_continue_to_breakpoint "end of main" ".*/$srcfile:$endmain.*"
> +
> +###
> +###
> +###
> +
> +# Now run backward to each of several points where data is changed.
> +#
> +
> +# Module global variable
> +
> +set breakloc [gdb_get_line_number \
> + "module_global_state: set breakpoint here" $srcfile]
> +
> +gdb_test "tbreak $breakloc" ".*/$srcfile, line $breakloc.*" ""
> +gdb_test "reverse-continue" ".*/$srcfile:$breakloc.*" "reverse to
> $breakloc"
> +
> +gdb_test "print aglobal" ".* = 0$newline" "module global reverse"
> +gdb_test "step" ".* module global post-change .*" ""
> +gdb_test "print aglobal" ".* = 1$newline" "module global forward"
> +
> +
> +# Module static variable
> +
> +set breakloc [gdb_get_line_number \
> + "module_static_state: set breakpoint here" $srcfile]
> +
> +gdb_test "tbreak $breakloc" ".*/$srcfile, line $breakloc.*" ""
> +gdb_test "reverse-continue" ".*/$srcfile:$breakloc.*" "reverse to
> $breakloc"
> +
> +gdb_test "print astatic" ".* = 0$newline" "module static
> reverse-breakpoint"
> +gdb_test "step" ".* module static post-change .*" ""
> +gdb_test "print astatic" ".* = 1$newline" "module static forward"
> +gdb_test "reverse-step" ".*$newline$breakloc.*" ""
> +gdb_test "print astatic" ".* = 0$newline" "module static reverse-step"
> +
> +# Function static variable
> +
> +set breakloc [gdb_get_line_number \
> + "function_static_state: set breakpoint here" $srcfile]
> +
> +gdb_test "tbreak $breakloc" ".*/$srcfile, line $breakloc.*" ""
> +gdb_test "reverse-continue" ".*/$srcfile:$breakloc.*" "reverse to
> $breakloc"
> +
> +gdb_test "print a" ".* = 0$newline" "function static
> reverse-breakpoint"
> +gdb_test "step" ".* function static post-change .*" ""
> +gdb_test "print a" ".* = 1$newline" "function static forward"
> +gdb_test "reverse-step" ".*$newline$breakloc.*" ""
> +gdb_test "print a" ".* = 0$newline" "function static reverse-step"
> +
> +# Auto variable
> +
> +set breakloc [gdb_get_line_number \
> + "auto_state: set breakpoint here" $srcfile]
> +
> +gdb_test "tbreak $breakloc" ".*/$srcfile, line $breakloc.*" ""
> +gdb_test "reverse-continue" ".*/$srcfile:$breakloc.*" "reverse to
> $breakloc"
> +
> +gdb_test "print a" ".* = 0$newline" "auto var reverse-breakpoint"
> +gdb_test "step" ".* auto post-change .*" ""
> +gdb_test "print a" ".* = 1$newline" "auto var forward"
> +gdb_test "reverse-step" ".*$newline$breakloc.*" ""
> +gdb_test "print a" ".* = 0$newline" "auto var reverse-step"
> +
> +# Register variable
> +
> +set breakloc [gdb_get_line_number \
> + "register_state: set breakpoint here" $srcfile]
> +
> +gdb_test "tbreak $breakloc" ".*/$srcfile, line $breakloc.*" ""
> +gdb_test "reverse-continue" ".*/$srcfile:$breakloc.*" "reverse to
> $breakloc"
> +
> +gdb_test "print a" ".* = 0$newline" "register var reverse-breakpoint"
> +gdb_test "step" ".* register post-change .*" ""
> +gdb_test "print a" ".* = 1$newline" "register var forward"
> +gdb_test "reverse-step" ".*$newline$breakloc.*" ""
> +gdb_test "print a" ".* = 0$newline" "register var reverse-step"
> +
> Index: machinestate1.c
> ===================================================================
> RCS file: machinestate1.c
> diff -N machinestate1.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ machinestate1.c 16 Sep 2008 23:43:04 -0000
> @@ -0,0 +1,25 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> + Copyright 2008 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>.
> */
> +
> +/*
> + * Aux function for machine state test.
> + */
> +
> +void
> +hide (int x)
> +{
> +}
> Index: Makefile.in
> ===================================================================
> RCS file: /cvs/src/src/gdb/testsuite/gdb.twreverse/Attic/Makefile.in,v
> retrieving revision 1.1.2.5
> diff -u -p -r1.1.2.5 Makefile.in
> --- Makefile.in 9 Sep 2008 19:05:17 -0000 1.1.2.5
> +++ Makefile.in 16 Sep 2008 23:43:04 -0000
> @@ -1,7 +1,9 @@
> VPATH = @srcdir@
> srcdir = @srcdir@
>
> -EXECUTABLES = break-reverse step-reverse return2-reverse watch-reverse
> +EXECUTABLES = break-reverse step-reverse finish-reverse \
> + until-reverse watch-reverse consecutive-reverse machinestate
> +
> MISCELLANEOUS =
>
> all info install-info dvi install uninstall installcheck check:
>
>