From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 422A3386191F for ; Wed, 7 Oct 2020 11:27:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 422A3386191F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E62B71E58E; Wed, 7 Oct 2020 07:27:09 -0400 (EDT) Subject: Re: [PATCH] Add common write_memory and read_memory NetBSD routines To: Kamil Rytarowski , gdb-patches@sourceware.org References: <20201007041352.4682-1-n54@gmx.com> From: Simon Marchi Message-ID: <7a0f3c3e-5d46-237b-afe0-f4cb1aec3022@simark.ca> Date: Wed, 7 Oct 2020 07:27:09 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201007041352.4682-1-n54@gmx.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Oct 2020 11:27:11 -0000 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