Go to the previous, next section.
To debug a program, you must run it under _GDBN__.
In order to debug a program effectively, you need to generate debugging information when you compile it. This debugging information is stored in the object file; it describes the data type of each variable or function and the correspondence between source line numbers and addresses in the executable code.
To request debugging information, specify the `-g' option when you run the compiler.
Many C compilers are unable to handle the `-g' and `-O' options together. Using those compilers, you cannot generate optimized executables containing debugging information.
_GCC__, the GNU C compiler, supports `-g' with or without `-O', making it possible to debug optimized code. We recommend that you always use `-g' whenever you compile a program. You may think your program is correct, but there is no sense in pushing your luck.
When you debug a program compiled with `-g -O', remember that the optimizer is rearranging your code; the debugger will show you what's really there. Don't be too surprised when the execution path doesn't exactly match your source file! An extreme example: if you define a variable, but never use it, _GDBN__ will never see that variable--because the compiler optimizes it out of existence.
Some things do not work as well with `-g -O' as with just `-g', particularly on machines with instruction scheduling. If in doubt, recompile with `-g' alone, and if this fixes the problem, please report it as a bug (including a test case!).
Older versions of the GNU C compiler permitted a variant option `-gg' for debugging information. _GDBN__ no longer supports this format; if your GNU C compiler has this option, do not use it.
run
r
run
command to start your program under _GDBN__. You must
first specify the program name
_if__(_VXWORKS__)
(except on VxWorks)
_fi__(_VXWORKS__)
with an argument to
_GDBN__ (see section Getting In and Out of _GDBN__), or by using the
file
or exec-file
command (see section Commands to Specify Files).
_if__(!_BARE__)
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. _GDBN__ provides ways to specify this information, which you must do before starting your program. (You can change it after starting your program, but such changes will only affect your program the next time you start it.) This information may be divided into four categories:
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. See section Your Program's Arguments.
set environment
and unset
environment
to change parts of the environment that will be given to
your program. See section Your Program's Environment}