1 /* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2008-2025 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 #include <stdio.h> 19 #include <stdlib.h> 20 #include <string.h> 21 22 int long_array[] = { 23 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 24 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 25 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 26 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 28 }; 29 30 struct s 31 { 32 int a; 33 int b; 34 }; 35 36 union u 37 { 38 int a; 39 float b; 40 }; 41 42 enum e 43 { 44 ONE = 1, 45 TWO = 2 46 }; 47 48 typedef struct s *PTR; 49 50 enum e evalue = TWO; 51 52 struct str 53 { 54 int length; 55 /* Variable length. */ 56 char text[1]; 57 }; 58 59 #ifdef __cplusplus 60 61 struct Base { 62 virtual int x() { return 5; } 63 }; 64 65 struct Derived : public Base { 66 }; 67 68 Base *base = new Derived (); 69 Derived derived; 70 Base &base_ref = derived; 71 struct str pod; 72 73 void ptr_ref(int*& rptr_int) 74 { 75 return; /* break to inspect pointer by reference. */ 76 } 77 #endif 78 79 void func1 () 80 { 81 printf ("void function called\n"); 82 } 83 84 int func2 (int arg1, int arg2) 85 { 86 return arg1 + arg2; 87 } 88 89 char **save_argv; 90 91 int shadowed = 23; 92 93 int 94 main (int argc, char *argv[]) 95 { 96 char *cp; 97 struct s s; 98 union u u; 99 PTR x = &s; 100 char st[17] = "divide et impera"; 101 char nullst[17] = "divide\0et\0impera"; 102 void (*fp1) (void) = &func1; 103 int (*fp2) (int, int) = &func2; 104 const char *embed = "embedded x\201\202\203\204"; 105 int a[3] = {1,2,3}; 106 int *p = a; 107 int i = 2; 108 int *ptr_i = &i; 109 struct str *xstr; 110 int shadowed = 97; 111 112 /* Prevent gcc from optimizing argv[] out. */ 113 114 /* We also check for a NULL argv in case we are dealing with a target 115 executing in a freestanding environment, therefore there are no 116 guarantees about argc or argv. */ 117 if (argv != NULL) 118 cp = argv[0]; 119 120 s.a = 3; 121 s.b = 5; 122 u.a = 7; 123 (*fp1) (); 124 (*fp2) (10,20); 125 126 #ifdef __cplusplus 127 ptr_ref(ptr_i); 128 #endif 129 130 #define STR_LENGTH 100 131 xstr = (struct str *) malloc (sizeof (*xstr) + STR_LENGTH); 132 xstr->length = STR_LENGTH; 133 memset (xstr->text, 'x', STR_LENGTH); 134 #undef STR_LENGTH 135 136 save_argv = argv; /* break to inspect struct and union */ 137 return 0; 138 } 139