public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: cygwin@cygwin.com
Subject: Re: [ANNOUNCEMENT] Updated: libreadline7-7.0.3-3
Date: Thu, 27 Jul 2017 21:39:00 -0000	[thread overview]
Message-ID: <fa8fcc71-5ff5-0cc1-e3ed-f7fece08ae08@redhat.com> (raw)
In-Reply-To: <5dbbf0e4-6374-a9bb-21e5-dd5537e0e19a@redhat.com>


[-- Attachment #1.1: Type: text/plain, Size: 3564 bytes --]

On 07/27/2017 12:08 PM, Eric Blake wrote:

> So I'm back to cmd to try and debug things.  Next, I tried:
> 
> c:\cygwin\bin> .\dash
> <alt-num2-num3-num4>
> 
> and again got Ω; pressing <enter> complains that ./dash: 1: Ω: not found

To double check things, I started .\dash, typed 'echo $$', then in a
second terminal, typed 'gdb --pid XXX' with the dash pid.

(gdb) b read
(gdb) b select
(gdb) c

then in the first window, typed <a><enter> to get dash back to its input
loop

and the second window hit a breakpoint in read.  But that didn't get me
very far:

Thread 1 hit Breakpoint 1, read (fd=0, ptr=0x41b540 <basebuf>, len=1024)
    at /usr/src/debug/cygwin-2.8.2-1/winsup/cygwin/syscalls.cc:1118
1118    {
(gdb) fin
Run till exit from #0  read (fd=0, ptr=0x41b540 <basebuf>, len=1024)
    at /usr/src/debug/cygwin-2.8.2-1/winsup/cygwin/syscalls.cc:1118
[New Thread 628.0x70c]

readline: readline_callback_read_char() called with no handler!
Aborted (core dumped)

Urgh - gdb uses readline, so debugging readline with gdb may prove
harder than planned if I don't time things right.  A second time around,
and instead of using fin, I stepped through:

1118   {
(gdb) n
...
(gdb) n
1139         cfd->read (ptr, len);
(gdb) n
[New Thread 736.0x960]

at the point of the new thread, I typed <alt-num2-num3-num4><enter> in
the first terminal, which let the read return, and the buffer contents
are correct:

1140         res = len;
(gdb) p len
$1 = 3
(gdb) p/x ((char*)ptr)[0]
$2 = 0xce
(gdb) p/x ((char*)ptr)[1]
$3 = 0xa9
(gdb) p ((char*)ptr)[2]
$4 = '\n'

so whatever dash did, it read a solid block of input from the terminal;
from there, I quit debugging - obviously dash is not doing things
piecemeal, and manages to replay the same output as it just read in
input (when you aren't trying hard to be interactive, life is easy).

> 
> However, when I try:
> 
> c:\cygwin\bin> .\bash --norc
> <alt-num2-num3-num4>
> 
> the display shows :\251

Repeating the gdb attach trick, I'm able to catch bash at this
breakpoint, even without hitting <enter>, just by typing <a>:

Thread 1 hit Breakpoint 1, read (fd=0, ptr=0x28c013, len=1)
    at /usr/src/debug/cygwin-2.8.2-1/winsup/cygwin/syscalls.cc:1118

Notice a difference?  dash had the terminal set up in line-oriented
mode, and blindly reads until EOL or until len=1024 is exhausted; bash
has the terminal set up in byte-oriented mode, and is only reading len=1
at a time.  So when entering a UTF-8 character to dash, the whole
character lands in the buffer at once, while under bash (presumably, as
I haven't debugged that far yet), bash must reconstruct the Unicode
characters from the individual bytes.

Stepping through the breakpoints on <alt-num2-num3-num4> sees 0xce on
the first read, and 0xa9 on the second.  But, in between the two read
breakpoints, the first terminal displayed ':'.  So the input is still
making it correctly INTO readline; but being munged on the way to
output; and it very much looks like readline's fault rather than
cygwin's.  I'm still trying to put breakpoints in the right places (the
call stack at read() points to rl_getc(), from rl_read_key(), from
readline_internal_char()...), but this is at least to let you know how
I'm tackling the issue, in case it helps someone else spot a solution
faster than me by starting from the same information.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

  reply	other threads:[~2017-07-27 18:38 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-13 19:53 [ANNOUNCEMENT] Updated: libreadline7-7.0.3-3, libreadline-devel-7.0.3-3 Eric Blake (cygwin)
2017-03-25  0:46 ` Steven Penny
2017-04-13 19:07   ` [ANNOUNCEMENT] Updated: libreadline7-7.0.3-3 Steven Penny
2017-04-14  8:27     ` Eric Blake
2017-04-15 10:59       ` Steven Penny
2017-05-15 18:21         ` Eric Blake
2017-05-15 20:46           ` Chet Ramey
2017-06-18 15:53             ` Steven Penny
2017-07-04 21:53             ` Steven Penny
2017-07-27 21:37         ` Eric Blake
2017-07-27 21:39           ` Eric Blake [this message]
2017-07-27 21:46           ` Steven Penny
2017-07-28  8:28             ` Eric Blake
2017-07-28 14:55               ` Steven Penny
2017-07-28 18:31                 ` Eric Blake
2017-07-28 18:39                   ` Steven Penny
2017-07-28 23:55                     ` Eric Blake
2017-07-29  1:55                       ` Cygwin.bat (was: [ANNOUNCEMENT] Updated: libreadline7-7.0.3-3) Achim Gratz
2017-07-29  2:48                       ` [ANNOUNCEMENT] Updated: libreadline7-7.0.3-3 Doug Henderson
2017-07-29  4:23                         ` Steven Penny
2017-07-30 18:38                           ` Doug Henderson
2017-07-30 19:54                             ` Steven Penny
2017-07-29  8:45                       ` Steven Penny
2017-07-29 10:08                         ` Eric Blake
2017-07-31 18:36                     ` Corinna Vinschen
2017-07-31 20:01                       ` Steven Penny
2017-07-31 20:05                       ` David Macek
2017-07-31 21:13                         ` David Macek
     [not found]                         ` <20170731200146.GD18950@calimero.vinschen.de>
     [not found]                           ` <20170731211327.GG18950@calimero.vinschen.de>
2017-08-01  0:56                             ` Steven Penny
2017-08-01  8:45                               ` Corinna Vinschen
2017-08-01 14:48                                 ` Corinna Vinschen
2017-08-01 18:20                                   ` Steven Penny
2017-08-01 18:54                                     ` Achim Gratz
2017-08-01 19:02                                       ` Eric Blake
2017-08-01  7:22                             ` David Macek
2017-08-01  8:46                               ` Corinna Vinschen
     [not found]                           ` <160b3569-d448-1898-3dcd-b7133a772527@SystematicSw.ab.ca>
2017-08-01  8:44                             ` Corinna Vinschen

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=fa8fcc71-5ff5-0cc1-e3ed-f7fece08ae08@redhat.com \
    --to=eblake@redhat.com \
    --cc=cygwin@cygwin.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).