Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fflush(stdout) in c

Tags:

c

stdout

fflush

Right when I am at fflush(stdout) and I break there in GDB, can I know what is there in stdout before I actually print it?

How can I know what is there in stdout at any point in time?

like image 633
hari Avatar asked Jun 29 '26 08:06

hari


1 Answers

If you allocate a buffer yourself and pass it to setvbuf, I suppose you can access it before a flush, since it's yours to begin with.

EDIT: Your comment made your intent more clear, but what you want won't be easy:

  1. Set up your own buffer as described above,
  2. Set a read watchpoint on stdout,
  3. Watch your program slow to a crawl.

From then on, gdb will break each time anything accesses stdout, and you can check your buffer for changes, weird output, etc.

That said, that's not an ideal solution at all. A far better approach would be using a logging-enabled output function everywhere in your code.

like image 182
Frédéric Hamidi Avatar answered Jul 01 '26 21:07

Frédéric Hamidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!