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]

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


I have restricted the macro definitions to only gdb_ptrace.h.
Something like this as seen below -

#ifdef PTRACE_TYPE_ARG5
# ifdef BFD64
#  define ptrace(request, pid, addr, data) \
          ptrace64 (request, (long long)pid, (long long)addr, data, 0)
# else
#  define ptrace(request, pid, addr, data) \
          ptrace(request, (int)pid, (PTRACE_TYPE_ARG3)addr, data, 0)
# endif
#endif

I have type cast pid here to avoid additional compiler warnings.

> So unless I'm missing something, you should not need to make any
> changes to inf-ptrace.c itself.

But, inf-ptrace.c makes ptrace calls as seen below -

	ptrace (PT_DETACH, fpid, (PTRACE_TYPE_ARG3)1, 0)

If I make the macro definitions in gdb_ptrace.h as seen above, then
the casts for the 'Address'(3rd parameter in ptrace call) should
be removed from ptrace calls in inf-ptrace.c as seen below -

	 ptrace (PT_DETACH, fpid, 1, 0)

The macro is taking care of all the type casts.
ptrace64() accepts (long long) as the address parameter while
ptrace() accepts int* or any integer pointer as the type for address.
So, this type cast is necessary. Agree that pid cast is not needed.

Here is the modified patch below -
---
Index: ./gdb/gdb_ptrace.h
===================================================================
--- ./gdb.orig/gdb_ptrace.h
+++ ./gdb/gdb_ptrace.h
@@ -135,7 +135,13 @@
    zero.  */

 #ifdef PTRACE_TYPE_ARG5
-# define ptrace(request, pid, addr, data) ptrace (request, pid, addr,
data, 0)
+# ifdef BFD64
+#  define ptrace(request, pid, addr, data) \
+          ptrace64 (request, (long long)pid, (long long)addr, data, 0)
+# else
+#  define ptrace(request, pid, addr, data) \
+          ptrace(request, (int)pid, (PTRACE_TYPE_ARG3)addr, data, 0)
+# endif
 #endif

 #endif /* gdb_ptrace.h */
Index: ./gdb/inf-ptrace.c
===================================================================
--- ./gdb.orig/inf-ptrace.c
+++ ./gdb/inf-ptrace.c
@@ -48,7 +48,7 @@
   pid = ptid_get_pid (inferior_ptid);

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

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

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

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

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

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

 /* Start a new inferior Unix child process.  EXEC_FILE is the file to
@@ -157,7 +157,7 @@
   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)
+                                &pe, sizeof pe) == -1)
     perror_with_name (("ptrace"));
 }

@@ -226,7 +226,7 @@

 #ifdef PT_ATTACH
   errno = 0;
-  ptrace (PT_ATTACH, pid, (PTRACE_TYPE_ARG3)0, 0);
+  ptrace (PT_ATTACH, pid, 0, 0);
   if (errno != 0)
     perror_with_name (("ptrace"));
 #else
@@ -256,7 +256,7 @@
   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)
+               &pe, sizeof pe) == -1)
     perror_with_name (("ptrace"));
 }

@@ -289,7 +289,7 @@
      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);
+  ptrace (PT_DETACH, pid, 1, sig);
   if (errno != 0)
     perror_with_name (("ptrace"));
 #else
@@ -314,7 +314,7 @@
   if (pid == 0)
     return;

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

   target_mourn_inferior ();
@@ -368,7 +368,7 @@
      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));
+  ptrace (request, pid, 1, gdb_signal_to_host (signal));
   if (errno != 0)
     perror_with_name (("ptrace"));
 }
@@ -422,7 +422,7 @@
       pid_t fpid;

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

       switch (pe.pe_report_event)
@@ -437,7 +437,7 @@
            perror_with_name (("waitpid"));

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

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

        errno = 0;
-       if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
+       if (ptrace (PT_IO, pid, &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
@@ -533,8 +533,7 @@
                    < 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)
-                                   rounded_offset, 0);
+                                   (uintptr_t)rounded_offset, 0);

            /* Copy data to be written over corresponding part of
               buffer.  */
@@ -543,16 +542,14 @@

            errno = 0;
            ptrace (PT_WRITE_D, pid,
-                   (PTRACE_TYPE_ARG3)(uintptr_t)rounded_offset,
-                   buffer.word);
+                   (uintptr_t)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,
-                       buffer.word);
+                       (uintptr_t)rounded_offset, buffer.word);
                if (errno)
                  return 0;
              }
@@ -562,8 +559,7 @@
          {
            errno = 0;
            buffer.word = ptrace (PT_READ_I, pid,
-
(PTRACE_TYPE_ARG3)(uintptr_t)rounded_offset,
-                                 0);
+                                 (uintptr_t)rounded_offset, 0);
            if (errno)
              return 0;
            /* Copy appropriate bytes out of the buffer.  */
@@ -593,7 +589,7 @@
        piod.piod_len = len;

        errno = 0;
-       if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
+       if (ptrace (PT_IO, pid, &piod, 0) == 0)
          /* Return the actual number of bytes read or written.  */
          return piod.piod_len;
       }
@@ -741,7 +737,7 @@
   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] = ptrace (PT_READ_U, pid, (uintptr_t)addr, 0);
       if (errno != 0)
        error (_("Couldn't read register %s (#%d): %s."),
               gdbarch_register_name (gdbarch, regnum),
@@ -800,7 +796,7 @@
   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]);
+      ptrace (PT_WRITE_U, pid, (uintptr_t)addr, buf[i]);
       if (errno != 0)
        error (_("Couldn't write register %s (#%d): %s."),
               gdbarch_register_name (gdbarch, regnum),
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
---
Kindly review this and tell me if the changes to inf-ptrace.c are
acceptable.

Thanks & Regards,
Raunaq


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