Your program's environment
The environment consists of a set of environment variables and their values. Environment variables conventionally record such things as your user name, your home directory, your terminal type, and your search path for programs to run. Usually you set up environment variables with the shell and they're inherited by all the other programs you run. When debugging, it can be useful to try running your program with a modified environment without having to start GDB over again.
- set nto-inherit-env value
- If value is 0, the process inherits its environment from GDB. If value is 1 (the default), the process inherits its environment from pdebug.
- path directory
- Add directory to the front of the PATH environment variable
(the search path for executables), for both GDB and your program.
You may specify several directory names, separated by a colon (:) or
whitespace. If directory is already in the path, it's moved to
the front, so it's searched sooner.
You can use the string $cwd to refer to the current working directory at the time GDB searches the path. A period (.) refers to the directory where you executed the path command. GDB replaces the period in the directory argument by the current path before adding directory to the search path.
- show paths
- Display the list of search paths for executables (the PATH environment variable).
- show environment [varname]
- Print the value of environment variable varname to be given to your program when it starts. If you don't supply varname, print the names and values of all environment variables to be given to your program. You can abbreviate environment as env.
- set environment varname [=] value
- Set environment variable varname to value. The value
changes for your program only, not for GDB itself. The value may
be any string; the values of environment variables are just strings, and
any interpretation is supplied by your program itself. The value
parameter is optional; if it's eliminated, the variable is set to a
For example, this command:
set env USER=footells a Unix program, when subsequently run, that its user is named foo.
- unset environment varname
- Remove variable varname from the environment to be passed to your program. This is different from set env varname =, in that unset environment removes the variable from the environment, rather than assign it an empty value.