1 /* Target-dependent code for Windows (including Cygwin) running on i386's,
4 Copyright (C) 2003-2020 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 "gdb_obstack.h"
27 #include "xml-support.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
94 struct gdbarch
*gdbarch
;
95 struct obstack
*obstack
;
100 core_process_module_section (bfd
*abfd
, asection
*sect
, void *obj
)
102 struct cpms_data
*data
= (struct cpms_data
*) obj
;
103 enum bfd_endian byte_order
= gdbarch_byte_order (data
->gdbarch
);
106 size_t module_name_size
;
109 gdb_byte
*buf
= NULL
;
111 if (!startswith (sect
->name
, ".module"))
114 buf
= (gdb_byte
*) xmalloc (bfd_section_size (sect
) + 1);
117 printf_unfiltered ("memory allocation failed for %s\n", sect
->name
);
120 if (!bfd_get_section_contents (abfd
, sect
,
121 buf
, 0, bfd_section_size (sect
)))
126 /* A DWORD (data_type) followed by struct windows_core_module_info. */
129 extract_unsigned_integer (buf
+ 4, 4, byte_order
);
132 extract_unsigned_integer (buf
+ 8, 4, byte_order
);
134 if (12 + module_name_size
> bfd_section_size (sect
))
136 module_name
= (char *) buf
+ 12;
138 /* The first module is the .exe itself. */
139 if (data
->module_count
!= 0)
140 windows_xfer_shared_library (module_name
, base_addr
,
141 NULL
, data
->gdbarch
, data
->obstack
);
142 data
->module_count
++;
151 windows_core_xfer_shared_libraries (struct gdbarch
*gdbarch
,
153 ULONGEST offset
, ULONGEST len
)
155 struct obstack obstack
;
158 struct cpms_data data
= { gdbarch
, &obstack
, 0 };
160 obstack_init (&obstack
);
161 obstack_grow_str (&obstack
, "<library-list>\n");
162 bfd_map_over_sections (core_bfd
,
163 core_process_module_section
,
165 obstack_grow_str0 (&obstack
, "</library-list>\n");
167 buf
= (const char *) obstack_finish (&obstack
);
168 len_avail
= strlen (buf
);
169 if (offset
>= len_avail
)
172 if (len
> len_avail
- offset
)
173 len
= len_avail
- offset
;
174 memcpy (readbuf
, buf
+ offset
, len
);
176 obstack_free (&obstack
, NULL
);
180 /* This is how we want PTIDs from core files to be printed. */
183 i386_windows_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
185 if (ptid
.lwp () != 0)
186 return string_printf ("Thread 0x%lx", ptid
.lwp ());
188 return normal_pid_to_str (ptid
);
192 i386_windows_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
194 return i386_pe_skip_trampoline_code (frame
, pc
, NULL
);
198 i386_windows_auto_wide_charset (void)
204 i386_windows_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
206 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
208 windows_init_abi (info
, gdbarch
);
210 set_gdbarch_skip_trampoline_code (gdbarch
, i386_windows_skip_trampoline_code
);
212 set_gdbarch_skip_main_prologue (gdbarch
, i386_skip_main_prologue
);
214 tdep
->struct_return
= reg_struct_return
;
216 tdep
->gregset_reg_offset
= i386_windows_gregset_reg_offset
;
217 tdep
->gregset_num_regs
= ARRAY_SIZE (i386_windows_gregset_reg_offset
);
218 tdep
->sizeof_gregset
= I386_WINDOWS_SIZEOF_GREGSET
;
220 tdep
->sizeof_fpregset
= 0;
222 /* Core file support. */
223 set_gdbarch_core_xfer_shared_libraries
224 (gdbarch
, windows_core_xfer_shared_libraries
);
225 set_gdbarch_core_pid_to_str (gdbarch
, i386_windows_core_pid_to_str
);
227 set_gdbarch_auto_wide_charset (gdbarch
, i386_windows_auto_wide_charset
);
231 i386_windows_osabi_sniffer (bfd
*abfd
)
233 const char *target_name
= bfd_get_target (abfd
);
235 if (!streq (target_name
, "pei-i386"))
236 return GDB_OSABI_UNKNOWN
;
238 if (is_linked_with_cygwin_dll (abfd
))
239 return GDB_OSABI_CYGWIN
;
241 return GDB_OSABI_WINDOWS
;
244 static enum gdb_osabi
245 i386_cygwin_core_osabi_sniffer (bfd
*abfd
)
247 const char *target_name
= bfd_get_target (abfd
);
249 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
250 check whether there is a .reg section of proper size. */
251 if (strcmp (target_name
, "elf32-i386") == 0)
253 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
254 if (section
!= nullptr
255 && bfd_section_size (section
) == I386_WINDOWS_SIZEOF_GREGSET
)
256 return GDB_OSABI_CYGWIN
;
259 return GDB_OSABI_UNKNOWN
;
262 void _initialize_i386_windows_tdep ();
264 _initialize_i386_windows_tdep ()
266 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_coff_flavour
,
267 i386_windows_osabi_sniffer
);
269 /* Cygwin uses elf core dumps. */
270 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_elf_flavour
,
271 i386_cygwin_core_osabi_sniffer
);
273 /* The Windows and Cygwin OS ABIs are currently equivalent. */
274 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_WINDOWS
,
275 i386_windows_init_abi
);
276 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_CYGWIN
,
277 i386_windows_init_abi
);