1 /* Target-dependent code for Windows (including Cygwin) running on i386's,
4 Copyright (C) 2003-2024 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "i386-tdep.h"
23 #include "windows-tdep.h"
25 #include "gdbsupport/gdb_obstack.h"
26 #include "xml-support.h"
29 #include "frame-unwind.h"
31 /* Core file support. */
33 /* This vector maps GDB's idea of a register's number into an address
34 in the windows exception context vector. */
36 static int i386_windows_gregset_reg_offset
[] =
58 56, /* FloatSave.RegisterArea[0 * 10] */
59 66, /* FloatSave.RegisterArea[1 * 10] */
60 76, /* FloatSave.RegisterArea[2 * 10] */
61 86, /* FloatSave.RegisterArea[3 * 10] */
62 96, /* FloatSave.RegisterArea[4 * 10] */
63 106, /* FloatSave.RegisterArea[5 * 10] */
64 116, /* FloatSave.RegisterArea[6 * 10] */
65 126, /* FloatSave.RegisterArea[7 * 10] */
67 28, /* FloatSave.ControlWord */
68 32, /* FloatSave.StatusWord */
69 36, /* FloatSave.TagWord */
70 44, /* FloatSave.ErrorSelector */
71 40, /* FloatSave.ErrorOffset */
72 52, /* FloatSave.DataSelector */
73 48, /* FloatSave.DataOffset */
74 44, /* FloatSave.ErrorSelector */
77 364, /* ExtendedRegisters[10*16] */
78 380, /* ExtendedRegisters[11*16] */
79 396, /* ExtendedRegisters[12*16] */
80 412, /* ExtendedRegisters[13*16] */
81 428, /* ExtendedRegisters[14*16] */
82 444, /* ExtendedRegisters[15*16] */
83 460, /* ExtendedRegisters[16*16] */
84 476, /* ExtendedRegisters[17*16] */
87 228 /* ExtendedRegisters[24] */
90 #define I386_WINDOWS_SIZEOF_GREGSET 716
93 i386_windows_skip_trampoline_code (const frame_info_ptr
&frame
, CORE_ADDR pc
)
95 return i386_pe_skip_trampoline_code (frame
, pc
, NULL
);
99 i386_windows_auto_wide_charset (void)
104 /* Implement the "push_dummy_call" gdbarch method. */
107 i386_windows_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
108 struct regcache
*regcache
, CORE_ADDR bp_addr
,
109 int nargs
, struct value
**args
, CORE_ADDR sp
,
110 function_call_return_method return_method
,
111 CORE_ADDR struct_addr
)
113 /* For non-static member functions of 32bit Windows programs, the thiscall
114 calling convention is used, so the 'this' pointer is passed in ECX. */
115 bool thiscall
= false;
117 struct type
*type
= check_typedef (function
->type ());
118 if (type
->code () == TYPE_CODE_PTR
)
119 type
= check_typedef (type
->target_type ());
121 /* read_subroutine_type sets for non-static member functions the
122 artificial flag of the first parameter ('this' pointer). */
123 if (type
->code () == TYPE_CODE_METHOD
124 && type
->num_fields () > 0
125 && type
->field (0).is_artificial ()
126 && type
->field (0).type ()->code () == TYPE_CODE_PTR
)
129 return i386_thiscall_push_dummy_call (gdbarch
, function
, regcache
, bp_addr
,
130 nargs
, args
, sp
, return_method
,
131 struct_addr
, thiscall
);
134 /* Common parts for gdbarch initialization for Windows and Cygwin on i386. */
137 i386_windows_init_abi_common (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
139 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
141 set_gdbarch_skip_trampoline_code (gdbarch
, i386_windows_skip_trampoline_code
);
143 set_gdbarch_skip_main_prologue (gdbarch
, i386_skip_main_prologue
);
145 tdep
->struct_return
= reg_struct_return
;
147 tdep
->gregset_reg_offset
= i386_windows_gregset_reg_offset
;
148 tdep
->gregset_num_regs
= ARRAY_SIZE (i386_windows_gregset_reg_offset
);
149 tdep
->sizeof_gregset
= I386_WINDOWS_SIZEOF_GREGSET
;
151 tdep
->sizeof_fpregset
= 0;
153 /* Core file support. */
154 set_gdbarch_core_xfer_shared_libraries
155 (gdbarch
, windows_core_xfer_shared_libraries
);
156 set_gdbarch_core_pid_to_str (gdbarch
, windows_core_pid_to_str
);
158 set_gdbarch_auto_wide_charset (gdbarch
, i386_windows_auto_wide_charset
);
161 /* gdbarch initialization for Windows on i386. */
164 i386_windows_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
166 i386_windows_init_abi_common (info
, gdbarch
);
167 windows_init_abi (info
, gdbarch
);
169 set_gdbarch_push_dummy_call (gdbarch
, i386_windows_push_dummy_call
);
172 /* Sigwrapper unwinder instruction patterns for i386. */
174 static const gdb_byte i386_sigbe_bytes
[] = {
175 0xb8, 0xfc, 0xff, 0xff, 0xff, /* movl $-4,%eax */
176 0x0f, 0xc1, 0x83, /* xadd %eax,$tls::stackptr(%ebx) */
177 /* 4 bytes for tls::stackptr operand. */
180 static const gdb::array_view
<const gdb_byte
> i386_sig_patterns
[] {
181 { i386_sigbe_bytes
},
184 /* The sigwrapper unwinder on i386. */
186 static const cygwin_sigwrapper_frame_unwind
187 i386_cygwin_sigwrapper_frame_unwind (i386_sig_patterns
);
189 /* gdbarch initialization for Cygwin on i386. */
192 i386_cygwin_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
194 frame_unwind_append_unwinder (gdbarch
, &i386_cygwin_sigwrapper_frame_unwind
);
196 i386_windows_init_abi_common (info
, gdbarch
);
197 cygwin_init_abi (info
, gdbarch
);
201 i386_windows_osabi_sniffer (bfd
*abfd
)
203 const char *target_name
= bfd_get_target (abfd
);
205 if (!streq (target_name
, "pei-i386"))
206 return GDB_OSABI_UNKNOWN
;
208 if (is_linked_with_cygwin_dll (abfd
))
209 return GDB_OSABI_CYGWIN
;
211 return GDB_OSABI_WINDOWS
;
214 static enum gdb_osabi
215 i386_cygwin_core_osabi_sniffer (bfd
*abfd
)
217 const char *target_name
= bfd_get_target (abfd
);
219 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
220 check whether there is a .reg section of proper size. */
221 if (strcmp (target_name
, "elf32-i386") == 0)
223 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
224 if (section
!= nullptr
225 && bfd_section_size (section
) == I386_WINDOWS_SIZEOF_GREGSET
)
226 return GDB_OSABI_CYGWIN
;
229 return GDB_OSABI_UNKNOWN
;
232 void _initialize_i386_windows_tdep ();
234 _initialize_i386_windows_tdep ()
236 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_coff_flavour
,
237 i386_windows_osabi_sniffer
);
239 /* Cygwin uses elf core dumps. */
240 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_elf_flavour
,
241 i386_cygwin_core_osabi_sniffer
);
243 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_WINDOWS
,
244 i386_windows_init_abi
);
245 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_CYGWIN
,
246 i386_cygwin_init_abi
);