X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fi386-cygwin-tdep.c;h=e3091a031c08c7aadbff498efea13b6d168d2c4b;hb=f42bf748e417cf9120fc57d144b6eaaf3adda247;hp=0185a0a36b3899b9b05352badd7dd4fa8a285718;hpb=de584861439dac10f422843cf2bf85d0ff4ad628;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/i386-cygwin-tdep.c b/gdb/i386-cygwin-tdep.c index 0185a0a36b..e3091a031c 100644 --- a/gdb/i386-cygwin-tdep.c +++ b/gdb/i386-cygwin-tdep.c @@ -1,6 +1,6 @@ /* Target-dependent code for Cygwin running on i386's, for GDB. - Copyright (C) 2003, 2007 Free Software Foundation, Inc. + Copyright (C) 2003-2016 Free Software Foundation, Inc. This file is part of GDB. @@ -19,19 +19,20 @@ #include "defs.h" #include "osabi.h" -#include "gdb_string.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" /* Core file support. */ /* This vector maps GDB's idea of a register's number into an address - in the win32 exception context vector. */ + in the windows exception context vector. */ -static int i386_win32_gregset_reg_offset[] = +static int i386_windows_gregset_reg_offset[] = { 176, /* eax */ 172, /* ecx */ @@ -85,49 +86,11 @@ static int i386_win32_gregset_reg_offset[] = 228 /* ExtendedRegisters[24] */ }; -#define I386_WIN32_SIZEOF_GREGSET 716 - -/* Return the appropriate register set for the core section identified - by SECT_NAME and SECT_SIZE. */ - -static const struct regset * -i386_win32_regset_from_core_section (struct gdbarch *gdbarch, - const char *sect_name, size_t sect_size) -{ - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - - if (strcmp (sect_name, ".reg") == 0 - && sect_size == I386_WIN32_SIZEOF_GREGSET) - { - if (tdep->gregset == NULL) - tdep->gregset = regset_alloc (gdbarch, i386_supply_gregset, - i386_collect_gregset); - return tdep->gregset; - } - - return NULL; -} - -static void -win32_xfer_shared_library (const char* so_name, CORE_ADDR load_addr, - struct obstack *obstack) -{ - char *p; - obstack_grow_str (obstack, ""); -} +#define I386_WINDOWS_SIZEOF_GREGSET 716 struct cpms_data { + struct gdbarch *gdbarch; struct obstack *obstack; int module_count; }; @@ -135,18 +98,19 @@ struct cpms_data static void core_process_module_section (bfd *abfd, asection *sect, void *obj) { - struct cpms_data *data = obj; + struct cpms_data *data = (struct cpms_data *) obj; + enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch); char *module_name; size_t module_name_size; CORE_ADDR base_addr; - char *buf = NULL; + gdb_byte *buf = NULL; - if (strncmp (sect->name, ".module", 7) != 0) + if (!startswith (sect->name, ".module")) return; - buf = xmalloc (bfd_get_section_size (sect) + 1); + buf = (gdb_byte *) xmalloc (bfd_get_section_size (sect) + 1); if (!buf) { printf_unfiltered ("memory allocation failed for %s\n", sect->name); @@ -158,21 +122,22 @@ core_process_module_section (bfd *abfd, asection *sect, void *obj) - /* A DWORD (data_type) followed by struct win32_core_module_info. */ + /* A DWORD (data_type) followed by struct windows_core_module_info. */ base_addr = - extract_unsigned_integer (buf + 4, 4); + extract_unsigned_integer (buf + 4, 4, byte_order); module_name_size = - extract_unsigned_integer (buf + 8, 4); + extract_unsigned_integer (buf + 8, 4, byte_order); - module_name = buf + 12; - if (module_name - buf + module_name_size > bfd_get_section_size (sect)) + if (12 + module_name_size > bfd_get_section_size (sect)) goto out; + module_name = (char *) buf + 12; /* The first module is the .exe itself. */ if (data->module_count != 0) - win32_xfer_shared_library (module_name, base_addr, data->obstack); + windows_xfer_shared_library (module_name, base_addr, + data->gdbarch, data->obstack); data->module_count++; out: @@ -181,15 +146,15 @@ out: return; } -static LONGEST -win32_core_xfer_shared_libraries (struct gdbarch *gdbarch, +static ULONGEST +windows_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb_byte *readbuf, - ULONGEST offset, LONGEST len) + ULONGEST offset, ULONGEST len) { struct obstack obstack; const char *buf; - LONGEST len_avail; - struct cpms_data data = { &obstack, 0 }; + ULONGEST len_avail; + struct cpms_data data = { gdbarch, &obstack, 0 }; obstack_init (&obstack); obstack_grow_str (&obstack, "\n"); @@ -198,7 +163,7 @@ win32_core_xfer_shared_libraries (struct gdbarch *gdbarch, &data); obstack_grow_str0 (&obstack, "\n"); - buf = obstack_finish (&obstack); + buf = (const char *) obstack_finish (&obstack); len_avail = strlen (buf); if (offset >= len_avail) return 0; @@ -211,10 +176,32 @@ win32_core_xfer_shared_libraries (struct gdbarch *gdbarch, return len; } +/* This is how we want PTIDs from core files to be printed. */ + +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 (pc, NULL); + return i386_pe_skip_trampoline_code (frame, pc, NULL); +} + +static const char * +i386_cygwin_auto_wide_charset (void) +{ + return "UTF-16"; } static void @@ -222,19 +209,26 @@ 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_win32_gregset_reg_offset; - tdep->gregset_num_regs = ARRAY_SIZE (i386_win32_gregset_reg_offset); - tdep->sizeof_gregset = I386_WIN32_SIZEOF_GREGSET; + 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; /* Core file support. */ - set_gdbarch_regset_from_core_section - (gdbarch, i386_win32_regset_from_core_section); set_gdbarch_core_xfer_shared_libraries - (gdbarch, win32_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 @@ -242,14 +236,18 @@ i386_cygwin_osabi_sniffer (bfd *abfd) { char *target_name = bfd_get_target (abfd); - /* Interix also uses pei-i386. - We need a way to distinguish between the two. */ if (strcmp (target_name, "pei-i386") == 0) return GDB_OSABI_CYGWIN; - /* Cygwin uses elf core dumps. */ + /* Cygwin uses elf core dumps. Do not claim all ELF executables, + check whether there is a .reg section of proper size. */ if (strcmp (target_name, "elf32-i386") == 0) - return GDB_OSABI_CYGWIN; + { + 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; }