xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.arch/i386-prologue.c (revision eceb233b9bd0dfebb902ed73b531ae6964fa3f9b)
1 /* Unwinder test program.
2 
3    Copyright (C) 2003-2019 Free Software Foundation, Inc.
4 
5    This file is part of GDB.
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19 
20 #ifdef SYMBOL_PREFIX
21 #define SYMBOL(str)	SYMBOL_PREFIX #str
22 #else
23 #define SYMBOL(str)	#str
24 #endif
25 
26 void gdb1253 (void);
27 void gdb1718 (void);
28 void gdb1338 (void);
29 void jump_at_beginning (void);
30 void standard (void);
31 void stack_align_ecx (void);
32 void stack_align_edx (void);
33 void stack_align_eax (void);
34 
35 int
36 main (void)
37 {
38   standard ();
39   stack_align_ecx ();
40   stack_align_edx ();
41   stack_align_eax ();
42   gdb1253 ();
43   gdb1718 ();
44   gdb1338 ();
45   jump_at_beginning ();
46   return 0;
47 }
48 
49 /* A normal prologue.  */
50 
51 asm(".text\n"
52     "    .align 8\n"
53     SYMBOL (standard) ":\n"
54     "    pushl %ebp\n"
55     "    movl  %esp, %ebp\n"
56     "    pushl %edi\n"
57     "    int   $0x03\n"
58     "    leave\n"
59     "    ret\n");
60 
61 /* Relevant part of the prologue from symtab/1253.  */
62 
63 asm(".text\n"
64     "    .align 8\n"
65     SYMBOL (gdb1253) ":\n"
66     "    pushl %ebp\n"
67     "    xorl  %ecx, %ecx\n"
68     "    movl  %esp, %ebp\n"
69     "    pushl %edi\n"
70     "    int   $0x03\n"
71     "    leave\n"
72     "    ret\n");
73 
74 /* Relevant part of the prologue from backtrace/1718.  */
75 
76 asm(".text\n"
77     "    .align 8\n"
78     SYMBOL (gdb1718) ":\n"
79     "    pushl %ebp\n"
80     "    movl  $0x11111111, %eax\n"
81     "    movl  %esp, %ebp\n"
82     "    pushl %esi\n"
83     "    movl  $0x22222222, %esi\n"
84     "    pushl %ebx\n"
85     "    int   $0x03\n"
86     "    leave\n"
87     "    ret\n");
88 
89 /* Relevant part of the prologue from backtrace/1338.  */
90 
91 asm(".text\n"
92     "    .align 8\n"
93     SYMBOL (gdb1338) ":\n"
94     "    pushl %edi\n"
95     "    pushl %esi\n"
96     "    pushl %ebx\n"
97     "    int   $0x03\n"
98     "    popl  %ebx\n"
99     "    popl  %esi\n"
100     "    popl  %edi\n"
101     "    ret\n");
102 
103 /* The purpose of this function is to verify that, during prologue
104    skip, GDB does not follow a jump at the beginnning of the "real"
105    code.  */
106 
107 asm(".text\n"
108     "    .align 8\n"
109     SYMBOL (jump_at_beginning) ":\n"
110     "    pushl %ebp\n"
111     "    movl  %esp,%ebp\n"
112     "    jmp   .gdbjump\n"
113     "    nop\n"
114     ".gdbjump:\n"
115     "    movl  %ebp,%esp\n"
116     "    popl  %ebp\n"
117     "    ret\n");
118 
119 asm(".text\n"
120     "    .align 8\n"
121     SYMBOL (stack_align_ecx) ":\n"
122     "    leal  4(%esp), %ecx\n"
123     "    andl  $-16, %esp\n"
124     "    pushl -4(%ecx)\n"
125     "    pushl %ebp\n"
126     "    movl  %esp, %ebp\n"
127     "    pushl %edi\n"
128     "    pushl %ecx\n"
129     "    int   $0x03\n"
130     "    popl  %ecx\n"
131     "    popl  %edi\n"
132     "    popl  %ebp\n"
133     "    leal  -4(%ecx), %esp\n"
134     "    ret\n");
135 
136 asm(".text\n"
137     "    .align 8\n"
138     SYMBOL (stack_align_edx) ":\n"
139     "    leal  4(%esp), %edx\n"
140     "    andl  $-16, %esp\n"
141     "    pushl -4(%edx)\n"
142     "    pushl %ebp\n"
143     "    movl  %esp, %ebp\n"
144     "    pushl %edi\n"
145     "    pushl %ecx\n"
146     "    int   $0x03\n"
147     "    popl  %ecx\n"
148     "    popl  %edi\n"
149     "    popl  %ebp\n"
150     "    leal  -4(%edx), %esp\n"
151     "    ret\n");
152 
153 asm(".text\n"
154     "    .align 8\n"
155     SYMBOL (stack_align_eax) ":\n"
156     "    leal  4(%esp), %eax\n"
157     "    andl  $-16, %esp\n"
158     "    pushl -4(%eax)\n"
159     "    pushl %ebp\n"
160     "    movl  %esp, %ebp\n"
161     "    pushl %edi\n"
162     "    pushl %ecx\n"
163     "    int   $0x03\n"
164     "    popl  %ecx\n"
165     "    popl  %edi\n"
166     "    popl  %ebp\n"
167     "    leal  -4(%eax), %esp\n"
168     "    ret\n");
169 
170