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: [commit] Adjust ia64_linux_xfer_partial following to_xfer_partial API change.


On 02/25/2014 04:24 PM, Joel Brobecker wrote:
> +  if (object == TARGET_OBJECT_UNWIND_TABLE && readbuf != NULL)
> +    {
> +      gdb_byte *tmp_buf = alloca (offset + len);
> +      ULONGEST xfered;
> +
> +      xfered = syscall (__NR_getunwind, readbuf, offset + len);

It seems this should have passed tmp_buf instead of readbuf?
Also, I don't think the "offset + len" size is the
right size to pass down to the syscall.

From:

http://lxr.free-electrons.com/source/arch/ia64/kernel/unwind.c#L2313

2291  * This system call copies the unwind data into the buffer pointed to by BUF and returns
2292  * the size of the unwind data.  If BUF_SIZE is smaller than the size of the unwind data
2293  * or if BUF is NULL, nothing is copied, but the system call still returns the size of the
2294  * unwind data.

So it looks like this code is getting lucky and the caller
is requesting enough bytes:

  x = target_read_alloc (&current_target, TARGET_OBJECT_UNWIND_TABLE,
			 NULL, buf_p);

But to_xfer_partial implementations should not assume that.  E.g.,
change target_read_alloc_1 to start by requesting a byte at a time
instead of 4096, and this will fail.

> +      if (xfered <= 0)

Note that because xfered is ULONGEST, this won't actually
detect errors.

> +	return TARGET_XFER_E_IO;
> +      else if (xfered <= offset)

Not sure I follow this one.

> +	return TARGET_XFER_EOF;
> +      else
> +	{
> +	  memcpy (readbuf, tmp_buf + offset, xfered - offset);
> +	  *xfered_len = xfered - offset;
> +	  return TARGET_XFER_OK;
> +	}
> +    }

I suggest something along the lines of the below instead.
Should handle partial requests, and clearer to read, I think.
Completely untested, though.

---
 gdb/ia64-linux-nat.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/gdb/ia64-linux-nat.c b/gdb/ia64-linux-nat.c
index c057b55..65a57d2 100644
--- a/gdb/ia64-linux-nat.c
+++ b/gdb/ia64-linux-nat.c
@@ -850,20 +850,30 @@ ia64_linux_xfer_partial (struct target_ops *ops,
 {
   if (object == TARGET_OBJECT_UNWIND_TABLE && readbuf != NULL)
     {
-      gdb_byte *tmp_buf = alloca (offset + len);
-      ULONGEST xfered;
+      static long gate_table_size;
+      gdb_byte *tmp_buf;
+      long res;
 
-      xfered = syscall (__NR_getunwind, readbuf, offset + len);
-      if (xfered <= 0)
-	return TARGET_XFER_E_IO;
-      else if (xfered <= offset)
+      /* Probe for the table size once.  */
+      if (gate_table_size == 0)
+        gate_table_size = syscall (__NR_getunwind, NULL, 0);
+      if (gate_table_size < 0)
+	return TARGET_XFER_EIO;
+
+      if (offset >= gate_table_size)
 	return TARGET_XFER_EOF;
-      else
-	{
-	  memcpy (readbuf, tmp_buf + offset, xfered - offset);
-	  *xfered_len = xfered - offset;
-	  return TARGET_XFER_OK;
-	}
+
+      tmp_buf = alloca (gate_table_size);
+      if (syscall (__NR_getunwind, tmp_buf, gate_table_size) < 0)
+	return TARGET_XFER_EIO;
+      gdb_assert (res == gate_table_size);
+
+      if (offset + len > gate_table_size)
+	len = gate_table_size - offset;
+
+      memcpy (readbuf, tmp_buf + offset, len);
+      *xfered_len = len;
+      return TARGET_XFER_OK;
     }
 
   return super_xfer_partial (ops, object, annex, readbuf, writebuf,
-- 
1.7.11.7



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