From: Simon Marchi <simark@simark.ca>
To: Kamil Rytarowski <n54@gmx.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Add common write_memory and read_memory NetBSD routines
Date: Wed, 7 Oct 2020 07:27:09 -0400 [thread overview]
Message-ID: <7a0f3c3e-5d46-237b-afe0-f4cb1aec3022@simark.ca> (raw)
In-Reply-To: <20201007041352.4682-1-n54@gmx.com>
Ok with these nits fixed:
On 2020-10-07 12:13 a.m., Kamil Rytarowski wrote:
> diff --git a/gdb/nat/netbsd-nat.c b/gdb/nat/netbsd-nat.c
> index 41b67cb72fc..8316935f039 100644
> --- a/gdb/nat/netbsd-nat.c
> +++ b/gdb/nat/netbsd-nat.c
> @@ -210,4 +210,84 @@ qxfer_siginfo (pid_t pid, const char *annex, unsigned char *readbuf,
> return len;
> }
>
> +/* See netbsd-nat.h. */
> +
> +int
> +write_memory (pid_t pid, unsigned const char *writebuf, CORE_ADDR offset,
> + size_t len, size_t *xfered_len)
> +{
> + struct ptrace_io_desc io;
> + io.piod_op = PIOD_WRITE_D;
> + io.piod_len = len;
> +
> + size_t bytes_written = 0;
> +
> + /* Zero length write always succeeds. */
> + if (len > 0)
> + {
> + do
> + {
> + io.piod_addr = (void *)(writebuf + bytes_written);
> + io.piod_offs = (void *)(offset + bytes_written);
> +
> + errno = 0;
> + int rv = ptrace (PT_IO, pid, &io, 0);
> + if (rv == -1)
> + {
> + gdb_assert (errno != 0);
> + return errno;
> + }
> + if (io.piod_len == 0)
> + return 0;
> +
> + bytes_written += io.piod_len;
> + io.piod_len = len - bytes_written;
> + }
> + while (bytes_written < len);
> + }
> +
> + if (xfered_len)
!= nullptr
> + *xfered_len = bytes_written;
> +
> + return 0;
> +}
> +
> +/* See netbsd-nat.h. */
> +
> +int
> +read_memory (pid_t pid, unsigned char *readbuf, CORE_ADDR offset,
> + size_t len, size_t *xfered_len)
> +{
> + struct ptrace_io_desc io;
> + io.piod_op = PIOD_READ_D;
> + io.piod_len = len;
> +
> + size_t bytes_read = 0;
> +
> + /* Zero length write always succeeds. */
> + if (len > 0)
> + {
> + do
> + {
> + io.piod_offs = (void *)(offset + bytes_read);
> + io.piod_addr = readbuf + bytes_read;
> +
> + int rv = ptrace (PT_IO, pid, &io, 0);
> + if (rv == -1)
> + return errno;
> + if (io.piod_len == 0)
> + return 0;
> +
> + bytes_read += io.piod_len;
> + io.piod_len = len - bytes_read;
> + }
> + while (bytes_read < len);
> + }
> +
> + if (xfered_len)
!= nullptr
> diff --git a/gdbserver/netbsd-low.cc b/gdbserver/netbsd-low.cc
> index 7bec55a56ac..e5ea8233e00 100644
> --- a/gdbserver/netbsd-low.cc
> +++ b/gdbserver/netbsd-low.cc
> @@ -556,36 +556,8 @@ int
> netbsd_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
> int size)
> {
> - struct ptrace_io_desc io;
> - io.piod_op = PIOD_READ_D;
> - io.piod_len = size;
> -
> pid_t pid = current_process ()->pid;
> -
> - int bytes_read = 0;
> -
> - if (size == 0)
> - {
> - /* Zero length write always succeeds. */
write -> read
Simon
prev parent reply other threads:[~2020-10-07 11:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 4:13 Kamil Rytarowski
2020-10-07 11:27 ` Simon Marchi [this message]
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=7a0f3c3e-5d46-237b-afe0-f4cb1aec3022@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=n54@gmx.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).