This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3/5] powerpc64-aix inf-ptrace patch


powerpc64-ibm-aix - Make appropiate ptrace  calls in inf-ptrace.c in 64 BIT
mode

Macro for 64 bit ptrace call defined. i.e
	'#define ptrace64(request, pid, addr, data) ptrace64 (request, pid,
addr, data, 0)'

if we are in 64 bit mode, then ptrace64 should be called instead of ptrace.
i.e.

	 #ifdef BFD64
   	int ret = ptrace64 (req, (long long) id, (long long) addr, data,
buf);

inf-ptrace.c has many ptrace calls like -
	'ptrace (PT_WRITE_U, pid, (PTRACE_TYPE_ARG3)(uintptr_t)addr, buf[i])'

in 64 bit this has to be changed to -
	'ptrace64 (PT_WRITE_U, (long long) pid, (long long)addr, buf[i])'

There are many similar changes to be made through out inf-ptrace.c. These
changes are as seen below :-

--- inf-ptrace.c        2013-05-30 23:04:03 +0600
+++ inf-ptrace64.c      2013-06-18 16:07:35 +0600
@@ -36,7 +36,6 @@
 #include "gdbthread.h"

-
 #ifdef PT_GET_PROCESS_STATE

 static int
@@ -47,8 +46,8 @@ inf_ptrace_follow_fork (struct target_op

   pid = ptid_get_pid (inferior_ptid);

-  if (ptrace (PT_GET_PROCESS_STATE, pid,
-              (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
+  if (ptrace (PT_GET_PROCESS_STATE, (long long) pid,
+               (long long)&pe, sizeof pe) == -1)
     perror_with_name (("ptrace"));

   gdb_assert (pe.pe_report_event == PTRACE_FORK);
@@ -72,7 +71,7 @@ inf_ptrace_follow_fork (struct target_op
         it.  */
       remove_breakpoints ();

-      if (ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
+      if (ptrace64 (PT_DETACH, (long long) pid, (long long)1, 0) == -1)
        perror_with_name (("ptrace"));

       /* Switch inferior_ptid out of the parent's way.  */
@@ -88,7 +87,7 @@ inf_ptrace_follow_fork (struct target_op
       /* Breakpoints have already been detached from the child by
         infrun.c.  */

-      if (ptrace (PT_DETACH, fpid, (PTRACE_TYPE_ARG3)1, 0) == -1)
+      if (ptrace64 (PT_DETACH, (long long) fpid, (long long)1, 0) == -1)
        perror_with_name (("ptrace"));
     }

@@ -104,7 +103,7 @@ static void
 inf_ptrace_me (void)
 {
   /* "Trace me, Dr. Memory!"  */
-  ptrace (PT_TRACE_ME, 0, (PTRACE_TYPE_ARG3)0, 0);
+  ptrace64 (PT_TRACE_ME, (long long) 0, (long long)0, 0);
 }

 /* Start a new inferior Unix child process.  EXEC_FILE is the file to
@@ -122,18 +121,19 @@ inf_ptrace_create_inferior (struct targe
   /* Do not change either targets above or the same target if already
present.
      The reason is the target stack is shared across multiple inferiors.
*/
   int ops_already_pushed = target_is_pushed (ops);
-  struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
+  struct cleanup *back_to = NULL;

   if (! ops_already_pushed)
     {
       /* Clear possible core file with its process_stratum.  */
       push_target (ops);
-      make_cleanup_unpush_target (ops);
+      back_to = make_cleanup_unpush_target (ops);
     }

   pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
                       NULL, NULL, NULL);

+  if (! ops_already_pushed)
   discard_cleanups (back_to);

   /* START_INFERIOR_TRAPS_EXPECTED is defined in inferior.h, and will
@@ -156,8 +156,8 @@ inf_ptrace_post_startup_inferior (ptid_t
   /* Set the initial event mask.  */
   memset (&pe, 0, sizeof pe);
   pe.pe_set_event |= PTRACE_FORK;
-  if (ptrace (PT_SET_EVENT_MASK, ptid_get_pid (pid),
-             (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
+  if (ptrace64 (PT_SET_EVENT_MASK, (long long) ptid_get_pid (pid),
+              (long long)&pe, sizeof pe) == -1)
     perror_with_name (("ptrace"));
 }

@@ -195,7 +195,7 @@ inf_ptrace_attach (struct target_ops *op
   /* Do not change either targets above or the same target if already
present.
      The reason is the target stack is shared across multiple inferiors.
*/
   int ops_already_pushed = target_is_pushed (ops);
-  struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
+  struct cleanup *back_to = NULL;

   pid = parse_pid_to_attach (args);

@@ -207,7 +207,7 @@ inf_ptrace_attach (struct target_ops *op
       /* target_pid_to_str already uses the target.  Also clear possible
core
         file with its process_stratum.  */
       push_target (ops);
-      make_cleanup_unpush_target (ops);
+      back_to = make_cleanup_unpush_target (ops);
     }

   if (from_tty)
@@ -226,7 +226,7 @@ inf_ptrace_attach (struct target_ops *op

 #ifdef PT_ATTACH
   errno = 0;
-  ptrace (PT_ATTACH, pid, (PTRACE_TYPE_ARG3)0, 0);
+  ptrace64 (PT_ATTACH, (long long) pid, (long long)0, 0);
   if (errno != 0)
     perror_with_name (("ptrace"));
 #else
@@ -242,6 +242,7 @@ inf_ptrace_attach (struct target_ops *op
      target, it should decorate the ptid later with more info.  */
   add_thread_silent (inferior_ptid);

+  if (! ops_already_pushed)
   discard_cleanups (back_to);
 }

@@ -255,8 +256,8 @@ inf_ptrace_post_attach (int pid)
   /* Set the initial event mask.  */
   memset (&pe, 0, sizeof pe);
   pe.pe_set_event |= PTRACE_FORK;
-  if (ptrace (PT_SET_EVENT_MASK, pid,
-             (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
+  if (ptrace64 (PT_SET_EVENT_MASK, (long long) pid,
+              (long long)&pe, sizeof pe) == -1)
     perror_with_name (("ptrace"));
 }

@@ -289,7 +290,7 @@ inf_ptrace_detach (struct target_ops *op
      previously attached to the inferior.  It *might* work if we
      started the process ourselves.  */
   errno = 0;
-  ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, sig);
+  ptrace64 (PT_DETACH, (long long) pid, (long long) 1, sig);
   if (errno != 0)
     perror_with_name (("ptrace"));
 #else
@@ -314,7 +315,7 @@ inf_ptrace_kill (struct target_ops *ops)
   if (pid == 0)
     return;

-  ptrace (PT_KILL, pid, (PTRACE_TYPE_ARG3)0, 0);
+  ptrace64 (PT_KILL, (long long) pid, (long long) 0, 0);
   waitpid (pid, &status, 0);

   target_mourn_inferior ();
@@ -368,7 +369,7 @@ inf_ptrace_resume (struct target_ops *op
      where it was.  If GDB wanted it to start some other way, we have
      already written a new program counter value to the child.  */
   errno = 0;
-  ptrace (request, pid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal));
+  ptrace64 (request, (long long) pid, (long long)1, gdb_signal_to_host
(signal));
   if (errno != 0)
     perror_with_name (("ptrace"));
 }
@@ -421,8 +422,8 @@ inf_ptrace_wait (struct target_ops *ops,
       ptrace_state_t pe;
       pid_t fpid;

-      if (ptrace (PT_GET_PROCESS_STATE, pid,
-                 (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
+      if (ptrace64 (PT_GET_PROCESS_STATE, (long long) pid,
+                  (long long)&pe, sizeof pe) == -1)
        perror_with_name (("ptrace"));

       switch (pe.pe_report_event)
@@ -436,8 +437,8 @@ inf_ptrace_wait (struct target_ops *ops,
          if (fpid == -1)
            perror_with_name (("waitpid"));

-         if (ptrace (PT_GET_PROCESS_STATE, fpid,
-                     (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
+          if (ptrace64 (PT_GET_PROCESS_STATE, (long long) fpid,
+                      (long long)&pe, sizeof pe) == -1)
            perror_with_name (("ptrace"));

          gdb_assert (pe.pe_report_event == PTRACE_FORK);
@@ -491,7 +492,7 @@ inf_ptrace_xfer_partial (struct target_o
        piod.piod_len = len;

        errno = 0;
-       if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
+        if (ptrace64 (PT_IO, (long long) pid, (long long)&piod, 0) == 0)
          /* Return the actual number of bytes read or written.  */
          return piod.piod_len;
        /* If the PT_IO request is somehow not supported, fallback on
@@ -532,8 +533,8 @@ inf_ptrace_xfer_partial (struct target_o
                || (offset + partial_len
                    < rounded_offset + sizeof (PTRACE_TYPE_RET)))
              /* Need part of initial word -- fetch it.  */
-             buffer.word = ptrace (PT_READ_I, pid,
-                                   (PTRACE_TYPE_ARG3)(uintptr_t)
+              buffer.word = ptrace64 (PT_READ_I, (long long) pid,
+                                    (long long)
                                    rounded_offset, 0);

            /* Copy data to be written over corresponding part of
@@ -542,16 +543,16 @@ inf_ptrace_xfer_partial (struct target_o
                    writebuf, partial_len);

            errno = 0;
-           ptrace (PT_WRITE_D, pid,
-                   (PTRACE_TYPE_ARG3)(uintptr_t)rounded_offset,
+            ptrace64 (PT_WRITE_D, (long long) pid,
+                    (long long)rounded_offset,
                    buffer.word);
            if (errno)
              {
                /* Using the appropriate one (I or D) is necessary for
                   Gould NP1, at least.  */
                errno = 0;
-               ptrace (PT_WRITE_I, pid,
-                       (PTRACE_TYPE_ARG3)(uintptr_t)rounded_offset,
+                ptrace64 (PT_WRITE_I, (long long) pid,
+                        (long long)rounded_offset,
                        buffer.word);
                if (errno)
                  return 0;
@@ -561,8 +562,8 @@ inf_ptrace_xfer_partial (struct target_o
        if (readbuf)
          {
            errno = 0;
-           buffer.word = ptrace (PT_READ_I, pid,
-
(PTRACE_TYPE_ARG3)(uintptr_t)rounded_offset,
+            buffer.word = ptrace64 (PT_READ_I, (long long) pid,
+                                  (long long)rounded_offset,
                                  0);
            if (errno)
              return 0;
@@ -593,7 +594,7 @@ inf_ptrace_xfer_partial (struct target_o
        piod.piod_len = len;

        errno = 0;
-       if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
+        if (ptrace64 (PT_IO, (long long) pid, (long long)&piod, 0) == 0)
          /* Return the actual number of bytes read or written.  */
          return piod.piod_len;
       }
@@ -741,7 +742,7 @@ inf_ptrace_fetch_register (struct regcac
   for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
     {
       errno = 0;
-      buf[i] = ptrace (PT_READ_U, pid, (PTRACE_TYPE_ARG3)(uintptr_t)addr,
0);
+      buf[i] = ptrace64 (PT_READ_U, (long long) pid, (long long)addr, 0);
       if (errno != 0)
        error (_("Couldn't read register %s (#%d): %s."),
               gdbarch_register_name (gdbarch, regnum),
@@ -800,7 +801,7 @@ inf_ptrace_store_register (const struct
   for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
     {
       errno = 0;
-      ptrace (PT_WRITE_U, pid, (PTRACE_TYPE_ARG3)(uintptr_t)addr, buf[i]);
+      ptrace64 (PT_WRITE_U, (long long) pid, (long long)addr, buf[i]);
       if (errno != 0)
        error (_("Couldn't write register %s (#%d): %s."),
               gdbarch_register_name (gdbarch, regnum),


Note - Initially, I had used multiple ' #ifdef BFD64 ' checks to insert
these changes.

Since that is not the right way to go about it, I thought it would be
better to create a new file called 'inf-ptrace64.c' derived from inf-ptrace
instead,
This new file contains all these above mentioned changes.
inf-ptrace64 will be compiled only if the host is detected as
powerpc64-ibm-aix.
SO, it will not interfere with the original inf-ptrace that is used if host
is powerpc-ibm-aix

Since the patch that creates inf-ptrace64.c is very large as it contains
the full file. I have attached it as a text file below.
But the above mentioned changes is the only difference between inf-ptrace.c
and inf-ptrace64.c
---
Patch1 :

Index: ./gdb/gdb_ptrace.h
===================================================================
--- ./gdb.orig/gdb_ptrace.h
+++ ./gdb/gdb_ptrace.h
@@ -136,6 +136,8 @@ extern PTRACE_TYPE_RET ptrace();

 #ifdef PTRACE_TYPE_ARG5
 # define ptrace(request, pid, addr, data) ptrace (request, pid, addr,
data, 0)
+# define ptrace64(request, pid, addr, data) ptrace64 (request, pid, addr,
data, 0)
+
 #endif

 #endif /* gdb_ptrace.h */
Index: ./gdb/rs6000-nat.c
===================================================================
--- ./gdb.orig/rs6000-nat.c
+++ ./gdb/rs6000-nat.c
@@ -66,7 +66,7 @@
 /* In 32-bit compilation mode (which is the only mode from which ptrace()
    works on 4.3), __ld_info32 is #defined as equivalent to ld_info.  */

-#ifdef __ld_info32
+#if defined (__ld_info32) || defined (__ld_info64)
 # define ARCH3264
 #endif

@@ -181,7 +181,11 @@ regmap (struct gdbarch *gdbarch, int reg
 static int
 rs6000_ptrace32 (int req, int id, int *addr, int data, int *buf)
 {
+  #ifdef BFD64
+  int ret = ptrace64 (req, (long long) id, (long long) addr, data, buf);
+  #else
   int ret = ptrace (req, id, (int *)addr, data, buf);
+  #endif
 #if 0
   printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
 	  req, id, (unsigned int)addr, data, (unsigned int)buf, ret);
@@ -195,7 +199,11 @@ static int
 rs6000_ptrace64 (int req, int id, long long addr, int data, void *buf)
 {
 #ifdef ARCH3264
+  #ifdef BFD64
+  int ret = ptrace64 (req, (long long) id, addr, data, (int *)buf);
+  #else
   int ret = ptracex (req, id, addr, data, buf);
+  #endif
 #else
   int ret = 0;
 #endif

---
The patch  to create the file inf-ptrace64.c is attached below

(See attached file: gdb-7.6-infptrace64.patch)

Attachment: gdb-7.6-infptrace64.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]