* [commit] Run length encoding for gdbserver
@ 2006-09-21 16:12 Daniel Jacobowitz
2006-09-21 20:54 ` Michael Snyder
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2006-09-21 16:12 UTC (permalink / raw)
To: gdb-patches
The remote protocol supports a simple run length encoding mechanism (in only
one direction - from the stub to the client). This patch implements it in
gdbserver. It doesn't make a huge difference to overall performance, but
can reduce the amount of data sent in some cases by 50%.
I realize I didn't leave any room for the equivalent operation in
the new binary transfer packets in the direction from the client to
the stub, e.g. for downloading. I don't think this is a big deal.
Tested x86_64-pc-linux-gnu and checked in.
--
Daniel Jacobowitz
CodeSourcery
2006-09-21 Daniel Jacobowitz <dan@codesourcery.com>
* remote-utils.c (try_rle): New function.
(putpkt_binary): Use it.
---
gdb/gdbserver/remote-utils.c | 52 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 47 insertions(+), 5 deletions(-)
Index: gdb-trunk/gdb/gdbserver/remote-utils.c
===================================================================
--- gdb-trunk.orig/gdb/gdbserver/remote-utils.c 2006-08-29 09:22:38.000000000 -0400
+++ gdb-trunk/gdb/gdbserver/remote-utils.c 2006-08-29 09:22:49.000000000 -0400
@@ -406,6 +406,50 @@ remote_unescape_input (const gdb_byte *b
return output_index;
}
+/* Look for a sequence of characters which can be run-length encoded.
+ If there are any, update *CSUM and *P. Otherwise, output the
+ single character. Return the number of characters consumed. */
+
+static int
+try_rle (char *buf, int remaining, unsigned char *csum, char **p)
+{
+ int n;
+
+ /* Always output the character. */
+ *csum += buf[0];
+ *(*p)++ = buf[0];
+
+ /* Don't go past '~'. */
+ if (remaining > 97)
+ remaining = 97;
+
+ for (n = 1; n < remaining; n++)
+ if (buf[n] != buf[0])
+ break;
+
+ /* N is the index of the first character not the same as buf[0].
+ buf[0] is counted twice, so by decrementing N, we get the number
+ of characters the RLE sequence will replace. */
+ n--;
+
+ if (n < 3)
+ return 1;
+
+ /* Skip the frame characters. The manual says to skip '+' and '-'
+ also, but there's no reason to. Unfortunately these two unusable
+ characters double the encoded length of a four byte zero
+ value. */
+ while (n + 29 == '$' || n + 29 == '#')
+ n--;
+
+ *csum += '*';
+ *(*p)++ = '*';
+ *csum += n + 29;
+ *(*p)++ = n + 29;
+
+ return n + 1;
+}
+
/* Send a packet to the remote machine, with error checking.
The data of the packet is in BUF, and the length of the
packet is in CNT. Returns >= 0 on success, -1 otherwise. */
@@ -427,11 +471,9 @@ putpkt_binary (char *buf, int cnt)
p = buf2;
*p++ = '$';
- for (i = 0; i < cnt; i++)
- {
- csum += buf[i];
- *p++ = buf[i];
- }
+ for (i = 0; i < cnt;)
+ i += try_rle (buf + i, cnt - i, &csum, &p);
+
*p++ = '#';
*p++ = tohex ((csum >> 4) & 0xf);
*p++ = tohex (csum & 0xf);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [commit] Run length encoding for gdbserver
2006-09-21 16:12 [commit] Run length encoding for gdbserver Daniel Jacobowitz
@ 2006-09-21 20:54 ` Michael Snyder
2006-09-21 20:57 ` Daniel Jacobowitz
0 siblings, 1 reply; 3+ messages in thread
From: Michael Snyder @ 2006-09-21 20:54 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
On Thu, 2006-09-21 at 12:12 -0400, Daniel Jacobowitz wrote:
> The remote protocol supports a simple run length encoding mechanism (in only
> one direction - from the stub to the client). This patch implements it in
> gdbserver. It doesn't make a huge difference to overall performance, but
> can reduce the amount of data sent in some cases by 50%.
This should be a significant gain for libthread_db debugging,
where gdb does a lot of large memory reads behind the scenes.
For stack traces it may not make that much difference, since
those reads are usually small.
Does it work for register packets too?
>
> I realize I didn't leave any room for the equivalent operation in
> the new binary transfer packets in the direction from the client to
> the stub, e.g. for downloading. I don't think this is a big deal.
>
> Tested x86_64-pc-linux-gnu and checked in.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [commit] Run length encoding for gdbserver
2006-09-21 20:54 ` Michael Snyder
@ 2006-09-21 20:57 ` Daniel Jacobowitz
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Jacobowitz @ 2006-09-21 20:57 UTC (permalink / raw)
To: Michael Snyder; +Cc: gdb-patches
On Thu, Sep 21, 2006 at 01:54:48PM -0700, Michael Snyder wrote:
> On Thu, 2006-09-21 at 12:12 -0400, Daniel Jacobowitz wrote:
> > The remote protocol supports a simple run length encoding mechanism (in only
> > one direction - from the stub to the client). This patch implements it in
> > gdbserver. It doesn't make a huge difference to overall performance, but
> > can reduce the amount of data sent in some cases by 50%.
>
> This should be a significant gain for libthread_db debugging,
> where gdb does a lot of large memory reads behind the scenes.
Except none of those reads go over the remote protocol - we only use
libthread_db on the gdbserver side (plus qSymbol communication).
> For stack traces it may not make that much difference, since
> those reads are usually small.
>
> Does it work for register packets too?
Yes. It even works for 'T' packet responses... but that doesn't work
out, because the few characters we can't use to indicate the valid
length of RLE packets correspond to something like 6, 7, and 8 bytes.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-09-21 20:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-21 16:12 [commit] Run length encoding for gdbserver Daniel Jacobowitz
2006-09-21 20:54 ` Michael Snyder
2006-09-21 20:57 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox