Bug 14332 - Output from inferior confuses gdbtui
Summary: Output from inferior confuses gdbtui
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: tui (show other bugs)
Version: 7.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 17476 28482 30440 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-07-05 13:09 UTC by Joachim Protze
Modified: 2023-05-24 14:13 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
print 20 lines of "hello world!" (122 bytes, text/x-csrc)
2012-07-05 13:09 UTC, Joachim Protze
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Protze 2012-07-05 13:09:46 UTC
Created attachment 6510 [details]
print 20 lines of "hello world!"

To reproduce:
gcc -g hello2.c -o hello
gdb -ex run -tui ./hello

The first "Hello World!\n" is overwritten by the gdb output, therefore the printf is in a for-loop. 

Two symptoms can be viewed: 

- the \n produces a line feed only, no carriage return

- the output of the inferior is not fetched and reported in the output subscreen
Comment 1 Pedro Alves 2015-07-02 13:04:51 UTC
Can't see how to get around with unless we create a new pty master/slave for the inferior, instead of having it share the terminal with gdb.
Comment 2 Pedro Alves 2015-07-02 13:05:34 UTC
*** Bug 17476 has been marked as a duplicate of this bug. ***
Comment 3 Tom Tromey 2018-09-02 22:52:09 UTC
It would be interesting to specify how this would all work.

First, it seems like having gdb make a new pty and set TERM=dumb
would not be extremely hard.  This would allow capturing of
the output.

I am not sure how the input side would work.  Put the terminal
into raw mode and send the characters immediately?  Then what about
C-c?  (Perhaps obviously I do not know much about ptys.)

Perhaps this should be done in gdb/common so that it can be reused
by gdbserver.


In the TUI it would even be possible to emulate a real terminal
in a curses window.  I found libraries that would make this simpler:

https://github.com/deadpixi/libtmt
https://www.freedesktop.org/wiki/Software/libtsm/

The first seems simplest.  I'd been hoping that GNU screen would have
some kind of library mode we could reuse, but it doesn't seem to;
though an alternative approach might be to script screen a bit.

However, activating this mode seems tricky because it seems like it
wouldn't make sense from the CLI.
Comment 4 Pedro Alves 2018-09-03 11:39:24 UTC
Take a look at this branch:
 https://github.com/palves/gdb/commits/palves/tty-always-separate-session

Most of the branch is about infrastructure making GDB make a new pty for the inferior and then marshalling input/output between the inferior's pty and gdb's.
That allows fixing a set of problems, including being able to Ctrl-C when the inferior is stopped in a non-interruptible syscall (I think we could interrupt it with PTRACE_INTERRUPT), or when the inferior is ignoring SIGINT with SIG_IGN.

The tui patch on top is a hack, of course.  We'd need to come up with a cleaner interface.  

(The fork-child related changes in the branch need better abstracting too.)
Comment 5 Tom de Vries 2023-05-22 16:24:34 UTC
*** Bug 30440 has been marked as a duplicate of this bug. ***
Comment 6 Tom de Vries 2023-05-24 14:13:49 UTC
*** Bug 28482 has been marked as a duplicate of this bug. ***