gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / unavailable.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include <stdlib.h>
20 #include <string.h>
21
22 /* Test program partial trace data visualization. */
23
24 /* Typedefs. */
25
26 typedef struct TEST_STRUCT {
27 char memberc;
28 int memberi;
29 float memberf;
30 double memberd;
31 } test_struct;
32
33 typedef int test_array [4];
34
35 /* Global variables to be collected. */
36
37 char globalc;
38 int globali;
39 float globalf;
40 double globald;
41 test_struct globalstruct;
42 test_struct *globalp;
43 int globalarr[16];
44
45 /* Strings. */
46
47 const char g_const_string[] = "hello world";
48 char g_string_unavail[sizeof (g_const_string)];
49 char g_string_partial[sizeof (g_const_string)];
50 const char *g_string_p;
51
52 /* Used to check that <unavailable> is not the same as 0 in array
53 element repetitions. */
54
55 struct tuple
56 {
57 int a;
58 int b;
59 };
60
61 struct tuple tarray[8];
62
63 /* Random tests. */
64
65 struct StructA
66 {
67 int a, b;
68 int array[10000];
69 void *ptr;
70 int bitfield:1;
71 };
72
73 struct StructB
74 {
75 int d, ef;
76 StructA struct_a;
77 int s:1;
78 static StructA static_struct_a;
79 const char *string;
80 };
81
82 /* References. */
83
84 int g_int;
85 int &g_ref = g_int;
86
87 struct StructRef
88 {
89 StructRef (unsigned int val) : ref(d) {}
90
91 void clear ()
92 {
93 d = 0;
94 }
95
96 unsigned int d;
97 unsigned int &ref;
98 };
99
100 struct StructB struct_b;
101 struct StructA StructB::static_struct_a;
102
103 StructRef g_structref(0x12345678);
104 StructRef *g_structref_p = &g_structref;
105
106
107 /* Test functions. */
108
109 static void
110 begin () /* called before anything else */
111 {
112 }
113
114 static void
115 end () /* called after everything else */
116 {
117 }
118
119 int
120 globals_test_func ()
121 {
122 int i = 0;
123
124 i += globalc + globali + globalf + globald;
125 i += globalstruct.memberc + globalstruct.memberi;
126 i += globalstruct.memberf + globalstruct.memberd;
127 i += globalarr[1];
128
129 return i; /* set globals_test_func tracepoint here */
130 }
131
132 int
133 main (int argc, char **argv, char **envp)
134 {
135 int i = 0;
136 test_struct mystruct;
137 int myarray[4];
138
139 begin ();
140 /* Assign collectable values to global variables. */
141 globalc = 71;
142 globali = 72;
143 globalf = 73.3;
144 globald = 74.4;
145 globalstruct.memberc = 81;
146 globalstruct.memberi = 82;
147 globalstruct.memberf = 83.3;
148 globalstruct.memberd = 84.4;
149 globalp = &globalstruct;
150
151 for (i = 0; i < 15; i++)
152 globalarr[i] = i;
153
154 mystruct.memberc = 101;
155 mystruct.memberi = 102;
156 mystruct.memberf = 103.3;
157 mystruct.memberd = 104.4;
158 myarray[0] = 111;
159 myarray[1] = 112;
160 myarray[2] = 113;
161 myarray[3] = 114;
162
163 g_int = 123;
164 memset (&struct_b, 0xaa, sizeof struct_b);
165 memset (&struct_b.static_struct_a, 0xaa, sizeof struct_b.static_struct_a);
166 struct_b.string = g_const_string;
167 memcpy (g_string_unavail, g_const_string, sizeof (g_const_string));
168 memcpy (g_string_partial, g_const_string, sizeof (g_const_string));
169 g_string_p = g_const_string;
170
171 /* Call test functions, so they can be traced and data collected. */
172 i = 0;
173 i += globals_test_func ();
174
175 /* Set 'em back to zero, so that the collected values will be
176 distinctly different from the "realtime" (end of test) values. */
177
178 globalc = 0;
179 globali = 0;
180 globalf = 0;
181 globald = 0;
182 globalstruct.memberc = 0;
183 globalstruct.memberi = 0;
184 globalstruct.memberf = 0;
185 globalstruct.memberd = 0;
186 globalp = 0;
187 for (i = 0; i < 15; i++)
188 globalarr[i] = 0;
189
190 memset (&struct_b, 0, sizeof struct_b);
191 memset (&struct_b.static_struct_a, 0, sizeof struct_b.static_struct_a);
192 struct_b.string = NULL;
193 memset (g_string_unavail, 0, sizeof (g_string_unavail));
194 memset (g_string_partial, 0, sizeof (g_string_partial));
195 g_string_p = NULL;
196
197 g_int = 0;
198
199 g_structref.clear ();
200 g_structref_p = NULL;
201
202 end ();
203 return 0;
204 }
This page took 0.034522 seconds and 5 git commands to generate.