* (struct remote_state): New type, only containing
[deliverable/binutils-gdb.git] / gdb / wince.c
index 0a6e72d1b851889547481d888860bf39a480cb30..86bfaf6ab66acaff03f87aa79c48c2e398327eac 100644 (file)
@@ -1,5 +1,6 @@
 /* Target-vector operations for controlling Windows CE child processes, for GDB.
-   Copyright 1999, 2000 Free Software Foundation, Inc.
+
+   Copyright (C) 1999, 2000, 2001, 2004, 2006 Free Software Foundation, Inc.
    Contributed by Cygnus Solutions, A Red Hat Company.
 
    This file is part of GDB.
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without eve nthe implied warranty of
+   but WITHOUT ANY WARRANTY; without evethe implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
  */
 
 /* by Christopher Faylor (cgf@cygnus.com) */
 
 #ifdef SHx
 #undef SH4
-#define SH4                    /* Just to get all of the CONTEXT defines. */
+#define SH4            /* Just to get all of the CONTEXT defines.  */
 #endif
 
 #include "defs.h"
-#include "frame.h"             /* required by inferior.h */
+#include "frame.h"     /* required by inferior.h */
 #include "inferior.h"
 #include "target.h"
-#include "gdb_wait.h"
+#include "exceptions.h"
 #include "gdbcore.h"
 #include "command.h"
 #include <signal.h>
 #include "gdbcmd.h"
 #include <sys/param.h>
 #include "wince-stub.h"
-#include "dcache.h"
-
-/* The ui's event loop. */
-extern int (*ui_loop_hook) PARAMS ((int signo));
+#include <time.h>
+#include "regcache.h"
+#ifdef MIPS
+#include "mips-tdep.h"
+#endif
 
 /* If we're not using the old Cygwin header file set, define the
    following which never should have been in the generic Win32 API
-   headers in the first place since they were our own invention... */
+   headers in the first place since they were our own invention...  */
 #ifndef _GNU_H_WINDOWS_H
 #define FLAG_TRACE_BIT 0x100
 #ifdef CONTEXT_FLOATING_POINT
@@ -78,7 +80,7 @@ extern int (*ui_loop_hook) PARAMS ((int signo));
 #define CONTEXT_DEBUGGER CONTEXT_DEBUGGER0
 #endif
 /* The string sent by cygwin when it processes a signal.
-   FIXME: This should be in a cygwin include file. */
+   FIXME: This should be in a cygwin include file.  */
 #define CYGWIN_SIGNAL_STRING "cygwin: signal"
 
 #define CHECK(x)       check (x, __FILE__,__LINE__)
@@ -87,14 +89,13 @@ extern int (*ui_loop_hook) PARAMS ((int signo));
 #define DEBUG_MEM(x)   if (debug_memory)       printf x
 #define DEBUG_EXCEPT(x)        if (debug_exceptions)   printf x
 
-static int connection_initialized = 0; /* True if we've initialized a RAPI session. */
-
-static DCACHE *remote_dcache;
+static int connection_initialized = 0; /* True if we've initialized a
+                                          RAPI session.  */
 
-/* The directory where the stub and executable files are uploaded. */
+/* The directory where the stub and executable files are uploaded.  */
 static const char *remote_directory = "\\gdb";
 
-/* The types automatic upload available. */
+/* The types automatic upload available.  */
 static enum
   {
     UPLOAD_ALWAYS = 0,
@@ -104,7 +105,7 @@ static enum
 upload_when = UPLOAD_NEWER;
 
 /* Valid options for 'set remoteupload'.  Note that options
-   must track upload_when enum. */
+   must track upload_when enum.  */
 static struct opts
   {
     const char *name;
@@ -125,20 +126,17 @@ upload_options[3] =
   }
 };
 
-static char *remote_upload = NULL;     /* Set by set remoteupload */
+static char *remote_upload = NULL;     /* Set by set remoteupload */
 static int remote_add_host = 0;
 
-/* Forward declaration */
-extern struct target_ops child_ops;
-
-static int win32_child_thread_alive PARAMS ((int));
-void child_kill_inferior PARAMS ((void));
+static int win32_child_thread_alive (ptid_t);
+void child_kill_inferior (void);
 
-static int last_sig = 0;       /* Set if a signal was received from the
-                                  debugged process */
+static int last_sig = 0;       /* Set if a signal was received from
+                                  the debugged process.  */
 
 /* Thread information structure used to track information that is
-   not available in gdb's thread structure. */
+   not available in gdb's thread structure.  */
 typedef struct thread_info_struct
   {
     struct thread_info_struct *next;
@@ -146,34 +144,35 @@ typedef struct thread_info_struct
     HANDLE h;
     char *name;
     int suspend_count;
-    int stepped;               /* True if stepped. */
+    int stepped;               /* True if stepped.  */
     CORE_ADDR step_pc;
-    unsigned long step_instr;
-    unsigned long step_prev;
     CONTEXT context;
   }
 thread_info;
 
 static thread_info thread_head =
 {NULL};
+static thread_info * thread_rec (DWORD id, int get_context);
 
-/* The process and thread handles for the above context. */
+/* The process and thread handles for the above context.  */
 
 static DEBUG_EVENT current_event;      /* The current debug event from
-                                          WaitForDebugEvent */
-static HANDLE current_process_handle;  /* Currently executing process */
-static thread_info *current_thread;    /* Info on currently selected thread */
-static thread_info *this_thread;       /* Info on thread returned by wait_for_debug_event */
-static DWORD main_thread_id;   /* Thread ID of the main thread */
-
-/* Counts of things. */
+                                          WaitForDebugEvent.  */
+static HANDLE current_process_handle;  /* Currently executing process.  */
+static thread_info *current_thread;    /* Info on currently selected
+                                          thread.  */
+static thread_info *this_thread;       /* Info on thread returned by
+                                          wait_for_debug_event.  */
+static DWORD main_thread_id;           /* Thread ID of the main thread.  */
+
+/* Counts of things.  */
 static int exception_count = 0;
 static int event_count = 0;
 
-/* User options. */
-static int debug_exec = 0;     /* show execution */
-static int debug_events = 0;   /* show events from kernel */
-static int debug_memory = 0;   /* show target memory accesses */
+/* User options.  */
+static int debug_exec = 0;             /* show execution */
+static int debug_events = 0;           /* show events from kernel */
+static int debug_memory = 0;           /* show target memory accesses */
 static int debug_exceptions = 0;       /* show target exceptions */
 
 /* An array of offset mappings into a Win32 Context structure.
@@ -184,7 +183,7 @@ static int debug_exceptions = 0;    /* show target exceptions */
    register in it's CONTEXT structure.  regptr will return zero for this
    register.
 
-   This is used by the regptr function. */
+   This is used by the regptr function.  */
 #define context_offset(x) ((int)&(((PCONTEXT)NULL)->x))
 static const int mappings[NUM_REGS + 1] =
 {
@@ -375,24 +374,21 @@ static const int mappings[NUM_REGS + 1] =
   -1
 };
 
-/* This vector maps the target's idea of an exception (extracted
-   from the DEBUG_EVENT structure) to GDB's idea. */
-
-struct xlate_exception
-  {
-    int them;
-    enum target_signal us;
-  };
-
-static const struct xlate_exception
-  xlate[] =
+/* Return a pointer into a CONTEXT field indexed by gdb register number.
+   Return a pointer to an address pointing to zero if there is no
+   corresponding CONTEXT field for the given register number.
+ */
+static ULONG *
+regptr (LPCONTEXT c, int r)
 {
-  {EXCEPTION_ACCESS_VIOLATION, TARGET_SIGNAL_SEGV},
-  {STATUS_STACK_OVERFLOW, TARGET_SIGNAL_SEGV},
-  {EXCEPTION_BREAKPOINT, TARGET_SIGNAL_TRAP},
-  {DBG_CONTROL_C, TARGET_SIGNAL_INT},
-  {EXCEPTION_SINGLE_STEP, TARGET_SIGNAL_TRAP},
-  {-1, -1}};
+  static ULONG zero = 0;
+  ULONG *p;
+  if (mappings[r] < 0)
+    p = &zero;
+  else
+    p = (ULONG *) (((char *) c) + mappings[r]);
+  return p;
+}
 
 /******************** Beginning of stub interface ********************/
 
@@ -411,13 +407,13 @@ static const struct xlate_exception
    byte 1-2:    length
    byte 3-n:    arbitrary memory.
 
-   The interface is deterministic, i.e., if the stub expects a DWORD then
-   the gdb server should send a DWORD.
+   The interface is deterministic, i.e., if the stub expects a DWORD
+   then the gdb server should send a DWORD.
  */
 
-/* Note:  In the functions below, the `huh' parameter is a string passed from the
-   function containing a descriptive string concerning the current operation.
-   This is used for error reporting.
+/* Note: In the functions below, the `huh' parameter is a string
+   passed from the function containing a descriptive string concerning
+   the current operation.  This is used for error reporting.
 
    The 'what' parameter is a command id as found in wince-stub.h.
 
@@ -428,17 +424,17 @@ static int s;                     /* communication socket */
 
 /* v-style interface for handling varying argyment list error messages.
    Displays the error message in a dialog box and exits when user clicks
-   on OK. */
+   on OK.  */
 static void
 vstub_error (LPCSTR fmt, va_list * args)
 {
   char buf[4096];
   vsprintf (buf, fmt, args);
   s = -1;
-  error ("%s", buf);
+  error (("%s"), buf);
 }
 
-/* The standard way to display an error message and exit. */
+/* The standard way to display an error message and exit.  */
 static void
 stub_error (LPCSTR fmt,...)
 {
@@ -447,15 +443,15 @@ stub_error (LPCSTR fmt,...)
   vstub_error (fmt, args);
 }
 
-/* Standard "oh well" can't communicate error.  Someday this might attempt
-   synchronization. */
+/* Standard "oh well" can't communicate error.  Someday this might
+   attempt synchronization.  */
 static void
 attempt_resync (LPCSTR huh, int s)
 {
   stub_error ("lost synchronization with target attempting %s", huh);
 }
 
-/* Read arbitrary stuff from a socket. */
+/* Read arbitrary stuff from a socket.  */
 static int
 sockread (LPCSTR huh, int s, void *str, size_t n)
 {
@@ -467,7 +463,7 @@ sockread (LPCSTR huh, int s, void *str, size_t n)
     }
 }
 
-/* Write arbitrary stuff to a socket. */
+/* Write arbitrary stuff to a socket.  */
 static int
 sockwrite (LPCSTR huh, const void *str, size_t n)
 {
@@ -479,7 +475,7 @@ sockwrite (LPCSTR huh, const void *str, size_t n)
     }
 }
 
-/* Output an id/dword to the host */
+/* Output an id/dword to the host */
 static void
 putdword (LPCSTR huh, gdb_wince_id what, DWORD n)
 {
@@ -489,7 +485,7 @@ putdword (LPCSTR huh, gdb_wince_id what, DWORD n)
     stub_error ("error writing %s to host.", huh);
 }
 
-/* Output an id/word to the host */
+/* Output an id/word to the host */
 static void
 putword (LPCSTR huh, gdb_wince_id what, WORD n)
 {
@@ -499,23 +495,24 @@ putword (LPCSTR huh, gdb_wince_id what, WORD n)
     stub_error ("error writing %s host.", huh);
 }
 
-/* Convenience define for outputting a "gdb_wince_len" type. */
+/* Convenience define for outputting a "gdb_wince_len" type.  */
 #define putlen(huh, what, n) putword((huh), (what), (gdb_wince_len) (n))
 
 /* Put an arbitrary block of memory to the gdb host.  This comes in
-   two chunks an id/dword representing the length and the stream of memory
-   itself. */
+   two chunks an id/dword representing the length and the stream of
+   memory itself.  */
 static void
-putmemory (LPCSTR huh, gdb_wince_id what, const void *mem, gdb_wince_len len)
+putmemory (LPCSTR huh, gdb_wince_id what, 
+          const void *mem, gdb_wince_len len)
 {
   putlen (huh, what, len);
   if (((short) len > 0) && sockwrite (huh, mem, len) != len)
     stub_error ("error writing %s to host.", huh);
 }
 
-/* Output the result of an operation to the host.  If res != 0, sends a block of
-   memory starting at mem of len bytes.  If res == 0, sends -GetLastError () and
-   avoids sending the mem. */
+/* Output the result of an operation to the host.  If res != 0, sends
+   a block of memory starting at mem of len bytes.  If res == 0, sends
+   -GetLastError () and avoids sending the mem.  */
 static DWORD
 getdword (LPCSTR huh, gdb_wince_id what_this)
 {
@@ -534,7 +531,7 @@ getdword (LPCSTR huh, gdb_wince_id what_this)
 
 /* Get a an ID (possibly) and a WORD from the host gdb.
    Don't bother with the id if the main loop has already
-   read it. */
+   read it.  */
 static WORD
 getword (LPCSTR huh, gdb_wince_id what_this)
 {
@@ -551,19 +548,21 @@ getword (LPCSTR huh, gdb_wince_id what_this)
   return n;
 }
 
-/* Handy defines for getting/putting various types of values. */
+/* Handy defines for getting/putting various types of values.  */
 #define gethandle(huh, what) (HANDLE) getdword ((huh), (what))
 #define getpvoid(huh, what) (LPVOID) getdword ((huh), (what))
 #define getlen(huh, what) (gdb_wince_len) getword ((huh), (what))
 #define puthandle(huh, what, h) putdword ((huh), (what), (DWORD) (h))
 #define putpvoid(huh, what, p) putdword ((huh), (what), (DWORD) (p))
 
-/* Retrieve the result of an operation from the stub.  If nbytes < 0) then nbytes
-   is actually an error and nothing else follows.  Use SetLastError to remember this.
-   if nbytes > 0, retrieve a block of *nbytes into buf.
+/* Retrieve the result of an operation from the stub.  If nbytes < 0)
+   then nbytes is actually an error and nothing else follows.  Use
+   SetLastError to remember this.  if nbytes > 0, retrieve a block of
+   *nbytes into buf.
  */
 int
-getresult (LPCSTR huh, gdb_wince_id what, LPVOID buf, gdb_wince_len * nbytes)
+getresult (LPCSTR huh, gdb_wince_id what, LPVOID buf, 
+          gdb_wince_len * nbytes)
 {
   gdb_wince_len dummy;
   if (nbytes == NULL)
@@ -592,25 +591,26 @@ towide (const char *s, gdb_wince_len * out_len)
 {
   static int n = -1;
   static LPWSTR outs[8] =
-  {NULL /*, NULL, etc. */ };
+  {NULL /*, NULL, etc.  */ };
   gdb_wince_len dummy;
 
   if (!out_len)
     out_len = &dummy;
 
-  /* First determine the length required to hold the converted string. */
-  *out_len = sizeof (WCHAR) * MultiByteToWideChar (CP_ACP, 0, s, -1, NULL, 0);
+  /* First determine the length required to hold the converted string.  */
+  *out_len = sizeof (WCHAR) * MultiByteToWideChar (CP_ACP, 0, s, 
+                                                  -1, NULL, 0);
   if (!*out_len)
-    return NULL;               /* The conversion failed */
+    return NULL;               /* The conversion failed */
 
   if (++n >= (sizeof (outs) / sizeof (outs[0])))
     n = 0;                     /* wrap */
 
-  /* Allocate space for the converted string, reusing any previously allocated
-     space, if applicable. Note that if outs[n] is NULL, realloc will act as
-     a malloc (under cygwin, at least).
+  /* Allocate space for the converted string, reusing any previously
+     allocated space, if applicable. Note that if outs[n] is NULL,
+     xrealloc will act as a malloc (under cygwin, at least).
    */
-  outs[n] = (LPWSTR) realloc (outs[n], *out_len);
+  outs[n] = (LPWSTR) xrealloc (outs[n], *out_len);
   memset (outs[n], 0, *out_len);
   (void) MultiByteToWideChar (CP_ACP, 0, s, -1, outs[n], *out_len);
   return outs[n];
@@ -618,20 +618,24 @@ towide (const char *s, gdb_wince_len * out_len)
 
 /******************** Emulation routines start here. ********************
 
-  The functions below are modelled after their Win32 counterparts.  They are named
-  similarly to Win32 and take exactly the same arguments except where otherwise noted.
-  They communicate with the stub on the hand-held device by sending their arguments
-  over the socket and waiting for results from the socket.
-
-  There is one universal change.  In cases where a length is expected to be returned
-  in a DWORD, we use a gdb_wince_len type instead.  Currently this is an unsigned short
-  which is smaller than the standard Win32 DWORD.  This is done to minimize unnecessary
-  traffic since the connection to Windows CE can be slow.  To change this, modify the
-  typedef in wince-stub.h and change the putlen/getlen macros in this file and in
-  the stub.
+  The functions below are modelled after their Win32 counterparts.
+  They are named similarly to Win32 and take exactly the same
+  arguments except where otherwise noted.  They communicate with the
+  stub on the hand-held device by sending their arguments over the
+  socket and waiting for results from the socket.
+
+  There is one universal change.  In cases where a length is expected
+  to be returned in a DWORD, we use a gdb_wince_len type instead.
+  Currently this is an unsigned short which is smaller than the
+  standard Win32 DWORD.  This is done to minimize unnecessary traffic
+  since the connection to Windows CE can be slow.  To change this,
+  modify the typedef in wince-stub.h and change the putlen/getlen
+  macros in this file and in the stub.
 */
+
 static int
-create_process (LPSTR exec_file, LPSTR args, DWORD flags, PROCESS_INFORMATION * pi)
+create_process (LPSTR exec_file, LPSTR args, DWORD flags, 
+               PROCESS_INFORMATION * pi)
 {
   gdb_wince_len len;
   LPWSTR buf;
@@ -644,8 +648,8 @@ create_process (LPSTR exec_file, LPSTR args, DWORD flags, PROCESS_INFORMATION *
   return getresult ("CreateProcess result", GDB_CREATEPROCESS, pi, NULL);
 }
 
-/* Emulate TerminateProcess.  Don't bother with the second argument since CE
-   ignores it.
+/* Emulate TerminateProcess.  
+   Don't bother with the second argument since CE ignores it.
  */
 static int
 terminate_process (HANDLE h)
@@ -654,7 +658,9 @@ terminate_process (HANDLE h)
   if (s < 0)
     return 1;
   puthandle ("TerminateProcess handle", GDB_TERMINATEPROCESS, h);
-  return getresult ("TerminateProcess result", GDB_TERMINATEPROCESS, &res, NULL);
+
+  return getresult ("TerminateProcess result", 
+                   GDB_TERMINATEPROCESS, &res, NULL);
 }
 
 static int
@@ -663,7 +669,9 @@ wait_for_debug_event (DEBUG_EVENT * ev, DWORD ms)
   if (s < 0)
     return 1;
   putdword ("WaitForDebugEvent ms", GDB_WAITFORDEBUGEVENT, ms);
-  return getresult ("WaitForDebugEvent event", GDB_WAITFORDEBUGEVENT, ev, NULL);
+
+  return getresult ("WaitForDebugEvent event", 
+                   GDB_WAITFORDEBUGEVENT, ev, NULL);
 }
 
 static int
@@ -672,8 +680,11 @@ get_thread_context (HANDLE h, CONTEXT * c)
   if (s < 0)
     return 1;
   puthandle ("GetThreadContext handle", GDB_GETTHREADCONTEXT, h);
-  putdword ("GetThreadContext flags", GDB_GETTHREADCONTEXT, c->ContextFlags);
-  return getresult ("GetThreadContext context", GDB_GETTHREADCONTEXT, c, NULL);
+  putdword ("GetThreadContext flags", GDB_GETTHREADCONTEXT, 
+           c->ContextFlags);
+
+  return getresult ("GetThreadContext context", 
+                   GDB_GETTHREADCONTEXT, c, NULL);
 }
 
 static int
@@ -683,12 +694,17 @@ set_thread_context (HANDLE h, CONTEXT * c)
   if (s < 0)
     return 1;
   puthandle ("SetThreadContext handle", GDB_SETTHREADCONTEXT, h);
-  putmemory ("SetThreadContext context", GDB_SETTHREADCONTEXT, c, sizeof (*c));
-  return getresult ("SetThreadContext context", GDB_SETTHREADCONTEXT, &res, NULL);
+  putmemory ("SetThreadContext context", GDB_SETTHREADCONTEXT, 
+            c, sizeof (*c));
+
+  return getresult ("SetThreadContext context", 
+                   GDB_SETTHREADCONTEXT, &res, NULL);
 }
 
 static int
-read_process_memory (HANDLE h, LPCVOID where, LPVOID buf, gdb_wince_len len, gdb_wince_len * nbytes)
+read_process_memory (HANDLE h, LPCVOID where, 
+                    LPVOID buf, gdb_wince_len len, 
+                    gdb_wince_len * nbytes)
 {
   if (s < 0)
     return 1;
@@ -696,11 +712,14 @@ read_process_memory (HANDLE h, LPCVOID where, LPVOID buf, gdb_wince_len len, gdb
   putpvoid ("ReadProcessMemory location", GDB_READPROCESSMEMORY, where);
   putlen ("ReadProcessMemory size", GDB_READPROCESSMEMORY, len);
 
-  return getresult ("ReadProcessMemory buf", GDB_READPROCESSMEMORY, buf, nbytes);
+  return getresult ("ReadProcessMemory buf", 
+                   GDB_READPROCESSMEMORY, buf, nbytes);
 }
 
 static int
-write_process_memory (HANDLE h, LPCVOID where, LPCVOID buf, gdb_wince_len len, gdb_wince_len * nbytes)
+write_process_memory (HANDLE h, LPCVOID where, 
+                     LPCVOID buf, gdb_wince_len len, 
+                     gdb_wince_len * nbytes)
 {
   if (s < 0)
     return 1;
@@ -708,15 +727,18 @@ write_process_memory (HANDLE h, LPCVOID where, LPCVOID buf, gdb_wince_len len, g
   putpvoid ("WriteProcessMemory location", GDB_WRITEPROCESSMEMORY, where);
   putmemory ("WriteProcProcessMemory buf", GDB_WRITEPROCESSMEMORY, buf, len);
 
-  return getresult ("WriteProcessMemory result", GDB_WRITEPROCESSMEMORY, nbytes, NULL);
+  return getresult ("WriteProcessMemory result", 
+                   GDB_WRITEPROCESSMEMORY, nbytes, NULL);
 }
 
 static int
 remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 {
   gdb_wince_len nbytes;
-  if (!read_process_memory (current_process_handle, (LPCVOID) memaddr,
-                           (LPVOID) myaddr, len, &nbytes))
+  if (!read_process_memory (current_process_handle, 
+                           (LPCVOID) memaddr,
+                           (LPVOID) myaddr, 
+                           len, &nbytes))
     return -1;
   return nbytes;
 }
@@ -725,14 +747,16 @@ static int
 remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 {
   gdb_wince_len nbytes;
-  if (!write_process_memory (current_process_handle, (LPCVOID) memaddr,
-                            (LPCVOID) myaddr, len, &nbytes))
+  if (!write_process_memory (current_process_handle, 
+                            (LPCVOID) memaddr, 
+                            (LPCVOID) myaddr, 
+                            len, &nbytes))
     return -1;
   return nbytes;
 }
 
-/* This is not a standard Win32 function.  It instructs the stub to return TRUE
-   if the thread referenced by HANDLE h is alive.
+/* This is not a standard Win32 function.  It instructs the stub to
+   return TRUE if the thread referenced by HANDLE h is alive.
  */
 static int
 thread_alive (HANDLE h)
@@ -771,7 +795,8 @@ continue_debug_event (DWORD pid, DWORD tid, DWORD status)
   putdword ("ContinueDebugEvent pid", GDB_CONTINUEDEBUGEVENT, pid);
   putdword ("ContinueDebugEvent tid", GDB_CONTINUEDEBUGEVENT, tid);
   putdword ("ContinueDebugEvent status", GDB_CONTINUEDEBUGEVENT, status);
-  return getresult ("ContinueDebugEvent result", GDB_CONTINUEDEBUGEVENT, &res, NULL);
+  return getresult ("ContinueDebugEvent result", 
+                   GDB_CONTINUEDEBUGEVENT, &res, NULL);
 }
 
 static int
@@ -781,14 +806,15 @@ close_handle (HANDLE h)
   if (s < 0)
     return 1;
   puthandle ("CloseHandle handle", GDB_CLOSEHANDLE, h);
-  return (int) getresult ("CloseHandle result", GDB_CLOSEHANDLE, &res, NULL);
+  return (int) getresult ("CloseHandle result", 
+                         GDB_CLOSEHANDLE, &res, NULL);
 }
 
-/* This is not a standard Win32 interface.  This function tells the stub
-   to terminate.
+/* This is not a standard Win32 interface.  This function tells the
+   stub to terminate.
  */
 static void
-stop_stub ()
+stop_stub (void)
 {
   if (s < 0)
     return;
@@ -799,9 +825,233 @@ stop_stub ()
 /******************** End of emulation routines. ********************/
 /******************** End of stub interface ********************/
 
+#define check_for_step(a, x) (x)
+
+#ifdef MIPS
+static void
+undoSStep (thread_info * th)
+{
+  if (th->stepped)
+    {
+      remove_single_step_breakpoints ();
+      th->stepped = 0;
+    }
+}
+
+void
+wince_software_single_step (enum target_signal ignore,
+                           int insert_breakpoints_p)
+{
+  unsigned long pc;
+  /* Info on currently selected thread.  */
+  thread_info *th = current_thread;
+  CORE_ADDR mips_next_pc (CORE_ADDR pc);
+
+  if (!insert_breakpoints_p)
+    {
+      undoSStep (th);
+      return;
+    }
+
+  th->stepped = 1;
+  pc = read_register (PC_REGNUM);
+  th->step_pc = mips_next_pc (pc);
+  insert_single_step_breakpoint (th->step_pc);
+  return;
+}
+#elif SHx
+/* Renesas SH architecture instruction encoding masks */
+
+#define COND_BR_MASK   0xff00
+#define UCOND_DBR_MASK 0xe000
+#define UCOND_RBR_MASK 0xf0df
+#define TRAPA_MASK     0xff00
+
+#define COND_DISP      0x00ff
+#define UCOND_DISP     0x0fff
+#define UCOND_REG      0x0f00
+
+/* Renesas SH instruction opcodes */
+
+#define BF_INSTR       0x8b00
+#define BT_INSTR       0x8900
+#define BRA_INSTR      0xa000
+#define BSR_INSTR      0xb000
+#define JMP_INSTR      0x402b
+#define JSR_INSTR      0x400b
+#define RTS_INSTR      0x000b
+#define RTE_INSTR      0x002b
+#define TRAPA_INSTR    0xc300
+#define SSTEP_INSTR    0xc3ff
+
+
+#define T_BIT_MASK     0x0001
+
+static CORE_ADDR
+sh_get_next_pc (CONTEXT *c)
+{
+  short *instrMem;
+  int displacement;
+  int reg;
+  unsigned short opcode;
+
+  instrMem = (short *) c->Fir;
+
+  opcode = read_memory_integer ((CORE_ADDR) c->Fir, sizeof (opcode));
+
+  if ((opcode & COND_BR_MASK) == BT_INSTR)
+    {
+      if (c->Psr & T_BIT_MASK)
+       {
+         displacement = (opcode & COND_DISP) << 1;
+         if (displacement & 0x80)
+           displacement |= 0xffffff00;
+         /*
+            * Remember PC points to second instr.
+            * after PC of branch ... so add 4
+          */
+         instrMem = (short *) (c->Fir + displacement + 4);
+       }
+      else
+       instrMem += 1;
+    }
+  else if ((opcode & COND_BR_MASK) == BF_INSTR)
+    {
+      if (c->Psr & T_BIT_MASK)
+       instrMem += 1;
+      else
+       {
+         displacement = (opcode & COND_DISP) << 1;
+         if (displacement & 0x80)
+           displacement |= 0xffffff00;
+         /*
+            * Remember PC points to second instr.
+            * after PC of branch ... so add 4
+          */
+         instrMem = (short *) (c->Fir + displacement + 4);
+       }
+    }
+  else if ((opcode & UCOND_DBR_MASK) == BRA_INSTR)
+    {
+      displacement = (opcode & UCOND_DISP) << 1;
+      if (displacement & 0x0800)
+       displacement |= 0xfffff000;
+
+      /*
+        * Remember PC points to second instr.
+        * after PC of branch ... so add 4
+       */
+      instrMem = (short *) (c->Fir + displacement + 4);
+    }
+  else if ((opcode & UCOND_RBR_MASK) == JSR_INSTR)
+    {
+      reg = (char) ((opcode & UCOND_REG) >> 8);
+
+      instrMem = (short *) *regptr (c, reg);
+    }
+  else if (opcode == RTS_INSTR)
+    instrMem = (short *) c->PR;
+  else if (opcode == RTE_INSTR)
+    instrMem = (short *) *regptr (c, 15);
+  else if ((opcode & TRAPA_MASK) == TRAPA_INSTR)
+    instrMem = (short *) ((opcode & ~TRAPA_MASK) << 2);
+  else
+    instrMem += 1;
+
+  return (CORE_ADDR) instrMem;
+}
+/* Single step (in a painstaking fashion) by inspecting the current
+   instruction and setting a breakpoint on the "next" instruction
+   which would be executed.  This code hails from sh-stub.c.
+ */
+static void
+undoSStep (thread_info * th)
+{
+  if (th->stepped)
+    {
+      remove_single_step_breakpoints ();
+      th->stepped = 0;
+    }
+  return;
+}
+
+/* Single step (in a painstaking fashion) by inspecting the current
+   instruction and setting a breakpoint on the "next" instruction
+   which would be executed.  This code hails from sh-stub.c.
+ */
+void
+wince_software_single_step (enum target_signal ignore,
+                           int insert_breakpoints_p)
+{
+  /* Info on currently selected thread.  */
+  thread_info *th = current_thread;
+
+  if (!insert_breakpoints_p)
+    {
+      undoSStep (th);
+      return;
+    }
+
+  th->stepped = 1;
+  th->step_pc = sh_get_next_pc (&th->context);
+  insert_single_step_breakpoint (th->step_pc);
+  return;
+}
+#elif defined (ARM)
+#undef check_for_step
+
+static enum target_signal
+check_for_step (DEBUG_EVENT *ev, enum target_signal x)
+{
+  thread_info *th = thread_rec (ev->dwThreadId, 1);
+
+  if (th->stepped &&
+      th->step_pc == (CORE_ADDR) ev->u.Exception.ExceptionRecord.ExceptionAddress)
+    return TARGET_SIGNAL_TRAP;
+  else
+    return x;
+}
+
+/* Single step (in a painstaking fashion) by inspecting the current
+   instruction and setting a breakpoint on the "next" instruction
+   which would be executed.  This code hails from sh-stub.c.
+ */
+static void
+undoSStep (thread_info * th)
+{
+  if (th->stepped)
+    {
+      remove_single_step_breakpoints ();
+      th->stepped = 0;
+    }
+}
+
+void
+wince_software_single_step (enum target_signal ignore,
+                           int insert_breakpoints_p)
+{
+  unsigned long pc;
+  /* Info on currently selected thread.  */
+  thread_info *th = current_thread;
+  CORE_ADDR mips_next_pc (CORE_ADDR pc);
+
+  if (!insert_breakpoints_p)
+    {
+      undoSStep (th);
+      return;
+    }
+
+  th->stepped = 1;
+  pc = read_register (PC_REGNUM);
+  th->step_pc = arm_get_next_pc (pc);
+  insert_single_step_breakpoint (th->step_pc);
+  return;
+}
+#endif
+
 /* Find a thread record given a thread id.
-   If get_context then also retrieve the context for this
-   thread. */
+   If get_context then also retrieve the context for this thread.  */
+
 static thread_info *
 thread_rec (DWORD id, int get_context)
 {
@@ -822,11 +1072,10 @@ thread_rec (DWORD id, int get_context)
          }
        return th;
       }
-
   return NULL;
 }
 
-/* Add a thread to the thread list */
+/* Add a thread to the thread list */
 static thread_info *
 child_add_thread (DWORD id, HANDLE h)
 {
@@ -846,9 +1095,9 @@ child_add_thread (DWORD id, HANDLE h)
 }
 
 /* Clear out any old thread list and reintialize it to a
-   pristine state. */
+   pristine state.  */
 static void
-child_init_thread_list ()
+child_init_thread_list (void)
 {
   thread_info *th = &thread_head;
 
@@ -859,11 +1108,11 @@ child_init_thread_list ()
       thread_info *here = th->next;
       th->next = here->next;
       (void) close_handle (here->h);
-      free (here);
+      xfree (here);
     }
 }
 
-/* Delete a thread from the list of threads */
+/* Delete a thread from the list of threads */
 static void
 child_delete_thread (DWORD id)
 {
@@ -883,7 +1132,7 @@ child_delete_thread (DWORD id)
       thread_info *here = th->next;
       th->next = here->next;
       close_handle (here->h);
-      free (here);
+      xfree (here);
     }
 }
 
@@ -891,23 +1140,8 @@ static void
 check (BOOL ok, const char *file, int line)
 {
   if (!ok)
-    printf_filtered ("error return %s:%d was %d\n", file, line, GetLastError ());
-}
-
-/* Return a pointer into a CONTEXT field indexed by gdb register number.
-   Return a pointer to an address pointing to zero if there is no
-   corresponding CONTEXT field for the given register number.
- */
-static ULONG *
-regptr (LPCONTEXT c, int r)
-{
-  static ULONG zero = 0;
-  ULONG *p;
-  if (mappings[r] < 0)
-    p = &zero;
-  else
-    p = (ULONG *) (((char *) c) + mappings[r]);
-  return p;
+    printf_filtered ("error return %s:%d was %d\n", 
+                    file, line, GetLastError ());
 }
 
 static void
@@ -915,7 +1149,8 @@ do_child_fetch_inferior_registers (int r)
 {
   if (r >= 0)
     {
-      supply_register (r, (char *) regptr (&current_thread->context, r));
+      regcache_raw_supply (current_regcache, r,
+                          (char *) regptr (&current_thread->context, r));
     }
   else
     {
@@ -927,7 +1162,7 @@ do_child_fetch_inferior_registers (int r)
 static void
 child_fetch_inferior_registers (int r)
 {
-  current_thread = thread_rec (inferior_pid, TRUE);
+  current_thread = thread_rec (PIDGET (inferior_ptid), TRUE);
   do_child_fetch_inferior_registers (r);
 }
 
@@ -935,7 +1170,7 @@ static void
 do_child_store_inferior_registers (int r)
 {
   if (r >= 0)
-    read_register_gen (r, ((char *) &current_thread->context) + mappings[r]);
+    deprecated_read_register_gen (r, ((char *) &current_thread->context) + mappings[r]);
   else
     {
       for (r = 0; r < NUM_REGS; r++)
@@ -943,11 +1178,11 @@ do_child_store_inferior_registers (int r)
     }
 }
 
-/* Store a new register value into the current thread context */
+/* Store a new register value into the current thread context */
 static void
 child_store_inferior_registers (int r)
 {
-  current_thread = thread_rec (inferior_pid, TRUE);
+  current_thread = thread_rec (PIDGET (inferior_ptid), TRUE);
   do_child_store_inferior_registers (r);
 }
 
@@ -955,7 +1190,7 @@ child_store_inferior_registers (int r)
    of error; store status through argument pointer OURSTATUS.  */
 
 static int
-handle_load_dll (PTR dummy)
+handle_load_dll (void *dummy)
 {
   LOAD_DLL_DEBUG_INFO *event = &current_event.u.LoadDll;
   char dll_buf[MAX_PATH + 1];
@@ -992,7 +1227,9 @@ handle_load_dll (PTR dummy)
 out:
   if (!len)
     return 1;
+#if 0
   dll_buf[len] = '\0';
+#endif
   dll_name = alloca (len);
 
   if (!dll_name)
@@ -1001,14 +1238,14 @@ out:
   if (!event->fUnicode)
     memcpy (dll_name, dll_buf, len);
   else
-    WideCharToMultiByte (CP_ACP, 0, (LPCWSTR) dll_buf, len,
-                        dll_name, len, 0, 0);
+    WideCharToMultiByte (CP_ACP, 0, (LPCWSTR) dll_buf,
+                        len, dll_name, len, 0, 0);
 
   while ((p = strchr (dll_name, '\\')))
     *p = '/';
 
-  /* FIXME!! It would be nice to define one symbol which pointed to the
-     front of the dll if we can't find any symbols. */
+  /* FIXME!! It would be nice to define one symbol which pointed to
+     the front of the dll if we can't find any symbols.  */
 
   if (!(dll_basename = strrchr (dll_name, '/')))
     dll_basename = dll_name;
@@ -1022,22 +1259,12 @@ out:
      FIXME: Is this the real reason that we need the 0x1000 ? */
 
   printf_unfiltered ("%x:%s", event->lpBaseOfDll, dll_name);
-#if 0                          /* FIXME:  Need to use RAPI stuff to read the file someday. */
-  {
-    struct section_addr_info section_addrs;
-    memset (&section_addrs, 0, sizeof (section_addrs));
-    section_addrs.text_addr = (int) event->lpBaseOfDll + 0x1000;
-    symbol_file_add (dll_name, 0, &section_addrs, 0, OBJF_SHARED);
-  }
-#endif
   printf_unfiltered ("\n");
 
   return 1;
 }
 
-/* Handle DEBUG_STRING output from child process.
-   Cygwin prepends its messages with a "cygwin:".  Interpret this as
-   a Cygwin signal.  Otherwise just print the string as a warning. */
+/* Handle DEBUG_STRING output from child process.  */
 static void
 handle_output_debug_string (struct target_waitstatus *ourstatus)
 {
@@ -1058,8 +1285,8 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
     return;
 
   memset (s, 0, sizeof (s));
-  WideCharToMultiByte (CP_ACP, 0, (LPCWSTR) p, (int) nbytes_read, s,
-                      sizeof (s) - 1, NULL, NULL);
+  WideCharToMultiByte (CP_ACP, 0, (LPCWSTR) p, (int) nbytes_read,
+                      s, sizeof (s) - 1, NULL, NULL);
   q = strchr (s, '\n');
   if (q != NULL)
     {
@@ -1069,23 +1296,21 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
     }
 
   warning (s);
+
   return;
 }
 
-/* Handle target exceptions. */
+/* Handle target exceptions.  */
 static int
 handle_exception (struct target_waitstatus *ourstatus)
 {
-  thread_info *th;
-
+#if 0
   if (current_event.u.Exception.dwFirstChance)
     return 0;
+#endif
 
   ourstatus->kind = TARGET_WAITKIND_STOPPED;
 
-  /* Record the context of the current thread */
-  th = thread_rec (current_event.dwThreadId, -1);
-
   switch (current_event.u.Exception.ExceptionRecord.ExceptionCode)
     {
     case EXCEPTION_ACCESS_VIOLATION:
@@ -1107,22 +1332,29 @@ handle_exception (struct target_waitstatus *ourstatus)
       DEBUG_EXCEPT (("gdb: Target exception CONTROL_C at 0x%08x\n",
                     (unsigned) current_event.u.Exception.ExceptionRecord.ExceptionAddress));
       ourstatus->value.sig = TARGET_SIGNAL_INT;
-      /* User typed CTRL-C.  Continue with this status */
-      last_sig = SIGINT;       /* FIXME - should check pass state */
+      /* User typed CTRL-C.  Continue with this status */
+      last_sig = SIGINT;       /* FIXME - should check pass state */
       break;
     case EXCEPTION_SINGLE_STEP:
       DEBUG_EXCEPT (("gdb: Target exception SINGLE_STEP at 0x%08x\n",
                     (unsigned) current_event.u.Exception.ExceptionRecord.ExceptionAddress));
       ourstatus->value.sig = TARGET_SIGNAL_TRAP;
       break;
+    case EXCEPTION_ILLEGAL_INSTRUCTION:
+      DEBUG_EXCEPT (("gdb: Target exception SINGLE_ILL at 0x%08x\n",
+                    /* (unsigned)? */ current_event.u.Exception.ExceptionRecord.ExceptionAddress));
+      ourstatus->value.sig = check_for_step (&current_event, 
+                                            TARGET_SIGNAL_ILL);
+      break;
     default:
       /* This may be a structured exception handling exception.  In
-         that case, we want to let the program try to handle it, and
-         only break if we see the exception a second time.  */
+        that case, we want to let the program try to handle it, and
+        only break if we see the exception a second time.  */
 
-      printf_unfiltered ("gdb: unknown target exception 0x%08x at 0x%08x\n",
-                   current_event.u.Exception.ExceptionRecord.ExceptionCode,
-               current_event.u.Exception.ExceptionRecord.ExceptionAddress);
+      printf_unfiltered 
+       ("gdb: unknown target exception 0x%08x at 0x%08x\n",
+        current_event.u.Exception.ExceptionRecord.ExceptionCode,
+        current_event.u.Exception.ExceptionRecord.ExceptionAddress);
       ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
       break;
     }
@@ -1131,7 +1363,7 @@ handle_exception (struct target_waitstatus *ourstatus)
 }
 
 /* Resume all artificially suspended threads if we are continuing
-   execution */
+   execution */
 static BOOL
 child_continue (DWORD continue_status, int id)
 {
@@ -1140,7 +1372,8 @@ child_continue (DWORD continue_status, int id)
   BOOL res;
 
   DEBUG_EVENTS (("ContinueDebugEvent (cpid=%d, ctid=%d, DBG_CONTINUE);\n",
-                (unsigned) current_event.dwProcessId, (unsigned) current_event.dwThreadId));
+                (unsigned) current_event.dwProcessId, 
+                (unsigned) current_event.dwThreadId));
   res = continue_debug_event (current_event.dwProcessId,
                              current_event.dwThreadId,
                              continue_status);
@@ -1160,23 +1393,29 @@ child_continue (DWORD continue_status, int id)
    handling by WFI (or whatever).
  */
 static int
-get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * event_code, int *retval)
+get_child_debug_event (int pid, struct target_waitstatus *ourstatus,
+                      DWORD target_event_code, int *retval)
 {
+  int breakout = 0;
   BOOL debug_event;
-  DWORD continue_status;
-  int breakout = 1;
+  DWORD continue_status, event_code;
+  thread_info *th = NULL;
+  static thread_info dummy_thread_info;
 
   if (!(debug_event = wait_for_debug_event (&current_event, 1000)))
     {
-      breakout = *retval = *event_code = 0;
+      *retval = 0;
       goto out;
     }
 
-  this_thread = thread_rec (current_event.dwThreadId, FALSE);
   event_count++;
   continue_status = DBG_CONTINUE;
   *retval = 0;
-  switch (*event_code = current_event.dwDebugEventCode)
+
+  event_code = current_event.dwDebugEventCode;
+  breakout = event_code == target_event_code;
+
+  switch (event_code)
     {
     case CREATE_THREAD_DEBUG_EVENT:
       DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%x code=%s)\n",
@@ -1184,8 +1423,8 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * eve
                     (unsigned) current_event.dwThreadId,
                     "CREATE_THREAD_DEBUG_EVENT"));
       /* Record the existence of this thread */
-      child_add_thread (current_event.dwThreadId,
-                       current_event.u.CreateThread.hThread);
+      th = child_add_thread (current_event.dwThreadId,
+                            current_event.u.CreateThread.hThread);
       if (info_verbose)
        printf_unfiltered ("[New %s]\n",
                           target_pid_to_str (current_event.dwThreadId));
@@ -1197,6 +1436,7 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * eve
                     (unsigned) current_event.dwThreadId,
                     "EXIT_THREAD_DEBUG_EVENT"));
       child_delete_thread (current_event.dwThreadId);
+      th = &dummy_thread_info;
       break;
 
     case CREATE_PROCESS_DEBUG_EVENT:
@@ -1206,10 +1446,11 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * eve
                     "CREATE_PROCESS_DEBUG_EVENT"));
       current_process_handle = current_event.u.CreateProcessInfo.hProcess;
 
-      main_thread_id = inferior_pid = current_event.dwThreadId;
+      main_thread_id = current_event.dwThreadId;
+      inferior_ptid = pid_to_ptid (main_thread_id);
       /* Add the main thread */
-      current_thread = child_add_thread (inferior_pid,
-                                current_event.u.CreateProcessInfo.hThread);
+      th = child_add_thread (PIDGET (inferior_ptid),
+                            current_event.u.CreateProcessInfo.hThread);
       break;
 
     case EXIT_PROCESS_DEBUG_EVENT:
@@ -1221,14 +1462,16 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * eve
       ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
       close_handle (current_process_handle);
       *retval = current_event.dwProcessId;
-      goto out;
+      breakout = 1;
+      break;
 
     case LOAD_DLL_DEBUG_EVENT:
       DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
                     (unsigned) current_event.dwProcessId,
                     (unsigned) current_event.dwThreadId,
                     "LOAD_DLL_DEBUG_EVENT"));
-      catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL);
+      catch_errors (handle_load_dll, NULL, 
+                   (char *) "", RETURN_MASK_ALL);
       registers_changed ();    /* mark all regs invalid */
       break;
 
@@ -1245,14 +1488,12 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * eve
                     (unsigned) current_event.dwThreadId,
                     "EXCEPTION_DEBUG_EVENT"));
       if (handle_exception (ourstatus))
+       *retval = current_event.dwThreadId;
+      else
        {
-         char buf[32];
-         *retval = current_event.dwThreadId;
-         remote_read_bytes (read_pc (), buf, sizeof (buf));
-         dcache_xfer_memory (remote_dcache, read_pc (), buf, sizeof (buf), 0);
-         goto out;
+         continue_status = DBG_EXCEPTION_NOT_HANDLED;
+         breakout = 0;
        }
-      continue_status = DBG_EXCEPTION_NOT_HANDLED;
       break;
 
     case OUTPUT_DEBUG_STRING_EVENT:    /* message from the kernel */
@@ -1260,7 +1501,7 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * eve
                     (unsigned) current_event.dwProcessId,
                     (unsigned) current_event.dwThreadId,
                     "OUTPUT_DEBUG_STRING_EVENT"));
-      handle_output_debug_string (ourstatus);
+      handle_output_debug_string ( ourstatus);
       break;
     default:
       printf_unfiltered ("gdb: kernel event for pid=%d tid=%d\n",
@@ -1271,35 +1512,40 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus, DWORD * eve
       break;
     }
 
-  breakout = 0;
-  CHECK (child_continue (continue_status, -1));
+  if (breakout)
+    this_thread = current_thread = th ?: thread_rec (current_event.dwThreadId,
+                                                    TRUE);
+  else
+    CHECK (child_continue (continue_status, -1));
 
 out:
   return breakout;
 }
 
-/* Wait for interesting events to occur in the target process. */
-static int
-child_wait (int pid, struct target_waitstatus *ourstatus)
+/* Wait for interesting events to occur in the target process.  */
+static ptid_t
+child_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
 {
   DWORD event_code;
   int retval;
+  int pid = PIDGET (ptid);
 
   /* We loop when we get a non-standard exception rather than return
      with a SPURIOUS because resume can try and step or modify things,
      which needs a current_thread->h.  But some of these exceptions mark
      the birth or death of threads, which mean that the current thread
-     isn't necessarily what you think it is. */
+     isn't necessarily what you think it is.  */
 
   while (1)
-    if (get_child_debug_event (pid, ourstatus, &event_code, &retval))
-      return retval;
+    if (get_child_debug_event (pid, ourstatus, 
+                              EXCEPTION_DEBUG_EVENT, &retval))
+      return pid_to_ptid (retval);
     else
       {
        int detach = 0;
 
-       if (ui_loop_hook != NULL)
-         detach = ui_loop_hook (0);
+       if (deprecated_ui_loop_hook != NULL)
+         detach = deprecated_ui_loop_hook (0);
 
        if (detach)
          child_kill_inferior ();
@@ -1309,26 +1555,22 @@ child_wait (int pid, struct target_waitstatus *ourstatus)
 /* Print status information about what we're accessing.  */
 
 static void
-child_files_info (ignore)
-     struct target_ops *ignore;
+child_files_info (struct target_ops *ignore)
 {
   printf_unfiltered ("\tUsing the running image of child %s.\n",
-                    target_pid_to_str (inferior_pid));
+                    target_pid_to_str (inferior_ptid));
 }
 
-/* ARGSUSED */
 static void
-child_open (arg, from_tty)
-     char *arg;
-     int from_tty;
+child_open (char *arg, int from_tty)
 {
-  error ("Use the \"run\" command to start a child process.");
+  error (_("Use the \"run\" command to start a child process."));
 }
 
 #define FACTOR (0x19db1ded53ea710LL)
 #define NSPERSEC 10000000
 
-/* Convert a Win32 time to "UNIX" format. */
+/* Convert a Win32 time to "UNIX" format.  */
 long
 to_time_t (FILETIME * ptr)
 {
@@ -1338,96 +1580,109 @@ to_time_t (FILETIME * ptr)
 
   long rem;
   long long x = ((long long) ptr->dwHighDateTime << 32) + ((unsigned) ptr->dwLowDateTime);
-  x -= FACTOR;                 /* number of 100ns between 1601 and 1970 */
+  x -= FACTOR;                 /* Number of 100ns between 1601 and 1970.  */
   rem = x % ((long long) NSPERSEC);
   rem += (NSPERSEC / 2);
-  x /= (long long) NSPERSEC;   /* number of 100ns in a second */
+  x /= (long long) NSPERSEC;   /* Number of 100ns in a second.  */
   x += (long long) (rem / NSPERSEC);
   return x;
 }
 
 /* Upload a file to the remote device depending on the user's
-   'set remoteupload' specification. */
+   'set remoteupload' specification.  */
 char *
 upload_to_device (const char *to, const char *from)
 {
   HANDLE h;
-  const char *dir = remote_directory ? : "\\gdb";
+  const char *dir = remote_directory ?: "\\gdb";
   int len;
   static char *remotefile = NULL;
   LPWSTR wstr;
   char *p;
   DWORD err;
   const char *in_to = to;
-  FILETIME ctime, atime, wtime;
+  FILETIME crtime, actime, wrtime;
+  time_t utime;
   struct stat st;
   int fd;
 
-  /* Look for a path separator and only use trailing part. */
+  /* Look for a path separator and only use trailing part.  */
   while ((p = strpbrk (to, "/\\")) != NULL)
     to = p + 1;
 
   if (!*to)
-    error ("no filename found to upload - %s.", in_to);
+    error (_("no filename found to upload - %s."), in_to);
 
   len = strlen (dir) + strlen (to) + 2;
-  remotefile = (char *) realloc (remotefile, len);
+  remotefile = (char *) xrealloc (remotefile, len);
   strcpy (remotefile, dir);
   strcat (remotefile, "\\");
   strcat (remotefile, to);
 
   if (upload_when == UPLOAD_NEVER)
-    return remotefile;         /* Don't bother uploading. */
+    return remotefile;         /* Don't bother uploading.  */
 
-  /* Open the source. */
-  if ((fd = openp (getenv ("PATH"), TRUE, (char *) from, O_RDONLY, 0, NULL)) < 0)
-    error ("couldn't open %s", from);
+  /* Open the source.  */
+  if ((fd = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, (char *) from,
+                  O_RDONLY, 0, NULL)) < 0)
+    error (_("couldn't open %s"), from);
 
-  /* Get the time for later comparison. */
+  /* Get the time for later comparison.  */
   if (fstat (fd, &st))
     st.st_mtime = (time_t) - 1;
 
-  /* Always attempt to create the directory on the remote system. */
+  /* Always attempt to create the directory on the remote system.  */
   wstr = towide (dir, NULL);
   (void) CeCreateDirectory (wstr, NULL);
 
-  /* Attempt to open the remote file, creating it if it doesn't exist. */
+  /* Attempt to open the remote file, creating it if it doesn't exist.  */
   wstr = towide (remotefile, NULL);
   h = CeCreateFile (wstr, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                    OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 
-  /* Some kind of problem? */
+  /* Some kind of problem?  */
   err = CeGetLastError ();
-  if (h == NULL)
-    error ("error creating file to \"%s\".  Windows error %d.",
+  if (h == NULL || h == INVALID_HANDLE_VALUE)
+    error (_("error opening file \"%s\".  Windows error %d."),
           remotefile, err);
 
-  /* See if we need to upload the file. */
+  CeGetFileTime (h, &crtime, &actime, &wrtime);
+  utime = to_time_t (&wrtime);
+#if 0
+  if (utime < st.st_mtime)
+    {
+      char buf[80];
+      strcpy (buf, ctime(&utime));
+      printf ("%s < %s\n", buf, ctime(&st.st_mtime));
+    }
+#endif
+  /* See if we need to upload the file.  */
   if (upload_when == UPLOAD_ALWAYS ||
       err != ERROR_ALREADY_EXISTS ||
-      !CeGetFileTime (h, &ctime, &atime, &wtime) ||
-      to_time_t (&wtime) < st.st_mtime)
+      !CeGetFileTime (h, &crtime, &actime, &wrtime) ||
+      to_time_t (&wrtime) < st.st_mtime)
     {
       DWORD nbytes;
       char buf[4096];
       int n;
 
-      /* Upload the file. */
+      /* Upload the file.  */
       while ((n = read (fd, buf, sizeof (buf))) > 0)
        if (!CeWriteFile (h, buf, (DWORD) n, &nbytes, NULL))
-         error ("error writing to remote device - %d.",
+         error (_("error writing to remote device - %d."),
                 CeGetLastError ());
     }
 
   close (fd);
-  CeCloseHandle (h);
+  if (!CeCloseHandle (h))
+    error (_("error closing remote file - %d."), CeGetLastError ());
 
   return remotefile;
 }
 
-/* Initialize the connection to the remote device. */
+/* Initialize the connection to the remote device.  */
 static void
-wince_initialize ()
+wince_initialize (void)
 {
   int tmp;
   char args[256];
@@ -1445,11 +1700,10 @@ wince_initialize ()
        break;
       default:
        CeRapiUninit ();
-       error ("Can't initialize connection to remote device.\n");
-       break;
+       error (_("Can't initialize connection to remote device."));
       }
 
-  /* Upload the stub to the handheld device. */
+  /* Upload the stub to the handheld device.  */
   stub_file_name = upload_to_device ("wince-stub.exe", WINCE_STUB);
   strcpy (args, stub_file_name);
 
@@ -1458,49 +1712,54 @@ wince_initialize ()
       strcat (args, " ");
       hostname = strchr (args, '\0');
       if (gethostname (hostname, sizeof (args) - strlen (args)))
-       error ("couldn't get hostname of this system.");
+       error (_("couldn't get hostname of this system."));
     }
 
-  /* Get a socket. */
+  /* Get a socket.  */
   if ((s0 = socket (AF_INET, SOCK_STREAM, 0)) < 0)
     stub_error ("Couldn't connect to host system.");
 
-  /* Allow rapid reuse of the port. */
+  /* Allow rapid reuse of the port.  */
   tmp = 1;
-  (void) setsockopt (s0, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof (tmp));
+  (void) setsockopt (s0, SOL_SOCKET, SO_REUSEADDR, 
+                    (char *) &tmp, sizeof (tmp));
 
 
-  /* Set up the information for connecting to the host gdb process. */
+  /* Set up the information for connecting to the host gdb process.  */
   memset (&sin, 0, sizeof (sin));
   sin.sin_family = AF_INET;
-  sin.sin_port = htons (7000); /* FIXME: This should be configurable */
+  sin.sin_port = htons (7000); /* FIXME: This should be configurable */
 
   if (bind (s0, (struct sockaddr *) &sin, sizeof (sin)))
-    error ("couldn't bind socket");
+    error (_("couldn't bind socket"));
 
   if (listen (s0, 1))
-    error ("Couldn't open socket for listening.\n");
-
-  /* Start up the stub on the remote device. */
-  if (!CeCreateProcess (towide (stub_file_name, NULL), towide (args, NULL),
-                       NULL, NULL, 0, 0, NULL, NULL, NULL, &pi))
-    error ("Unable to start remote stub '%s'.  Windows CE error %d.",
+    error (_("Couldn't open socket for listening."));
+
+  /* Start up the stub on the remote device.  */
+  if (!CeCreateProcess (towide (stub_file_name, NULL), 
+                       towide (args, NULL),
+                       NULL, NULL, 0, 0, 
+                       NULL, NULL, NULL, &pi))
+    error (_("Unable to start remote stub '%s'.  Windows CE error %d."),
           stub_file_name, CeGetLastError ());
 
   /* Wait for a connection */
 
   if ((s = accept (s0, NULL, NULL)) < 0)
-    error ("couldn't set up server for connection.");
+    error (_("couldn't set up server for connection."));
 
   close (s0);
 }
 
-/* Start an inferior win32 child process and sets inferior_pid to its pid.
+/* Start an inferior win32 child process and sets inferior_ptid to its pid.
    EXEC_FILE is the file to run.
    ALLARGS is a string containing the arguments to the program.
-   ENV is the environment vector to pass.  Errors reported with error().  */
+   ENV is the environment vector to pass.  
+   Errors reported with error().  */
 static void
-child_create_inferior (char *exec_file, char *args, char **env)
+child_create_inferior (char *exec_file, char *args, char **env,
+                      int from_tty)
 {
   PROCESS_INFORMATION pi;
   struct target_waitstatus dummy;
@@ -1509,15 +1768,11 @@ child_create_inferior (char *exec_file, char *args, char **env)
   char *exec_and_args;
 
   if (!exec_file)
-    error ("No executable specified, use `target exec'.\n");
+    error (_("No executable specified, use `target exec'."));
 
   flags = DEBUG_PROCESS;
 
-  wince_initialize ();         /* Make sure we've got a connection. */
-  if (!remote_dcache)
-    remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
-  else
-    dcache_flush (remote_dcache);
+  wince_initialize ();         /* Make sure we've got a connection.  */
 
   exec_file = upload_to_device (exec_file, exec_file);
 
@@ -1537,9 +1792,10 @@ child_create_inferior (char *exec_file, char *args, char **env)
     }
 
   memset (&pi, 0, sizeof (pi));
-  /* Execute the process */
+  /* Execute the process */
   if (!create_process (exec_file, exec_and_args, flags, &pi))
-    error ("Error creating process %s, (error %d)\n", exec_file, GetLastError ());
+    error (_("Error creating process %s, (error %d)."), 
+          exec_file, GetLastError ());
 
   exception_count = 0;
   event_count = 0;
@@ -1547,8 +1803,9 @@ child_create_inferior (char *exec_file, char *args, char **env)
   current_process_handle = pi.hProcess;
   current_event.dwProcessId = pi.dwProcessId;
   memset (&current_event, 0, sizeof (current_event));
-  inferior_pid = current_event.dwThreadId = pi.dwThreadId;
-  push_target (&child_ops);
+  current_event.dwThreadId = pi.dwThreadId;
+  inferior_ptid = pid_to_ptid (current_event.dwThreadId);
+  push_target (&deprecated_child_ops);
   child_init_thread_list ();
   child_add_thread (pi.dwThreadId, pi.hThread);
   init_wait_for_inferior ();
@@ -1556,38 +1813,44 @@ child_create_inferior (char *exec_file, char *args, char **env)
   target_terminal_init ();
   target_terminal_inferior ();
 
-
   /* Run until process and threads are loaded */
-  do
-    get_child_debug_event (inferior_pid, &dummy, &event_code, &ret);
-  while (event_code != CREATE_PROCESS_DEBUG_EVENT);
-
-  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
+  while (!get_child_debug_event (PIDGET (inferior_ptid), &dummy,
+                                CREATE_PROCESS_DEBUG_EVENT, &ret))
+    continue;
 }
 
-/* Chile has gone bye-bye. */
+/* Chile has gone bye-bye.  */
 static void
-child_mourn_inferior ()
+child_mourn_inferior (void)
 {
   (void) child_continue (DBG_CONTINUE, -1);
-  unpush_target (&child_ops);
+  unpush_target (&deprecated_child_ops);
   stop_stub ();
   CeRapiUninit ();
   connection_initialized = 0;
   generic_mourn_inferior ();
 }
 
-/* Move memory from child to/from gdb. */
+/* Move memory from child to/from gdb.  */
 int
-child_xfer_memory (CORE_ADDR memaddr, char *our, int len,
-                  int write, struct target_ops *target)
+child_xfer_memory (CORE_ADDR memaddr, gdb_byte *our, 
+                  int len, int write,
+                  struct mem_attrib *attrib,
+                  struct target_ops *target)
 {
   if (len <= 0)
     return 0;
-  return dcache_xfer_memory (remote_dcache, memaddr, our, len, write);
+
+  if (write)
+    res = remote_write_bytes (memaddr, our, len);
+  else
+    res = remote_read_bytes (memaddr, our, len);
+
+  return res;
 }
 
-/* Terminate the process and wait for child to tell us it has completed. */
+/* Terminate the process and wait for child to tell us it has
+   completed.  */
 void
 child_kill_inferior (void)
 {
@@ -1605,223 +1868,17 @@ child_kill_inferior (void)
 
   CHECK (close_handle (current_process_handle));
   close_handle (current_thread->h);
-  target_mourn_inferior ();    /* or just child_mourn_inferior? */
-}
-
-#ifdef MIPS
-static void
-undoSStep (thread_info * th)
-{
-  if (th->stepped)
-    {
-      memory_remove_breakpoint (th->step_pc, (void *) &th->step_prev);
-      th->stepped = 0;
-    }
+  target_mourn_inferior ();    /* or just child_mourn_inferior?  */
 }
 
+/* Resume the child after an exception.  */
 void
-wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
-{
-  unsigned long pc;
-  thread_info *th = current_thread;    /* Info on currently selected thread */
-  CORE_ADDR mips_next_pc (CORE_ADDR pc);
-
-  if (!insert_breakpoints_p)
-    {
-      undoSStep (th);
-      return;
-    }
-
-  th->stepped = 1;
-  pc = read_register (PC_REGNUM);
-  th->step_pc = mips_next_pc (pc);
-  th->step_prev = 0;
-  memory_insert_breakpoint (th->step_pc, (void *) &th->step_prev);
-}
-#elif SHx
-/* Hitachi SH architecture instruction encoding masks */
-
-#define COND_BR_MASK   0xff00
-#define UCOND_DBR_MASK 0xe000
-#define UCOND_RBR_MASK 0xf0df
-#define TRAPA_MASK     0xff00
-
-#define COND_DISP      0x00ff
-#define UCOND_DISP     0x0fff
-#define UCOND_REG      0x0f00
-
-/* Hitachi SH instruction opcodes */
-
-#define BF_INSTR       0x8b00
-#define BT_INSTR       0x8900
-#define BRA_INSTR      0xa000
-#define BSR_INSTR      0xb000
-#define JMP_INSTR      0x402b
-#define JSR_INSTR      0x400b
-#define RTS_INSTR      0x000b
-#define RTE_INSTR      0x002b
-#define TRAPA_INSTR    0xc300
-#define SSTEP_INSTR    0xc3ff
-
-
-#define T_BIT_MASK     0x0001
-
-/* Undo the effect of a previous doSStep.  If we single stepped,
-   restore the old instruction. */
-
-static void
-undoSStep (thread_info * th)
-{
-  if (th->stepped)
-    {
-      gdb_wince_len done;
-      write_process_memory (current_process_handle, (LPVOID) th->step_pc,
-                         (LPVOID) & th->step_instr, sizeof (short), &done);
-      if (done != sizeof (short))
-         error ("error unsetting single step.");
-      th->stepped = 0;
-    }
-}
-
-/* Single step (in a painstaking fashion) by inspecting the current
-   instruction and setting a breakpoint on the "next" instruction
-   which would be executed.  This code hails from sh-stub.c.
- */
-void
-wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
-{
-  thread_info *th = current_thread;    /* Info on currently selected thread */
-
-  if (!insert_breakpoints_p)
-    undoSStep (th);
-  else
-    {
-      short *instrMem;
-      int displacement;
-      int reg;
-      unsigned short opcode;
-      gdb_wince_len done;
-      LPCONTEXT c = &th->context;
-
-      instrMem = (short *) c->Fir;
-
-      read_process_memory (current_process_handle, (LPCVOID) c->Fir, &opcode,
-                          sizeof (opcode), &done);
-      if (done != sizeof (opcode))
-       error ("couldn't retrieve opcode");
-      th->stepped = 1;
-
-      if ((opcode & COND_BR_MASK) == BT_INSTR)
-       {
-         if (c->Psr & T_BIT_MASK)
-           {
-             displacement = (opcode & COND_DISP) << 1;
-             if (displacement & 0x80)
-               displacement |= 0xffffff00;
-             /*
-                * Remember PC points to second instr.
-                * after PC of branch ... so add 4
-              */
-             instrMem = (short *) (c->Fir + displacement + 4);
-           }
-         else
-           instrMem += 1;
-       }
-      else if ((opcode & COND_BR_MASK) == BF_INSTR)
-       {
-         if (c->Psr & T_BIT_MASK)
-           instrMem += 1;
-         else
-           {
-             displacement = (opcode & COND_DISP) << 1;
-             if (displacement & 0x80)
-               displacement |= 0xffffff00;
-             /*
-                * Remember PC points to second instr.
-                * after PC of branch ... so add 4
-              */
-             instrMem = (short *) (c->Fir + displacement + 4);
-           }
-       }
-      else if ((opcode & UCOND_DBR_MASK) == BRA_INSTR)
-       {
-         displacement = (opcode & UCOND_DISP) << 1;
-         if (displacement & 0x0800)
-           displacement |= 0xfffff000;
-
-         /*
-            * Remember PC points to second instr.
-            * after PC of branch ... so add 4
-          */
-         instrMem = (short *) (c->Fir + displacement + 4);
-       }
-      else if ((opcode & UCOND_RBR_MASK) == JSR_INSTR)
-       {
-         reg = (char) ((opcode & UCOND_REG) >> 8);
-
-         instrMem = (short *) *regptr (c, reg);
-       }
-      else if (opcode == RTS_INSTR)
-       instrMem = (short *) c->PR;
-      else if (opcode == RTE_INSTR)
-       instrMem = (short *) *regptr (c, 15);
-      else if ((opcode & TRAPA_MASK) == TRAPA_INSTR)
-       instrMem = (short *) ((opcode & ~TRAPA_MASK) << 2);
-      else
-       instrMem += 1;
-
-      th->step_pc = (CORE_ADDR) instrMem;
-
-      read_process_memory (current_process_handle, (LPVOID) instrMem,
-                          (LPVOID) & th->step_instr, sizeof (short), &done);
-      opcode = SSTEP_INSTR;
-      write_process_memory (current_process_handle, (LPVOID) instrMem,
-                           (LPVOID) & opcode, sizeof (short), &done);
-    }
-}
-#elif defined (ARM)
-/* Single step (in a painstaking fashion) by inspecting the current
-   instruction and setting a breakpoint on the "next" instruction
-   which would be executed.  This code hails from sh-stub.c.
- */
-static void
-undoSStep (thread_info * th)
-{
-  if (th->stepped)
-    {
-      memory_remove_breakpoint (th->step_pc, (void *) &th->step_prev);
-      th->stepped = 0;
-    }
-}
-
-void
-wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
-{
-  unsigned long pc;
-  thread_info *th = current_thread;    /* Info on currently selected thread */
-  CORE_ADDR mips_next_pc (CORE_ADDR pc);
-
-  if (!insert_breakpoints_p)
-    {
-      undoSStep (th);
-      return;
-    }
-
-  th->stepped = 1;
-  pc = read_register (PC_REGNUM);
-  th->step_pc = arm_get_next_pc (pc);
-  th->step_prev = 0;
-  memory_insert_breakpoint (th->step_pc, (void *) &th->step_prev);
-}
-#endif
-
-/* Resume the child after an exception. */
-void
-child_resume (int pid, int step, enum target_signal sig)
+child_resume (ptid_t ptid, int step, enum target_signal sig)
 {
   thread_info *th;
   DWORD continue_status = last_sig > 0 && last_sig < NSIG ?
-  DBG_EXCEPTION_NOT_HANDLED : DBG_CONTINUE;
+    DBG_EXCEPTION_NOT_HANDLED : DBG_CONTINUE;
+  int pid = PIDGET (ptid);
 
   DEBUG_EXEC (("gdb: child_resume (pid=%d, step=%d, sig=%d);\n",
               pid, step, sig));
@@ -1835,33 +1892,34 @@ child_resume (int pid, int step, enum target_signal sig)
       th->context.ContextFlags = 0;
     }
 
-  dcache_flush (remote_dcache);
-
   /* Allow continuing with the same signal that interrupted us.
-     Otherwise complain. */
+     Otherwise complain.  */
   if (sig && sig != last_sig)
-    fprintf_unfiltered (gdb_stderr, "Can't send signals to the child.  signal %d\n", sig);
+    fprintf_unfiltered (gdb_stderr, 
+                       "Can't send signals to the child.  signal %d\n", 
+                       sig);
 
   last_sig = 0;
   child_continue (continue_status, pid);
 }
 
 static void
-child_prepare_to_store ()
+child_prepare_to_store (void)
 {
   /* Do nothing, since we can store individual regs */
 }
 
 static int
-child_can_run ()
+child_can_run (void)
 {
   return 1;
 }
 
 static void
-child_close ()
+child_close (void)
 {
-  DEBUG_EVENTS (("gdb: child_close, inferior_pid=%d\n", inferior_pid));
+  DEBUG_EVENTS (("gdb: child_close, inferior_ptid=%d\n",
+                PIDGET (inferior_ptid)));
 }
 
 /* Explicitly upload file to remotedir */
@@ -1872,55 +1930,53 @@ child_load (char *file, int from_tty)
   upload_to_device (file, file);
 }
 
-struct target_ops child_ops;
-
 static void
 init_child_ops (void)
 {
-  memset (&child_ops, 0, sizeof (child_ops));
-  child_ops.to_shortname = (char *) "child";
-  child_ops.to_longname = (char *) "Windows CE process";
-  child_ops.to_doc = (char *) "Windows CE process (started by the \"run\" command).";
-  child_ops.to_open = child_open;
-  child_ops.to_close = child_close;
-  child_ops.to_resume = child_resume;
-  child_ops.to_wait = child_wait;
-  child_ops.to_fetch_registers = child_fetch_inferior_registers;
-  child_ops.to_store_registers = child_store_inferior_registers;
-  child_ops.to_prepare_to_store = child_prepare_to_store;
-  child_ops.to_xfer_memory = child_xfer_memory;
-  child_ops.to_files_info = child_files_info;
-  child_ops.to_insert_breakpoint = memory_insert_breakpoint;
-  child_ops.to_remove_breakpoint = memory_remove_breakpoint;
-  child_ops.to_terminal_init = terminal_init_inferior;
-  child_ops.to_terminal_inferior = terminal_inferior;
-  child_ops.to_terminal_ours_for_output = terminal_ours_for_output;
-  child_ops.to_terminal_ours = terminal_ours;
-  child_ops.to_terminal_info = child_terminal_info;
-  child_ops.to_kill = child_kill_inferior;
-  child_ops.to_load = child_load;
-  child_ops.to_create_inferior = child_create_inferior;
-  child_ops.to_mourn_inferior = child_mourn_inferior;
-  child_ops.to_can_run = child_can_run;
-  child_ops.to_thread_alive = win32_child_thread_alive;
-  child_ops.to_stratum = process_stratum;
-  child_ops.to_has_all_memory = 1;
-  child_ops.to_has_memory = 1;
-  child_ops.to_has_stack = 1;
-  child_ops.to_has_registers = 1;
-  child_ops.to_has_execution = 1;
-  child_ops.to_sections = 0;
-  child_ops.to_sections_end = 0;
-  child_ops.to_magic = OPS_MAGIC;
-}
-
-
-/* Handle 'set remoteupload' parameter. */
+  memset (&deprecated_child_ops, 0, sizeof (deprecated_child_ops));
+  deprecated_child_ops.to_shortname = (char *) "child";
+  deprecated_child_ops.to_longname = (char *) "Windows CE process";
+  deprecated_child_ops.to_doc = (char *) "Windows CE process (started by the \"run\" command).";
+  deprecated_child_ops.to_open = child_open;
+  deprecated_child_ops.to_close = child_close;
+  deprecated_child_ops.to_resume = child_resume;
+  deprecated_child_ops.to_wait = child_wait;
+  deprecated_child_ops.to_fetch_registers = child_fetch_inferior_registers;
+  deprecated_child_ops.to_store_registers = child_store_inferior_registers;
+  deprecated_child_ops.to_prepare_to_store = child_prepare_to_store;
+  deprecated_child_ops.deprecated_xfer_memory = child_xfer_memory;
+  deprecated_child_ops.to_files_info = child_files_info;
+  deprecated_child_ops.to_insert_breakpoint = memory_insert_breakpoint;
+  deprecated_child_ops.to_remove_breakpoint = memory_remove_breakpoint;
+  deprecated_child_ops.to_terminal_init = terminal_init_inferior;
+  deprecated_child_ops.to_terminal_inferior = terminal_inferior;
+  deprecated_child_ops.to_terminal_ours_for_output = terminal_ours_for_output;
+  deprecated_child_ops.to_terminal_ours = terminal_ours;
+  deprecated_child_ops.to_terminal_save_ours = terminal_save_ours;
+  deprecated_child_ops.to_terminal_info = child_terminal_info;
+  deprecated_child_ops.to_kill = child_kill_inferior;
+  deprecated_child_ops.to_load = child_load;
+  deprecated_child_ops.to_create_inferior = child_create_inferior;
+  deprecated_child_ops.to_mourn_inferior = child_mourn_inferior;
+  deprecated_child_ops.to_can_run = child_can_run;
+  deprecated_child_ops.to_thread_alive = win32_child_thread_alive;
+  deprecated_child_ops.to_stratum = process_stratum;
+  deprecated_child_ops.to_has_all_memory = 1;
+  deprecated_child_ops.to_has_memory = 1;
+  deprecated_child_ops.to_has_stack = 1;
+  deprecated_child_ops.to_has_registers = 1;
+  deprecated_child_ops.to_has_execution = 1;
+  deprecated_child_ops.to_magic = OPS_MAGIC;
+}
+
+
+/* Handle 'set remoteupload' parameter.  */
 
 #define replace_upload(what) \
-      upload_when = UPLOAD_NEWER; \
-      remote_upload = realloc (remote_upload, strlen (upload_options[upload_when].name)); \
-      strcpy (remote_upload, upload_options[upload_when].name);
+    upload_when = what; \
+    remote_upload = xrealloc (remote_upload, \
+                             strlen (upload_options[upload_when].name) + 1); \
+    strcpy (remote_upload, upload_options[upload_when].name);
 
 static void
 set_upload_type (char *ignore, int from_tty)
@@ -1937,91 +1993,98 @@ set_upload_type (char *ignore, int from_tty)
     }
 
   len = strlen (remote_upload);
-  for (i = 0; i < (sizeof (upload_options) / sizeof (upload_options[0])); i++)
+  for (i = 0; 
+       i < (sizeof (upload_options) / sizeof (upload_options[0])); 
+       i++)
     if (len >= upload_options[i].abbrev &&
        strncasecmp (remote_upload, upload_options[i].name, len) == 0)
       {
-       remote_upload = (char *) upload_options[i].name;
-       upload_when = i;
+       replace_upload (i);
        return;
       }
 
   bad_option = remote_upload;
   replace_upload (UPLOAD_NEWER);
-  error ("Unknown upload type: %s.", bad_option);
+  error (_("Unknown upload type: %s."), bad_option);
 }
 
 void
-_initialize_inftarg ()
+_initialize_wince (void)
 {
   struct cmd_list_element *set;
   init_child_ops ();
 
-  add_show_from_set
-    (add_set_cmd ((char *) "remotedirectory", no_class,
-                 var_string_noescape, (char *) &remote_directory,
-                 (char *) "Set directory for remote upload.\n",
-                 &setlist),
-     &showlist);
+  add_setshow_string_noescape_cmd ("remotedirectory", no_class,
+                                  &remote_directory, _("\
+Set directory for remote upload."), _("\
+Show directory for remote upload."), NULL,
+                                  NULL, /* FIXME: i18n: */
+                                  NULL, NULL,
+                                  &setlist, &showlist);
   remote_directory = xstrdup (remote_directory);
 
-  set = add_set_cmd ((char *) "remoteupload", no_class,
-                    var_string_noescape, (char *) &remote_upload,
-              (char *) "Set how to upload executables to remote device.\n",
-                    &setlist);
-  add_show_from_set (set, &showlist);
-  set->function.cfunc = set_upload_type;
+  add_setshow_string_noescape_cmd ("remoteupload", no_class,
+                                  &remote_upload, _("\
+Set how to upload executables to remote device."), _("\
+Show how to upload executables to remote device."), NULL,
+                                  NULL, /* FIXME: i18n: */
+                                  set_upload_type, NULL,
+                                  &setlist, &showlist);
   set_upload_type (NULL, 0);
-  set_dcache_state (1);
-
-  add_show_from_set
-    (add_set_cmd ((char *) "debugexec", class_support, var_boolean,
-                 (char *) &debug_exec,
-             (char *) "Set whether to display execution in child process.",
-                 &setlist),
-     &showlist);
-
-  add_show_from_set
-    (add_set_cmd ((char *) "remoteaddhost", class_support, var_boolean,
-                 (char *) &remote_add_host,
-                 (char *) "Set whether to add this host to remote stub arguments for\n
-debugging over a network.", &setlist),
-     &showlist);
-
-  add_show_from_set
-    (add_set_cmd ((char *) "debugevents", class_support, var_boolean,
-                 (char *) &debug_events,
-         (char *) "Set whether to display kernel events in child process.",
-                 &setlist),
-     &showlist);
-
-  add_show_from_set
-    (add_set_cmd ((char *) "debugmemory", class_support, var_boolean,
-                 (char *) &debug_memory,
-       (char *) "Set whether to display memory accesses in child process.",
-                 &setlist),
-     &showlist);
-
-  add_show_from_set
-    (add_set_cmd ((char *) "debugexceptions", class_support, var_boolean,
-                 (char *) &debug_exceptions,
-      (char *) "Set whether to display kernel exceptions in child process.",
-                 &setlist),
-     &showlist);
-
-  add_target (&child_ops);
-}
-
-/* Determine if the thread referenced by "pid" is alive
-   by "polling" it.  If WaitForSingleObject returns WAIT_OBJECT_0
-   it means that the pid has died.  Otherwise it is assumed to be alive. */
+
+  add_setshow_boolean_cmd ("debugexec", class_support, &debug_exec, _("\
+Set whether to display execution in child process."), _("\
+Show whether to display execution in child process."), NULL,
+                          NULL,
+                          NULL, /* FIXME: i18n: */
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("remoteaddhost", class_support,
+                          &remote_add_host, _("\
+Set whether to add this host to remote stub arguments for\n\
+debugging over a network."), _("\
+Show whether to add this host to remote stub arguments for\n\
+debugging over a network."), NULL,
+                          NULL,
+                          NULL, /* FIXME: i18n: */
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("debugevents", class_support, &debug_events, _("\
+Set whether to display kernel events in child process."), _("\
+Show whether to display kernel events in child process."), NULL,
+                          NULL,
+                          NULL, /* FIXME: i18n: */
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("debugmemory", class_support, &debug_memory, _("\
+Set whether to display memory accesses in child process."), _("\
+Show whether to display memory accesses in child process."), NULL,
+                          NULL,
+                          NULL, /* FIXME: i18n: */
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("debugexceptions", class_support,
+                          &debug_exceptions, _("\
+Set whether to display kernel exceptions in child process."), _("\
+Show whether to display kernel exceptions in child process."), NULL,
+                          NULL,
+                          NULL, /* FIXME: i18n: */
+                          &setlist, &showlist);
+
+  add_target (&deprecated_child_ops);
+}
+
+/* Determine if the thread referenced by "pid" is alive by "polling"
+   it.  If WaitForSingleObject returns WAIT_OBJECT_0 it means that the
+   pid has died.  Otherwise it is assumed to be alive.  */
 static int
-win32_child_thread_alive (int pid)
+win32_child_thread_alive (ptid_t ptid)
 {
+  int pid = PIDGET (ptid);
   return thread_alive (thread_rec (pid, FALSE)->h);
 }
 
-/* Convert pid to printable format. */
+/* Convert pid to printable format.  */
 char *
 cygwin_pid_to_str (int pid)
 {
@@ -2029,6 +2092,7 @@ cygwin_pid_to_str (int pid)
   if (pid == current_event.dwProcessId)
     sprintf (buf, "process %d", pid);
   else
-    sprintf (buf, "thread %d.0x%x", (unsigned) current_event.dwProcessId, pid);
+    sprintf (buf, "thread %d.0x%x", 
+            (unsigned) current_event.dwProcessId, pid);
   return buf;
 }
This page took 0.049152 seconds and 4 git commands to generate.