diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.twreverse/machinestate.c | 101 | ||||
-rw-r--r-- | gdb/testsuite/gdb.twreverse/machinestate.exp | 142 | ||||
-rw-r--r-- | gdb/testsuite/gdb.twreverse/machinestate1.c | 25 |
4 files changed, 275 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 49d51671525..982fca5ca20 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +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. + 2008-09-15 Michael Snyder <msnyder@vmware.com> * gdb.twreverse/consecutive-reverse.exp: New file. diff --git a/gdb/testsuite/gdb.twreverse/machinestate.c b/gdb/testsuite/gdb.twreverse/machinestate.c new file mode 100644 index 00000000000..99c368ddda0 --- /dev/null +++ b/gdb/testsuite/gdb.twreverse/machinestate.c @@ -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 */ +} diff --git a/gdb/testsuite/gdb.twreverse/machinestate.exp b/gdb/testsuite/gdb.twreverse/machinestate.exp new file mode 100644 index 00000000000..63f11727152 --- /dev/null +++ b/gdb/testsuite/gdb.twreverse/machinestate.exp @@ -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" + diff --git a/gdb/testsuite/gdb.twreverse/machinestate1.c b/gdb/testsuite/gdb.twreverse/machinestate1.c new file mode 100644 index 00000000000..435ff12bd66 --- /dev/null +++ b/gdb/testsuite/gdb.twreverse/machinestate1.c @@ -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) +{ +} |