1 /* Target-dependent code for Cygwin running on i386's, for GDB.
3 Copyright (C) 2003, 2007, 2008, 2009 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
22 #include "gdb_string.h"
23 #include "i386-tdep.h"
24 #include "windows-tdep.h"
26 #include "gdb_obstack.h"
27 #include "xml-support.h"
30 #include "solib-target.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
93 /* Return the appropriate register set for the core section identified
94 by SECT_NAME and SECT_SIZE. */
96 static const struct regset *
97 i386_windows_regset_from_core_section (struct gdbarch *gdbarch,
98 const char *sect_name, size_t sect_size)
100 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
102 if (strcmp (sect_name, ".reg") == 0
103 && sect_size == I386_WINDOWS_SIZEOF_GREGSET)
105 if (tdep->gregset == NULL)
106 tdep->gregset = regset_alloc (gdbarch, i386_supply_gregset,
107 i386_collect_gregset);
108 return tdep->gregset;
116 struct obstack *obstack;
121 core_process_module_section (bfd *abfd, asection *sect, void *obj)
123 struct cpms_data *data = obj;
126 size_t module_name_size;
131 if (strncmp (sect->name, ".module", 7) != 0)
134 buf = xmalloc (bfd_get_section_size (sect) + 1);
137 printf_unfiltered ("memory allocation failed for %s\n", sect->name);
140 if (!bfd_get_section_contents (abfd, sect,
141 buf, 0, bfd_get_section_size (sect)))
146 /* A DWORD (data_type) followed by struct windows_core_module_info. */
149 extract_unsigned_integer (buf + 4, 4);
152 extract_unsigned_integer (buf + 8, 4);
154 module_name = buf + 12;
155 if (module_name - buf + module_name_size > bfd_get_section_size (sect))
158 /* The first module is the .exe itself. */
159 if (data->module_count != 0)
160 windows_xfer_shared_library (module_name, base_addr, data->obstack);
161 data->module_count++;
170 windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
172 ULONGEST offset, LONGEST len)
174 struct obstack obstack;
177 struct cpms_data data = { &obstack, 0 };
179 obstack_init (&obstack);
180 obstack_grow_str (&obstack, "<library-list>\n");
181 bfd_map_over_sections (core_bfd,
182 core_process_module_section,
184 obstack_grow_str0 (&obstack, "</library-list>\n");
186 buf = obstack_finish (&obstack);
187 len_avail = strlen (buf);
188 if (offset >= len_avail)
191 if (len > len_avail - offset)
192 len = len_avail - offset;
193 memcpy (readbuf, buf + offset, len);
195 obstack_free (&obstack, NULL);
200 i386_cygwin_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
202 return i386_pe_skip_trampoline_code (pc, NULL);
206 i386_cygwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
208 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
210 set_gdbarch_skip_trampoline_code (gdbarch, i386_cygwin_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 set_solib_ops (gdbarch, &solib_target_so_ops);
222 /* Core file support. */
223 set_gdbarch_regset_from_core_section
224 (gdbarch, i386_windows_regset_from_core_section);
225 set_gdbarch_core_xfer_shared_libraries
226 (gdbarch, windows_core_xfer_shared_libraries);
229 static enum gdb_osabi
230 i386_cygwin_osabi_sniffer (bfd *abfd)
232 char *target_name = bfd_get_target (abfd);
234 /* Interix also uses pei-i386.
235 We need a way to distinguish between the two. */
236 if (strcmp (target_name, "pei-i386") == 0)
237 return GDB_OSABI_CYGWIN;
239 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
240 check whether there is a .reg section of proper size. */
241 if (strcmp (target_name, "elf32-i386") == 0)
243 asection *section = bfd_get_section_by_name (abfd, ".reg");
245 && bfd_section_size (abfd, section) == I386_WINDOWS_SIZEOF_GREGSET)
246 return GDB_OSABI_CYGWIN;
249 return GDB_OSABI_UNKNOWN;
252 /* Provide a prototype to silence -Wmissing-prototypes. */
253 void _initialize_i386_cygwin_tdep (void);
256 _initialize_i386_cygwin_tdep (void)
258 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
259 i386_cygwin_osabi_sniffer);
261 /* Cygwin uses elf core dumps. */
262 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
263 i386_cygwin_osabi_sniffer);
265 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_CYGWIN,
266 i386_cygwin_init_abi);