Re: ld plugin bfd_make_readable leak
[binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint-unaligned.c
blob6f709259b6c9d5db35ebaf881ec23295286b4c9b
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2017-2024 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/>. */
18 #include <stdint.h>
19 #include <assert.h>
21 static int again;
23 static volatile struct
25 uint64_t alignment;
26 union
28 uint64_t size8[1];
29 uint32_t size4[2];
30 uint16_t size2[4];
31 uint8_t size1[8];
32 uint64_t size8twice[3];
35 } data;
37 static int size = 0;
38 static int offset;
40 static void
41 write_size8twice (void)
43 static const uint64_t first = 1;
44 static const uint64_t second = 2;
46 #ifdef __aarch64__
47 volatile void *p = &data.u.size8twice[offset];
48 asm volatile ("stp %1, %2, [%0]"
49 : /* output */
50 : "r" (p), "r" (first), "r" (second) /* input */
51 : "memory" /* clobber */);
52 #else
53 data.u.size8twice[offset] = first;
54 data.u.size8twice[offset + 1] = second;
55 #endif
58 int
59 main (void)
61 volatile uint64_t local;
63 assert (sizeof (data) == 8 + 3 * 8);
65 write_size8twice ();
67 while (size)
69 switch (size)
71 /* __s390x__ also defines __s390__ */
72 #ifdef __s390__
73 # define ACCESS(var) var = ~var
74 #else
75 # define ACCESS(var) local = var
76 #endif
77 case 8:
78 ACCESS (data.u.size8[offset]);
79 break;
80 case 4:
81 ACCESS (data.u.size4[offset]);
82 break;
83 case 2:
84 ACCESS (data.u.size2[offset]);
85 break;
86 case 1:
87 ACCESS (data.u.size1[offset]);
88 break;
89 #undef ACCESS
90 default:
91 assert (0);
93 size = 0;
94 size = size; /* start_again */
96 return 0; /* final_return */