gdb/i386-cygwin-tdep.c - gdb
Global variables defined
Data types defined
Functions defined
Macros defined
Source code
- #include "defs.h"
- #include "osabi.h"
- #include "i386-tdep.h"
- #include "windows-tdep.h"
- #include "regset.h"
- #include "gdb_obstack.h"
- #include "xml-support.h"
- #include "gdbcore.h"
- #include "inferior.h"
- static int i386_windows_gregset_reg_offset[] =
- {
- 176,
- 172,
- 168,
- 164,
- 196,
- 180,
- 160,
- 156,
- 184,
- 192,
- 188,
- 200,
- 152,
- 148,
- 144,
- 140,
- 56,
- 66,
- 76,
- 86,
- 96,
- 106,
- 116,
- 126,
- 28,
- 32,
- 36,
- 44,
- 40,
- 52,
- 48,
- 44,
-
- 364,
- 380,
- 396,
- 412,
- 428,
- 444,
- 460,
- 476,
-
- 228
- };
- #define I386_WINDOWS_SIZEOF_GREGSET 716
- struct cpms_data
- {
- struct gdbarch *gdbarch;
- struct obstack *obstack;
- int module_count;
- };
- static void
- core_process_module_section (bfd *abfd, asection *sect, void *obj)
- {
- struct cpms_data *data = obj;
- enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
- char *module_name;
- size_t module_name_size;
- CORE_ADDR base_addr;
- gdb_byte *buf = NULL;
- if (strncmp (sect->name, ".module", 7) != 0)
- return;
- buf = xmalloc (bfd_get_section_size (sect) + 1);
- if (!buf)
- {
- printf_unfiltered ("memory allocation failed for %s\n", sect->name);
- goto out;
- }
- if (!bfd_get_section_contents (abfd, sect,
- buf, 0, bfd_get_section_size (sect)))
- goto out;
-
- base_addr =
- extract_unsigned_integer (buf + 4, 4, byte_order);
- module_name_size =
- extract_unsigned_integer (buf + 8, 4, byte_order);
- if (12 + module_name_size > bfd_get_section_size (sect))
- goto out;
- module_name = (char *) buf + 12;
-
- if (data->module_count != 0)
- windows_xfer_shared_library (module_name, base_addr,
- data->gdbarch, data->obstack);
- data->module_count++;
- out:
- if (buf)
- xfree (buf);
- return;
- }
- static ULONGEST
- windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
- gdb_byte *readbuf,
- ULONGEST offset, ULONGEST len)
- {
- struct obstack obstack;
- const char *buf;
- ULONGEST len_avail;
- struct cpms_data data = { gdbarch, &obstack, 0 };
- obstack_init (&obstack);
- obstack_grow_str (&obstack, "<library-list>\n");
- bfd_map_over_sections (core_bfd,
- core_process_module_section,
- &data);
- obstack_grow_str0 (&obstack, "</library-list>\n");
- buf = obstack_finish (&obstack);
- len_avail = strlen (buf);
- if (offset >= len_avail)
- return 0;
- if (len > len_avail - offset)
- len = len_avail - offset;
- memcpy (readbuf, buf + offset, len);
- obstack_free (&obstack, NULL);
- return len;
- }
- static char *
- i386_windows_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
- {
- static char buf[80];
- if (ptid_get_lwp (ptid) != 0)
- {
- snprintf (buf, sizeof (buf), "Thread 0x%lx", ptid_get_lwp (ptid));
- return buf;
- }
- return normal_pid_to_str (ptid);
- }
- static CORE_ADDR
- i386_cygwin_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
- {
- return i386_pe_skip_trampoline_code (frame, pc, NULL);
- }
- static const char *
- i386_cygwin_auto_wide_charset (void)
- {
- return "UTF-16";
- }
- static void
- i386_cygwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
- {
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
- windows_init_abi (info, gdbarch);
- set_gdbarch_skip_trampoline_code (gdbarch, i386_cygwin_skip_trampoline_code);
- set_gdbarch_skip_main_prologue (gdbarch, i386_skip_main_prologue);
- tdep->struct_return = reg_struct_return;
- tdep->gregset_reg_offset = i386_windows_gregset_reg_offset;
- tdep->gregset_num_regs = ARRAY_SIZE (i386_windows_gregset_reg_offset);
- tdep->sizeof_gregset = I386_WINDOWS_SIZEOF_GREGSET;
- tdep->sizeof_fpregset = 0;
-
- set_gdbarch_core_xfer_shared_libraries
- (gdbarch, windows_core_xfer_shared_libraries);
- set_gdbarch_core_pid_to_str (gdbarch, i386_windows_core_pid_to_str);
- set_gdbarch_auto_wide_charset (gdbarch, i386_cygwin_auto_wide_charset);
- }
- static enum gdb_osabi
- i386_cygwin_osabi_sniffer (bfd *abfd)
- {
- char *target_name = bfd_get_target (abfd);
- if (strcmp (target_name, "pei-i386") == 0)
- return GDB_OSABI_CYGWIN;
-
- if (strcmp (target_name, "elf32-i386") == 0)
- {
- asection *section = bfd_get_section_by_name (abfd, ".reg");
- if (section
- && bfd_section_size (abfd, section) == I386_WINDOWS_SIZEOF_GREGSET)
- return GDB_OSABI_CYGWIN;
- }
- return GDB_OSABI_UNKNOWN;
- }
- void _initialize_i386_cygwin_tdep (void);
- void
- _initialize_i386_cygwin_tdep (void)
- {
- gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
- i386_cygwin_osabi_sniffer);
-
- gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
- i386_cygwin_osabi_sniffer);
- gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_CYGWIN,
- i386_cygwin_init_abi);
- }