Block output of a debugged program (gdb)

I have a program and you want to debug it in gdb.

Will I see the usual output of the program? How to enable or disable this output, leaving only gdb messages.

+4
gdb
Mar 05 '10 at 17:14
source share
4 answers

You can redirect output from gdb:

(gdb) run > somefile.txt 

redirects standard output to somefile.txt file. You can also specify the terminal to send output to:

 (gdb) tty /dev/ttyb 
+6
Mar 05 '10 at 17:20
source share

Yes, you will see all the output from your program.

You can disable this by sending it elsewhere. For example:

 (gdb) run > /dev/null 
+5
Mar 05 '10 at 17:16
source share

If you just want to see the output of a program as it passes without gdb output, this script may be useful.

 #!/bin/bash file=$1 delay=1 #seconds lastTime=`stat --printf=%y "$file"` while [ 1 ] do thisTime=`stat --printf=%y "$file"` if [ "$thisTime" != "$lastTime" ] then clear cat "$file" fi lastTime="$thisTime" sleep $delay done 

LastTime = "$ thisTime" sleep $ delay done

+2
Feb 19 '13 at 22:38
source share

Ignore stdout and stderr

 run &>/dev/null 

Similar to Bash syntax.

Tested on GDB 7.10.

+2
Feb 17 '16 at
source share



All Articles