1 /* Target-dependent code for Cygwin running on i386's, for GDB.
3 Copyright (C) 2003, 2007-2012 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"
33 /* Core file support. */
35 /* This vector maps GDB's idea of a register's number into an address
36 in the windows exception context vector. */
38 static int i386_windows_gregset_reg_offset
[] =
60 56, /* FloatSave.RegisterArea[0 * 10] */
61 66, /* FloatSave.RegisterArea[1 * 10] */
62 76, /* FloatSave.RegisterArea[2 * 10] */
63 86, /* FloatSave.RegisterArea[3 * 10] */
64 96, /* FloatSave.RegisterArea[4 * 10] */
65 106, /* FloatSave.RegisterArea[5 * 10] */
66 116, /* FloatSave.RegisterArea[6 * 10] */
67 126, /* FloatSave.RegisterArea[7 * 10] */
69 28, /* FloatSave.ControlWord */
70 32, /* FloatSave.StatusWord */
71 36, /* FloatSave.TagWord */
72 44, /* FloatSave.ErrorSelector */
73 40, /* FloatSave.ErrorOffset */
74 52, /* FloatSave.DataSelector */
75 48, /* FloatSave.DataOffset */
76 44, /* FloatSave.ErrorSelector */
79 364, /* ExtendedRegisters[10*16] */
80 380, /* ExtendedRegisters[11*16] */
81 396, /* ExtendedRegisters[12*16] */
82 412, /* ExtendedRegisters[13*16] */
83 428, /* ExtendedRegisters[14*16] */
84 444, /* ExtendedRegisters[15*16] */
85 460, /* ExtendedRegisters[16*16] */
86 476, /* ExtendedRegisters[17*16] */
89 228 /* ExtendedRegisters[24] */
92 #define I386_WINDOWS_SIZEOF_GREGSET 716
94 /* Return the appropriate register set for the core section identified
95 by SECT_NAME and SECT_SIZE. */
97 static const struct regset
*
98 i386_windows_regset_from_core_section (struct gdbarch
*gdbarch
,
99 const char *sect_name
, size_t sect_size
)
101 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
103 if (strcmp (sect_name
, ".reg") == 0
104 && sect_size
== I386_WINDOWS_SIZEOF_GREGSET
)
106 if (tdep
->gregset
== NULL
)
107 tdep
->gregset
= regset_alloc (gdbarch
, i386_supply_gregset
,
108 i386_collect_gregset
);
109 return tdep
->gregset
;
117 struct gdbarch
*gdbarch
;
118 struct obstack
*obstack
;
123 core_process_module_section (bfd
*abfd
, asection
*sect
, void *obj
)
125 struct cpms_data
*data
= obj
;
126 enum bfd_endian byte_order
= gdbarch_byte_order (data
->gdbarch
);
129 size_t module_name_size
;
134 if (strncmp (sect
->name
, ".module", 7) != 0)
137 buf
= xmalloc (bfd_get_section_size (sect
) + 1);
140 printf_unfiltered ("memory allocation failed for %s\n", sect
->name
);
143 if (!bfd_get_section_contents (abfd
, sect
,
144 buf
, 0, bfd_get_section_size (sect
)))
149 /* A DWORD (data_type) followed by struct windows_core_module_info. */
152 extract_unsigned_integer (buf
+ 4, 4, byte_order
);
155 extract_unsigned_integer (buf
+ 8, 4, byte_order
);
157 module_name
= buf
+ 12;
158 if (module_name
- buf
+ module_name_size
> bfd_get_section_size (sect
))
161 /* The first module is the .exe itself. */
162 if (data
->module_count
!= 0)
163 windows_xfer_shared_library (module_name
, base_addr
,
164 data
->gdbarch
, data
->obstack
);
165 data
->module_count
++;
174 windows_core_xfer_shared_libraries (struct gdbarch
*gdbarch
,
176 ULONGEST offset
, LONGEST len
)
178 struct obstack obstack
;
181 struct cpms_data data
= { gdbarch
, &obstack
, 0 };
183 obstack_init (&obstack
);
184 obstack_grow_str (&obstack
, "<library-list>\n");
185 bfd_map_over_sections (core_bfd
,
186 core_process_module_section
,
188 obstack_grow_str0 (&obstack
, "</library-list>\n");
190 buf
= obstack_finish (&obstack
);
191 len_avail
= strlen (buf
);
192 if (offset
>= len_avail
)
195 if (len
> len_avail
- offset
)
196 len
= len_avail
- offset
;
197 memcpy (readbuf
, buf
+ offset
, len
);
199 obstack_free (&obstack
, NULL
);
203 /* This is how we want PTIDs from core files to be printed. */
206 i386_windows_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
210 if (ptid_get_lwp (ptid
) != 0)
212 snprintf (buf
, sizeof (buf
), "Thread 0x%lx", ptid_get_lwp (ptid
));
216 return normal_pid_to_str (ptid
);
220 i386_cygwin_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
222 return i386_pe_skip_trampoline_code (frame
, pc
, NULL
);
226 i386_cygwin_auto_wide_charset (void)
232 i386_cygwin_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
234 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
236 set_gdbarch_skip_trampoline_code (gdbarch
, i386_cygwin_skip_trampoline_code
);
238 set_gdbarch_skip_main_prologue (gdbarch
, i386_skip_main_prologue
);
240 tdep
->struct_return
= reg_struct_return
;
242 tdep
->gregset_reg_offset
= i386_windows_gregset_reg_offset
;
243 tdep
->gregset_num_regs
= ARRAY_SIZE (i386_windows_gregset_reg_offset
);
244 tdep
->sizeof_gregset
= I386_WINDOWS_SIZEOF_GREGSET
;
246 set_solib_ops (gdbarch
, &solib_target_so_ops
);
248 /* Core file support. */
249 set_gdbarch_regset_from_core_section
250 (gdbarch
, i386_windows_regset_from_core_section
);
251 set_gdbarch_core_xfer_shared_libraries
252 (gdbarch
, windows_core_xfer_shared_libraries
);
253 set_gdbarch_core_pid_to_str (gdbarch
, i386_windows_core_pid_to_str
);
255 set_gdbarch_auto_wide_charset (gdbarch
, i386_cygwin_auto_wide_charset
);
257 /* Canonical paths on this target look like
258 `c:\Program Files\Foo App\mydll.dll', for example. */
259 set_gdbarch_has_dos_based_file_system (gdbarch
, 1);
261 set_gdbarch_iterate_over_objfiles_in_search_order
262 (gdbarch
, windows_iterate_over_objfiles_in_search_order
);
265 static enum gdb_osabi
266 i386_cygwin_osabi_sniffer (bfd
*abfd
)
268 char *target_name
= bfd_get_target (abfd
);
270 /* Interix also uses pei-i386.
271 We need a way to distinguish between the two. */
272 if (strcmp (target_name
, "pei-i386") == 0)
273 return GDB_OSABI_CYGWIN
;
275 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
276 check whether there is a .reg section of proper size. */
277 if (strcmp (target_name
, "elf32-i386") == 0)
279 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
281 && bfd_section_size (abfd
, section
) == I386_WINDOWS_SIZEOF_GREGSET
)
282 return GDB_OSABI_CYGWIN
;
285 return GDB_OSABI_UNKNOWN
;
288 /* Provide a prototype to silence -Wmissing-prototypes. */
289 void _initialize_i386_cygwin_tdep (void);
292 _initialize_i386_cygwin_tdep (void)
294 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_coff_flavour
,
295 i386_cygwin_osabi_sniffer
);
297 /* Cygwin uses elf core dumps. */
298 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_elf_flavour
,
299 i386_cygwin_osabi_sniffer
);
301 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_CYGWIN
,
302 i386_cygwin_init_abi
);