[RFA] Implement darwin remote TARGET_OBJECT_DARWIN_DYLD_INFO.

Message ID 1519726190-31009-1-git-send-email-roirand@adacore.com
State New, archived
Headers

Commit Message

Xavier Roirand Feb. 27, 2018, 10:09 a.m. UTC
  From: Xavier Roirand <xavier.roirand@adacore.com>

gdb/ChangeLog (Tristan Gingold <gingold@adacore.com>):

	* remote.c (remote_xfer_partial): Handle DARWIN_DYLD_INFO.
---
 gdb/ChangeLog |  6 ++++++
 gdb/remote.c  | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
  

Comments

tgingold@free.fr Feb. 27, 2018, 10:25 a.m. UTC | #1
Hi,

A bit of context.

I have never submitted this code before because it doesn't use the official gdb remote packet (‘qXfer:libraries:read’) but the one used by Apple (aka lldb) debugserver.

So with this patch, gdb is able to use debugserver.

Tristan.

----- Mail original -----
> From: Xavier Roirand <xavier.roirand@adacore.com>
> 
> gdb/ChangeLog (Tristan Gingold <gingold@adacore.com>):
> 
> 	* remote.c (remote_xfer_partial): Handle DARWIN_DYLD_INFO.
> ---
>  gdb/ChangeLog |  6 ++++++
>  gdb/remote.c  | 33 +++++++++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index b9a9bcd..098ebda 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,9 @@
> +
> +2018-02-27  Tristan Gingold  <gingold@adacore.com>
> +
> +	Pushed by Xavier Roirand <roirand@adacore.com>.
> +	* remote.c (remote_xfer_partial): Handle DARWIN_DYLD_INFO.
> +
>  2018-02-26  Maciej W. Rozycki  <macro@mips.com>
>  
>  	* mips-tdep.c (mips_gdbarch_init): Don't use a 32-bit BFD
> diff --git a/gdb/remote.c b/gdb/remote.c
> index 15d6c5b..95fbfc1 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -10495,6 +10495,39 @@ remote_xfer_partial (struct target_ops *ops,
> enum target_object object,
>  	return TARGET_XFER_E_IO;
>      }
>  
> +  if (object == TARGET_OBJECT_DARWIN_DYLD_INFO)
> +    {
> +      /* Can only read.  */
> +      if (readbuf == NULL)
> +	return TARGET_XFER_E_IO;
> +
> +      if (offset == 0 && len <= 8)
> +	{
> +	  ULONGEST addr;
> +	  int i;
> +
> +	  putpkt ("qShlibInfoAddr");
> +	  getpkt (&rs->buf, &rs->buf_size, 0);
> +	  if (packet_check_result (rs->buf) != PACKET_OK)
> +	    return TARGET_XFER_E_IO;
> +
> +	  /* The packet contains the address in hex (but not suitable for
> +	     hex2bin as the number of digits is arbitrary.  */
> +	  addr = strtoulst (rs->buf, NULL, 16);
> +
> +	  /* Store it in big-endian.  */
> +	  for (i = len - 1; i >= 0; i--)
> +	    {
> +	      readbuf[i] = addr & 0xff;
> +	      addr >>= 8;
> +	    }
> +
> +	  *xfered_len = len;
> +	  return TARGET_XFER_OK;
> +	}
> +      else
> +	return TARGET_XFER_EOF;
> +    }
>    /* Only handle flash writes.  */
>    if (writebuf != NULL)
>      {
> --
> 2.7.4
> 
>
  
Yao Qi Feb. 27, 2018, 10:42 a.m. UTC | #2
tgingold@free.fr writes:

Hi Tristan,
Thanks for the input,

> I have never submitted this code before because it doesn't use the
> official gdb remote packet (‘qXfer:libraries:read’) but the one used
> by Apple (aka lldb) debugserver.

With this patch applied, GDB starts to send packet qShlibInfoAddr.

> So with this patch, gdb is able to use debugserver.

This is a good justification to add this packet, but we still need to
document this packet.
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b9a9bcd..098ebda 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@ 
+
+2018-02-27  Tristan Gingold  <gingold@adacore.com>
+
+	Pushed by Xavier Roirand <roirand@adacore.com>.
+	* remote.c (remote_xfer_partial): Handle DARWIN_DYLD_INFO.
+
 2018-02-26  Maciej W. Rozycki  <macro@mips.com>
 
 	* mips-tdep.c (mips_gdbarch_init): Don't use a 32-bit BFD
diff --git a/gdb/remote.c b/gdb/remote.c
index 15d6c5b..95fbfc1 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -10495,6 +10495,39 @@  remote_xfer_partial (struct target_ops *ops, enum target_object object,
 	return TARGET_XFER_E_IO;
     }
 
+  if (object == TARGET_OBJECT_DARWIN_DYLD_INFO)
+    {
+      /* Can only read.  */
+      if (readbuf == NULL)
+	return TARGET_XFER_E_IO;
+
+      if (offset == 0 && len <= 8)
+	{
+	  ULONGEST addr;
+	  int i;
+
+	  putpkt ("qShlibInfoAddr");
+	  getpkt (&rs->buf, &rs->buf_size, 0);
+	  if (packet_check_result (rs->buf) != PACKET_OK)
+	    return TARGET_XFER_E_IO;
+
+	  /* The packet contains the address in hex (but not suitable for
+	     hex2bin as the number of digits is arbitrary.  */
+	  addr = strtoulst (rs->buf, NULL, 16);
+
+	  /* Store it in big-endian.  */
+	  for (i = len - 1; i >= 0; i--)
+	    {
+	      readbuf[i] = addr & 0xff;
+	      addr >>= 8;
+	    }
+
+	  *xfered_len = len;
+	  return TARGET_XFER_OK;
+	}
+      else
+	return TARGET_XFER_EOF;
+    }
   /* Only handle flash writes.  */
   if (writebuf != NULL)
     {