GDB (xrefs)
/tmp/gdb-7.10/gdb/i386-cygwin-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for Cygwin running on i386's, for GDB.
2 
3  Copyright (C) 2003-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
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.
11 
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.
16 
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/>. */
19 
20 #include "defs.h"
21 #include "osabi.h"
22 #include "i386-tdep.h"
23 #include "windows-tdep.h"
24 #include "regset.h"
25 #include "gdb_obstack.h"
26 #include "xml-support.h"
27 #include "gdbcore.h"
28 #include "inferior.h"
29 
30 /* Core file support. */
31 
32 /* This vector maps GDB's idea of a register's number into an address
33  in the windows exception context vector. */
34 
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 
89 #define I386_WINDOWS_SIZEOF_GREGSET 716
90 
91 struct cpms_data
92 {
93  struct gdbarch *gdbarch;
94  struct obstack *obstack;
96 };
97 
98 static void
99 core_process_module_section (bfd *abfd, asection *sect, void *obj)
100 {
101  struct cpms_data *data = obj;
102  enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
103 
104  char *module_name;
105  size_t module_name_size;
106  CORE_ADDR base_addr;
107 
108  gdb_byte *buf = NULL;
109 
110  if (!startswith (sect->name, ".module"))
111  return;
112 
113  buf = xmalloc (bfd_get_section_size (sect) + 1);
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,
120  buf, 0, bfd_get_section_size (sect)))
121  goto out;
122 
123 
124 
125  /* A DWORD (data_type) followed by struct windows_core_module_info. */
126 
127  base_addr =
128  extract_unsigned_integer (buf + 4, 4, byte_order);
129 
130  module_name_size =
131  extract_unsigned_integer (buf + 8, 4, byte_order);
132 
133  if (12 + module_name_size > bfd_get_section_size (sect))
134  goto out;
135  module_name = (char *) buf + 12;
136 
137  /* The first module is the .exe itself. */
138  if (data->module_count != 0)
139  windows_xfer_shared_library (module_name, base_addr,
140  data->gdbarch, data->obstack);
141  data->module_count++;
142 
143 out:
144  if (buf)
145  xfree (buf);
146  return;
147 }
148 
149 static ULONGEST
151  gdb_byte *readbuf,
153 {
154  struct obstack obstack;
155  const char *buf;
156  ULONGEST len_avail;
157  struct cpms_data data = { gdbarch, &obstack, 0 };
158 
159  obstack_init (&obstack);
160  obstack_grow_str (&obstack, "<library-list>\n");
161  bfd_map_over_sections (core_bfd,
163  &data);
164  obstack_grow_str0 (&obstack, "</library-list>\n");
165 
166  buf = obstack_finish (&obstack);
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 }
178 
179 /* This is how we want PTIDs from core files to be printed. */
180 
181 static char *
183 {
184  static char buf[80];
185 
186  if (ptid_get_lwp (ptid) != 0)
187  {
188  snprintf (buf, sizeof (buf), "Thread 0x%lx", ptid_get_lwp (ptid));
189  return buf;
190  }
191 
192  return normal_pid_to_str (ptid);
193 }
194 
195 static CORE_ADDR
197 {
198  return i386_pe_skip_trampoline_code (frame, pc, NULL);
199 }
200 
201 static const char *
203 {
204  return "UTF-16";
205 }
206 
207 static void
209 {
210  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
211 
212  windows_init_abi (info, gdbarch);
213 
215 
217 
219 
223 
224  tdep->sizeof_fpregset = 0;
225 
226  /* Core file support. */
230 
232 }
233 
234 static enum gdb_osabi
236 {
237  char *target_name = bfd_get_target (abfd);
238 
239  if (strcmp (target_name, "pei-i386") == 0)
240  return GDB_OSABI_CYGWIN;
241 
242  /* Cygwin uses elf core dumps. Do not claim all ELF executables,
243  check whether there is a .reg section of proper size. */
244  if (strcmp (target_name, "elf32-i386") == 0)
245  {
246  asection *section = bfd_get_section_by_name (abfd, ".reg");
247  if (section
248  && bfd_section_size (abfd, section) == I386_WINDOWS_SIZEOF_GREGSET)
249  return GDB_OSABI_CYGWIN;
250  }
251 
252  return GDB_OSABI_UNKNOWN;
253 }
254 
255 /* Provide a prototype to silence -Wmissing-prototypes. */
256 void _initialize_i386_cygwin_tdep (void);
257 
258 void
260 {
261  gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
263 
264  /* Cygwin uses elf core dumps. */
265  gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
267 
268  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_CYGWIN,
270 }
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
void set_gdbarch_skip_main_prologue(struct gdbarch *gdbarch, gdbarch_skip_main_prologue_ftype skip_main_prologue)
Definition: gdbarch.c:2614
static int i386_windows_gregset_reg_offset[]
static CORE_ADDR i386_cygwin_skip_trampoline_code(struct frame_info *frame, CORE_ADDR pc)
void set_gdbarch_core_pid_to_str(struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype core_pid_to_str)
Definition: gdbarch.c:3542
bfd_vma CORE_ADDR
Definition: common-types.h:41
void xfree(void *)
Definition: common-utils.c:97
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3084
struct gdbarch * gdbarch
void _initialize_i386_cygwin_tdep(void)
void gdbarch_register_osabi_sniffer(enum bfd_architecture arch, enum bfd_flavour flavour, enum gdb_osabi(*sniffer_fn)(bfd *))
Definition: osabi.c:225
size_t sizeof_fpregset
Definition: i386-tdep.h:64
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
Definition: ptid.h:35
static enum gdb_osabi i386_cygwin_osabi_sniffer(bfd *abfd)
void set_gdbarch_core_xfer_shared_libraries(struct gdbarch *gdbarch, gdbarch_core_xfer_shared_libraries_ftype core_xfer_shared_libraries)
Definition: gdbarch.c:3494
static char * i386_windows_core_pid_to_str(struct gdbarch *gdbarch, ptid_t ptid)
static void i386_cygwin_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
enum struct_return struct_return
Definition: arm-tdep.h:197
CORE_ADDR i386_skip_main_prologue(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: i386-tdep.c:1901
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
void set_gdbarch_auto_wide_charset(struct gdbarch *gdbarch, gdbarch_auto_wide_charset_ftype auto_wide_charset)
Definition: gdbarch.c:4441
struct obstack * obstack
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:75
void printf_unfiltered(const char *format,...)
Definition: utils.c:2399
void * xmalloc(YYSIZE_T)
char * normal_pid_to_str(ptid_t ptid)
Definition: target.c:3207
int * gregset_reg_offset
Definition: i386-tdep.h:59
bfd_byte gdb_byte
Definition: common-types.h:38
static ULONGEST windows_core_xfer_shared_libraries(struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
void windows_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: windows-tdep.c:491
int offset
Definition: agent.c:65
size_t sizeof_gregset
Definition: i386-tdep.h:61
#define obstack_grow_str(OBSTACK, STRING)
Definition: gdb_obstack.h:46
static const char * i386_cygwin_auto_wide_charset(void)
const char target_name[]
Definition: version.c:4
unsigned long long ULONGEST
Definition: common-types.h:53
long ptid_get_lwp(ptid_t ptid)
Definition: ptid.c:60
#define obstack_grow_str0(OBSTACK, STRING)
Definition: gdb_obstack.h:48
static void core_process_module_section(bfd *abfd, asection *sect, void *obj)
bfd * core_bfd
Definition: corefile.c:58
int gregset_num_regs
Definition: i386-tdep.h:60
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:148
CORE_ADDR i386_pe_skip_trampoline_code(struct frame_info *frame, CORE_ADDR pc, char *name)
Definition: i386-tdep.c:3848
void windows_xfer_shared_library(const char *so_name, CORE_ADDR load_addr, struct gdbarch *gdbarch, struct obstack *obstack)
Definition: windows-tdep.c:393
#define I386_WINDOWS_SIZEOF_GREGSET
gdb_osabi
Definition: defs.h:540
const ULONGEST const LONGEST len
Definition: target.h:309