26
Chapter 6. Running Programs Under gdb
If you are running your program in an execution environment that supports processes,
run
creates an
inferior process and makes that process run your program. (In environments without processes,
run
jumps to the start of your program.)
The execution of a program is affected by certain information it receives from its superior. gdb pro-
vides ways to specify this information, which you must do
before
starting your program. (You can
change it after starting your program, but such changes only affect your program the next time you
start it.) This information may be divided into four categories:
The
arguments.
Specify the arguments to give your program as the arguments of the
run
command. If a shell
is available on your target, the shell is used to pass the arguments, so that you may use normal
conventions (such as wildcard expansion or variable substitution) in describing the arguments. In
Unix systems, you can control which shell is used with the
SHELL
environment variable. Refer
to Section 6.3
Your program’s arguments
.
The
environment.
Your program normally inherits its environment from gdb, but you can use the gdb commands
set environment
and
unset environment
to change parts of the environment that affect
your program. Refer to Section 6.4
Your program’s environment
.
The
working directory.
Your program inherits its working directory from gdb. You can set the gdb working directory
with the
cd
command in gdb. Refer to Section 6.5
Your program’s working directory
.
The
standard input and output.
Your program normally 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. Refer to Section 6.6
Your program’s input
and output
.
Warning:
While input and output redirection work, 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.
When you issue the
run
command, your program begins to execute immediately. Refer to Chapter
7
Stopping and Continuing
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
or
call
commands.
Refer to Chapter 10
Examining Data
.
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.
6.3. Your program’s arguments
The arguments to your program can be specified by the arguments of the
run
command. They are
passed to a shell, which expands wildcard characters and performs redirection of I/O, and thence to
your program. Your
SHELL
environment variable (if it exists) specifies what shell gdb uses. If you do
not define
SHELL
, gdb uses the default shell (
/bin/sh
on Unix).
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.
Summary of Contents for ENTERPRISE LINUX 3 - SECURITY GUIDE
Page 1: ...Red Hat Enterprise Linux 3 Debugging with gdb ...
Page 12: ...2 Chapter 1 Debugging with gdb ...
Page 28: ...18 Chapter 4 Getting In and Out of gdb ...
Page 34: ...24 Chapter 5 gdb Commands ...
Page 44: ...34 Chapter 6 Running Programs Under gdb ...
Page 68: ...58 Chapter 8 Examining the Stack ...
Page 98: ...88 Chapter 10 Examining Data ...
Page 112: ...102 Chapter 12 Tracepoints ...
Page 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Page 138: ...128 Chapter 14 Using gdb with Different Languages ...
Page 144: ...134 Chapter 15 Examining the Symbol Table ...
Page 170: ...160 Chapter 19 Debugging remote programs ...
Page 198: ...188 Chapter 21 Controlling gdb ...
Page 204: ...194 Chapter 22 Canned Sequences of Commands ...
Page 206: ...196 Chapter 23 Command Interpreters ...
Page 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Page 296: ...286 Chapter 27 gdb Annotations ...
Page 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Page 322: ...312 Chapter 30 Using History Interactively ...
Page 362: ...352 Appendix D gdb Remote Serial Protocol ...
Page 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Page 386: ...376 Appendix G GNU Free Documentation License ...
Page 410: ......