summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/watchpoint-unaligned.c
blob: 101b5c88a8b3f5cb463f1235f1b45c82e5ba7ab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* This testcase is part of GDB, the GNU debugger.

   Copyright 2017-2019 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <stdint.h>
#include <assert.h>

static int again;

static volatile struct
{
  uint64_t alignment;
  union
    {
      uint64_t size8[1];
      uint32_t size4[2];
      uint16_t size2[4];
      uint8_t size1[8];
      uint64_t size8twice[2];
    }
  u;
} data;

static int size = 0;
static int offset;

static void
write_size8twice (void)
{
  static const uint64_t first = 1;
  static const uint64_t second = 2;

#ifdef __aarch64__
  asm volatile ("stp %1, %2, [%0]"
		: /* output */
		: "r" (data.u.size8twice), "r" (first), "r" (second) /* input */
		: "memory" /* clobber */);
#else
  data.u.size8twice[0] = first;
  data.u.size8twice[1] = second;
#endif
}

int
main (void)
{
  volatile uint64_t local;

  assert (sizeof (data) == 8 + 2 * 8);

  write_size8twice ();

  while (size)
    {
      switch (size)
	{
/* __s390x__ also defines __s390__ */
#ifdef __s390__
# define ACCESS(var) var = ~var
#else
# define ACCESS(var) local = var
#endif
	case 8:
	  ACCESS (data.u.size8[offset]);
	  break;
	case 4:
	  ACCESS (data.u.size4[offset]);
	  break;
	case 2:
	  ACCESS (data.u.size2[offset]);
	  break;
	case 1:
	  ACCESS (data.u.size1[offset]);
	  break;
#undef ACCESS
	default:
	  assert (0);
	}
      size = 0;
      size = size; /* start_again */
    }
  return 0; /* final_return */
}