GDB - Realtime output


 
Thread Tools Search this Thread
Top Forums Programming GDB - Realtime output
# 1  
Old 03-17-2011
GDB - Realtime output

Hi guys,

Using gdb when we run executable it doesn't show the output of our program(such as printf, ...). it shows all of them when execution finishes. Is there any solution?
# 2  
Old 03-17-2011
Compile the code with the -g switch...start gdb and put a break on main followed by running and single stepping through your program.
# 3  
Old 03-17-2011
Quote:
Originally Posted by majid.merkava
Hi guys,

Using gdb when we run executable it doesn't show the output of our program(such as printf, ...). it shows all of them when execution finishes. Is there any solution?
What exactly do you mean? the output of printf() literally doesn't appear anywhere until the program finishes?

That's probably because printf() is buffered. It holds the data in memory until you print a newline character. Try fprintf(stderr, ...); stderr defaults to unbuffered so should print immediately.
# 4  
Old 03-17-2011
I have a loop in the program and I put a break inside loop which has printf. when using next, instead of showing the output each time when i enter next. it waits and after the program finishes then shows the putput
# 5  
Old 03-17-2011
Again, that's because printf() buffers -- it holds everything in memory until you print an \n (or until you quit) then prints it all.

If you print to standard error like fprintf(stderr, ...); that won't buffer.

You can also force standard output to flush its buffer whenever you want with fflush(stdout).
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 03-17-2011
More information on fflush().
This User Gave Thanks to m1xram For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying files realtime

I have a primary server where certain files are created real time. These files have varying file sizes. I want to FTP or copy them over to a different server server as soon a file gets created. I have to ensure that only full file is copied. The receiving end process expects a FULL file. I am ok... (3 Replies)
Discussion started by: vskr72
3 Replies

2. Shell Programming and Scripting

compare realtime

I have two log files which keeps appending every sec...I want to extract a certain field from each file(using awk for extracting the data) and compare them in real time... ex: log1 122 234 567 log2 234 567 log3 122 i need a log3 which keeps appending the data found in log1 and... (7 Replies)
Discussion started by: wannalearn
7 Replies
Login or Register to Ask a Question