Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

179 lines
8.9KB

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