7

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.

4 Answers 4

9

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
Sign up to request clarification or add additional context in comments.

Comments

7

Yes, you will see all output from your program.

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

(gdb) run > /dev/null

Comments

3

Ignore stdout and stderr

run &>/dev/null

Analogous to the Bash syntax.

Tested on GDB 7.10.

Comments

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.