blob: e47b17385091999574f6e5c3c3ac5ab2728f6799 [file] [log] [blame]
<html lang="en">
<head>
<title>Environment - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Running.html#Running" title="Running">
<link rel="prev" href="Arguments.html#Arguments" title="Arguments">
<link rel="next" href="Working-Directory.html#Working-Directory" title="Working Directory">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Environment"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Working-Directory.html#Working-Directory">Working Directory</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Arguments.html#Arguments">Arguments</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Running.html#Running">Running</a>
<hr>
</div>
<h3 class="section">4.4 Your Program's Environment</h3>
<p><a name="index-environment-_0028of-your-program_0029-113"></a>The <dfn>environment</dfn> 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 are 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 <span class="sc">gdb</span> over again.
<a name="index-path-114"></a>
<dl><dt><code>path </code><var>directory</var><dd>Add <var>directory</var> to the front of the <code>PATH</code> environment variable
(the search path for executables) that will be passed to your program.
The value of <code>PATH</code> used by <span class="sc">gdb</span> does not change.
You may specify several directory names, separated by whitespace or by a
system-dependent separator character (&lsquo;<samp><span class="samp">:</span></samp>&rsquo; on Unix, &lsquo;<samp><span class="samp">;</span></samp>&rsquo; on
MS-DOS and MS-Windows). If <var>directory</var> is already in the path, it
is moved to the front, so it is searched sooner.
<p>You can use the string &lsquo;<samp><span class="samp">$cwd</span></samp>&rsquo; to refer to whatever is the current
working directory at the time <span class="sc">gdb</span> searches the path. If you
use &lsquo;<samp><span class="samp">.</span></samp>&rsquo; instead, it refers to the directory where you executed the
<code>path</code> command. <span class="sc">gdb</span> replaces &lsquo;<samp><span class="samp">.</span></samp>&rsquo; in the
<var>directory</var> argument (with the current path) before adding
<var>directory</var> to the search path.
<!-- 'path' is explicitly nonrepeatable, but RMS points out it is silly to -->
<!-- document that, since repeating it would be a no-op. -->
<p><a name="index-show-paths-115"></a><br><dt><code>show paths</code><dd>Display the list of search paths for executables (the <code>PATH</code>
environment variable).
<p><a name="index-show-environment-116"></a><br><dt><code>show environment </code><span class="roman">[</span><var>varname</var><span class="roman">]</span><dd>Print the value of environment variable <var>varname</var> to be given to
your program when it starts. If you do not supply <var>varname</var>,
print the names and values of all environment variables to be given to
your program. You can abbreviate <code>environment</code> as <code>env</code>.
<p><a name="index-set-environment-117"></a><br><dt><code>set environment </code><var>varname</var> <span class="roman">[</span><code>=</code><var>value</var><span class="roman">]</span><dd>Set environment variable <var>varname</var> to <var>value</var>. The value
changes for your program only, not for <span class="sc">gdb</span> itself. <var>value</var> may
be any string; the values of environment variables are just strings, and
any interpretation is supplied by your program itself. The <var>value</var>
parameter is optional; if it is eliminated, the variable is set to a
null value.
<!-- "any string" here does not include leading, trailing -->
<!-- blanks. Gnu asks: does anyone care? -->
<p>For example, this command:
<pre class="smallexample"> set env USER = foo
</pre>
<p class="noindent">tells the debugged program, when subsequently run, that its user is named
&lsquo;<samp><span class="samp">foo</span></samp>&rsquo;. (The spaces around &lsquo;<samp><span class="samp">=</span></samp>&rsquo; are used for clarity here; they
are not actually required.)
<p><a name="index-unset-environment-118"></a><br><dt><code>unset environment </code><var>varname</var><dd>Remove variable <var>varname</var> from the environment to be passed to your
program. This is different from &lsquo;<samp><span class="samp">set env </span><var>varname</var><span class="samp"> =</span></samp>&rsquo;;
<code>unset environment</code> removes the variable from the environment,
rather than assigning it an empty value.
</dl>
<p><em>Warning:</em> On Unix systems, <span class="sc">gdb</span> runs your program using
the shell indicated
by your <code>SHELL</code> environment variable if it exists (or
<code>/bin/sh</code> if not). If your <code>SHELL</code> variable names a shell
that runs an initialization file&mdash;such as <samp><span class="file">.cshrc</span></samp> for C-shell, or
<samp><span class="file">.bashrc</span></samp> for BASH&mdash;any variables you set in that file affect
your program. You may wish to move setting of environment variables to
files that are only run when you sign on, such as <samp><span class="file">.login</span></samp> or
<samp><span class="file">.profile</span></samp>.
</body></html>