Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » no printf-outputs during debugging
no printf-outputs during debugging [message #1821947] Mon, 24 February 2020 10:51 Go to next message
Nick Schweyer is currently offline Nick SchweyerFriend
Messages: 175
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
David VavraFriend
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 Go to previous messageGo to next message
Nick Schweyer is currently offline Nick SchweyerFriend
Messages: 175
Registered: July 2009
Senior Member
David Vavra wrote on Mon, 24 February 2020 18:25
This 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 #1821982 is a reply to message #1821971] Tue, 25 February 2020 05:52 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
This thread may be helpful.
Can't tell how similar it is to your problem.
You cut off some of the message.

https://www.eclipse.org/forums/index.php?t=msg&th=75201&goto=235660&#msg_235660

Another:
https://stackoverflow.com/questions/17387950/cant-continue-stepping-in-debug-mode-when-reaching-printf-in-eclipse

And another.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=327766
Something about mixing program output with Eclipse talking to the debugger.
Apparently an issue when running under windows.

You may be able to get around it by using "Run to Line" instead of stepping over prints.

[Updated on: Tue, 25 February 2020 06:15]

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 Go to previous messageGo to next message
Nick Schweyer is currently offline Nick SchweyerFriend
Messages: 175
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Nick Schweyer is currently offline Nick SchweyerFriend
Messages: 175
Registered: July 2009
Senior Member
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
Re: no printf-outputs during debugging [message #1822202 is a reply to message #1822193] Sat, 29 February 2020 20:28 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
The problem is caused by mixing program streams with streams to the debugger.

Windows doesn't provide an easy approach similar to Linux.

This has been addressed at least twice in bug reports since Indigo.
There doesn't appear to be any intention to fix it.
or the fix is deemed too difficult considering any benefit
or the fix would have to be implemented in the debugger -- a GNU problem.

You can try reopening the issue at Bugzilla.
But you would still have to work around it until it is fixed.
Re: no printf-outputs during debugging [message #1822821 is a reply to message #1821947] Sat, 14 March 2020 11:29 Go to previous messageGo to next message
Tyson Jonas is currently offline Tyson JonasFriend
Messages: 1
Registered: February 2020
Junior Member
There was a memory leak in the program and using the debugger displace the leak to other place in the code.
Re: no printf-outputs during debugging [message #1830902 is a reply to message #1821947] Thu, 06 August 2020 10:00 Go to previous messageGo to next message
Norman Argiolas is currently offline Norman ArgiolasFriend
Messages: 1
Registered: August 2020
Junior Member
Hello,
a little trick to do a single step over the print statments:


#include <stdio.h>

#define LOG_INFO printf

int main(void) 
{
	setvbuf(stdout, NULL, _IONBF, 0);
	LOG_INFO("This is v%s built on %s %s.\r\n",
			__VERSION__, __DATE__, __TIME__);
}



This works fine with step by step debugging mode.

Hope this helpful
Re: no printf-outputs during debugging [message #1834187 is a reply to message #1830902] Wed, 04 November 2020 13:25 Go to previous message
Mark Smith is currently offline Mark SmithFriend
Messages: 82
Registered: September 2020
Member
Please check this
https://stackoverflow.com/questions/44098943/printf-not-print-on-the-console-in-eclipse
Previous Topic:Can't select text in editors
Next Topic:Debugger error
Goto Forum:
  


Current Time: Wed Oct 09 19:06:55 GMT 2024

Powered by FUDForum. Page generated in 0.04116 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top