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/>. */
23 #include "i386-tdep.h"
24 #include "windows-tdep.h"
26 #include "gdbsupport/gdb_obstack.h"
27 #include "xml-support.h"
30 #include "frame-unwind.h"
32 /* Core file support. */
34 /* This vector maps GDB's idea of a register's number into an address
35 in the windows exception context vector. */
37 static int i386_windows_gregset_reg_offset
[] =
59 56, /* FloatSave.RegisterArea[0 * 10] */
60 66, /* FloatSave.RegisterArea[1 * 10] */
61 76, /* FloatSave.RegisterArea[2 * 10] */
62 86, /* FloatSave.RegisterArea[3 * 10] */
63 96, /* FloatSave.RegisterArea[4 * 10] */
64 106, /* FloatSave.RegisterArea[5 * 10] */
65 116, /* FloatSave.RegisterArea[6 * 10] */
66 126, /* FloatSave.RegisterArea[7 * 10] */
68 28, /* FloatSave.ControlWord */
69 32, /* FloatSave.StatusWord */
70 36, /* FloatSave.TagWord */
71 44, /* FloatSave.ErrorSelector */
72 40, /* FloatSave.ErrorOffset */
73 52, /* FloatSave.DataSelector */
74 48, /* FloatSave.DataOffset */
75 44, /* FloatSave.ErrorSelector */
78 364, /* ExtendedRegisters[10*16] */
79 380, /* ExtendedRegisters[11*16] */
80 396, /* ExtendedRegisters[12*16] */
81 412, /* ExtendedRegisters[13*16] */
82 428, /* ExtendedRegisters[14*16] */
83 444, /* ExtendedRegisters[15*16] */
84 460, /* ExtendedRegisters[16*16] */
85 476, /* ExtendedRegisters[17*16] */
88 228 /* ExtendedRegisters[24] */
91 #define I386_WINDOWS_SIZEOF_GREGSET 716
94 i386_windows_skip_trampoline_code (const frame_info_ptr
&frame
, CORE_ADDR pc
)
96 return i386_pe_skip_trampoline_code (frame
, pc
, NULL
);
100 i386_windows_auto_wide_charset (void)
105 /* Implement the "push_dummy_call" gdbarch method. */
108 i386_windows_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
109 struct regcache
*regcache
, CORE_ADDR bp_addr
,
110 int nargs
, struct value
**args
, CORE_ADDR sp
,
111 function_call_return_method return_method
,
112 CORE_ADDR struct_addr
)
114 /* For non-static member functions of 32bit Windows programs, the thiscall
115 calling convention is used, so the 'this' pointer is passed in ECX. */
116 bool thiscall
= false;
118 struct type
*type
= check_typedef (function
->type ());
119 if (type
->code () == TYPE_CODE_PTR
)
120 type
= check_typedef (type
->target_type ());
122 /* read_subroutine_type sets for non-static member functions the
123 artificial flag of the first parameter ('this' pointer). */
124 if (type
->code () == TYPE_CODE_METHOD
125 && type
->num_fields () > 0
126 && type
->field (0).is_artificial ()
127 && type
->field (0).type ()->code () == TYPE_CODE_PTR
)
130 return i386_thiscall_push_dummy_call (gdbarch
, function
, regcache
, bp_addr
,
131 nargs
, args
, sp
, return_method
,
132 struct_addr
, thiscall
);
135 /* Common parts for gdbarch initialization for Windows and Cygwin on i386. */
138 i386_windows_init_abi_common (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
140 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
142 set_gdbarch_skip_trampoline_code (gdbarch
, i386_windows_skip_trampoline_code
);
144 set_gdbarch_skip_main_prologue (gdbarch
, i386_skip_main_prologue
);
146 tdep
->struct_return
= reg_struct_return
;
148 tdep
->gregset_reg_offset
= i386_windows_gregset_reg_offset
;
149 tdep
->gregset_num_regs
= ARRAY_SIZE (i386_windows_gregset_reg_offset
);
150 tdep
->sizeof_gregset
= I386_WINDOWS_SIZEOF_GREGSET
;
152 tdep
->sizeof_fpregset
= 0;
154 /* Core file support. */
155 set_gdbarch_core_xfer_shared_libraries
156 (gdbarch
, windows_core_xfer_shared_libraries
);
157 set_gdbarch_core_pid_to_str (gdbarch
, windows_core_pid_to_str
);
159 set_gdbarch_auto_wide_charset (gdbarch
, i386_windows_auto_wide_charset
);
162 /* gdbarch initialization for Windows on i386. */
165 i386_windows_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
167 i386_windows_init_abi_common (info
, gdbarch
);
168 windows_init_abi (info
, gdbarch
);
170 set_gdbarch_push_dummy_call (gdbarch
, i386_windows_push_dummy_call
);
173 /* Sigwrapper unwinder instruction patterns for i386. */
175 static const gdb_byte i386_sigbe_bytes
[] = {
176 0xb8, 0xfc, 0xff, 0xff, 0xff, /* movl $-4,%eax */
177 0x0f, 0xc1, 0x83, /* xadd %eax,$tls::stackptr(%ebx) */
178 /* 4 bytes for tls::stackptr operand. */
181 static const gdb::array_view
<const gdb_byte
> i386_sig_patterns
[] {
182 { i386_sigbe_bytes
},
185 /* The sigwrapper unwinder on i386. */
187 static const cygwin_sigwrapper_frame_unwind
188 i386_cygwin_sigwrapper_frame_unwind (i386_sig_patterns
);
190 /* gdbarch initialization for Cygwin on i386. */
193 i386_cygwin_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
195 frame_unwind_append_unwinder (gdbarch
, &i386_cygwin_sigwrapper_frame_unwind
);
197 i386_windows_init_abi_common (info
, gdbarch
);
198 cygwin_init_abi (info
, gdbarch
);
202 i386_windows_osabi_sniffer (bfd
*abfd
)
204 const char *target_name
= bfd_get_target (abfd
);
206 if (!streq (target_name
, "pei-i386"))
207 return GDB_OSABI_UNKNOWN
;
209 if (is_linked_with_cygwin_dll (abfd
))
210 return GDB_OSABI_CYGWIN
;
212 return GDB_OSABI_WINDOWS
;
215 static enum gdb_osabi
216 i386_cygwin_core_osabi_sniffer (bfd
*abfd
)
218 const char *target_name
= bfd_get_target (abfd
);
220 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
221 check whether there is a .reg section of proper size. */
222 if (strcmp (target_name
, "elf32-i386") == 0)
224 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
225 if (section
!= nullptr
226 && bfd_section_size (section
) == I386_WINDOWS_SIZEOF_GREGSET
)
227 return GDB_OSABI_CYGWIN
;
230 return GDB_OSABI_UNKNOWN
;
233 void _initialize_i386_windows_tdep ();
235 _initialize_i386_windows_tdep ()
237 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_coff_flavour
,
238 i386_windows_osabi_sniffer
);
240 /* Cygwin uses elf core dumps. */
241 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_elf_flavour
,
242 i386_cygwin_core_osabi_sniffer
);
244 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_WINDOWS
,
245 i386_windows_init_abi
);
246 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_CYGWIN
,
247 i386_cygwin_init_abi
);