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
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.
*** Bug 17476 has been marked as a duplicate of this bug. ***
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.
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.)
*** Bug 30440 has been marked as a duplicate of this bug. ***
*** Bug 28482 has been marked as a duplicate of this bug. ***