Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-03-2005, 09:24 PM   #1
LQ Newbie
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Rep: Reputation: 15
how can I debug the interactinve program with GDB

hi ,all
Now I want to debug a program with GDB,and the program is like the 'echo" program, you can input a string ,and it print it on the screen.
I use the function fgets() to got the input string.
So I want to use GDB to debug the program ,and want to set break point after the fgets(), then print the varible to see the input string.
But I have no experience on use GDB, and who can tell me how to debug the interactive program ,such this one.
Thanks for all your suggestion!
Old 08-03-2005, 09:55 PM   #2
LQ Newbie
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Original Poster
Rep: Reputation: 15
ok ,I have got the document from, as following
4.6 Your program's input and output
By default, the program you run under GDB does input and output to the same terminal that GDB uses. GDB switches the terminal to its own terminal modes to interact with you, but it records the terminal modes your program was using and switches back to them when you continue running your program.

info terminal
Displays information recorded by GDB about the terminal modes your program is using.
You can redirect your program's input and/or output using shell redirection with the run command. For example,

run > outfile

starts your program, diverting its output to the file `outfile'.

Another way to specify where your program should do input and output is with the tty command. This command accepts a file name as argument, and causes this file to be the default for future run commands. It also resets the controlling terminal for the child process, for future run commands. For example,

tty /dev/ttyb

directs that processes started with subsequent run commands default to do input and output on the terminal `/dev/ttyb' and have that as their controlling terminal.

An explicit redirection in run overrides the tty command's effect on the input/output device, but not its effect on the controlling terminal.

When you use the tty command or redirect input in the run command, only the input for your program is affected. The input for GDB still comes from your terminal. tty is an alias for set inferior-tty.

You can use the show inferior-tty command to tell GDB to display the name of the terminal that will be used for future runs of your program.

set inferior-tty /dev/ttyb
Set the tty for the program being debugged to /dev/ttyb.

show inferior-tty
Show the current tty for the program being debugged.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i debug my c++ program please? twirl Programming 1 09-12-2005 02:34 AM
How to use gdb to debug child process? ariana Programming 2 05-03-2005 01:50 PM
GDB unable to debug pthreads linuxdeveloper Programming 1 03-06-2005 05:18 AM
Using gdb to debug different arhitectures george_mercury Linux - Software 1 01-07-2005 06:19 PM
how to debug multithread using GDB? ryanux Programming 1 05-11-2004 12:58 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration