1 /* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 1998-2023 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 program for trace collection 20 */ 21 22 /* 23 * Typedefs 24 */ 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 /* 36 * Global variables to be collected 37 */ 38 39 char globalc; 40 int globali; 41 float globalf; 42 double globald; 43 test_struct globalstruct; 44 test_struct *globalp; 45 int globalarr[16]; 46 int globalarr2[4]; 47 int globalarr3[4]; 48 49 struct global_pieces { 50 unsigned int a; 51 unsigned int b; 52 } global_pieces = 53 { 54 0x12345678, 0x87654321 55 }; 56 57 /* 58 * Additional globals used in arithmetic tests 59 */ 60 61 signed char c0, c1, c2, c3, c4, c5, c6, c7, 62 c8, c9, c10, c11, c12, c13, c14, c15, cminus; 63 signed short s0, s1, s2, s3, s4, s5, s6, s7, 64 s8, s9, s10, s11, s12, s13, s14, s15, sminus; 65 signed long l0, l1, l2, l3, l4, l5, l6, l7, 66 l8, l9, l10, l11, l12, l13, l14, l15, lminus; 67 68 69 /* 70 * Test functions 71 */ 72 73 static void begin () /* called before anything else */ 74 { 75 } 76 77 static void end () /* called after everything else */ 78 { 79 } 80 81 /* Test collecting args. */ 82 int args_test_func (argc, argi, argf, argd, argstruct, argarray) 83 char argc; 84 int argi; 85 float argf; 86 double argd; 87 test_struct argstruct; 88 int argarray[4]; 89 { 90 int i; 91 92 i = (int) argc + argi + argf + argd + argstruct.memberi + argarray[1]; 93 94 return i; 95 } 96 97 /* Test collecting struct args. */ 98 int argstruct_test_func (argstruct) 99 test_struct argstruct; 100 { 101 return (int) argstruct.memberc + argstruct.memberi + 102 argstruct.memberf + argstruct.memberd; 103 } 104 105 /* Test collecting array args. */ 106 int argarray_test_func (argarray) 107 int argarray[4]; 108 { 109 return (int) argarray[0] + argarray[1] + argarray[2] + argarray[3]; 110 } 111 112 113 114 int local_test_func () /* test collecting locals */ 115 { 116 char locc = 11; 117 int loci = 12; 118 float locf = 13.3; 119 double locd = 14.4; 120 test_struct locst; 121 int locar[4]; 122 int i; 123 struct localstruct {} locdefst; 124 125 locst.memberc = 15; 126 locst.memberi = 16; 127 locst.memberf = 17.7; 128 locst.memberd = 18.8; 129 locar[0] = 121; 130 locar[1] = 122; 131 locar[2] = 123; 132 locar[3] = 124; 133 134 i = /* Set_Tracepoint_Here */ 135 (int) locc + loci + locf + locd + locst.memberi + locar[1]; 136 137 return i; 138 } 139 140 int reglocal_test_func () /* test collecting register locals */ 141 { 142 register char locc = 11; 143 register int loci = 12; 144 register float locf = 13.3; 145 register double locd = 14.4; 146 register test_struct locst; 147 register int locar[4]; 148 int i; 149 150 locst.memberc = 15; 151 locst.memberi = 16; 152 locst.memberf = 17.7; 153 locst.memberd = 18.8; 154 locar[0] = 121; 155 locar[1] = 122; 156 locar[2] = 123; 157 locar[3] = 124; 158 159 i = /* Set_Tracepoint_Here */ 160 (int) locc + loci + locf + locd + locst.memberi + locar[1]; 161 162 return i; 163 } 164 165 int statlocal_test_func () /* test collecting static locals */ 166 { 167 static char locc; 168 static int loci; 169 static float locf; 170 static double locd; 171 static test_struct locst; 172 static int locar[4]; 173 int i; 174 175 locc = 11; 176 loci = 12; 177 locf = 13.3; 178 locd = 14.4; 179 locst.memberc = 15; 180 locst.memberi = 16; 181 locst.memberf = 17.7; 182 locst.memberd = 18.8; 183 locar[0] = 121; 184 locar[1] = 122; 185 locar[2] = 123; 186 locar[3] = 124; 187 188 i = /* Set_Tracepoint_Here */ 189 (int) locc + loci + locf + locd + locst.memberi + locar[1]; 190 191 /* Set static locals back to zero so collected values are clearly special. */ 192 locc = 0; 193 loci = 0; 194 locf = 0; 195 locd = 0; 196 locst.memberc = 0; 197 locst.memberi = 0; 198 locst.memberf = 0; 199 locst.memberd = 0; 200 locar[0] = 0; 201 locar[1] = 0; 202 locar[2] = 0; 203 locar[3] = 0; 204 205 return i; 206 } 207 208 209 int globals_test_func () 210 { 211 int i = 0; 212 213 i += globalc + globali + globalf + globald; 214 i += globalstruct.memberc + globalstruct.memberi; 215 i += globalstruct.memberf + globalstruct.memberd; 216 i += globalarr[1]; 217 218 return i; /* Set_Tracepoint_Here */ 219 } 220 221 int strings_test_func () 222 { 223 int i = 0; 224 char *locstr, *longloc; 225 226 locstr = "abcdef"; 227 longloc = malloc(500); 228 strcpy(longloc, "how now brown cow spam spam spam wonderful wonderful spam"); 229 230 i += strlen (locstr); 231 i += strlen (longloc); 232 233 return i; /* Set_Tracepoint_Here */ 234 } 235 236 int 237 main (argc, argv, envp) 238 int argc; 239 char *argv[], **envp; 240 { 241 int i = 0; 242 test_struct mystruct; 243 int myarray[4]; 244 245 begin (); 246 /* Assign collectable values to global variables. */ 247 l0 = s0 = c0 = 0; l1 = s1 = c1 = 1; 248 l2 = s2 = c2 = 2; l3 = s3 = c3 = 3; 249 l4 = s4 = c4 = 4; l5 = s5 = c5 = 5; 250 l6 = s6 = c6 = 6; l7 = s7 = c7 = 7; 251 l8 = s8 = c8 = 8; l9 = s9 = c9 = 9; 252 l10 = s10 = c10 = 10; l11 = s11 = c11 = 11; 253 l12 = s12 = c12 = 12; l13 = s13 = c13 = 13; 254 l14 = s14 = c14 = 14; l15 = s15 = c15 = 15; 255 lminus = sminus = cminus = -2; 256 globalc = 71; 257 globali = 72; 258 globalf = 73.3; 259 globald = 74.4; 260 globalstruct.memberc = 81; 261 globalstruct.memberi = 82; 262 globalstruct.memberf = 83.3; 263 globalstruct.memberd = 84.4; 264 globalp = &globalstruct; 265 266 for (i = 0; i < 15; i++) 267 globalarr[i] = i; 268 269 for (i = 0; i < 4; i++) 270 globalarr2[i] = i; 271 272 for (i = 0; i < 4; i++) 273 globalarr3[3 - i] = i; 274 275 mystruct.memberc = 101; 276 mystruct.memberi = 102; 277 mystruct.memberf = 103.3; 278 mystruct.memberd = 104.4; 279 myarray[0] = 111; 280 myarray[1] = 112; 281 myarray[2] = 113; 282 myarray[3] = 114; 283 284 /* Call test functions, so they can be traced and data collected. */ 285 i = 0; 286 i += args_test_func (1, 2, 3.3, 4.4, mystruct, myarray); 287 i += argstruct_test_func (mystruct); 288 i += argarray_test_func (myarray); 289 i += local_test_func (); 290 i += reglocal_test_func (); 291 i += statlocal_test_func (); 292 i += globals_test_func (); 293 i += strings_test_func (); 294 295 /* Values of globals at end of test should be different from 296 values that they had when trace data was captured. */ 297 298 l0 = s0 = c0 = 0; l1 = s1 = c1 = 0; 299 l2 = s2 = c2 = 0; l3 = s3 = c3 = 0; 300 l4 = s4 = c4 = 0; l5 = s5 = c5 = 0; 301 l6 = s6 = c6 = 0; l7 = s7 = c7 = 0; 302 l8 = s8 = c8 = 0; l9 = s9 = c9 = 0; 303 l10 = s10 = c10 = 0; l11 = s11 = c11 = 0; 304 l12 = s12 = c12 = 0; l13 = s13 = c13 = 0; 305 l14 = s14 = c14 = 0; l15 = s15 = c15 = 0; 306 lminus = sminus = cminus = 0; 307 308 /* Set 'em back to zero, so that the collected values will be 309 distinctly different from the "realtime" (end of test) values. */ 310 311 globalc = 0; 312 globali = 0; 313 globalf = 0; 314 globald = 0; 315 globalstruct.memberc = 0; 316 globalstruct.memberi = 0; 317 globalstruct.memberf = 0; 318 globalstruct.memberd = 0; 319 globalp = 0; 320 for (i = 0; i < 15; i++) 321 globalarr[i] = 0; 322 for (i = 0; i < 4; i++) 323 globalarr2[i] = 0; 324 for (i = 0; i < 4; i++) 325 globalarr3[i] = 0; 326 327 end (); 328 return 0; 329 } 330