Update years in copyright notice for the GDB files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / long_long.c
1 /* This test script is part of GDB, the GNU debugger.
2
3 Copyright 1999-2013 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 long long expression; test printing in general.
20 *
21 * /CLO/BUILD_ENV/Exports/cc -g +e -o long_long long_long.c
22 *
23 * or
24 *
25 * cc +e +DA2.0 -g -o long_long long_long.c
26 */
27
28 #include <string.h>
29
30 enum { MAX_BYTES = 16 };
31
32 void
33 pack (unsigned char b[MAX_BYTES], int size, int nr)
34 {
35 static long long val[] = { 0x123456789abcdefLL, 01234567123456701234567LL, 12345678901234567890ULL};
36 volatile static int e = 1;
37 int i;
38 for (i = 0; i < nr; i++)
39 {
40 int offset;
41 if (*(char *)&e)
42 /* Little endian. */
43 offset = sizeof (long long) - size;
44 else
45 /* Big endian endian. */
46 offset = 0;
47 memcpy (b + size * i, (char *) val + sizeof (long long) * i + offset, size);
48 }
49 }
50
51 unsigned char b[MAX_BYTES];
52 unsigned char h[MAX_BYTES];
53 unsigned char w[MAX_BYTES];
54 unsigned char g[MAX_BYTES];
55
56 unsigned char c[MAX_BYTES];
57 unsigned char s[MAX_BYTES];
58 unsigned char i[MAX_BYTES];
59 unsigned char l[MAX_BYTES];
60 unsigned char ll[MAX_BYTES];
61
62 int known_types()
63 {
64 /* A union is used here as, hopefully it has well defined packing
65 rules. */
66 struct {
67 long long bin, oct, dec, hex;
68 } val;
69 memset (&val, 0, sizeof val);
70
71 /* Known values, filling the full 64 bits. */
72 val.bin = 0x123456789abcdefLL; /* 64 bits = 16 hex digits */
73 val.oct = 01234567123456701234567LL; /* = 21+ octal digits */
74 val.dec = 12345678901234567890ULL; /* = 19+ decimal digits */
75
76 /* Stop here and look! */
77 val.hex = val.bin - val.dec | val.oct;
78
79 return 0;
80 }
81
82 int main() {
83
84 /* Pack Byte, Half, Word and Giant arrays with byte-orderd values.
85 That way "(gdb) x" gives the same output on different
86 architectures. */
87 pack (b, 1, 2);
88 pack (h, 2, 2);
89 pack (w, 4, 2);
90 pack (g, 8, 2);
91 pack (c, sizeof (char), 2);
92 pack (s, sizeof (short), 2);
93 pack (i, sizeof (int), 2);
94 pack (l, sizeof (long), 2);
95 pack (ll, sizeof (long long), 2);
96
97 known_types();
98
99 return 0;
100 }
This page took 0.033853 seconds and 4 git commands to generate.