1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2002-2019 Free Software Foundation, Inc.
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.
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.
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/>. */
21 /* Test program partial trace data visualization. */
25 typedef struct TEST_STRUCT
{
37 struct small_struct_b
: public small_struct
41 typedef int test_array
[4];
43 /* Global variables to be collected. */
49 test_struct globalstruct
;
52 small_struct g_smallstruct
;
53 small_struct_b g_smallstruct_b
;
57 const char g_const_string
[] = "hello world";
58 char g_string_unavail
[sizeof (g_const_string
)];
59 char g_string_partial
[sizeof (g_const_string
)];
60 const char *g_string_p
;
62 /* Used to check that <unavailable> is not the same as 0 in array
63 element repetitions. */
71 struct tuple tarray
[8];
73 /* Test for overcollection. GDB used to merge memory ranges to
74 collect if they were close enough --- say, collect `a' and 'c'
75 below, and you'd get 'b' as well. This had been presumably done to
76 cater for some target's inefficient trace buffer layout, but it is
77 really not GDB's business to assume how the target manages its
78 buffer. If the target wants to overcollect, that's okay, since it
79 knows what is and what isn't safe to touch (think memory mapped
80 registers), and knows it's buffer layout.
82 The test assumes these three variables are laid out consecutively
83 in memory. Unfortunately, we can't use an array instead, since the
84 agent expression generator does not even do constant folding,
85 meaning that anything that's more complicated than collecting a
86 global will generate an agent expression action to evaluate on the
87 target, instead of a simple "collect memory" action. */
107 static StructA static_struct_a
;
118 StructRef (unsigned int val
) : ref(d
) {}
129 struct StructB struct_b
;
130 struct StructA
StructB::static_struct_a
;
132 StructRef
g_structref(0x12345678);
133 StructRef
*g_structref_p
= &g_structref
;
141 Base(void) { x
= 2; };
144 class Middle
: public virtual Base
150 Middle(void): Base() { y
= 3; };
153 class Derived
: public virtual Middle
{
158 Derived(void): Middle() { z
= 4; };
161 Derived derived_unavail
;
162 Derived derived_partial
;
163 Derived derived_whole
;
168 virtual ~Virtual() {}
171 Virtual virtual_partial
;
172 Virtual
*virtualp
= &virtual_partial
;
174 /* Test functions. */
177 begin () /* called before anything else */
182 end () /* called after everything else */
186 /* Test (not) collecting args. */
189 args_test_func (char argc
,
193 test_struct argstruct
,
198 i
= (int) argc
+ argi
+ argf
+ argd
+ argstruct
.memberi
+ argarray
[1];
203 /* Test (not) collecting array args. */
205 /* Test (not) collecting locals. */
217 struct localstruct
{} locdefst
;
221 locst
.memberf
= 17.7;
222 locst
.memberd
= 18.8;
228 i
= /* set local_test_func tracepoint here */
229 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
234 /* Test collecting register locals. */
237 reglocal_test_func ()
239 register char locc
= 11;
240 register int loci
= 12;
241 register float locf
= 13.3;
242 register double locd
= 14.4;
243 register test_struct locst
;
244 register int locar
[4];
249 locst
.memberf
= 17.7;
250 locst
.memberd
= 18.8;
256 i
= /* set reglocal_test_func tracepoint here */
257 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
262 /* Test collecting static locals. */
265 statlocal_test_func ()
271 static test_struct locst
;
281 locst
.memberf
= 17.7;
282 locst
.memberd
= 18.8;
288 i
= /* set statlocal_test_func tracepoint here */
289 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
291 /* Set static locals back to zero so collected values are clearly special. */
313 i
+= globalc
+ globali
+ globalf
+ globald
;
314 i
+= globalstruct
.memberc
+ globalstruct
.memberi
;
315 i
+= globalstruct
.memberf
+ globalstruct
.memberd
;
318 return i
; /* set globals_test_func tracepoint here */
322 main (int argc
, char **argv
, char **envp
)
325 test_struct mystruct
;
329 /* Assign collectable values to global variables. */
334 globalstruct
.memberc
= 81;
335 globalstruct
.memberi
= 82;
336 globalstruct
.memberf
= 83.3;
337 globalstruct
.memberd
= 84.4;
338 globalp
= &globalstruct
;
340 for (i
= 0; i
< 15; i
++)
343 mystruct
.memberc
= 101;
344 mystruct
.memberi
= 102;
345 mystruct
.memberf
= 103.3;
346 mystruct
.memberd
= 104.4;
353 memset (&struct_b
, 0xaa, sizeof struct_b
);
354 memset (&struct_b
.static_struct_a
, 0xaa, sizeof struct_b
.static_struct_a
);
355 struct_b
.string
= g_const_string
;
356 memcpy (g_string_unavail
, g_const_string
, sizeof (g_const_string
));
357 memcpy (g_string_partial
, g_const_string
, sizeof (g_const_string
));
358 g_string_p
= g_const_string
;
361 /* Call test functions, so they can be traced and data collected. */
363 i
+= args_test_func (1, 2, 3.3, 4.4, mystruct
, myarray
);
364 i
+= local_test_func ();
365 i
+= reglocal_test_func ();
366 i
+= statlocal_test_func ();
367 i
+= globals_test_func ();
369 /* Set 'em back to zero, so that the collected values will be
370 distinctly different from the "realtime" (end of test) values. */
376 globalstruct
.memberc
= 0;
377 globalstruct
.memberi
= 0;
378 globalstruct
.memberf
= 0;
379 globalstruct
.memberd
= 0;
381 for (i
= 0; i
< 15; i
++)
384 memset (&struct_b
, 0, sizeof struct_b
);
385 memset (&struct_b
.static_struct_a
, 0, sizeof struct_b
.static_struct_a
);
386 struct_b
.string
= NULL
;
387 memset (g_string_unavail
, 0, sizeof (g_string_unavail
));
388 memset (g_string_partial
, 0, sizeof (g_string_partial
));
395 g_structref
.clear ();
396 g_structref_p
= NULL
;