public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "aburgess at redhat dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug mi/28711] gdb closes when displaying structs with long field names in eclipse
Date: Mon, 20 Dec 2021 18:44:00 +0000	[thread overview]
Message-ID: <bug-28711-4717-mHh5PM5m9H@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28711-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=28711

--- Comment #4 from Andrew Burgess <aburgess at redhat dot com> ---
So what happens is that a lot of input arrives on the read file descriptor in
one go.  GDB does a fgetc, and glibc then does a read on the file descriptor. 
I see glibc read up to 1024 bytes.  Clearly, the original bug reporter saw much
smaller reads from glibs, but that's not really important.

If the first command that arrives (including the commands final \n character)
is larger than one read buffer (so for me, larger than 1024 bytes), then glibc
will perform a second read, also of up to 1024 bytes to find the rest of the
command.

If we imagine that the final \n character is the first character in the second
read buffer, and that we get a full 1024 bytes in the second read buffer, then
GDB has read 1023 bytes more than it actually needed.  As a result, the file
position of the file descriptor is 1023 bytes ahead of where glibc actually
thinks it should be in the file.

But, moving on, GDB processes the first command, which results in some output. 
GDB wants to print this output, and eventually, this output is sent to the
output file descriptor via glibc.

glibc notices that the file position is 1023 bytes ahead of where it should be,
and so tries to lseek the file position back to the expected location.

lseek isn't supported on terminals, and so things start to go wrong.  I haven't
bothered to track down exactly what causes GDB to exit, because I'm not
convinced it's important.  What matters is that by sharing the file descriptor
for both reading and writing, we end up triggering these invalid lseeks from
within glibc.


It turns out that the code I changed in comment #3, once upon a time, did open
the terminal 3 times.  This was changed in this commit:

  commit afe09f0b6311a4dd1a7e2dc6491550bb228734f8
  Date:   Thu Jul 18 17:20:04 2019 +0100

    Fix for using named pipes on Windows

The idea seemed to be, to use a named pipe on windows instead of a terminal.

First, I don't know anything about named pipes on windows, but...

... if we consider named pipes on Linux, I'm not convinced that using named
pipes will work here.  My assumption is that the debugger frontend would create
a named pipe, and then try to attach the MI interface to that pipe.

GDB would then be writing MI output to the pipe, and also, reading incoming
commands from the pipe.

The problem is, that when GDB writes out MI output, it will also see that
output as incoming commands.

On the other end, we have the same problem.  The front end writes commands to
the pipe and then tries to read MI output from the pipe.  But the command that
was just written will be available for reading, and so will be consumed as MI
output.

In short, you end up in a mess with everyone pumping output into the pipe and
then competing to consume that same output.

What I wonder instead is, maybe we should change the `new-ui` command. 
Currently we allow `new-ui INTERPRETER PATH-TO-PTTY`.  Maybe we should allow
something like this too: `new-ui INTERPRETER PATH-TO-INPUT-PIPE
PATH-TO-OUTPUT-PIPE PATH-TO-ERROR-PIPE`

If only one path is provided, we open it 3 times for in/out/err.  If three
paths are provided then each is opened once.  This would require the front end
to then manage three named pipes though.

Maybe named pipes on windows behave differently though...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2021-12-20 18:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-17 13:07 [Bug mi/28711] New: " cristian.lupascu at nxp dot com
2021-12-17 16:53 ` [Bug mi/28711] " aburgess at redhat dot com
2021-12-17 16:55 ` aburgess at redhat dot com
2021-12-18 11:39 ` aburgess at redhat dot com
2021-12-20 18:44 ` aburgess at redhat dot com [this message]
2021-12-24 17:03 ` fweimer at redhat dot com
2021-12-26 19:06 ` tromey at sourceware dot org
2021-12-27 10:15   ` Andrew Burgess
2021-12-27 10:15 ` aburgess at redhat dot com
2022-01-17 16:43 ` aburgess at redhat dot com
2022-02-07 10:25 ` cvs-commit at gcc dot gnu.org
2022-02-08 10:16 ` aburgess at redhat dot com
2022-02-09 19:48 ` cristian.lupascu at nxp dot com
2022-02-09 23:42 ` tromey at sourceware dot org
2022-10-31 16:48 ` jonah at kichwacoders dot com
2022-10-31 16:54 ` jonah at kichwacoders dot com

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=bug-28711-4717-mHh5PM5m9H@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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).