public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Ciaran Woodward <ciaranwoodward@xmos.com>
To: Pedro Alves <pedro@palves.net>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH] gdb/doc: Fix incorrect information in RSP doc
Date: Wed, 24 Apr 2024 16:28:49 +0000	[thread overview]
Message-ID: <PAXPR09MB5583D5479F4798B7031F5041B9102@PAXPR09MB5583.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <5ff21602-f875-4eda-8507-12a48bcbe340@palves.net>


> > For instance, GDB's remote.c treats it as the maximum
> > number of data bytes.  See remote_read_bytes_1, where the
> > size of the request is capped at PacketSize/2 (for
> > hex-encoding).
> 
> 
> OTOH, we have code like this:
> 
> 
>   /* Should rsa->sizeof_g_packet needs more space than the
>      default, adjust the size accordingly.  Remember that each byte is
>      encoded as two characters.  32 is the overhead for the packet
>      header / footer.  NOTE: cagney/1999-10-26: I suspect that 8
>      (``$NN:G...#NN'') is a better guess, the below has been padded a
>      little.  */
>   if (this->sizeof_g_packet > ((this->remote_packet_size - 32) / 2))
>     this->remote_packet_size = (this->sizeof_g_packet * 2 + 32);
> 
> 
> and this:
> 
>  remote_target::remote_write_bytes_aux ()
>  ...
>    payload_capacity_bytes = get_memory_write_packet_size ();
> 
>    /* The packet buffer will be large enough for the payload;
>       get_memory_packet_size ensures this.  */
>    rs->buf[0] = '\0';
> 
>    /* Compute the size of the actual payload by subtracting out the
>       packet header and footer overhead: "$M<memaddr>,<len>:...#nn".  */
> 
>    payload_capacity_bytes -= strlen ("$,:#NN");
> 
> 
> So looks like we have a mess?  Most code in remote.c seems to assume
> get_remote_packet_size() returns the max payload size, except, not always.
> 
> I think it would be good to rename remote_packet_size to
> remote_packet_data_size
> or remote_packet_payload_size and similarly rename the few functions
> around this,
> like get_remote_packet_size and get_memory_write_packet_size, and fix
> those
> cases above accordingly.

Ah, yes - not sure where that '32' came from, since it seems like it
could guess the remote packet size too high. In combination with the
fact that many remotes won't return *all* of the registers in the g
response either, so it has 2 mechanisms to over-estimate.

Thankfully I don't think that really matters since modern remotes
should always specify PacketSize explicitly.

I think the rename is a good idea - I don’t know how I feel about
'fixing' things though, since the RSP is very sensitive to backwards
compatibility issues and its impossible to check all the potential
stubs. It looks like the remote_write_packet_aux underestimates
the size of the buffer at least, so we won't overflow any remote
server in the current state.

      reply	other threads:[~2024-04-24 16:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 15:35 Ciaran Woodward
2024-04-22 15:40 ` Eli Zaretskii
2024-04-23 16:04   ` Luis Machado
2024-04-23 18:58 ` Pedro Alves
2024-04-24 16:28   ` Ciaran Woodward [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=PAXPR09MB5583D5479F4798B7031F5041B9102@PAXPR09MB5583.eurprd09.prod.outlook.com \
    --to=ciaranwoodward@xmos.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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).