Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: Josip Seketa <josip.seketa@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: read a serial's error fd once per input chunk, not per character
Date: Thu, 05 Nov 2026 13:05:05 -0700	[thread overview]
Message-ID: <87pkwjxcwe.fsf@tromey.com> (raw)
In-Reply-To: <179373584304.213326.6133225504256345073@gmail.com> (Josip Seketa's message of "Tue, 03 Nov 2026 19:57:23 +0000")

>>>>> Josip Seketa <josip.seketa@gmail.com> writes:

> generic_readchar reads the error fd after every character it returns.
> For a pipe target ("target remote | command"), that fd is the
> command's stderr.
> ser-pipe.c has no "avail" method, so each of these reads is a read(2)
> on a non-blocking socket, which nearly always fails with EAGAIN.
> Reading memory therefore costs one extra system call per byte.

Thank you for the patch.

I hadn't previously taken any notice of this code.  Ugly stuff :-(

> Read the error fd only when the character is the first one of a chunk
> read from the device, or is an error or end of file.

I find it a bit hard to untangle all this but I think there are two
cases here:

1. In async mode, the error fd is handled via the main select/poll loop.

2. In sync mode, the error fd is handled when reading from the main
   serial fd as well.

And (again IIUC) your patch addresses an issue with scenario 2.

And I guess this makes sense.  We can't always handle the error fd via
the poll loop, because in sync mode gdb will be blocked in some read()
in remote.c.

Ok so far.  But then, consider this comment from ser-base.c:

      /* We also need to check and consume the stderr because it could
	 come before the stdout for some stubs.  If we just sit and wait
	 for stdout, we would hit a deadlock for that case.  */

From this I think the idea is to consider a remote that's writing to
both its stdout and stderr.  And, if the stderr pipe fills up, then a
read attempt by gdb on the remote's stdout will never finish -- because
the remote will be blocked while writing.

So, gdb has to be sure to drain the error output while reading.

And so my question is whether your patch preserves this.  I somewhat
suspect it does not.

Also I was wondering why you changed the call in generic_readchar (which
passes "1" as the close_fd parameter) and not the call in
do_ser_base_readchar.

I didn't dig much deeper than this.  The code here is a bit confusing I
think.

Anyway, I do think some kind of change here would be good.  I'm just not
sure exactly what.

Maybe one idea would be if the read from the remote's stdout fails (like
if we're doing a non-blocking read, which I didn't look into), then that
might be a good time to read from the error fd?

I also have a crazier idea involving threads but TBH I'm not sure that
is sensible at all.


Finally I wanted to say:

> Before: 1.86 to 1.89 s, 2,689,827 read calls.
> After: 0.034 to 0.035 s, 1,793 read calls.

This is a nice find, thank you.

Here at AdaCore, we've noticed that remote testing over ssh is
noticeably slower than remote testing over a socket.  Investigating this
has never gotten to the top of my to-do list -- but I wonder if you've
found the problem.

Tom

  reply	other threads:[~2026-11-05 20:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 19:57 Josip Seketa
2026-11-05 20:05 ` Tom Tromey [this message]
2026-11-06 18:44   ` [PATCH v2 0/2] gdb: read a pipe command's stderr while waiting, " Josip Seketa
2026-11-06 18:44     ` [PATCH v2 1/2] gdb: watch a serial's error fd while waiting for input Josip Seketa
2026-11-06 18:44     ` [PATCH v2 2/2] gdb: read a serial's error fd once per input chunk, not per character Josip Seketa

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=87pkwjxcwe.fsf@tromey.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=josip.seketa@gmail.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