Community
Participate
Working Groups
If I run this program on Eclipse Oxygen 32-bit on Windows 7: int main(void) { char buf[200]; scanf("%s\n", buf); printf("%s\n", buf); return EXIT_SUCCESS; } Without typing anything in the Console View, I get: 41-thread-select Or other GDB/MI commands. It appears as though somehow the old gdb-traces console is getting mixed up with stdin.
Some other strange Console behaviour. If I step through int main(void) { printf("hello1\n"); printf("hello2\n"); return EXIT_SUCCESS; } No output appears in the Console until the program has finished.
This appears to only be a problem on Windows. Linux works fine. This worked fine on Windows Neon 9.0 release. Also it only appears to be an issue when debugging. Run works ok.
I am not sure why you were not seeing this in Neon and are in Oxygen as little has changed in this area. On Windows the stdin/out of the program under GDB inherits the stdin/out of GDB causing garbling between the two. (It can work if there are nice perfect newlines everywhere, but that isn't often the case. There is a good blog post that shows a workaround in detail: http://nicolas.riousset.com/category/software-methodologies/eclipse-how-to-debug-a-c-console-application-using-a-native-dos-console-instead-of-the-ide-integrated-one/ The post has more details, but the summary is use "set new-console on" to cause a new console window to be created. (In reply to Jon Beniston from comment #1) > Some other strange Console behaviour. If I step through > > int main(void) { > printf("hello1\n"); > printf("hello2\n"); > return EXIT_SUCCESS; > } > > No output appears in the Console until the program has finished. This is most likely buffering: https://wiki.eclipse.org/CDT/User/FAQ#Eclipse_console_does_not_show_output_on_Windows It would also be solved by using the workaround.
This type of issue comes up too often in CDT for users on Windows. I think that we should add "set new-console on" as an option in the launch configuration and then on Windows set that as the default or in some way make it easier for users to find. I have assigned to myself for consideration in 9.4. I have also lowered the priority to normal (from critical) because of the workaround. Jon, if you believe I have misunderstood and there is still something critical, please let me know and I can re-raise the priority.
Hi Jonah. Yep, you can ignore the second comment regarding no output, as that is due to buffering (I thought line buffering was the default, as is the case on my usual embedded target from Windows). However, regarding the initial problem, one change between 9.0 and 9.3 is that there was no "Debugger Console" view before. It's perhaps not specifically related to that, but I've just tried 9.1 and 9.2 with Neon as well. 9.1 works OK. 9.2 doesn't, it has the same issue as 9.3. It seems 9.2 was when the Debugger Console was introduced. There are a couple of things that I think aren't ideal with using set new-console on, as a default. Firstly, the console disappears when the program exits so you can't see the output (Perhaps there's a way to prevent this, besides setting breakpoints). Also, you then get different behaviour whether you Run or Debug your program (As Run will still use the Eclipse console - stdin seems to work ok in that case). Also, it's quite handy to have some of the features of the Eclipse console. I'll see if I can track down what is the difference is between 9.1 and 9.2. Thanks, Jon
Thanks Jon for tracking this down more. The change from 9.1 to 9.2 was supposed to have no effect on Windows, other than to change the UI location of the console. This is because CDT on Windows does not take advantage to the new-ui feature in GDB yet. See Bug 516371 for that. I take your point on changing the default. Perhaps just making it easier for users to workaround these problems (like buffering). I'll hold off on anything in this area pending your further investigation.
Hi Jon, I can reproduce this problem on CDT 9.0 (Neon.0). There is a timing issue that means that causing it to come in is different. But there is a fundamental problem that GDB's MI and GDB's inferior are using the same stdin/out. Bug 516371 should improve this problem because the MI and the inferior's GDB channels are separated. But the GDB's CLI input and the inferior will still share a channel. On Linux, the -inferior-tty-set is used to connect a different input/output between CDT and GDB's inferior.
Hi Jonah. Yep, I think fixing Bug 516371 and using -inferior-tty-set is probably the way to resolve this. I'm actually using a Cygwin build of GDB rather than mingw though. I've just written a pair of test programs to try out the new-ui command: one is Cygwin based that opens a Cygwin pty and then redirects the master-side to stdin/stdout. This gets run by a second pure Windows program, which uses pipes to the Cygwin prog to allow it to send and receive MI commands which seems to work. (I'll try integrating this in to the pty JNI DLL in Eclipse next). A different solution would be needed for mingw. Unfortunately I can't yet get -inferior-tty-set to work fully in either Windows or Linux. In both Windows & Linux, it works for running native programs. However, it doesn't seem to work for remote targets or sim targets (which is what I'm personally interested in).
I've posted a patch for GDB that adds support for -inferior-tty-set for remote and simulator targets. https://cygwin.com/ml/gdb-patches/2017-08/msg00403.html Without this, their I/O always appears in the GDB console. CDT will also need a patch here for remote targets. In StartOrRestartProcessSequence_7_0.stepInitializeInputOutput, a PTY is not created if SessionType is REMOTE. The comment says this is because gdbserver handles the I/O, but that isn't always the case. Some remote targets use GDB's remote-fileio to redirect I/O to GDB - and thus a PTY is needed here too. I've written a JNI DLL that with the above patches has the Console view working. It just needs a bit more work to get the GDB Console working properly.
(In reply to Jonah Graham from comment #4) > This type of issue comes up too often in CDT for users on Windows. I think > that we should add "set new-console on" as an option in the launch > configuration and then on Windows set that as the default or in some way > make it easier for users to find. I plan to add the "set new-console on" as an explicit option in the launch config in 9.4 (upcoming release). I will not change the default on Windows at this time. --- Longer term the solution is to use the new-ui feature of CDT, that requires changes on the CDT and GDB side to work.
*** Bug 527008 has been marked as a duplicate of this bug. ***
(In reply to Jonah Graham from comment #10) > Longer term the solution is to use the new-ui feature of CDT, that requires > changes on the CDT and GDB side to work. Sorry, two halves to longer term solution. 1 is new-ui to separate CLI/program output from MI, second is having separate TTY as Jon has been looking into.
I have this working with Cygwin GDB now and it also supports the GDB Console (Bug 516371). I'll post the patches in a bit.
Created attachment 271400 [details] Add Cygwin PTY support This patch adds PTY support for Cygwin. It includes the Java classes (CygwinPTY and PersistentCygwinPTY) as well as the corresponding JNI code (core/org.eclipse.cdt.core.win32/library/pty/jni/src/cygwin_pty.cpp) and some helper utilities (cygwin_pty/cygwin_resize_pty/cygwin_exec_with_pty) that allow Win32 programs to interface to Cygwin PTYs. At the moment, this doesn't include a patch to the code that instantiates the PTYs (I use my own launch delegates, so haven't tried to modify the standard versions). There would presumably need to be some way for a user to choose between a Cygwin PTY or the standard Windows PTY depending on the debugger they are running. This PTY currently works well enough to support the gdb new-ui command and also supports the GDB Console on Windows.
(In reply to Jon Beniston from comment #14) > Created attachment 271400 [details] Thanks for the patch, can you please make it a gerrit as all contributions need to come in that way these days -- https://wiki.eclipse.org/CDT/git#Using_Gerrit_for_CDT The change looks interesting. AFAICT* this is a fix for Bug 516371, can you submit it to gerrit with "Bug 516371: ..." as the commit message so it connects there. *This looks like you are changing how to launch so that CLI uses the new-ui and the stdin/out of the inferior goes through that terminal too. Do you also have -inferior-tty-set for a new pty so that the stdin/out of the inferior is completely independent of GDB?
It fixes Bug 516371, but only for Cygwin based GDB. It will not work for Ming based GDB. Yes, I run gdb and used new-ui for mi stream and use -inferior-tty-set for stdio. This means we end up with 3 PTYs, one for GDB console, one for MI and one for stdio, so they are all completely separate.
(In reply to Jon Beniston from comment #16) > It fixes Bug 516371, but only for Cygwin based GDB. It will not work for > Ming based GDB. Do you know if it addresses Msys2?
New Gerrit change created: https://git.eclipse.org/r/111347
(In reply to Jonah Graham from comment #17) > (In reply to Jon Beniston from comment #16) > > It fixes Bug 516371, but only for Cygwin based GDB. It will not work for > > Ming based GDB. > Do you know if it addresses Msys2? I don't know - I've never used it. I understand it's a fork of Cygwin, so maybe.
Gerrit change https://git.eclipse.org/r/111347 was merged to [master]. Commit: http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=b090f32e646527db07ab1b1b4f2374256ec43af9
I have added the option for external console to N&N -- https://wiki.eclipse.org/CDT/User/NewIn94#Debug -- and created Bug 527252 for the ongoing work of using -inferior-tty-set
*** Bug 570357 has been marked as a duplicate of this bug. ***
*** Bug 259986 has been marked as a duplicate of this bug. ***