Debugging with GDB (September 2007)
26 Debugging with GDB
character (‘:’ on Unix, ‘;’ on MS-DOS and MS-Windows). If directory is
already in the path, it is moved to the front, so it is searched sooner.
You can use the string ‘$cwd’ to refer to whatever is the current working directory at
the time GDB searches the path. If you use ‘.’ instead, it refers to the directory where you
executed the path command. GDB replaces ‘.’ in the directory argument (with the current
path) before adding directory to the search path.
4.5 Working directory
Each time you start your program with run, it inherits its working directory from the
current working directory of GDB. The GDB working directory is initially whatever it
inherited from its parent proc es s (typically the shell), but you can specify a new working
directory in GDB with the cd command.
The GDB working directory also serves as a default for the commands that specify files
for GDB to operate on. See Section 12.1 [Commands to spec ify files], page 103.
Following commands are used to set the working directory for your program:
cd directory
Set the GDB working directory to directory.
pwd Print the GDB working directory.
4.6 Program 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.
Following commands are used for redirecting the input and output:
info terminal
Displays information recorded by GDB about the terminal modes your program
is using.
tty
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 proc es s, 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.
Note:
• You can redirect your program input and output using shell redirection with the run
command. For example,