]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/i386-cygwin-tdep.c
bfd_section_* macros
[thirdparty/binutils-gdb.git] / gdb / i386-cygwin-tdep.c
CommitLineData
1762d96d 1/* Target-dependent code for Cygwin running on i386's, for GDB.
acd5c798 2
42a4f53d 3 Copyright (C) 2003-2019 Free Software Foundation, Inc.
1762d96d 4
acd5c798 5 This file is part of GDB.
1762d96d 6
acd5c798
MK
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
acd5c798 10 (at your option) any later version.
1762d96d 11
acd5c798
MK
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.
1762d96d 16
acd5c798 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1762d96d
CV
19
20#include "defs.h"
1762d96d 21#include "osabi.h"
acd5c798 22#include "i386-tdep.h"
31b060a2 23#include "windows-tdep.h"
de584861
PA
24#include "regset.h"
25#include "gdb_obstack.h"
26#include "xml-support.h"
27#include "gdbcore.h"
a5ee0f0c 28#include "inferior.h"
de584861
PA
29
30/* Core file support. */
31
32/* This vector maps GDB's idea of a register's number into an address
dc05df57 33 in the windows exception context vector. */
de584861 34
dc05df57 35static int i386_windows_gregset_reg_offset[] =
de584861
PA
36{
37 176, /* eax */
38 172, /* ecx */
39 168, /* edx */
40 164, /* ebx */
41
42 196, /* esp */
43 180, /* ebp */
44 160, /* esi */
45 156, /* edi */
46
47 184, /* eip */
48 192, /* eflags */
49 188, /* cs */
50 200, /* ss */
51
52 152, /* ds */
53 148, /* es */
54 144, /* fs */
55 140, /* gs */
56
57 56, /* FloatSave.RegisterArea[0 * 10] */
58 66, /* FloatSave.RegisterArea[1 * 10] */
59 76, /* FloatSave.RegisterArea[2 * 10] */
60 86, /* FloatSave.RegisterArea[3 * 10] */
61 96, /* FloatSave.RegisterArea[4 * 10] */
62 106, /* FloatSave.RegisterArea[5 * 10] */
63 116, /* FloatSave.RegisterArea[6 * 10] */
64 126, /* FloatSave.RegisterArea[7 * 10] */
65
66 28, /* FloatSave.ControlWord */
67 32, /* FloatSave.StatusWord */
68 36, /* FloatSave.TagWord */
69 44, /* FloatSave.ErrorSelector */
70 40, /* FloatSave.ErrorOffset */
71 52, /* FloatSave.DataSelector */
72 48, /* FloatSave.DataOffset */
73 44, /* FloatSave.ErrorSelector */
74
75 /* XMM0-7 */
76 364, /* ExtendedRegisters[10*16] */
77 380, /* ExtendedRegisters[11*16] */
78 396, /* ExtendedRegisters[12*16] */
79 412, /* ExtendedRegisters[13*16] */
80 428, /* ExtendedRegisters[14*16] */
81 444, /* ExtendedRegisters[15*16] */
82 460, /* ExtendedRegisters[16*16] */
83 476, /* ExtendedRegisters[17*16] */
84
85 /* MXCSR */
86 228 /* ExtendedRegisters[24] */
87};
88
dc05df57 89#define I386_WINDOWS_SIZEOF_GREGSET 716
de584861 90
de584861
PA
91struct cpms_data
92{
5af949e3 93 struct gdbarch *gdbarch;
de584861
PA
94 struct obstack *obstack;
95 int module_count;
96};
97
98static void
99core_process_module_section (bfd *abfd, asection *sect, void *obj)
100{
9a3c8263 101 struct cpms_data *data = (struct cpms_data *) obj;
e17a4113 102 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
de584861
PA
103
104 char *module_name;
105 size_t module_name_size;
106 CORE_ADDR base_addr;
107
001f13d8 108 gdb_byte *buf = NULL;
de584861 109
61012eef 110 if (!startswith (sect->name, ".module"))
de584861
PA
111 return;
112
fd361982 113 buf = (gdb_byte *) xmalloc (bfd_section_size (sect) + 1);
de584861
PA
114 if (!buf)
115 {
116 printf_unfiltered ("memory allocation failed for %s\n", sect->name);
117 goto out;
118 }
119 if (!bfd_get_section_contents (abfd, sect,
fd361982 120 buf, 0, bfd_section_size (sect)))
de584861
PA
121 goto out;
122
123
124
dc05df57 125 /* A DWORD (data_type) followed by struct windows_core_module_info. */
de584861
PA
126
127 base_addr =
e17a4113 128 extract_unsigned_integer (buf + 4, 4, byte_order);
de584861
PA
129
130 module_name_size =
e17a4113 131 extract_unsigned_integer (buf + 8, 4, byte_order);
de584861 132
fd361982 133 if (12 + module_name_size > bfd_section_size (sect))
de584861 134 goto out;
001f13d8 135 module_name = (char *) buf + 12;
de584861
PA
136
137 /* The first module is the .exe itself. */
138 if (data->module_count != 0)
5af949e3
UW
139 windows_xfer_shared_library (module_name, base_addr,
140 data->gdbarch, data->obstack);
de584861
PA
141 data->module_count++;
142
143out:
144 if (buf)
145 xfree (buf);
146 return;
147}
148
c09f20e4 149static ULONGEST
dc05df57 150windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
de584861 151 gdb_byte *readbuf,
7ec1862d 152 ULONGEST offset, ULONGEST len)
de584861
PA
153{
154 struct obstack obstack;
155 const char *buf;
c09f20e4 156 ULONGEST len_avail;
5af949e3 157 struct cpms_data data = { gdbarch, &obstack, 0 };
de584861
PA
158
159 obstack_init (&obstack);
160 obstack_grow_str (&obstack, "<library-list>\n");
161 bfd_map_over_sections (core_bfd,
162 core_process_module_section,
163 &data);
164 obstack_grow_str0 (&obstack, "</library-list>\n");
165
224c3ddb 166 buf = (const char *) obstack_finish (&obstack);
de584861
PA
167 len_avail = strlen (buf);
168 if (offset >= len_avail)
169 return 0;
170
171 if (len > len_avail - offset)
172 len = len_avail - offset;
173 memcpy (readbuf, buf + offset, len);
174
175 obstack_free (&obstack, NULL);
176 return len;
177}
1762d96d 178
a5ee0f0c
PA
179/* This is how we want PTIDs from core files to be printed. */
180
a068643d 181static std::string
a5ee0f0c
PA
182i386_windows_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
183{
e38504b3 184 if (ptid.lwp () != 0)
a068643d 185 return string_printf ("Thread 0x%lx", ptid.lwp ());
a5ee0f0c
PA
186
187 return normal_pid_to_str (ptid);
188}
189
f7948b5f 190static CORE_ADDR
52f729a7 191i386_cygwin_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
f7948b5f 192{
e17a4113 193 return i386_pe_skip_trampoline_code (frame, pc, NULL);
f7948b5f
JB
194}
195
f870a310
TT
196static const char *
197i386_cygwin_auto_wide_charset (void)
198{
199 return "UTF-16";
200}
201
1762d96d
CV
202static void
203i386_cygwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
204{
205 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
206
64870a42
YQ
207 windows_init_abi (info, gdbarch);
208
f7948b5f
JB
209 set_gdbarch_skip_trampoline_code (gdbarch, i386_cygwin_skip_trampoline_code);
210
4309257c
PM
211 set_gdbarch_skip_main_prologue (gdbarch, i386_skip_main_prologue);
212
1762d96d 213 tdep->struct_return = reg_struct_return;
de584861 214
dc05df57
CF
215 tdep->gregset_reg_offset = i386_windows_gregset_reg_offset;
216 tdep->gregset_num_regs = ARRAY_SIZE (i386_windows_gregset_reg_offset);
217 tdep->sizeof_gregset = I386_WINDOWS_SIZEOF_GREGSET;
de584861 218
490496c3
AA
219 tdep->sizeof_fpregset = 0;
220
de584861 221 /* Core file support. */
de584861 222 set_gdbarch_core_xfer_shared_libraries
dc05df57 223 (gdbarch, windows_core_xfer_shared_libraries);
a5ee0f0c 224 set_gdbarch_core_pid_to_str (gdbarch, i386_windows_core_pid_to_str);
f870a310
TT
225
226 set_gdbarch_auto_wide_charset (gdbarch, i386_cygwin_auto_wide_charset);
1762d96d
CV
227}
228
229static enum gdb_osabi
de584861
PA
230i386_cygwin_osabi_sniffer (bfd *abfd)
231{
1d38e9d1 232 const char *target_name = bfd_get_target (abfd);
1762d96d 233
1762d96d
CV
234 if (strcmp (target_name, "pei-i386") == 0)
235 return GDB_OSABI_CYGWIN;
236
c0993dbe
UW
237 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
238 check whether there is a .reg section of proper size. */
de584861 239 if (strcmp (target_name, "elf32-i386") == 0)
c0993dbe
UW
240 {
241 asection *section = bfd_get_section_by_name (abfd, ".reg");
242 if (section
fd361982 243 && bfd_section_size (section) == I386_WINDOWS_SIZEOF_GREGSET)
c0993dbe
UW
244 return GDB_OSABI_CYGWIN;
245 }
de584861 246
1762d96d
CV
247 return GDB_OSABI_UNKNOWN;
248}
249
250void
251_initialize_i386_cygwin_tdep (void)
252{
253 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
254 i386_cygwin_osabi_sniffer);
255
de584861
PA
256 /* Cygwin uses elf core dumps. */
257 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
258 i386_cygwin_osabi_sniffer);
259
1762d96d
CV
260 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_CYGWIN,
261 i386_cygwin_init_abi);
262}