1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Environment</title> 18 19<meta name="description" content="Debugging with GDB: Environment"> 20<meta name="keywords" content="Debugging with GDB: Environment"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Running.html#Running" rel="up" title="Running"> 29<link href="Working-Directory.html#Working-Directory" rel="next" title="Working Directory"> 30<link href="Arguments.html#Arguments" rel="previous" title="Arguments"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Environment"></a> 65<div class="header"> 66<p> 67Next: <a href="Working-Directory.html#Working-Directory" accesskey="n" rel="next">Working Directory</a>, Previous: <a href="Arguments.html#Arguments" accesskey="p" rel="previous">Arguments</a>, Up: <a href="Running.html#Running" accesskey="u" rel="up">Running</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 68</div> 69<hr> 70<a name="Your-Program_0027s-Environment"></a> 71<h3 class="section">4.4 Your Program’s Environment</h3> 72 73<a name="index-environment-_0028of-your-program_0029"></a> 74<p>The <em>environment</em> consists of a set of environment variables and 75their values. Environment variables conventionally record such things as 76your user name, your home directory, your terminal type, and your search 77path for programs to run. Usually you set up environment variables with 78the shell and they are inherited by all the other programs you run. When 79debugging, it can be useful to try running your program with a modified 80environment without having to start <small>GDB</small> over again. 81</p> 82<dl compact="compact"> 83<dd><a name="index-path"></a> 84</dd> 85<dt><code>path <var>directory</var></code></dt> 86<dd><p>Add <var>directory</var> to the front of the <code>PATH</code> environment variable 87(the search path for executables) that will be passed to your program. 88The value of <code>PATH</code> used by <small>GDB</small> does not change. 89You may specify several directory names, separated by whitespace or by a 90system-dependent separator character (‘<samp>:</samp>’ on Unix, ‘<samp>;</samp>’ on 91MS-DOS and MS-Windows). If <var>directory</var> is already in the path, it 92is moved to the front, so it is searched sooner. 93</p> 94<p>You can use the string ‘<samp>$cwd</samp>’ to refer to whatever is the current 95working directory at the time <small>GDB</small> searches the path. If you 96use ‘<samp>.</samp>’ instead, it refers to the directory where you executed the 97<code>path</code> command. <small>GDB</small> replaces ‘<samp>.</samp>’ in the 98<var>directory</var> argument (with the current path) before adding 99<var>directory</var> to the search path. 100</p> 101<a name="index-show-paths"></a> 102</dd> 103<dt><code>show paths</code></dt> 104<dd><p>Display the list of search paths for executables (the <code>PATH</code> 105environment variable). 106</p> 107<a name="index-show-environment"></a> 108</dd> 109<dt><code>show environment <span class="roman">[</span><var>varname</var><span class="roman">]</span></code></dt> 110<dd><p>Print the value of environment variable <var>varname</var> to be given to 111your program when it starts. If you do not supply <var>varname</var>, 112print the names and values of all environment variables to be given to 113your program. You can abbreviate <code>environment</code> as <code>env</code>. 114</p> 115<a name="index-set-environment"></a> 116<a name="set-environment"></a></dd> 117<dt><code>set environment <var>varname</var> <span class="roman">[</span>=<var>value</var><span class="roman">]</span></code></dt> 118<dd><p>Set environment variable <var>varname</var> to <var>value</var>. The value 119changes for your program (and the shell <small>GDB</small> uses to launch 120it), not for <small>GDB</small> itself. The <var>value</var> may be any string; the 121values of environment variables are just strings, and any 122interpretation is supplied by your program itself. The <var>value</var> 123parameter is optional; if it is eliminated, the variable is set to a 124null value. 125</p> 126<p>For example, this command: 127</p> 128<div class="smallexample"> 129<pre class="smallexample">set env USER = foo 130</pre></div> 131 132<p>tells the debugged program, when subsequently run, that its user is named 133‘<samp>foo</samp>’. (The spaces around ‘<samp>=</samp>’ are used for clarity here; they 134are not actually required.) 135</p> 136<p>Note that on Unix systems, <small>GDB</small> runs your program via a shell, 137which also inherits the environment set with <code>set environment</code>. 138If necessary, you can avoid that by using the ‘<samp>env</samp>’ program as a 139wrapper instead of using <code>set environment</code>. See <a href="Starting.html#set-exec_002dwrapper">set exec-wrapper</a>, for an example doing just that. 140</p> 141<p>Environment variables that are set by the user are also transmitted to 142<code>gdbserver</code> to be used when starting the remote inferior. 143see <a href="General-Query-Packets.html#QEnvironmentHexEncoded">QEnvironmentHexEncoded</a>. 144</p> 145<a name="index-unset-environment"></a> 146<a name="unset-environment"></a></dd> 147<dt><code>unset environment <var>varname</var></code></dt> 148<dd><p>Remove variable <var>varname</var> from the environment to be passed to your 149program. This is different from ‘<samp>set env <var>varname</var> =</samp>’; 150<code>unset environment</code> removes the variable from the environment, 151rather than assigning it an empty value. 152</p> 153<p>Environment variables that are unset by the user are also unset on 154<code>gdbserver</code> when starting the remote inferior. 155see <a href="General-Query-Packets.html#QEnvironmentUnset">QEnvironmentUnset</a>. 156</p></dd> 157</dl> 158 159<p><em>Warning:</em> On Unix systems, <small>GDB</small> runs your program using 160the shell indicated by your <code>SHELL</code> environment variable if it 161exists (or <code>/bin/sh</code> if not). If your <code>SHELL</code> variable 162names a shell that runs an initialization file when started 163non-interactively—such as <samp>.cshrc</samp> for C-shell, $<samp>.zshenv</samp> 164for the Z shell, or the file specified in the ‘<samp>BASH_ENV</samp>’ 165environment variable for BASH—any variables you set in that file 166affect your program. You may wish to move setting of environment 167variables to files that are only run when you sign on, such as 168<samp>.login</samp> or <samp>.profile</samp>. 169</p> 170<hr> 171<div class="header"> 172<p> 173Next: <a href="Working-Directory.html#Working-Directory" accesskey="n" rel="next">Working Directory</a>, Previous: <a href="Arguments.html#Arguments" accesskey="p" rel="previous">Arguments</a>, Up: <a href="Running.html#Running" accesskey="u" rel="up">Running</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 174</div> 175 176 177 178</body> 179</html> 180