osgx
osgx

Reputation: 94175

block output of debugged program (gdb)

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.

Upvotes: 7

Views: 8715

Answers (4)

Ignore stdout and stderr

run &>/dev/null

Analogous to the Bash syntax.

Tested on GDB 7.10.

Upvotes: 3

abc
abc

Reputation: 21

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

Upvotes: 2

anon
anon

Reputation:

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

Upvotes: 9

Thomas
Thomas

Reputation: 181705

Yes, you will see all output from your program.

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

(gdb) run > /dev/null

Upvotes: 7

Related Questions