Debugging with GDB (September 2007)
24 Debugging with GDB
or variable substitution) in describing the arguments. On Unix systems, you
can control which shell is used with the SHELL environment variable. GDB
uses the C shell (/usr/bin/csh). See hundefinedi [Your program’s arguments],
page hundefinedi.
environment.
Your program inherits its environment from GDB. However, you can use the
GDB commands set environment and unset environment to change parts of
the environment that affect your program. See hundefinedi [Your program’s
environment], page hundefinedi.
working directory.
Your program inherits its working directory from GDB. You can set the GDB
working directory with the cd command in GDB. See Section 4.5 [Your pro-
gram’s working directory], page 26.
standard input and output.
Your program as default uses the same device for standard input and standard
output as GDB is using. You can redirect input and output in the run command
line, or you can use the tty command to set a different device for your program.
See Section 4.6 [Your program’s input and output], page 26.
Warning: You can redirect input and output, but you cannot use pipes to
pass the output of the program you are debugging to another program; if you
attempt this, GDB is likely to wind up debugging the wrong program.
Note:
• When you issue the run command, your program begins to execute immediately. See
Chapter 5 [Stopping and continuing], page 33, for discussion of how to arrange for
your program to stop. Once your program has stopped, you may call functions in
your program, using the print or call commands. See Chapter 8 [Examining Data],
page 63.
• If the modification time of your symbol file has changed since the last time GDB read
its symbols, GDB discards its symbol table, and reads it again. When it does this,
GDB tries to retain your current breakpoints.
4.3 Arguments To Your Program
The arguments to your program can be spec ified by the arguments of the run com-
mand. On HP-UX, they are passed to the C shell (/usr/bin/csh), which expands wildcard
characters and performs redirection of I/O, and thence to your program.
On non-Unix systems, the program is usually invoked directly by GDB, which emulates
I/O redirection via the appropriate system calls, and the wildcard characters are expanded
by the startup code of the program, not by the shell.
The run command used w ith no arguments uses the same arguments used by the previous
run, or those set by the set args command.
Following commands are used to pass the argument values to your program: