From: Pedro Alves <palves@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [commit] Adjust ia64_linux_xfer_partial following to_xfer_partial API change.
Date: Tue, 25 Feb 2014 17:31:00 -0000 [thread overview]
Message-ID: <530CD37F.3050106@redhat.com> (raw)
In-Reply-To: <1393345450-20878-1-git-send-email-brobecker@adacore.com>
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 (¤t_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
next prev parent reply other threads:[~2014-02-25 17:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-25 16:24 Joel Brobecker
2014-02-25 17:31 ` Pedro Alves [this message]
2014-02-26 2:14 ` Joel Brobecker
2014-02-26 11:16 ` Pedro Alves
2014-02-26 14:10 ` Joel Brobecker
2014-02-26 11:19 ` 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=530CD37F.3050106@redhat.com \
--to=palves@redhat.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/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