From: Pedro Alves <pedro@palves.net>
To: Lancelot SIX <lsix@lancelotsix.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] gdbserver/linux: Access memory even if threads are running
Date: Mon, 4 Apr 2022 15:34:44 +0100 [thread overview]
Message-ID: <542fdf92-fe28-b9eb-9d7e-d46805400b42@palves.net> (raw)
In-Reply-To: <c0e12e1c-0ed0-e5b9-58e8-0cf8eb709073@palves.net>
On 2022-03-31 12:39, Pedro Alves wrote:
> On 2022-03-30 14:22, Lancelot SIX wrote:
>>> +/* Helper for read_memory/write_memory using /proc/PID/mem. Because
>>> + we can use a single read/write call, this can be much more
>>> + efficient than banging away at PTRACE_PEEKTEXT. Also, unlike
>>> + PTRACE_PEEKTEXT/PTRACE_POKETEXT, this works with running threads.
>>> + One an only one of READBUF and WRITEBUF is non-null. If READBUF is
>>> + not null, then we're reading, otherwise we're writing. */
>>
>> Hi,
>>
>> Seems to me that this property can be asserted. WDYT?
>>
>> Something like
>>
>> gdb_assert ((readbuf == nullptr) != (writebuf == nullptr));
>>
>> should do.
>>
>
> Doesn't hurt. I've added that locally. Thanks.
Funny enough, it does hurt... Running the testsuite with that change
shows the assertion triggering. This is because GDB may ask to write LEN==0
bytes, and we have this
int
target_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
ssize_t len)
{
/* Make a copy of the data because check_mem_write may need to
update it. */
gdb::byte_vector buffer (myaddr, myaddr + len);
check_mem_write (memaddr, buffer.data (), myaddr, len);
return the_target->write_memory (memaddr, buffer.data (), len);
}
... and buffer.data() may return NULL if the vector is empty. I've added
a new patch to the series to add an early return if len==0. I'll send
a v2 series in a bit.
next prev parent reply other threads:[~2022-04-04 14:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 12:43 [PATCH 0/3] gdbserver/linux: access memory while threads are running without pausing Pedro Alves
2022-03-30 12:43 ` [PATCH 1/3] gdbserver/qXfer::threads, prepare_to_access_memory=>target_pause_all Pedro Alves
2022-03-30 12:43 ` [PATCH 2/3] gdbserver/linux: Access memory even if threads are running Pedro Alves
2022-03-30 13:22 ` Lancelot SIX
2022-03-31 11:39 ` Pedro Alves
2022-04-04 14:34 ` Pedro Alves [this message]
2022-03-30 12:43 ` [PATCH 3/3] gdbserver: Eliminate prepare_to_access_memory 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=542fdf92-fe28-b9eb-9d7e-d46805400b42@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--cc=lsix@lancelotsix.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).