1 /* This testcase is part of GDB, the GNU debugger.
2 
3    Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17 
18 /*
19  * Test restoration of machine state
20  */
21 
22 extern void hide (int);
23 
24 /* Test register variable
25    Requires -- compiler honors 'register'.  */
26 
27 void
register_state(void)28 register_state (void)
29 {
30   register int a = 0;
31 
32   hide (a);	/* External function to defeat optimization.  */
33   a++;		/* register_state: set breakpoint here */
34   hide (a);	/* register post-change */
35 }
36 
37 /* Test auto variable (whatever that means).  */
38 
39 void
auto_state(void)40 auto_state (void)
41 {
42   auto int a = 0;
43 
44   hide (a);	/* External function to defeat optimization.  */
45   a++;		/* auto_state: set breakpoint here */
46   hide (a);	/* auto post-change */
47 }
48 
49 /* Test function-static variable.  */
50 
51 void
function_static_state(void)52 function_static_state (void)
53 {
54   static int a = 0;
55 
56   hide (a);	/* External function to defeat optimization.  */
57   a++;		/* function_static_state: set breakpoint here */
58   hide (a);	/* function static post-change */
59 }
60 
61 /* Test module-static variable.  */
62 
63 static int astatic;
64 
65 void
module_static_state(void)66 module_static_state (void)
67 {
68   astatic = 0;
69 
70   hide (astatic);	/* External function to defeat optimization.  */
71   astatic++;		/* module_static_state: set breakpoint here */
72   hide (astatic);	/* module static post-change */
73 }
74 
75 /* Test module-global variable.  */
76 
77 int aglobal;
78 
79 void
module_global_state(void)80 module_global_state (void)
81 {
82   aglobal = 0;
83 
84   hide (aglobal);	/* External function to defeat optimization.  */
85   aglobal++;		/* module_global_state: set breakpoint here */
86   hide (aglobal);	/* module global post-change */
87 }
88 
89 /* main test driver */
90 
91 int
main(int argc,char ** argv)92 main (int argc, char **argv)
93 {
94   register_state ();	/* begin main */
95   auto_state ();
96   function_static_state ();
97   module_static_state ();
98   module_global_state ();
99 
100   return 0;		/* end main */
101 }
102