* config/i386/nm-cygwin.h (ATTACH_NO_WAIT): Delete.
[deliverable/binutils-gdb.git] / gdb / win32-nat.c
index 061430b74d012f26ea555361a298eb712a0983bb..eb15c97142291a09347859ca601d4426ccbd9a2b 100644 (file)
@@ -48,7 +48,6 @@
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "gdb_string.h"
-#include "gdb_stdint.h"
 #include "gdbthread.h"
 #include "gdbcmd.h"
 #include <sys/param.h>
@@ -359,6 +358,8 @@ static void
 do_win32_fetch_inferior_registers (struct regcache *regcache, int r)
 {
   char *context_offset = ((char *) &current_thread->context) + mappings[r];
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   long l;
 
   if (!current_thread)
@@ -397,14 +398,12 @@ do_win32_fetch_inferior_registers (struct regcache *regcache, int r)
       current_thread->reload_context = 0;
     }
 
-#define I387_ST0_REGNUM I386_ST0_REGNUM
-
-  if (r == I387_FISEG_REGNUM)
+  if (r == I387_FISEG_REGNUM (tdep))
     {
       l = *((long *) context_offset) & 0xffff;
       regcache_raw_supply (regcache, r, (char *) &l);
     }
-  else if (r == I387_FOP_REGNUM)
+  else if (r == I387_FOP_REGNUM (tdep))
     {
       l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
       regcache_raw_supply (regcache, r, (char *) &l);
@@ -413,11 +412,9 @@ do_win32_fetch_inferior_registers (struct regcache *regcache, int r)
     regcache_raw_supply (regcache, r, context_offset);
   else
     {
-      for (r = 0; r < gdbarch_num_regs (get_regcache_arch (regcache)); r++)
+      for (r = 0; r < gdbarch_num_regs (gdbarch); r++)
        do_win32_fetch_inferior_registers (regcache, r);
     }
-
-#undef I387_ST0_REGNUM
 }
 
 static void
@@ -558,8 +555,6 @@ static int
 safe_symbol_file_add_stub (void *argv)
 {
 #define p ((struct safe_symbol_file_add_args *) argv)
-  struct so_list *so = &solib_start;
-
   p->ret = symbol_file_add (p->name, p->from_tty, p->addrs, p->mainline, p->flags);
   return !!p->ret;
 #undef p
@@ -749,6 +744,9 @@ handle_load_dll (void *dummy)
   solib_end->next = win32_make_so (dll_name, (DWORD) event->lpBaseOfDll);
   solib_end = solib_end->next;
 
+  DEBUG_EVENTS (("gdb: Loading dll \"%s\" at 0x%lx.\n", solib_end->so_name,
+                (DWORD) solib_end->lm_info->load_addr));
+
   return 1;
 }
 
@@ -773,6 +771,8 @@ handle_unload_dll (void *dummy)
        so->next = sodel->next;
        if (!so->next)
          solib_end = so;
+       DEBUG_EVENTS (("gdb: Unloading dll \"%s\".\n", sodel->so_name));
+
        win32_free_so (sodel);
        solib_add (NULL, 0, NULL, auto_solib_add);
        return 1;
@@ -1460,7 +1460,25 @@ win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
 
   while (1)
     {
-      int retval = get_win32_debug_event (pid, ourstatus);
+      int retval;
+      
+      /* Ignore CTRL+C signals while waiting for a debug event.
+         FIXME: brobecker/2008-05-20: When the user presses CTRL+C while
+         the inferior is running, both the inferior and GDB receive the
+         associated signal.  If the inferior receives the signal first
+         and the delay until GDB receives that signal is sufficiently long,
+         GDB can sometimes receive the SIGINT after we have unblocked
+         the CTRL+C handler.  This would lead to the debugger to stop
+         prematurely while handling the new-thread event that comes
+         with the handling of the SIGINT inside the inferior, and then
+         stop again immediately when the user tries to resume the execution
+         in the inferior.  This is a classic race, and it would be nice
+         to find a better solution to that problem.  But in the meantime,
+         the current approach already greatly mitigate this issue.  */
+      SetConsoleCtrlHandler (NULL, TRUE);
+      retval = get_win32_debug_event (pid, ourstatus);
+      SetConsoleCtrlHandler (NULL, FALSE);
+
       if (retval)
        return pid_to_ptid (retval);
       else
@@ -1504,15 +1522,18 @@ do_initial_win32_stuff (DWORD pid)
   terminal_init_inferior_with_pgrp (pid);
   target_terminal_inferior ();
 
+  stop_soon = STOP_QUIETLY;
   while (1)
     {
       stop_after_trap = 1;
-      wait_for_inferior ();
+      wait_for_inferior (0);
       if (stop_signal != TARGET_SIGNAL_TRAP)
        resume (0, stop_signal);
       else
        break;
     }
+
+  stop_soon = NO_STOP_QUIETLY;
   stop_after_trap = 0;
   return;
 }
@@ -1990,7 +2011,7 @@ win32_pid_to_str (ptid_t ptid)
   if ((DWORD) pid == current_event.dwProcessId)
     sprintf (buf, "process %d", pid);
   else
-    sprintf (buf, "thread %ld.0x%x", current_event.dwProcessId, pid);
+    sprintf (buf, "Thread %ld.0x%x", current_event.dwProcessId, pid);
   return buf;
 }
 
@@ -2037,7 +2058,7 @@ win32_xfer_partial (struct target_ops *ops, enum target_object object,
     case TARGET_OBJECT_MEMORY:
       if (readbuf)
        return (*ops->deprecated_xfer_memory) (offset, readbuf,
-                                              len, 0/*write*/, NULL, ops);
+                                              len, 0/*read*/, NULL, ops);
       if (writebuf)
        return (*ops->deprecated_xfer_memory) (offset, (gdb_byte *) writebuf,
                                               len, 1/*write*/, NULL, ops);
@@ -2064,6 +2085,7 @@ init_win32_ops (void)
   win32_ops.to_open = win32_open;
   win32_ops.to_close = win32_close;
   win32_ops.to_attach = win32_attach;
+  win32_ops.to_attach_no_wait = 1;
   win32_ops.to_detach = win32_detach;
   win32_ops.to_resume = win32_resume;
   win32_ops.to_wait = win32_wait;
This page took 0.025954 seconds and 4 git commands to generate.