*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / gnu-nat.c
index 6d69b93ff9dff85a9279b332e35c7286e626f2ef..0e584e9fc5d37dca22e7ada9d5f85814cea37c3c 100644 (file)
@@ -1,5 +1,6 @@
 /* Interface GDB to the GNU Hurd.
-   Copyright (C) 1992, 95, 96, 97, 1999, 2000 Free Software Foundation, Inc.
+   Copyright 1992, 1995, 1996, 1997, 1998, 1999, 2000
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -23,7 +24,7 @@
    Boston, MA 02111-1307, USA.
  */
 
-#include <assert.h>
+#include <ctype.h>
 #include <errno.h>
 #include <limits.h>
 #include <setjmp.h>
@@ -60,6 +61,7 @@
 #include "gdbcmd.h"
 #include "gdbcore.h"
 #include "gdbthread.h"
+#include "gdb_assert.h"
 
 #include "gnu-nat.h"
 
@@ -261,10 +263,10 @@ proc_update_sc (struct proc *proc)
   if (proc->sc == 0 && proc->state_changed)
     /* Since PROC may start running, we must write back any state changes. */
     {
-      assert (proc_is_thread (proc));
+      gdb_assert (proc_is_thread (proc));
       proc_debug (proc, "storing back changed thread state");
       err = thread_set_state (proc->port, THREAD_STATE_FLAVOR,
-                        (thread_state_t) & proc->state, THREAD_STATE_SIZE);
+                        (thread_state_t) &proc->state, THREAD_STATE_SIZE);
       if (!err)
        proc->state_changed = 0;
     }
@@ -317,7 +319,7 @@ proc_update_sc (struct proc *proc)
 void
 proc_abort (struct proc *proc, int force)
 {
-  assert (proc_is_thread (proc));
+  gdb_assert (proc_is_thread (proc));
 
   if (!proc->aborted)
     {
@@ -370,7 +372,7 @@ proc_get_state (struct proc *proc, int will_modify)
       mach_msg_type_number_t state_size = THREAD_STATE_SIZE;
       error_t err =
       thread_get_state (proc->port, THREAD_STATE_FLAVOR,
-                       (thread_state_t) & proc->state, &state_size);
+                       (thread_state_t) &proc->state, &state_size);
       proc_debug (proc, "getting thread state");
       proc->state_valid = !err;
     }
@@ -379,7 +381,7 @@ proc_get_state (struct proc *proc, int will_modify)
     {
       if (will_modify)
        proc->state_changed = 1;
-      return (thread_state_t) & proc->state;
+      return (thread_state_t) &proc->state;
     }
   else
     return 0;
@@ -538,7 +540,7 @@ make_proc (struct inf *inf, mach_port_t port, int tid)
 {
   error_t err;
   mach_port_t prev_port = MACH_PORT_NULL;
-  struct proc *proc = malloc (sizeof (struct proc));
+  struct proc *proc = xmalloc (sizeof (struct proc));
 
   proc->port = port;
   proc->tid = tid;
@@ -627,18 +629,15 @@ _proc_free (struct proc *proc)
       mach_port_deallocate (mach_task_self (), proc->port);
     }
 
-  free (proc);
+  xfree (proc);
   return next;
 }
 
 \f
 struct inf *
-make_inf ()
+make_inf (void)
 {
-  struct inf *inf = malloc (sizeof (struct inf));
-
-  if (!inf)
-    return 0;
+  struct inf *inf = xmalloc (sizeof (struct inf));
 
   inf->task = 0;
   inf->threads = 0;
@@ -796,7 +795,7 @@ inf_validate_procinfo (struct inf *inf)
   int info_flags = 0;
   error_t err =
   proc_getprocinfo (proc_server, inf->pid, &info_flags,
-                   (procinfo_t *) & pi, &pi_len, &noise, &noise_len);
+                   (procinfo_t *) &pi, &pi_len, &noise, &noise_len);
 
   if (!err)
     {
@@ -1066,7 +1065,7 @@ inf_validate_procs (struct inf *inf)
            (last ? last->next : inf->threads) = thread;
            last = thread;
            proc_debug (thread, "new thread: %d", threads[i]);
-           add_thread (thread->tid);   /* Tell GDB's generic thread code.  */
+           add_thread (pid_to_ptid (thread->tid));     /* Tell GDB's generic thread code.  */
          }
       }
 
@@ -1156,7 +1155,7 @@ inf_suspend (struct inf *inf)
 void
 inf_set_step_thread (struct inf *inf, struct proc *thread)
 {
-  assert (!thread || proc_is_thread (thread));
+  gdb_assert (!thread || proc_is_thread (thread));
 
   if (thread)
     inf_debug (inf, "setting step thread: %d/%d", inf->pid, thread->tid);
@@ -1410,8 +1409,8 @@ struct inf *current_inferior = 0;
 struct inf *waiting_inf;
 
 /* Wait for something to happen in the inferior, returning what in STATUS. */
-static int
-gnu_wait (int tid, struct target_waitstatus *status)
+static ptid_t
+gnu_wait (ptid_t tid, struct target_waitstatus *status)
 {
   struct msg
     {
@@ -1428,7 +1427,7 @@ gnu_wait (int tid, struct target_waitstatus *status)
   extern int notify_server (mach_msg_header_t *, mach_msg_header_t *);
   extern int process_reply_server (mach_msg_header_t *, mach_msg_header_t *);
 
-  assert (inf->task);
+  gdb_assert (inf->task);
 
   if (!inf->threads && !inf->pending_execs)
     /* No threads!  Assume that maybe some outside agency is frobbing our
@@ -1442,7 +1441,7 @@ gnu_wait (int tid, struct target_waitstatus *status)
 
   waiting_inf = inf;
 
-  inf_debug (inf, "waiting for: %d", tid);
+  inf_debug (inf, "waiting for: %d", PIDGET (tid));
 
 rewait:
   if (proc_wait_pid != inf->pid && !inf->no_wait)
@@ -1578,20 +1577,20 @@ rewait:
 
   thread = inf->wait.thread;
   if (thread)
-    tid = thread->tid;
+    tid = pid_to_ptid (thread->tid);
   else
-    thread = inf_tid_to_thread (inf, tid);
+    thread = inf_tid_to_thread (inf, PIDGET (tid));
 
   if (!thread || thread->port == MACH_PORT_NULL)
     {
       /* TID is dead; try and find a new thread.  */
       if (inf_update_procs (inf) && inf->threads)
-       tid = inf->threads->tid; /* The first available thread.  */
+       tid = pid_to_ptid (inf->threads->tid); /* The first available thread.  */
       else
-       tid = inferior_pid;     /* let wait_for_inferior handle exit case */
+       tid = inferior_ptid;    /* let wait_for_inferior handle exit case */
     }
 
-  if (thread && tid >= 0 && status->kind != TARGET_WAITKIND_SPURIOUS
+  if (thread && PIDGET (tid) >= 0 && status->kind != TARGET_WAITKIND_SPURIOUS
       && inf->pause_sc == 0 && thread->pause_sc == 0)
     /* If something actually happened to THREAD, make sure we
        suspend it.  */
@@ -1600,7 +1599,7 @@ rewait:
       inf_update_suspends (inf);
     }
 
-  inf_debug (inf, "returning tid = %d, status = %s (%d)", tid,
+  inf_debug (inf, "returning tid = %d, status = %s (%d)", PIDGET (tid),
             status->kind == TARGET_WAITKIND_EXITED ? "EXITED"
             : status->kind == TARGET_WAITKIND_STOPPED ? "STOPPED"
             : status->kind == TARGET_WAITKIND_SIGNALLED ? "SIGNALLED"
@@ -1659,16 +1658,16 @@ S_exception_raise_request (mach_port_t port, mach_port_t reply_port,
        {
          if (thread->exc_port == port)
            {
-             inf_debug (waiting_inf, "Handler is thread exeption port <%d>",
+             inf_debug (waiting_inf, "Handler is thread exception port <%d>",
                         thread->saved_exc_port);
              inf->wait.exc.handler = thread->saved_exc_port;
            }
          else
            {
-             inf_debug (waiting_inf, "Handler is task exeption port <%d>",
+             inf_debug (waiting_inf, "Handler is task exception port <%d>",
                         inf->task->saved_exc_port);
              inf->wait.exc.handler = inf->task->saved_exc_port;
-             assert (inf->task->exc_port == port);
+             gdb_assert (inf->task->exc_port == port);
            }
          if (inf->wait.exc.handler != MACH_PORT_NULL)
            /* Add a reference to the exception handler. */
@@ -1927,12 +1926,12 @@ port_msgs_queued (mach_port_t port)
    in multiple events returned by wait).
  */
 static void
-gnu_resume (int tid, int step, enum target_signal sig)
+gnu_resume (ptid_t tid, int step, enum target_signal sig)
 {
   struct proc *step_thread = 0;
   struct inf *inf = current_inferior;
 
-  inf_debug (inf, "tid = %d, step = %d, sig = %d", tid, step, sig);
+  inf_debug (inf, "tid = %d, step = %d, sig = %d", PIDGET (tid), step, sig);
 
   inf_validate_procinfo (inf);
 
@@ -1960,17 +1959,17 @@ gnu_resume (int tid, int step, enum target_signal sig)
 
   inf_update_procs (inf);
 
-  if (tid < 0)
+  if (PIDGET (tid) < 0)
     /* Allow all threads to run, except perhaps single-stepping one.  */
     {
-      inf_debug (inf, "running all threads; tid = %d", inferior_pid);
-      tid = inferior_pid;      /* What to step. */
+      inf_debug (inf, "running all threads; tid = %d", PIDGET (inferior_ptid));
+      tid = inferior_ptid;     /* What to step. */
       inf_set_threads_resume_sc (inf, 0, 1);
     }
   else
     /* Just allow a single thread to run.  */
     {
-      struct proc *thread = inf_tid_to_thread (inf, tid);
+      struct proc *thread = inf_tid_to_thread (inf, PIDGET (tid));
       if (!thread)
        error ("Can't run single thread id %d: no such thread!");
       inf_debug (inf, "running one thread: %d/%d", inf->pid, thread->tid);
@@ -1979,9 +1978,9 @@ gnu_resume (int tid, int step, enum target_signal sig)
 
   if (step)
     {
-      step_thread = inf_tid_to_thread (inf, tid);
+      step_thread = inf_tid_to_thread (inf, PIDGET (tid));
       if (!step_thread)
-       warning ("Can't step thread id %d: no such thread.", tid);
+       warning ("Can't step thread id %d: no such thread.", PIDGET (tid));
       else
        inf_debug (inf, "stepping thread: %d/%d", inf->pid, step_thread->tid);
     }
@@ -1994,7 +1993,7 @@ gnu_resume (int tid, int step, enum target_signal sig)
 
 \f
 static void
-gnu_kill_inferior ()
+gnu_kill_inferior (void)
 {
   struct proc *task = current_inferior->task;
   if (task)
@@ -2008,7 +2007,7 @@ gnu_kill_inferior ()
 
 /* Clean up after the inferior dies.  */
 static void
-gnu_mourn_inferior ()
+gnu_mourn_inferior (void)
 {
   inf_debug (current_inferior, "rip");
   inf_detach (current_inferior);
@@ -2021,7 +2020,7 @@ gnu_mourn_inferior ()
 
 /* Set INFERIOR_PID to the first thread available in the child, if any.  */
 static int
-inf_pick_first_thread ()
+inf_pick_first_thread (void)
 {
   if (current_inferior->task && current_inferior->threads)
     /* The first thread.  */
@@ -2032,7 +2031,7 @@ inf_pick_first_thread ()
 }
 
 static struct inf *
-cur_inf ()
+cur_inf (void)
 {
   if (!current_inferior)
     current_inferior = make_inf ();
@@ -2040,10 +2039,7 @@ cur_inf ()
 }
 
 static void
-gnu_create_inferior (exec_file, allargs, env)
-     char *exec_file;
-     char *allargs;
-     char **env;
+gnu_create_inferior (char *exec_file, char *allargs, char **env)
 {
   struct inf *inf = cur_inf ();
 
@@ -2071,7 +2067,7 @@ gnu_create_inferior (exec_file, allargs, env)
     /* Now let the child run again, knowing that it will stop immediately
        because of the ptrace. */
     inf_resume (inf);
-    inferior_pid = inf_pick_first_thread ();
+    inferior_ptid = pid_to_ptid (inf_pick_first_thread ());
 
     startup_inferior (inf->pending_execs);
   }
@@ -2099,7 +2095,7 @@ gnu_create_inferior (exec_file, allargs, env)
 /* Mark our target-struct as eligible for stray "run" and "attach"
    commands.  */
 static int
-gnu_can_run ()
+gnu_can_run (void)
 {
   return 1;
 }
@@ -2110,16 +2106,14 @@ gnu_can_run ()
 /* Attach to process PID, then initialize for debugging it
    and wait for the trace-trap that results from attaching.  */
 static void
-gnu_attach (args, from_tty)
-     char *args;
-     int from_tty;
+gnu_attach (char *args, int from_tty)
 {
   int pid;
   char *exec_file;
   struct inf *inf = cur_inf ();
 
   if (!args)
-    error_no_arg ("PID to attach");
+    error_no_arg ("process-id to attach");
 
   pid = atoi (args);
 
@@ -2144,7 +2138,7 @@ gnu_attach (args, from_tty)
   inf_attach (inf, pid);
   inf_update_procs (inf);
 
-  inferior_pid = inf_pick_first_thread ();
+  inferior_ptid = pid_to_ptid (inf_pick_first_thread ());
 
   attach_flag = 1;
   push_target (&gnu_ops);
@@ -2174,9 +2168,7 @@ gnu_attach (args, from_tty)
    previously attached.  It *might* work if the program was
    started via fork.  */
 static void
-gnu_detach (args, from_tty)
-     char *args;
-     int from_tty;
+gnu_detach (char *args, int from_tty)
 {
   if (from_tty)
     {
@@ -2191,7 +2183,7 @@ gnu_detach (args, from_tty)
 
   inf_detach (current_inferior);
 
-  inferior_pid = 0;
+  inferior_ptid = null_ptid;
 
   unpush_target (&gnu_ops);    /* Pop out of handling an inferior */
 }
@@ -2199,9 +2191,9 @@ gnu_detach (args, from_tty)
 
 \f
 static void
-gnu_terminal_init_inferior ()
+gnu_terminal_init_inferior (void)
 {
-  assert (current_inferior);
+  gdb_assert (current_inferior);
   terminal_init_inferior_with_pgrp (current_inferior->pid);
 }
 
@@ -2211,7 +2203,7 @@ gnu_terminal_init_inferior ()
    that registers contains all the registers from the program being
    debugged.  */
 static void
-gnu_prepare_to_store ()
+gnu_prepare_to_store (void)
 {
 #ifdef CHILD_PREPARE_TO_STORE
   CHILD_PREPARE_TO_STORE ();
@@ -2219,21 +2211,19 @@ gnu_prepare_to_store ()
 }
 
 static void
-gnu_open (arg, from_tty)
-     char *arg;
-     int from_tty;
+gnu_open (char *arg, int from_tty)
 {
   error ("Use the \"run\" command to start a Unix child process.");
 }
 
 static void
-gnu_stop ()
+gnu_stop (void)
 {
   error ("to_stop target function not implemented");
 }
 
 static char *
-gnu_pid_to_exec_file ()
+gnu_pid_to_exec_file (int pid)
 {
   error ("to_pid_to_exec_file target function not implemented");
   return NULL;
@@ -2241,10 +2231,10 @@ gnu_pid_to_exec_file ()
 
 
 static int
-gnu_thread_alive (int tid)
+gnu_thread_alive (ptid_t tid)
 {
   inf_update_procs (current_inferior);
-  return !!inf_tid_to_thread (current_inferior, tid);
+  return !!inf_tid_to_thread (current_inferior, PIDGET (tid));
 }
 
 \f
@@ -2252,11 +2242,7 @@ gnu_thread_alive (int tid)
    gdb's address space.  Return 0 on failure; number of bytes read
    otherwise.  */
 int
-gnu_read_inferior (task, addr, myaddr, length)
-     task_t task;
-     CORE_ADDR addr;
-     char *myaddr;
-     int length;
+gnu_read_inferior (task_t task, CORE_ADDR addr, char *myaddr, int length)
 {
   error_t err;
   vm_address_t low_address = (vm_address_t) trunc_page (addr);
@@ -2300,11 +2286,7 @@ struct obstack region_obstack;
 /* Write gdb's LEN bytes from MYADDR and copy it to ADDR in inferior
    task's address space.  */
 int
-gnu_write_inferior (task, addr, myaddr, length)
-     task_t task;
-     CORE_ADDR addr;
-     char *myaddr;
-     int length;
+gnu_write_inferior (task_t task, CORE_ADDR addr, char *myaddr, int length)
 {
   error_t err = 0;
   vm_address_t low_address = (vm_address_t) trunc_page (addr);
@@ -2459,14 +2441,12 @@ out:
 }
 
 \f
-/* Return 0 on failure, number of bytes handled otherwise.  */
+/* Return 0 on failure, number of bytes handled otherwise.  TARGET
+   is ignored. */
 static int
-gnu_xfer_memory (memaddr, myaddr, len, write, target)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
-     int write;
-     struct target_ops *target;        /* IGNORED */
+gnu_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
+                struct mem_attrib *attrib,
+                struct target_ops *target)
 {
   task_t task = (current_inferior
                 ? (current_inferior->task
@@ -2497,14 +2477,15 @@ proc_string (struct proc *proc)
     sprintf (tid_str, "process %d", proc->inf->pid);
   else
     sprintf (tid_str, "thread %d.%d",
-            proc->inf->pid, pid_to_thread_id (proc->tid));
+            proc->inf->pid, pid_to_thread_id (MERGEPID (proc->tid, 0)));
   return tid_str;
 }
 
 static char *
-gnu_pid_to_str (int tid)
+gnu_pid_to_str (ptid_t ptid)
 {
   struct inf *inf = current_inferior;
+  int tid = PIDGET (ptid);
   struct proc *thread = inf_tid_to_thread (inf, tid);
 
   if (thread)
@@ -2582,7 +2563,6 @@ init_gnu_ops (void)
   gnu_ops.to_pid_to_str = gnu_pid_to_str;   /* to_pid_to_str */
   gnu_ops.to_stop = gnu_stop;  /* to_stop */
   gnu_ops.to_pid_to_exec_file = gnu_pid_to_exec_file; /* to_pid_to_exec_file */
-  gnu_ops.to_core_file_to_sym_file = NULL;
   gnu_ops.to_stratum = process_stratum;                /* to_stratum */
   gnu_ops.DONT_USE = 0;                        /* to_next */
   gnu_ops.to_has_all_memory = 1;       /* to_has_all_memory */
@@ -2672,10 +2652,10 @@ check_empty (char *args, char *cmd_prefix)
 
 /* Returns the alive thread named by INFERIOR_PID, or signals an error.  */
 static struct proc *
-cur_thread ()
+cur_thread (void)
 {
   struct inf *inf = cur_inf ();
-  struct proc *thread = inf_tid_to_thread (inf, inferior_pid);
+  struct proc *thread = inf_tid_to_thread (inf, PIDGET (inferior_ptid));
   if (!thread)
     error ("No current thread.");
   return thread;
@@ -2683,7 +2663,7 @@ cur_thread ()
 
 /* Returns the current inferior, but signals an error if it has no task.  */
 static struct inf *
-active_inf ()
+active_inf (void)
 {
   struct inf *inf = cur_inf ();
   if (!inf->task)
@@ -2857,7 +2837,7 @@ set_sig_thread_cmd (char *args, int from_tty)
     inf->signal_thread = 0;
   else
     {
-      int tid = thread_id_to_pid (atoi (args));
+      int tid = PIDGET (thread_id_to_pid (atoi (args)));
       if (tid < 0)
        error ("Thread ID %s not known.  Use the \"info threads\" command to\n"
               "see the IDs of currently known threads.", args);
@@ -3361,8 +3341,7 @@ _initialize_gnu_nat (void)
    end up looping in mysterious Bpt traps */
 
 void
-flush_inferior_icache (pc, amount)
-     CORE_ADDR pc;
+flush_inferior_icache (CORE_ADDR pc, int amount)
 {
   vm_machine_attribute_val_t flush = MATTR_VAL_ICACHE_FLUSH;
   error_t ret;
This page took 0.03351 seconds and 4 git commands to generate.