no printf-outputs during debugging [message #1821947] |
Mon, 24 February 2020 10:51 |
|
Hi,
there are several printf() statements in my console program. Running the program the console tab shows all the outputs.
But running the program in debug mode there are no outputs at all in the console tab. Execution stops at breakpoints, variable contents can be analyzed, but there is no output in the console tab.
In this forum there are several postings with similar problems but no solution.
What can I do to see the program outputs?
Niko
Eclipse-CDT Version: 2019-12 (4.14.0), Win10 64bit
|
|
|
Re: no printf-outputs during debugging [message #1821965 is a reply to message #1821947] |
Mon, 24 February 2020 17:25 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
This sounds like an old issue.
What do you mean by "Running the program the console tab"?
In Eclipse there is no difference between "Run" and "Debug" launch configurations.
They are, in fact, the same configuration except the "Debug" configuration
- allows setting parameters for debugging (Debugger tab);
- the bottom right button changes from "Run" to "Debug";
- and the debugger is used to launch the program when debugging.
A possible solution:
The console output is buffered in the program.
Try flushing stdout (or cout) or
try setting them to no buffering.
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
or
std::cout.setf(std::ios::unitbuf);
[Updated on: Mon, 24 February 2020 17:57] Report message to a moderator
|
|
|
Re: no printf-outputs during debugging [message #1821971 is a reply to message #1821965] |
Mon, 24 February 2020 22:21 |
|
David Vavra wrote on Mon, 24 February 2020 18:25This sounds like an old issue.
Yes, it is a very old issue, but still not solved.
Quote:What do you mean by "Running the program the console tab"?
Running the program in normal mode, not debug mode, then all printf's are shown in the console tab.
------------------
Output buffering really is the reason why outputs of printf statements are not visible in the console tab during debugging.
But setting to no buffering as you suggested
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
shows some outputs and then the debugger crashes. The only remaining control is terminating the program, see the attachment crashedDebugger.PNG.
In the console tab you can see three lines of outputs. The output from program line 433 is visible, and in the same line the debugger reports an error "*stopped,reason="end-stepping-range", ..."
The content of the debugger console can be seen in attachment DebuggerConsole.PNG.
The debugger crashes only when I am stepping line by line over the printf statements. The debugger performs correctly when I run the program from breakpoint to breakpoint with the "resume" button.
In this forum I read a posting where adding an external console was solving the problem. But I cannot find any settings in launch configuration to do this.
Niko
Eclipse-CDT Version: 2019-12 (4.14.0), Win10 64bit
[Updated on: Mon, 24 February 2020 22:29] Report message to a moderator
|
|
|
|
Re: no printf-outputs during debugging [message #1822065 is a reply to message #1821982] |
Wed, 26 February 2020 13:48 |
|
Thank you for the links.
I found some similar postings. It seems that Eclipse CDT on windows suffers from this problem since many years.
In your links there are some tips I will try in my program. Hopefully I understood the discussions and can do the necessary configurations. If not, I will switch to another IDE.
Niko
Eclipse-CDT Version: 2019-12 (4.14.0), Win10 64bit
|
|
|
Re: no printf-outputs during debugging [message #1822193 is a reply to message #1822065] |
Sat, 29 February 2020 16:21 |
|
The behaviour of the debugger under Win10 is really curious. All the discussions in this forum about this problem are many years ago. The conclusion is that this bug will not be corrected because console programs with C++ are very seldom.
Anyway, to see printf outputs in the console tab immediately during debugging, it is necessary to avoid buffering of stdout, i.e to insert setvbuf(stdout, NULL, _IONBF, 0);
Finally, my way to cope with this problem is:
- never do a single step over a printf statement
- always use Resume to run over printf statements either with a breakpoint after the printf statement or with Run to line
A problem still remains. Sometimes the output of the printf statement is followed in the same line by some extra outputs from the debugger.
Niko
Eclipse-CDT Version: 2019-12 (4.14.0), Win10 64bit
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04116 seconds