136 lines
8.1 KiB
HTML
136 lines
8.1 KiB
HTML
<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-2019 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>
|
|
</head>
|
|
<body>
|
|
<div class="node">
|
|
<a name="Environment"></a>
|
|
<p>
|
|
Next: <a rel="next" accesskey="n" href="Working-Directory.html#Working-Directory">Working Directory</a>,
|
|
Previous: <a rel="previous" accesskey="p" href="Arguments.html#Arguments">Arguments</a>,
|
|
Up: <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-129"></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-130"></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 (‘<samp><span class="samp">:</span></samp>’ on Unix, ‘<samp><span class="samp">;</span></samp>’ 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 ‘<samp><span class="samp">$cwd</span></samp>’ to refer to whatever is the current
|
|
working directory at the time <span class="sc">gdb</span> searches the path. If you
|
|
use ‘<samp><span class="samp">.</span></samp>’ instead, it refers to the directory where you executed the
|
|
<code>path</code> command. <span class="sc">gdb</span> replaces ‘<samp><span class="samp">.</span></samp>’ 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-131"></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-132"></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-133"></a><a name="set-environment"></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 (and the shell <span class="sc">gdb</span> uses to launch
|
|
it), not for <span class="sc">gdb</span> itself. The <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
|
|
‘<samp><span class="samp">foo</span></samp>’. (The spaces around ‘<samp><span class="samp">=</span></samp>’ are used for clarity here; they
|
|
are not actually required.)
|
|
|
|
<p>Note that on Unix systems, <span class="sc">gdb</span> runs your program via a shell,
|
|
which also inherits the environment set with <code>set environment</code>.
|
|
If necessary, you can avoid that by using the ‘<samp><span class="samp">env</span></samp>’ program as a
|
|
wrapper instead of using <code>set environment</code>. See <a href="set-exec_002dwrapper.html#set-exec_002dwrapper">set exec-wrapper</a>, for an example doing just that.
|
|
|
|
<p>Environment variables that are set by the user are also transmitted to
|
|
<samp><span class="command">gdbserver</span></samp> to be used when starting the remote inferior.
|
|
see <a href="QEnvironmentHexEncoded.html#QEnvironmentHexEncoded">QEnvironmentHexEncoded</a>.
|
|
|
|
<p><a name="index-unset-environment-134"></a><a name="unset-environment"></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 ‘<samp><span class="samp">set env </span><var>varname</var><span class="samp"> =</span></samp>’;
|
|
<code>unset environment</code> removes the variable from the environment,
|
|
rather than assigning it an empty value.
|
|
|
|
<p>Environment variables that are unset by the user are also unset on
|
|
<samp><span class="command">gdbserver</span></samp> when starting the remote inferior.
|
|
see <a href="QEnvironmentUnset.html#QEnvironmentUnset">QEnvironmentUnset</a>.
|
|
</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 when started
|
|
non-interactively—such as <samp><span class="file">.cshrc</span></samp> for C-shell, $<samp><span class="file">.zshenv</span></samp>
|
|
for the Z shell, or the file specified in the ‘<samp><span class="samp">BASH_ENV</span></samp>’
|
|
environment variable for BASH—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>
|
|
|