2011-02-16 Tom Tromey <tromey@redhat.com>
[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 struct small_struct
34 {
35 int member;
36 };
37
38 struct small_struct_b : public small_struct
39 {
40 };
41
42 typedef int test_array [4];
43
44 /* Global variables to be collected. */
45
46 char globalc;
47 int globali;
48 float globalf;
49 double globald;
50 test_struct globalstruct;
51 test_struct *globalp;
52 int globalarr[16];
53 small_struct g_smallstruct;
54 small_struct_b g_smallstruct_b;
55
56 /* Strings. */
57
58 const char g_const_string[] = "hello world";
59 char g_string_unavail[sizeof (g_const_string)];
60 char g_string_partial[sizeof (g_const_string)];
61 const char *g_string_p;
62
63 /* Used to check that <unavailable> is not the same as 0 in array
64 element repetitions. */
65
66 struct tuple
67 {
68 int a;
69 int b;
70 };
71
72 struct tuple tarray[8];
73
74 /* Test for overcollection. GDB used to merge memory ranges to
75 collect if they were close enough --- say, collect `a' and 'c'
76 below, and you'd get 'b' as well. This had been presumably done to
77 cater for some target's inefficient trace buffer layout, but it is
78 really not GDB's business to assume how the target manages its
79 buffer. If the target wants to overcollect, that's okay, since it
80 knows what is and what isn't safe to touch (think memory mapped
81 registers), and knows it's buffer layout.
82
83 The test assumes these three variables are laid out consecutively
84 in memory. Unfortunately, we can't use an array instead, since the
85 agent expression generator does not even do constant folding,
86 meaning that anything that's more complicated than collecting a
87 global will generate an agent expression action to evaluate on the
88 target, instead of a simple "collect memory" action. */
89 int a;
90 int b;
91 int c;
92
93 /* Random tests. */
94
95 struct StructA
96 {
97 int a, b;
98 int array[10000];
99 void *ptr;
100 int bitfield:1;
101 };
102
103 struct StructB
104 {
105 int d, ef;
106 StructA struct_a;
107 int s:1;
108 static StructA static_struct_a;
109 const char *string;
110 };
111
112 /* References. */
113
114 int g_int;
115 int &g_ref = g_int;
116
117 struct StructRef
118 {
119 StructRef (unsigned int val) : ref(d) {}
120
121 void clear ()
122 {
123 d = 0;
124 }
125
126 unsigned int d;
127 unsigned int &ref;
128 };
129
130 struct StructB struct_b;
131 struct StructA StructB::static_struct_a;
132
133 StructRef g_structref(0x12345678);
134 StructRef *g_structref_p = &g_structref;
135
136 class Base
137 {
138 protected:
139 int x;
140
141 public:
142 Base(void) { x = 2; };
143 };
144
145 class Middle: public virtual Base
146 {
147 protected:
148 int y;
149
150 public:
151 Middle(void): Base() { y = 3; };
152 };
153
154 class Derived: public virtual Middle {
155 protected:
156 int z;
157
158 public:
159 Derived(void): Middle() { z = 4; };
160 };
161
162 Derived derived_unavail;
163 Derived derived_partial;
164 Derived derived_whole;
165
166 struct Virtual {
167 int z;
168
169 virtual ~Virtual() {}
170 };
171
172 Virtual virtual_partial;
173 Virtual *virtualp = &virtual_partial;
174
175 /* Test functions. */
176
177 static void
178 begin () /* called before anything else */
179 {
180 }
181
182 static void
183 end () /* called after everything else */
184 {
185 }
186
187 int
188 globals_test_func ()
189 {
190 int i = 0;
191
192 i += globalc + globali + globalf + globald;
193 i += globalstruct.memberc + globalstruct.memberi;
194 i += globalstruct.memberf + globalstruct.memberd;
195 i += globalarr[1];
196
197 return i; /* set globals_test_func tracepoint here */
198 }
199
200 int
201 main (int argc, char **argv, char **envp)
202 {
203 int i = 0;
204 test_struct mystruct;
205 int myarray[4];
206
207 begin ();
208 /* Assign collectable values to global variables. */
209 globalc = 71;
210 globali = 72;
211 globalf = 73.3;
212 globald = 74.4;
213 globalstruct.memberc = 81;
214 globalstruct.memberi = 82;
215 globalstruct.memberf = 83.3;
216 globalstruct.memberd = 84.4;
217 globalp = &globalstruct;
218
219 for (i = 0; i < 15; i++)
220 globalarr[i] = i;
221
222 mystruct.memberc = 101;
223 mystruct.memberi = 102;
224 mystruct.memberf = 103.3;
225 mystruct.memberd = 104.4;
226 myarray[0] = 111;
227 myarray[1] = 112;
228 myarray[2] = 113;
229 myarray[3] = 114;
230
231 g_int = 123;
232 memset (&struct_b, 0xaa, sizeof struct_b);
233 memset (&struct_b.static_struct_a, 0xaa, sizeof struct_b.static_struct_a);
234 struct_b.string = g_const_string;
235 memcpy (g_string_unavail, g_const_string, sizeof (g_const_string));
236 memcpy (g_string_partial, g_const_string, sizeof (g_const_string));
237 g_string_p = g_const_string;
238 a = 1; b = 2; c = 3;
239
240 /* Call test functions, so they can be traced and data collected. */
241 i = 0;
242 i += globals_test_func ();
243
244 /* Set 'em back to zero, so that the collected values will be
245 distinctly different from the "realtime" (end of test) values. */
246
247 globalc = 0;
248 globali = 0;
249 globalf = 0;
250 globald = 0;
251 globalstruct.memberc = 0;
252 globalstruct.memberi = 0;
253 globalstruct.memberf = 0;
254 globalstruct.memberd = 0;
255 globalp = 0;
256 for (i = 0; i < 15; i++)
257 globalarr[i] = 0;
258
259 memset (&struct_b, 0, sizeof struct_b);
260 memset (&struct_b.static_struct_a, 0, sizeof struct_b.static_struct_a);
261 struct_b.string = NULL;
262 memset (g_string_unavail, 0, sizeof (g_string_unavail));
263 memset (g_string_partial, 0, sizeof (g_string_partial));
264 g_string_p = NULL;
265
266 a = b = c = 0;
267
268 g_int = 0;
269
270 g_structref.clear ();
271 g_structref_p = NULL;
272
273 end ();
274 return 0;
275 }
This page took 0.039008 seconds and 4 git commands to generate.