Commit | Line | Data |
---|---|---|
08fd625c MC |
1 | /* This test script is part of GDB, the GNU debugger. |
2 | ||
3 | Copyright 1999, 2004, | |
4 | Free Software Foundation, Inc. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 8 | the Free Software Foundation; either version 3 of the License, or |
08fd625c MC |
9 | (at your option) any later version. |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
a9762ec7 | 15 | |
08fd625c | 16 | You should have received a copy of the GNU General Public License |
a9762ec7 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
08fd625c MC |
18 | */ |
19 | ||
c906108c SS |
20 | /* Test long long expression; test printing in general. |
21 | * | |
22 | * /CLO/BUILD_ENV/Exports/cc -g +e -o long_long long_long.c | |
23 | * | |
24 | * or | |
25 | * | |
26 | * cc +e +DA2.0 -g -o long_long long_long.c | |
27 | */ | |
28 | ||
e425eb2b MC |
29 | #include <string.h> |
30 | ||
acd4ad44 AC |
31 | enum { MAX_BYTES = 16 }; |
32 | ||
33 | void | |
34 | pack (unsigned char b[MAX_BYTES], int size, int nr) | |
c906108c | 35 | { |
acd4ad44 AC |
36 | static long long val[] = { 0x123456789abcdefLL, 01234567123456701234567LL, 12345678901234567890ULL}; |
37 | volatile static int e = 1; | |
38 | int i; | |
39 | for (i = 0; i < nr; i++) | |
40 | { | |
41 | int offset; | |
42 | if (*(char *)&e) | |
43 | /* Little endian. */ | |
44 | offset = sizeof (long long) - size; | |
45 | else | |
46 | /* Big endian endian. */ | |
47 | offset = 0; | |
48 | memcpy (b + size * i, (char *) val + sizeof (long long) * i + offset, size); | |
49 | } | |
50 | } | |
c906108c | 51 | |
acd4ad44 AC |
52 | unsigned char b[MAX_BYTES]; |
53 | unsigned char h[MAX_BYTES]; | |
54 | unsigned char w[MAX_BYTES]; | |
55 | unsigned char g[MAX_BYTES]; | |
c906108c | 56 | |
acd4ad44 AC |
57 | unsigned char c[MAX_BYTES]; |
58 | unsigned char s[MAX_BYTES]; | |
59 | unsigned char i[MAX_BYTES]; | |
60 | unsigned char l[MAX_BYTES]; | |
61 | unsigned char ll[MAX_BYTES]; | |
c906108c SS |
62 | |
63 | int known_types() | |
64 | { | |
acd4ad44 AC |
65 | /* A union is used here as, hopefully it has well defined packing |
66 | rules. */ | |
67 | struct { | |
68 | long long bin, oct, dec, hex; | |
69 | } val; | |
70 | memset (&val, 0, sizeof val); | |
71 | ||
72 | /* Known values, filling the full 64 bits. */ | |
73 | val.bin = 0x123456789abcdefLL; /* 64 bits = 16 hex digits */ | |
74 | val.oct = 01234567123456701234567LL; /* = 21+ octal digits */ | |
75 | val.dec = 12345678901234567890ULL; /* = 19+ decimal digits */ | |
76 | ||
77 | /* Stop here and look! */ | |
78 | val.hex = val.bin - val.dec | val.oct; | |
79 | ||
80 | return 0; | |
c906108c SS |
81 | } |
82 | ||
83 | int main() { | |
84 | ||
acd4ad44 AC |
85 | /* Pack Byte, Half, Word and Giant arrays with byte-orderd values. |
86 | That way "(gdb) x" gives the same output on different | |
87 | architectures. */ | |
88 | pack (b, 1, 2); | |
89 | pack (h, 2, 2); | |
90 | pack (w, 4, 2); | |
91 | pack (g, 8, 2); | |
92 | pack (c, sizeof (char), 2); | |
93 | pack (s, sizeof (short), 2); | |
94 | pack (i, sizeof (int), 2); | |
95 | pack (l, sizeof (long), 2); | |
96 | pack (ll, sizeof (long long), 2); | |
c906108c SS |
97 | |
98 | known_types(); | |
99 | ||
100 | return 0; | |
101 | } |