* hppa-hpux-tdep.c: Update copyright notice and year.
[deliverable/binutils-gdb.git] / gdb / wince.c
index 3b4f67cb3eed011437b0e4790726c60c830a00e4..0397bd45c013fec2e2e7cc55aee4dd66e51f992b 100644 (file)
@@ -1,5 +1,6 @@
 /* Target-vector operations for controlling Windows CE child processes, for GDB.
-   Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+
+   Copyright 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
    Contributed by Cygnus Solutions, A Red Hat Company.
 
    This file is part of GDB.
@@ -56,9 +57,9 @@
 #include "wince-stub.h"
 #include <time.h>
 #include "regcache.h"
-
-/* The ui's event loop. */
-extern int (*ui_loop_hook) (int signo);
+#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
@@ -126,10 +127,7 @@ upload_options[3] =
 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 (int);
+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
@@ -602,10 +600,10 @@ towide (const char *s, gdb_wince_len * out_len)
     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
+     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];
@@ -809,7 +807,8 @@ undoSStep (thread_info * th)
 }
 
 void
-wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
+wince_software_single_step (enum target_signal ignore,
+                           int insert_breakpoints_p)
 {
   unsigned long pc;
   thread_info *th = current_thread;    /* Info on currently selected thread */
@@ -829,7 +828,7 @@ wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
   return;
 }
 #elif SHx
-/* Hitachi SH architecture instruction encoding masks */
+/* Renesas SH architecture instruction encoding masks */
 
 #define COND_BR_MASK   0xff00
 #define UCOND_DBR_MASK 0xe000
@@ -840,7 +839,7 @@ wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
 #define UCOND_DISP     0x0fff
 #define UCOND_REG      0x0f00
 
-/* Hitachi SH instruction opcodes */
+/* Renesas SH instruction opcodes */
 
 #define BF_INSTR       0x8b00
 #define BT_INSTR       0x8900
@@ -949,7 +948,8 @@ undoSStep (thread_info * th)
    which would be executed.  This code hails from sh-stub.c.
  */
 void
-wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
+wince_software_single_step (enum target_signal ignore,
+                           int insert_breakpoints_p)
 {
   thread_info *th = current_thread;    /* Info on currently selected thread */
 
@@ -995,7 +995,8 @@ undoSStep (thread_info * th)
 }
 
 void
-wince_software_single_step (unsigned int ignore, int insert_breakpoints_p)
+wince_software_single_step (enum target_signal ignore,
+                           int insert_breakpoints_p)
 {
   unsigned long pc;
   thread_info *th = current_thread;    /* Info on currently selected thread */
@@ -1116,7 +1117,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
     {
@@ -1128,7 +1130,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);
 }
 
@@ -1136,7 +1138,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++)
@@ -1148,7 +1150,7 @@ do_child_store_inferior_registers (int r)
 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);
 }
 
@@ -1156,7 +1158,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];
@@ -1409,9 +1411,10 @@ get_child_debug_event (int pid, struct target_waitstatus *ourstatus,
                     "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 */
-      th = child_add_thread (inferior_pid,
+      th = child_add_thread (PIDGET (inferior_ptid),
                             current_event.u.CreateProcessInfo.hThread);
       break;
 
@@ -1483,11 +1486,12 @@ out:
 }
 
 /* Wait for interesting events to occur in the target process. */
-static int
-child_wait (int pid, struct target_waitstatus *ourstatus)
+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,
@@ -1497,13 +1501,13 @@ child_wait (int pid, struct target_waitstatus *ourstatus)
 
   while (1)
     if (get_child_debug_event (pid, ourstatus, EXCEPTION_DEBUG_EVENT, &retval))
-      return 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 ();
@@ -1516,10 +1520,9 @@ static void
 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 (char *arg, int from_tty)
 {
@@ -1573,7 +1576,7 @@ upload_to_device (const char *to, const char *from)
     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);
@@ -1582,7 +1585,8 @@ upload_to_device (const char *to, const char *from)
     return remotefile;         /* Don't bother uploading. */
 
   /* Open the source. */
-  if ((fd = openp (getenv ("PATH"), TRUE, (char *) from, O_RDONLY, 0, NULL)) < 0)
+  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. */
@@ -1708,12 +1712,13 @@ wince_initialize (void)
   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().  */
 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;
@@ -1756,8 +1761,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 ();
@@ -1766,7 +1772,7 @@ child_create_inferior (char *exec_file, char *args, char **env)
   target_terminal_inferior ();
 
   /* Run until process and threads are loaded */
-  while (!get_child_debug_event (inferior_pid, &dummy,
+  while (!get_child_debug_event (PIDGET (inferior_ptid), &dummy,
                                 CREATE_PROCESS_DEBUG_EVENT, &ret))
     continue;
 
@@ -1778,7 +1784,7 @@ static void
 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;
@@ -1787,8 +1793,9 @@ child_mourn_inferior (void)
 
 /* 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, char *our, int len, int write,
+                  struct mem_attrib *attrib,
+                  struct target_ops *target)
 {
   if (len <= 0)
     return 0;
@@ -1824,11 +1831,12 @@ child_kill_inferior (void)
 
 /* 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;
+  int pid = PIDGET (ptid);
 
   DEBUG_EXEC (("gdb: child_resume (pid=%d, step=%d, sig=%d);\n",
               pid, step, sig));
@@ -1866,7 +1874,8 @@ child_can_run (void)
 static void
 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 */
@@ -1877,46 +1886,43 @@ 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;
+  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;
 }
 
 
@@ -1924,7 +1930,7 @@ init_child_ops (void)
 
 #define replace_upload(what) \
       upload_when = what; \
-      remote_upload = realloc (remote_upload, strlen (upload_options[upload_when].name) + 1); \
+      remote_upload = xrealloc (remote_upload, strlen (upload_options[upload_when].name) + 1); \
       strcpy (remote_upload, upload_options[upload_when].name);
 
 static void
@@ -1956,12 +1962,12 @@ set_upload_type (char *ignore, int from_tty)
 }
 
 void
-_initialize_inftarg (void)
+_initialize_wince (void)
 {
   struct cmd_list_element *set;
   init_child_ops ();
 
-  add_show_from_set
+  deprecated_add_show_from_set
     (add_set_cmd ((char *) "remotedirectory", no_class,
                  var_string_noescape, (char *) &remote_directory,
                  (char *) "Set directory for remote upload.\n",
@@ -1973,54 +1979,56 @@ _initialize_inftarg (void)
                     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;
+  deprecated_add_show_from_set (set, &showlist);
+  set_cmd_cfunc (set, set_upload_type);
   set_upload_type (NULL, 0);
 
-  add_show_from_set
+  deprecated_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
+  deprecated_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
+                 (char *) "\
+Set whether to add this host to remote stub arguments for\n\
 debugging over a network.", &setlist),
      &showlist);
 
-  add_show_from_set
+  deprecated_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
+  deprecated_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
+  deprecated_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);
+  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);
 }
 
This page took 0.029401 seconds and 4 git commands to generate.