public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "simark at simark dot ca" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/27156] gdb.tui/tui-missing-src.exp is unstable
Date: Fri, 08 Jan 2021 23:45:50 +0000	[thread overview]
Message-ID: <bug-27156-4717-EP1eA6tPkQ@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27156-4717@http.sourceware.org/bugzilla/>

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

--- Comment #3 from Simon Marchi <simark at simark dot ca> ---
After comparing two runs, one where the test passed and one where it failed,
with this patch applied:

  https://sourceware.org/pipermail/gdb-patches/2021-January/174827.html

which adds some logging about what happens with the cursor, I think I figured
out what happens.

Tip: when using the patch above, use "make check-read1", that makes the output
easier to read, because we read and handle one character at a time.

When we do "start", this is expected to appear:

---8<---
(gdb) start
Temporary breakpoint 1 at 0x1135: file
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/main.c,
line 6.
Starting program:
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/tui-missing-src

Temporary breakpoint 1, main () at
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/
main.c:6
(gdb)
--->8---

If you're wondering what's up with those paths, it's because the issue happens
when the path is long enough.

In the working case, we see that this is first drawn:

    Temporary breakpoint 1 at 0x1135: file
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/main.c,
line 6.
    Starting program:
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/tui-missing-src

and then the cursor is moved to redraw the locator window:

    +++ Vertical Line Position Absolute (16), cursor: (23, 0) -> (15, 0)

Then, the breakpoint is hit and this is drawn:

    Temporary breakpoint 1, main () at
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/main.c:6
    (gdb)

and then we see "next", the following command.

In the failing case, GDB draws:

    Temporary breakpoint 1 at 0x1135: file
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/main.c,
line 6.
    Starting program:
/tmp/blah/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/allo/src/gdb/testsuite/outputs/gdb.tui/tui-missing-src/tui-missing-src

But then it looks like GDB immediatly draws "next\n".

I think this is happening:

1. GDB executes the start command
2. As part of this, the pty is given to the inferior and put in its original
state, that means "echo" mode is on
3. The testsuite sends "next\n", which gets echo'ed back, before the breakpoint
has hit and GDB has taken back control of the terminal.
4. If the path printed in the previous message was long enough, the cursor is
at the last line of the terminal, so "next\n" goes beyond the last line and we
hit a situation where scrolling would be needed.

To make the issue happen all the time:

1. Build GDB in a directory with a long name
2. Apply this little patch to the test case, which makes "start" take a bit of
time, and guarantees that "next\n" will be sent while terminal is in "inferior"
mode.

diff --git a/gdb/testsuite/gdb.tui/tui-missing-src.exp
b/gdb/testsuite/gdb.tui/tui-missing-src.exp
index 3116864ec801..031b8c003703 100644
--- a/gdb/testsuite/gdb.tui/tui-missing-src.exp
+++ b/gdb/testsuite/gdb.tui/tui-missing-src.exp
@@ -37,7 +37,12 @@ set srcfiles [list $mainfile $f2file]
 # This file will be removed after compilation.
 set fd [open "$mainfile" w]
 puts $fd {
+#include <unistd.h>
 extern int f2(int);
+__attribute__((constructor))
+static void add_a_delay() {
+  sleep (3);
+}
 int
 main ()
 {

I've taken a screen dump when that "FIXME scroll" is hit, we can see that
"next" is at the last line:

Screen Dump (80 x 24):
    0
+------------------------------------------------------------------------------+
    1 |                                                                        
     |
    2 |                                                                        
     |
    3 |                                                                        
     |
    4 |                                                                        
     |
    5 |                                                                        
     |
    6 |                                                                        
     |
    7 |               [ No Source Available ]                                  
     |
    8 |                                                                        
     |
    9 |                                                                        
     |
   10 |                                                                        
     |
   11 |                                                                        
     |
   12 |                                                                        
     |
   13 |                                                                        
     |
   14
+------------------------------------------------------------------------------+
   15 exec No process In:                                                L??  
PC: ?? 
   16 (gdb) startTemporary breakpoint 1 at 0x1152: file
/tmp/blah/blah/blah/blah/blah/
   17
blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/
   18
blah/blah/blah/blah/blah/gdb/testsuite/outputs/gdb.tui/tui-missing-src/main.c,
l
   19 ine 11.                                                                   
   20 Starting program:
/tmp/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/bl
   21
ah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah/gdb/tes
   22 tsuite/outputs/gdb.tui/tui-missing-src/tui-missing-src                    
   23 next

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

      parent reply	other threads:[~2021-01-08 23:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07 15:33 [Bug gdb/27156] New: " simark at simark dot ca
2021-01-07 15:33 ` [Bug gdb/27156] " simark at simark dot ca
2021-01-07 15:33 ` simark at simark dot ca
2021-01-08 23:45 ` simark at simark dot ca [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=bug-27156-4717-EP1eA6tPkQ@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).