2003-11-20 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / hpux-thread.c
index 4efeb4a5725aaf9486f3e76cf1fbc5b4b3edd0a5..242d3a39a099dcff88faef8a2073228e0a289d12 100644 (file)
@@ -41,7 +41,7 @@
 #include "inferior.h"
 #include "regcache.h"
 #include <fcntl.h>
-#include <sys/stat.h>
+#include "gdb_stat.h"
 #include "gdbcore.h"
 
 extern int child_suppress_run;
@@ -62,10 +62,6 @@ static ptid_t main_ptid;             /* Real process ID */
 static CORE_ADDR P_cma__g_known_threads;
 static CORE_ADDR P_cma__g_current_thread;
 
-static struct cleanup *save_inferior_ptid (void);
-
-static void restore_inferior_ptid (ptid_t pid);
-
 static void hpux_thread_resume (ptid_t ptid, int step,
                                 enum target_signal signo);
 
@@ -73,78 +69,35 @@ static void init_hpux_thread_ops (void);
 
 static struct target_ops hpux_thread_ops;
 \f
-/*
-
-   LOCAL FUNCTION
-
-   save_inferior_ptid - Save inferior_ptid on the cleanup list
-   restore_inferior_ptid - Restore inferior_ptid from the cleanup list
-
-   SYNOPSIS
-
-   struct cleanup *save_inferior_ptid ()
-   void restore_inferior_ptid (int pid)
-
-   DESCRIPTION
-
-   These two functions act in unison to restore inferior_ptid in
-   case of an error.
-
-   NOTES
-
-   inferior_ptid is a global variable that needs to be changed by many of
-   these routines before calling functions in procfs.c.  In order to
-   guarantee that inferior_ptid gets restored (in case of errors), you
-   need to call save_inferior_ptid before changing it.  At the end of the
-   function, you should invoke do_cleanups to restore it.
-
- */
-
-
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  return make_cleanup (restore_inferior_ptid, inferior_ptid);
-}
-
-static void
-restore_inferior_ptid (ptid_t ptid)
-{
-  inferior_ptid = ptid;
-}
-\f
-static int find_active_thread (void);
+static ptid_t find_active_thread (void);
 
 static int cached_thread;
-static int cached_active_thread;
 static cma__t_int_tcb cached_tcb;
 
-static int
+static ptid_t
 find_active_thread (void)
 {
   static cma__t_int_tcb tcb;
   CORE_ADDR tcb_ptr;
 
-  if (cached_active_thread != 0)
-    return cached_active_thread;
-
   read_memory ((CORE_ADDR) P_cma__g_current_thread,
               (char *) &tcb_ptr,
               sizeof tcb_ptr);
 
   read_memory (tcb_ptr, (char *) &tcb, sizeof tcb);
 
-  return (cma_thread_get_unique (&tcb.prolog.client_thread) << 16) 
-         | PIDGET (main_ptid);
+  return (ptid_build (PIDGET (main_ptid), 0,
+                      cma_thread_get_unique (&tcb.prolog.client_thread)));
 }
 
-static cma__t_int_tcb *find_tcb (int thread);
+static cma__t_int_tcb *find_tcb (ptid_t ptid);
 
 static cma__t_int_tcb *
-find_tcb (int thread)
+find_tcb (ptid_t ptid)
 {
   cma__t_known_object queue_header;
   cma__t_queue *queue_ptr;
+  int thread = ptid_get_tid (ptid);
 
   if (thread == cached_thread)
     return &cached_tcb;
@@ -164,21 +117,20 @@ find_tcb (int thread)
       read_memory ((CORE_ADDR) tcb_ptr, (char *) &cached_tcb, sizeof cached_tcb);
 
       if (cached_tcb.header.type == cma__c_obj_tcb)
-       if (cma_thread_get_unique (&cached_tcb.prolog.client_thread) == thread >> 16)
+       if (cma_thread_get_unique (&cached_tcb.prolog.client_thread) == thread)
          {
            cached_thread = thread;
            return &cached_tcb;
          }
     }
 
-  error ("Can't find TCB %d,%d", thread >> 16, thread & 0xffff);
+  error ("Can't find TCB %d", thread);
   return NULL;
 }
 \f
 /* Most target vector functions from here on actually just pass through to
    inftarg.c, as they don't need to do anything specific for threads.  */
 
-/* ARGSUSED */
 static void
 hpux_thread_open (char *arg, int from_tty)
 {
@@ -237,7 +189,6 @@ hpux_thread_resume (ptid_t ptid, int step, enum target_signal signo)
   child_ops.to_resume (ptid, step, signo);
 
   cached_thread = 0;
-  cached_active_thread = 0;
 
   do_cleanups (old_chain);
 }
@@ -301,7 +252,7 @@ hpux_thread_fetch_registers (int regno)
   int i;
   int first_regno, last_regno;
 
-  tcb_ptr = find_tcb (PIDGET (inferior_ptid));
+  tcb_ptr = find_tcb (inferior_ptid);
 
   old_chain = save_inferior_ptid ();
 
@@ -333,20 +284,20 @@ hpux_thread_fetch_registers (int regno)
        child_ops.to_fetch_registers (regno);
       else
        {
-         unsigned char buf[MAX_REGISTER_RAW_SIZE];
+         unsigned char buf[MAX_REGISTER_SIZE];
          CORE_ADDR sp;
 
          sp = (CORE_ADDR) tcb_ptr->static_ctx.sp - 160;
 
          if (regno == FLAGS_REGNUM)
            /* Flags must be 0 to avoid bogus value for SS_INSYSCALL */
-           memset (buf, '\000', REGISTER_RAW_SIZE (regno));
+           memset (buf, '\000', DEPRECATED_REGISTER_RAW_SIZE (regno));
          else if (regno == SP_REGNUM)
-           store_address (buf, sizeof sp, sp);
+           store_unsigned_integer (buf, sizeof sp, sp);
          else if (regno == PC_REGNUM)
-           read_memory (sp - 20, buf, REGISTER_RAW_SIZE (regno));
+           read_memory (sp - 20, buf, DEPRECATED_REGISTER_RAW_SIZE (regno));
          else
-           read_memory (sp + regmap[regno], buf, REGISTER_RAW_SIZE (regno));
+           read_memory (sp + regmap[regno], buf, DEPRECATED_REGISTER_RAW_SIZE (regno));
 
          supply_register (regno, buf);
        }
@@ -363,7 +314,7 @@ hpux_thread_store_registers (int regno)
   int i;
   int first_regno, last_regno;
 
-  tcb_ptr = find_tcb (PIDGET (inferior_ptid));
+  tcb_ptr = find_tcb (inferior_ptid);
 
   old_chain = save_inferior_ptid ();
 
@@ -395,7 +346,7 @@ hpux_thread_store_registers (int regno)
        child_ops.to_store_registers (regno);
       else
        {
-         unsigned char buf[MAX_REGISTER_RAW_SIZE];
+         unsigned char buf[MAX_REGISTER_SIZE];
          CORE_ADDR sp;
 
          sp = (CORE_ADDR) tcb_ptr->static_ctx.sp - 160;
@@ -405,19 +356,20 @@ hpux_thread_store_registers (int regno)
          else if (regno == SP_REGNUM)
            {
              write_memory ((CORE_ADDR) & tcb_ptr->static_ctx.sp,
-                           registers + REGISTER_BYTE (regno),
-                           REGISTER_RAW_SIZE (regno));
+                           &deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)],
+                           DEPRECATED_REGISTER_RAW_SIZE (regno));
              tcb_ptr->static_ctx.sp = (cma__t_hppa_regs *)
-               (extract_address (registers + REGISTER_BYTE (regno), REGISTER_RAW_SIZE (regno)) + 160);
+               (extract_unsigned_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)],
+                                          DEPRECATED_REGISTER_RAW_SIZE (regno)) + 160);
            }
          else if (regno == PC_REGNUM)
            write_memory (sp - 20,
-                         registers + REGISTER_BYTE (regno),
-                         REGISTER_RAW_SIZE (regno));
+                         &deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)],
+                         DEPRECATED_REGISTER_RAW_SIZE (regno));
          else
            write_memory (sp + regmap[regno],
-                         registers + REGISTER_BYTE (regno),
-                         REGISTER_RAW_SIZE (regno));
+                         &deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)],
+                         DEPRECATED_REGISTER_RAW_SIZE (regno));
        }
     }
 
@@ -576,7 +528,7 @@ hpux_pid_to_str (ptid_t ptid)
   static char buf[100];
   int pid = PIDGET (ptid);
 
-  sprintf (buf, "Thread %d", pid >> 16);
+  sprintf (buf, "Thread %ld", ptid_get_tid (ptid));
 
   return buf;
 }
@@ -602,6 +554,7 @@ init_hpux_thread_ops (void)
   hpux_thread_ops.to_terminal_init = terminal_init_inferior;
   hpux_thread_ops.to_terminal_inferior = terminal_inferior;
   hpux_thread_ops.to_terminal_ours_for_output = terminal_ours_for_output;
+  hpux_thread_ops.to_terminal_save_ours = terminal_save_ours;
   hpux_thread_ops.to_terminal_ours = terminal_ours;
   hpux_thread_ops.to_terminal_info = child_terminal_info;
   hpux_thread_ops.to_kill = hpux_thread_kill_inferior;
This page took 0.041308 seconds and 4 git commands to generate.