Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / long_long.c
CommitLineData
08fd625c
MC
1/* This test script is part of GDB, the GNU debugger.
2
88b9d363 3 Copyright 1999-2022 Free Software Foundation, Inc.
08fd625c
MC
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
a9762ec7 7 the Free Software Foundation; either version 3 of the License, or
08fd625c
MC
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.
a9762ec7 14
08fd625c 15 You should have received a copy of the GNU General Public License
47d48711 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
08fd625c 17
c906108c
SS
18/* Test long long expression; test printing in general.
19 *
20 * /CLO/BUILD_ENV/Exports/cc -g +e -o long_long long_long.c
21 *
22 * or
23 *
24 * cc +e +DA2.0 -g -o long_long long_long.c
25 */
26
e425eb2b
MC
27#include <string.h>
28
acd4ad44
AC
29enum { MAX_BYTES = 16 };
30
31void
32pack (unsigned char b[MAX_BYTES], int size, int nr)
c906108c 33{
acd4ad44
AC
34 static long long val[] = { 0x123456789abcdefLL, 01234567123456701234567LL, 12345678901234567890ULL};
35 volatile static int e = 1;
36 int i;
37 for (i = 0; i < nr; i++)
38 {
39 int offset;
40 if (*(char *)&e)
41 /* Little endian. */
42 offset = sizeof (long long) - size;
43 else
44 /* Big endian endian. */
45 offset = 0;
46 memcpy (b + size * i, (char *) val + sizeof (long long) * i + offset, size);
47 }
48}
c906108c 49
acd4ad44
AC
50unsigned char b[MAX_BYTES];
51unsigned char h[MAX_BYTES];
52unsigned char w[MAX_BYTES];
53unsigned char g[MAX_BYTES];
c906108c 54
acd4ad44
AC
55unsigned char c[MAX_BYTES];
56unsigned char s[MAX_BYTES];
57unsigned char i[MAX_BYTES];
58unsigned char l[MAX_BYTES];
59unsigned char ll[MAX_BYTES];
c906108c
SS
60
61int known_types()
62{
acd4ad44
AC
63 /* A union is used here as, hopefully it has well defined packing
64 rules. */
65 struct {
66 long long bin, oct, dec, hex;
67 } val;
68 memset (&val, 0, sizeof val);
69
70 /* Known values, filling the full 64 bits. */
71 val.bin = 0x123456789abcdefLL; /* 64 bits = 16 hex digits */
72 val.oct = 01234567123456701234567LL; /* = 21+ octal digits */
73 val.dec = 12345678901234567890ULL; /* = 19+ decimal digits */
74
75 /* Stop here and look! */
76 val.hex = val.bin - val.dec | val.oct;
77
78 return 0;
c906108c
SS
79}
80
81int main() {
82
30baf67b 83 /* Pack Byte, Half, Word and Giant arrays with byte-ordered values.
acd4ad44
AC
84 That way "(gdb) x" gives the same output on different
85 architectures. */
86 pack (b, 1, 2);
87 pack (h, 2, 2);
88 pack (w, 4, 2);
89 pack (g, 8, 2);
90 pack (c, sizeof (char), 2);
91 pack (s, sizeof (short), 2);
92 pack (i, sizeof (int), 2);
93 pack (l, sizeof (long), 2);
94 pack (ll, sizeof (long long), 2);
c906108c
SS
95
96 known_types();
97
98 return 0;
99}
This page took 3.489633 seconds and 4 git commands to generate.