gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / unavailable.cc
CommitLineData
06d72e16
PA
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
26typedef struct TEST_STRUCT {
27 char memberc;
28 int memberi;
29 float memberf;
30 double memberd;
31} test_struct;
32
39d37385
PA
33struct small_struct
34{
35 int member;
36};
37
38struct small_struct_b : public small_struct
39{
40};
41
06d72e16
PA
42typedef int test_array [4];
43
44/* Global variables to be collected. */
45
46char globalc;
47int globali;
48float globalf;
49double globald;
50test_struct globalstruct;
51test_struct *globalp;
52int globalarr[16];
39d37385
PA
53small_struct g_smallstruct;
54small_struct_b g_smallstruct_b;
06d72e16
PA
55
56/* Strings. */
57
58const char g_const_string[] = "hello world";
59char g_string_unavail[sizeof (g_const_string)];
60char g_string_partial[sizeof (g_const_string)];
61const char *g_string_p;
62
63/* Used to check that <unavailable> is not the same as 0 in array
64 element repetitions. */
65
66struct tuple
67{
68 int a;
69 int b;
70};
71
72struct tuple tarray[8];
73
74/* Random tests. */
75
76struct StructA
77{
78 int a, b;
79 int array[10000];
80 void *ptr;
81 int bitfield:1;
82};
83
84struct StructB
85{
86 int d, ef;
87 StructA struct_a;
88 int s:1;
89 static StructA static_struct_a;
90 const char *string;
91};
92
93/* References. */
94
95int g_int;
96int &g_ref = g_int;
97
98struct StructRef
99{
100 StructRef (unsigned int val) : ref(d) {}
101
102 void clear ()
103 {
104 d = 0;
105 }
106
107 unsigned int d;
108 unsigned int &ref;
109};
110
111struct StructB struct_b;
112struct StructA StructB::static_struct_a;
113
114StructRef g_structref(0x12345678);
115StructRef *g_structref_p = &g_structref;
116
ec0a52e1
PA
117struct Virtual {
118 int z;
119
120 virtual ~Virtual() {}
121};
122
123Virtual *virtualp;
06d72e16
PA
124
125/* Test functions. */
126
127static void
128begin () /* called before anything else */
129{
130}
131
132static void
133end () /* called after everything else */
134{
135}
136
137int
138globals_test_func ()
139{
140 int i = 0;
141
142 i += globalc + globali + globalf + globald;
143 i += globalstruct.memberc + globalstruct.memberi;
144 i += globalstruct.memberf + globalstruct.memberd;
145 i += globalarr[1];
146
147 return i; /* set globals_test_func tracepoint here */
148}
149
150int
151main (int argc, char **argv, char **envp)
152{
153 int i = 0;
154 test_struct mystruct;
155 int myarray[4];
156
157 begin ();
158 /* Assign collectable values to global variables. */
159 globalc = 71;
160 globali = 72;
161 globalf = 73.3;
162 globald = 74.4;
163 globalstruct.memberc = 81;
164 globalstruct.memberi = 82;
165 globalstruct.memberf = 83.3;
166 globalstruct.memberd = 84.4;
167 globalp = &globalstruct;
168
169 for (i = 0; i < 15; i++)
170 globalarr[i] = i;
171
172 mystruct.memberc = 101;
173 mystruct.memberi = 102;
174 mystruct.memberf = 103.3;
175 mystruct.memberd = 104.4;
176 myarray[0] = 111;
177 myarray[1] = 112;
178 myarray[2] = 113;
179 myarray[3] = 114;
180
181 g_int = 123;
182 memset (&struct_b, 0xaa, sizeof struct_b);
183 memset (&struct_b.static_struct_a, 0xaa, sizeof struct_b.static_struct_a);
184 struct_b.string = g_const_string;
185 memcpy (g_string_unavail, g_const_string, sizeof (g_const_string));
186 memcpy (g_string_partial, g_const_string, sizeof (g_const_string));
187 g_string_p = g_const_string;
188
189 /* Call test functions, so they can be traced and data collected. */
190 i = 0;
191 i += globals_test_func ();
192
193 /* Set 'em back to zero, so that the collected values will be
194 distinctly different from the "realtime" (end of test) values. */
195
196 globalc = 0;
197 globali = 0;
198 globalf = 0;
199 globald = 0;
200 globalstruct.memberc = 0;
201 globalstruct.memberi = 0;
202 globalstruct.memberf = 0;
203 globalstruct.memberd = 0;
204 globalp = 0;
205 for (i = 0; i < 15; i++)
206 globalarr[i] = 0;
207
208 memset (&struct_b, 0, sizeof struct_b);
209 memset (&struct_b.static_struct_a, 0, sizeof struct_b.static_struct_a);
210 struct_b.string = NULL;
211 memset (g_string_unavail, 0, sizeof (g_string_unavail));
212 memset (g_string_partial, 0, sizeof (g_string_partial));
213 g_string_p = NULL;
214
215 g_int = 0;
216
217 g_structref.clear ();
218 g_structref_p = NULL;
219
220 end ();
221 return 0;
222}
This page took 0.034338 seconds and 4 git commands to generate.