6

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

Will I see usual program output? How can I enable/disable this output, leaving only gdb messages.

osgx
  • 90,338
  • 53
  • 357
  • 513

4 Answers4

8

You can redirect output from within gdb:

(gdb) run > somefile.txt

will redirect standard output to somefile.txt. You can also specify a terminal to send output to:

(gdb) tty /dev/ttyb
6

Yes, you will see all output from your program.

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

(gdb) run > /dev/null
Thomas
  • 174,939
  • 50
  • 355
  • 478
2

If you just want to see the output of the program as you step through it without gdb's output, this script can 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

abc
  • 21
  • 1
  • 2
    Wat? Where is gdb? How to use this? I wanted just what I asked, start program in gdb, work wiht gdb, but not to see program's stderr and stdout. – osgx Feb 20 '13 at 02:35
2

Ignore stdout and stderr

run &>/dev/null

Analogous to the Bash syntax.

Tested on GDB 7.10.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985