examine-backward.c revision 1.1.1.6 1 1.1 christos /* This testcase is part of GDB, the GNU debugger.
2 1.1 christos
3 1.1.1.6 christos Copyright 2015-2024 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This program is free software; you can redistribute it and/or modify
6 1.1 christos it under the terms of the GNU General Public License as published by
7 1.1 christos the Free Software Foundation; either version 3 of the License, or
8 1.1 christos (at your option) any later version.
9 1.1 christos
10 1.1 christos This program is distributed in the hope that it will be useful,
11 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 1.1 christos GNU General Public License for more details.
14 1.1 christos
15 1.1 christos You should have received a copy of the GNU General Public License
16 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 1.1 christos
18 1.1 christos /*
19 1.1 christos Define TestStrings, TestStringsH, and TestStringsW to test utf8, utf16,
20 1.1 christos and utf32 strings respectively.
21 1.1 christos To avoid compile errors due to old compiler mode, we don't use string
22 1.1 christos literals. The content of each array is the same as followings:
23 1.1 christos
24 1.1 christos const char TestStrings[] = {
25 1.1 christos "ABCD"
26 1.1 christos "EFGHIJKLMNOPQRSTUVWXYZ\0"
27 1.1 christos "\0"
28 1.1 christos "\0"
29 1.1 christos "\u307B\u3052\u307B\u3052\0"
30 1.1 christos "012345678901234567890123456789\0"
31 1.1 christos "!!!!!!\0"
32 1.1 christos };
33 1.1 christos */
34 1.1 christos
35 1.1.1.6 christos unsigned char TestStringsBase[] = {
36 1.1.1.6 christos /* This is here just to ensure we have a null character before
37 1.1.1.6 christos TestStrings, to avoid showing garbage when we look for strings
38 1.1.1.6 christos backwards from TestStrings. */
39 1.1.1.6 christos 0x0,
40 1.1.1.2 christos
41 1.1 christos 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
42 1.1 christos 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
43 1.1 christos 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
44 1.1 christos 0x59, 0x5a, 0x00, 0x00, 0x00, 0xe3, 0x81, 0xbb,
45 1.1 christos 0xe3, 0x81, 0x92, 0xe3, 0x81, 0xbb, 0xe3, 0x81,
46 1.1 christos 0x92, 0x00, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
47 1.1 christos 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33,
48 1.1 christos 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31,
49 1.1 christos 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
50 1.1 christos 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00,
51 1.1 christos 0x00
52 1.1 christos };
53 1.1 christos
54 1.1.1.6 christos unsigned char *TestStrings = &TestStringsBase[1];
55 1.1.1.6 christos
56 1.1.1.6 christos short TestStringsHBase[] = {
57 1.1.1.6 christos /* This is here just to ensure we have a null character before
58 1.1.1.6 christos TestStringsH, to avoid showing garbage when we look for strings
59 1.1.1.6 christos backwards from TestStringsH. */
60 1.1.1.6 christos 0x0,
61 1.1.1.6 christos
62 1.1 christos 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048,
63 1.1 christos 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 0x0050,
64 1.1 christos 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058,
65 1.1 christos 0x0059, 0x005a, 0x0000, 0x0000, 0x0000, 0x307b, 0x3052, 0x307b,
66 1.1 christos 0x3052, 0x0000, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
67 1.1 christos 0x0036, 0x0037, 0x0038, 0x0039, 0x0030, 0x0031, 0x0032, 0x0033,
68 1.1 christos 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x0030, 0x0031,
69 1.1 christos 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039,
70 1.1 christos 0x0000, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0000,
71 1.1 christos 0x0000
72 1.1 christos };
73 1.1 christos
74 1.1.1.6 christos short *TestStringsH = &TestStringsHBase[1];
75 1.1.1.6 christos
76 1.1.1.6 christos int TestStringsWBase[] = {
77 1.1.1.6 christos /* This is here just to ensure we have a null character before
78 1.1.1.6 christos TestStringsW, to avoid showing garbage when we look for strings
79 1.1.1.6 christos backwards from TestStringsW. */
80 1.1.1.6 christos 0x0,
81 1.1.1.6 christos
82 1.1 christos 0x00000041, 0x00000042, 0x00000043, 0x00000044,
83 1.1 christos 0x00000045, 0x00000046, 0x00000047, 0x00000048,
84 1.1 christos 0x00000049, 0x0000004a, 0x0000004b, 0x0000004c,
85 1.1 christos 0x0000004d, 0x0000004e, 0x0000004f, 0x00000050,
86 1.1 christos 0x00000051, 0x00000052, 0x00000053, 0x00000054,
87 1.1 christos 0x00000055, 0x00000056, 0x00000057, 0x00000058,
88 1.1 christos 0x00000059, 0x0000005a, 0x00000000, 0x00000000,
89 1.1 christos 0x00000000, 0x0000307b, 0x00003052, 0x0000307b,
90 1.1 christos 0x00003052, 0x00000000, 0x00000030, 0x00000031,
91 1.1 christos 0x00000032, 0x00000033, 0x00000034, 0x00000035,
92 1.1 christos 0x00000036, 0x00000037, 0x00000038, 0x00000039,
93 1.1 christos 0x00000030, 0x00000031, 0x00000032, 0x00000033,
94 1.1 christos 0x00000034, 0x00000035, 0x00000036, 0x00000037,
95 1.1 christos 0x00000038, 0x00000039, 0x00000030, 0x00000031,
96 1.1 christos 0x00000032, 0x00000033, 0x00000034, 0x00000035,
97 1.1 christos 0x00000036, 0x00000037, 0x00000038, 0x00000039,
98 1.1 christos 0x00000000, 0x00000021, 0x00000021, 0x00000021,
99 1.1 christos 0x00000021, 0x00000021, 0x00000021, 0x00000000,
100 1.1 christos 0x00000000
101 1.1 christos };
102 1.1 christos
103 1.1.1.6 christos int *TestStringsW = &TestStringsWBase[1];
104 1.1.1.6 christos
105 1.1 christos int
106 1.1 christos main (void)
107 1.1 christos {
108 1.1.1.5 christos /* Clang++ eliminates the variables if nothing references them. */
109 1.1.1.6 christos int dummy = TestStrings[0] + TestStringsH[0] + TestStringsW[0];
110 1.1.1.5 christos
111 1.1 christos /* Backward disassemble test requires at least 20 instructions in
112 1.1 christos this function. Adding a simple bubble sort. */
113 1.1 christos int i, j;
114 1.1 christos int n[] = {3, 1, 4, 1, 5, 9};
115 1.1 christos int len = sizeof (n) / sizeof (n[0]);
116 1.1 christos
117 1.1 christos for (i = 0; i < len - 1; ++i)
118 1.1 christos {
119 1.1 christos for (j = i; j < len; ++j)
120 1.1 christos {
121 1.1 christos if (n[j] < n[i])
122 1.1 christos {
123 1.1 christos int tmp = n[i];
124 1.1 christos n[i] = n[j];
125 1.1 christos n[j] = tmp;
126 1.1 christos }
127 1.1 christos }
128 1.1 christos }
129 1.1 christos return 42;
130 1.1 christos }
131