Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
To: Pedro Alves <palves@redhat.com>
Cc: Mark Kettenis <mark.kettenis@xs4all.nl>, gdb-patches@sourceware.org
Subject: Re: [RFA] handle android bionic ptrace in gdbserver.
Date: Fri, 30 Mar 2012 20:29:00 -0000	[thread overview]
Message-ID: <1333139333.11673.4.camel@hactar> (raw)
In-Reply-To: <4F7490E9.40903@redhat.com>

On Thu, 2012-03-29 at 17:42 +0100, Pedro Alves wrote:
> On 03/28/2012 01:26 AM, Thiago Jung Bauermann wrote:
> > Good catch, that's what happened indeed. I don't know what would be the
> > correct fix. I changed the types of the variables that are passed to
> > ptrace from int to long.  At least it hurts the eyes less than two casts
> 
> > in a row.
> 
> :-)
> 
> Honestly, I'd prefer the double cast, in order to leave the ptrace arg
> type intricacy closest the the ptrace call as possible, instead of that care
> being spread and diluted about.  It's also what other places in the code
> base already do (both gdb and gdbserver).

Makes sense. I'm still wondering why the current code works on 64 bit
Linux platforms though.

Updated patch follows.

-- 
[]'s
Thiago Jung Bauermann
Linaro Toolchain Working Group


2012-03-30  Thiago Jung Bauermann  <thiago.bauermann@linaro.org>

	* linux-low.h (PTRACE_ARG3_TYPE): Move macro from linux-low.c.
	(PTRACE_ARG4_TYPE): Likewise.
	(PTRACE_XFER_TYPE): Likewise.
	* linux-arm-low.c (arm_prepare_to_resume): Cast third argument of
	ptrace to PTRACE_ARG3_TYPE.
	* linux-low.c (PTRACE_ARG3_TYPE): Move macro to linux-low.h.
	(PTRACE_ARG4_TYPE): Likewise.
	(PTRACE_XFER_TYPE): Likewise.
	(linux_detach_one_lwp): Cast fourth argument of
	ptrace to long then PTRACE_ARG4_TYPE.
	(regsets_fetch_inferior_registers): Cast third argument of
	ptrace to long then PTRACE_ARG3_TYPE.
	(regsets_store_inferior_registers): Likewise.


diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
index bf1792b..c4d2000 100644
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -709,13 +709,15 @@ arm_prepare_to_resume (struct lwp_info *lwp)
 	errno = 0;
 
 	if (arm_hwbp_control_is_enabled (proc_info->bpts[i].control))
-	  if (ptrace (PTRACE_SETHBPREGS, pid, ((i << 1) + 1),
-	      &proc_info->bpts[i].address) < 0)
+	  if (ptrace (PTRACE_SETHBPREGS, pid,
+		      (PTRACE_ARG3_TYPE) ((i << 1) + 1),
+		      &proc_info->bpts[i].address) < 0)
 	    perror_with_name ("Unexpected error setting breakpoint address");
 
 	if (arm_hwbp_control_is_initialized (proc_info->bpts[i].control))
-	  if (ptrace (PTRACE_SETHBPREGS, pid, ((i << 1) + 2),
-	      &proc_info->bpts[i].control) < 0)
+	  if (ptrace (PTRACE_SETHBPREGS, pid,
+		      (PTRACE_ARG3_TYPE) ((i << 1) + 2),
+		      &proc_info->bpts[i].control) < 0)
 	    perror_with_name ("Unexpected error setting breakpoint");
 
 	lwp_info->bpts_changed[i] = 0;
@@ -727,13 +729,15 @@ arm_prepare_to_resume (struct lwp_info *lwp)
 	errno = 0;
 
 	if (arm_hwbp_control_is_enabled (proc_info->wpts[i].control))
-	  if (ptrace (PTRACE_SETHBPREGS, pid, -((i << 1) + 1),
-	      &proc_info->wpts[i].address) < 0)
+	  if (ptrace (PTRACE_SETHBPREGS, pid,
+		      (PTRACE_ARG3_TYPE) -((i << 1) + 1),
+		      &proc_info->wpts[i].address) < 0)
 	    perror_with_name ("Unexpected error setting watchpoint address");
 
 	if (arm_hwbp_control_is_initialized (proc_info->wpts[i].control))
-	  if (ptrace (PTRACE_SETHBPREGS, pid, -((i << 1) + 2),
-	      &proc_info->wpts[i].control) < 0)
+	  if (ptrace (PTRACE_SETHBPREGS, pid,
+		      (PTRACE_ARG3_TYPE) -((i << 1) + 2),
+		      &proc_info->wpts[i].control) < 0)
 	    perror_with_name ("Unexpected error setting watchpoint");
 
 	lwp_info->wpts_changed[i] = 0;
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 043451d..51f6801 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -241,10 +241,6 @@ struct pending_signals
   struct pending_signals *prev;
 };
 
-#define PTRACE_ARG3_TYPE void *
-#define PTRACE_ARG4_TYPE void *
-#define PTRACE_XFER_TYPE long
-
 #ifdef HAVE_LINUX_REGSETS
 static char *disabled_regsets;
 static int num_regsets;
@@ -1151,7 +1147,8 @@ linux_detach_one_lwp (struct inferior_list_entry *entry, void *args)
   /* Finally, let it resume.  */
   if (the_low_target.prepare_to_resume != NULL)
     the_low_target.prepare_to_resume (lwp);
-  if (ptrace (PTRACE_DETACH, lwpid_of (lwp), 0, sig) < 0)
+  if (ptrace (PTRACE_DETACH, lwpid_of (lwp), 0,
+	      (PTRACE_ARG4_TYPE) (long) sig) < 0)
     error (_("Can't detach %s: %s"),
 	   target_pid_to_str (ptid_of (lwp)),
 	   strerror (errno));
@@ -3991,7 +3988,8 @@ regsets_fetch_inferior_registers (struct regcache *regcache)
 	data = buf;
 
 #ifndef __sparc__
-      res = ptrace (regset->get_request, pid, nt_type, data);
+      res = ptrace (regset->get_request, pid,
+		    (PTRACE_ARG3_TYPE) (long) nt_type, data);
 #else
       res = ptrace (regset->get_request, pid, data, nt_type);
 #endif
@@ -4064,7 +4062,8 @@ regsets_store_inferior_registers (struct regcache *regcache)
 	data = buf;
 
 #ifndef __sparc__
-      res = ptrace (regset->get_request, pid, nt_type, data);
+      res = ptrace (regset->get_request, pid,
+		    (PTRACE_ARG3_TYPE) (long) nt_type, data);
 #else
       res = ptrace (regset->get_request, pid, data, nt_type);
 #endif
@@ -4076,7 +4075,8 @@ regsets_store_inferior_registers (struct regcache *regcache)
 
 	  /* Only now do we write the register set.  */
 #ifndef __sparc__
-	  res = ptrace (regset->set_request, pid, nt_type, data);
+	  res = ptrace (regset->set_request, pid,
+			(PTRACE_ARG3_TYPE) (long) nt_type, data);
 #else
 	  res = ptrace (regset->set_request, pid, data, nt_type);
 #endif
diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h
index 07eda12..de4d1fa 100644
--- a/gdb/gdbserver/linux-low.h
+++ b/gdb/gdbserver/linux-low.h
@@ -24,6 +24,10 @@
 
 #include "gdb_proc_service.h"
 
+#define PTRACE_ARG3_TYPE void *
+#define PTRACE_ARG4_TYPE void *
+#define PTRACE_XFER_TYPE long
+
 #ifdef HAVE_LINUX_REGSETS
 typedef void (*regset_fill_func) (struct regcache *, void *);
 typedef void (*regset_store_func) (struct regcache *, const void *);



  reply	other threads:[~2012-03-30 20:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26 22:47 Thiago Jung Bauermann
2012-03-27 16:12 ` Mark Kettenis
2012-03-28  0:27   ` Thiago Jung Bauermann
2012-03-29 16:42     ` Pedro Alves
2012-03-30 20:29       ` Thiago Jung Bauermann [this message]
2012-04-23 18:53         ` Thiago Jung Bauermann
2012-04-24 13:14           ` Pedro Alves
2012-04-24 15:08             ` Thiago Jung Bauermann
2012-03-29 17:02     ` sparc gdbserver bug? (Re: [RFA] handle android bionic ptrace in gdbserver.) Pedro Alves
2012-03-29 17:23       ` H.J. Lu
2012-03-29 18:50         ` Pedro Alves
2012-03-29 21:29           ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1333139333.11673.4.camel@hactar \
    --to=thiago.bauermann@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox