The stdio is usually buffered. When I hit a breakpoint and there's a printf before the breakpoint, the printed string may still be in the buffer and I can not see it.
I know I can flush the stdio by adding some flush code in the program.
Without doing this, is there any way to tell GDB to flush the stdio of the program being debugged after GDB stops? This way is more friendly when debugging a program.
Best Answer
Many recent UNIX stdio implementations will flush all buffers if you call
fflush(NULL)
:If you don't have
libc
debug symbols installed, you may have to tell GDB about the type offflush
:But normally you shouldn't have to do that: if you called
printf
(and notfprintf
), that goesstdout
, which goes to your terminal, which would normally be line-buffered. So, so long as yourprintf
printed a new line, the buffer would have been flushed afterprintf
returned.