1 /* Target-dependent code for Cygwin running on i386's, for GDB.
3 Copyright (C) 2003, 2007, 2008, 2009, 2010, 2011
4 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 "gdb_string.h"
24 #include "i386-tdep.h"
25 #include "windows-tdep.h"
27 #include "gdb_obstack.h"
28 #include "xml-support.h"
31 #include "solib-target.h"
34 /* Core file support. */
36 /* This vector maps GDB's idea of a register's number into an address
37 in the windows exception context vector. */
39 static int i386_windows_gregset_reg_offset
[] =
61 56, /* FloatSave.RegisterArea[0 * 10] */
62 66, /* FloatSave.RegisterArea[1 * 10] */
63 76, /* FloatSave.RegisterArea[2 * 10] */
64 86, /* FloatSave.RegisterArea[3 * 10] */
65 96, /* FloatSave.RegisterArea[4 * 10] */
66 106, /* FloatSave.RegisterArea[5 * 10] */
67 116, /* FloatSave.RegisterArea[6 * 10] */
68 126, /* FloatSave.RegisterArea[7 * 10] */
70 28, /* FloatSave.ControlWord */
71 32, /* FloatSave.StatusWord */
72 36, /* FloatSave.TagWord */
73 44, /* FloatSave.ErrorSelector */
74 40, /* FloatSave.ErrorOffset */
75 52, /* FloatSave.DataSelector */
76 48, /* FloatSave.DataOffset */
77 44, /* FloatSave.ErrorSelector */
80 364, /* ExtendedRegisters[10*16] */
81 380, /* ExtendedRegisters[11*16] */
82 396, /* ExtendedRegisters[12*16] */
83 412, /* ExtendedRegisters[13*16] */
84 428, /* ExtendedRegisters[14*16] */
85 444, /* ExtendedRegisters[15*16] */
86 460, /* ExtendedRegisters[16*16] */
87 476, /* ExtendedRegisters[17*16] */
90 228 /* ExtendedRegisters[24] */
93 #define I386_WINDOWS_SIZEOF_GREGSET 716
95 /* Return the appropriate register set for the core section identified
96 by SECT_NAME and SECT_SIZE. */
98 static const struct regset
*
99 i386_windows_regset_from_core_section (struct gdbarch
*gdbarch
,
100 const char *sect_name
, size_t sect_size
)
102 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
104 if (strcmp (sect_name
, ".reg") == 0
105 && sect_size
== I386_WINDOWS_SIZEOF_GREGSET
)
107 if (tdep
->gregset
== NULL
)
108 tdep
->gregset
= regset_alloc (gdbarch
, i386_supply_gregset
,
109 i386_collect_gregset
);
110 return tdep
->gregset
;
118 struct gdbarch
*gdbarch
;
119 struct obstack
*obstack
;
124 core_process_module_section (bfd
*abfd
, asection
*sect
, void *obj
)
126 struct cpms_data
*data
= obj
;
127 enum bfd_endian byte_order
= gdbarch_byte_order (data
->gdbarch
);
130 size_t module_name_size
;
135 if (strncmp (sect
->name
, ".module", 7) != 0)
138 buf
= xmalloc (bfd_get_section_size (sect
) + 1);
141 printf_unfiltered ("memory allocation failed for %s\n", sect
->name
);
144 if (!bfd_get_section_contents (abfd
, sect
,
145 buf
, 0, bfd_get_section_size (sect
)))
150 /* A DWORD (data_type) followed by struct windows_core_module_info. */
153 extract_unsigned_integer (buf
+ 4, 4, byte_order
);
156 extract_unsigned_integer (buf
+ 8, 4, byte_order
);
158 module_name
= buf
+ 12;
159 if (module_name
- buf
+ module_name_size
> bfd_get_section_size (sect
))
162 /* The first module is the .exe itself. */
163 if (data
->module_count
!= 0)
164 windows_xfer_shared_library (module_name
, base_addr
,
165 data
->gdbarch
, data
->obstack
);
166 data
->module_count
++;
175 windows_core_xfer_shared_libraries (struct gdbarch
*gdbarch
,
177 ULONGEST offset
, LONGEST len
)
179 struct obstack obstack
;
182 struct cpms_data data
= { gdbarch
, &obstack
, 0 };
184 obstack_init (&obstack
);
185 obstack_grow_str (&obstack
, "<library-list>\n");
186 bfd_map_over_sections (core_bfd
,
187 core_process_module_section
,
189 obstack_grow_str0 (&obstack
, "</library-list>\n");
191 buf
= obstack_finish (&obstack
);
192 len_avail
= strlen (buf
);
193 if (offset
>= len_avail
)
196 if (len
> len_avail
- offset
)
197 len
= len_avail
- offset
;
198 memcpy (readbuf
, buf
+ offset
, len
);
200 obstack_free (&obstack
, NULL
);
204 /* This is how we want PTIDs from core files to be printed. */
207 i386_windows_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
211 if (ptid_get_lwp (ptid
) != 0)
213 snprintf (buf
, sizeof (buf
), "Thread 0x%lx", ptid_get_lwp (ptid
));
217 return normal_pid_to_str (ptid
);
221 i386_cygwin_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
223 return i386_pe_skip_trampoline_code (frame
, pc
, NULL
);
227 i386_cygwin_auto_wide_charset (void)
233 i386_cygwin_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
235 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
237 set_gdbarch_skip_trampoline_code (gdbarch
, i386_cygwin_skip_trampoline_code
);
239 set_gdbarch_skip_main_prologue (gdbarch
, i386_skip_main_prologue
);
241 tdep
->struct_return
= reg_struct_return
;
243 tdep
->gregset_reg_offset
= i386_windows_gregset_reg_offset
;
244 tdep
->gregset_num_regs
= ARRAY_SIZE (i386_windows_gregset_reg_offset
);
245 tdep
->sizeof_gregset
= I386_WINDOWS_SIZEOF_GREGSET
;
247 set_solib_ops (gdbarch
, &solib_target_so_ops
);
249 /* Core file support. */
250 set_gdbarch_regset_from_core_section
251 (gdbarch
, i386_windows_regset_from_core_section
);
252 set_gdbarch_core_xfer_shared_libraries
253 (gdbarch
, windows_core_xfer_shared_libraries
);
254 set_gdbarch_core_pid_to_str (gdbarch
, i386_windows_core_pid_to_str
);
256 set_gdbarch_auto_wide_charset (gdbarch
, i386_cygwin_auto_wide_charset
);
258 /* Canonical paths on this target look like
259 `c:\Program Files\Foo App\mydll.dll', for example. */
260 set_gdbarch_has_dos_based_file_system (gdbarch
, 1);
263 static enum gdb_osabi
264 i386_cygwin_osabi_sniffer (bfd
*abfd
)
266 char *target_name
= bfd_get_target (abfd
);
268 /* Interix also uses pei-i386.
269 We need a way to distinguish between the two. */
270 if (strcmp (target_name
, "pei-i386") == 0)
271 return GDB_OSABI_CYGWIN
;
273 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
274 check whether there is a .reg section of proper size. */
275 if (strcmp (target_name
, "elf32-i386") == 0)
277 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
279 && bfd_section_size (abfd
, section
) == I386_WINDOWS_SIZEOF_GREGSET
)
280 return GDB_OSABI_CYGWIN
;
283 return GDB_OSABI_UNKNOWN
;
286 /* Provide a prototype to silence -Wmissing-prototypes. */
287 void _initialize_i386_cygwin_tdep (void);
290 _initialize_i386_cygwin_tdep (void)
292 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_coff_flavour
,
293 i386_cygwin_osabi_sniffer
);
295 /* Cygwin uses elf core dumps. */
296 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_elf_flavour
,
297 i386_cygwin_osabi_sniffer
);
299 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_CYGWIN
,
300 i386_cygwin_init_abi
);