Auto_002dloading-safe-path.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Auto-loading safe path</title>
  16. <meta name="description" content="Debugging with GDB: Auto-loading safe path">
  17. <meta name="keywords" content="Debugging with GDB: Auto-loading safe path">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="Auto_002dloading.html#Auto_002dloading" rel="up" title="Auto-loading">
  26. <link href="Auto_002dloading-verbose-mode.html#Auto_002dloading-verbose-mode" rel="next" title="Auto-loading verbose mode">
  27. <link href="libthread_005fdb_002eso_002e1-file.html#libthread_005fdb_002eso_002e1-file" rel="previous" title="libthread_db.so.1 file">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Auto_002dloading-safe-path"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Auto_002dloading-verbose-mode.html#Auto_002dloading-verbose-mode" accesskey="n" rel="next">Auto-loading verbose mode</a>, Previous: <a href="libthread_005fdb_002eso_002e1-file.html#libthread_005fdb_002eso_002e1-file" accesskey="p" rel="previous">libthread_db.so.1 file</a>, Up: <a href="Auto_002dloading.html#Auto_002dloading" accesskey="u" rel="up">Auto-loading</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>
  62. </div>
  63. <hr>
  64. <a name="Security-restriction-for-auto_002dloading"></a>
  65. <h4 class="subsection">22.8.3 Security restriction for auto-loading</h4>
  66. <a name="index-auto_002dloading-safe_002dpath"></a>
  67. <p>As the files of inferior can come from untrusted source (such as submitted by
  68. an application user) <small>GDB</small> does not always load any files automatically.
  69. <small>GDB</small> provides the &lsquo;<samp>set auto-load safe-path</samp>&rsquo; setting to list
  70. directories trusted for loading files not explicitly requested by user.
  71. Each directory can also be a shell wildcard pattern.
  72. </p>
  73. <p>If the path is not set properly you will see a warning and the file will not
  74. get loaded:
  75. </p>
  76. <div class="smallexample">
  77. <pre class="smallexample">$ ./gdb -q ./gdb
  78. Reading symbols from /home/user/gdb/gdb...
  79. warning: File &quot;/home/user/gdb/gdb-gdb.gdb&quot; auto-loading has been
  80. declined by your `auto-load safe-path' set
  81. to &quot;$debugdir:$datadir/auto-load&quot;.
  82. warning: File &quot;/home/user/gdb/gdb-gdb.py&quot; auto-loading has been
  83. declined by your `auto-load safe-path' set
  84. to &quot;$debugdir:$datadir/auto-load&quot;.
  85. </pre></div>
  86. <p>To instruct <small>GDB</small> to go ahead and use the init files anyway,
  87. invoke <small>GDB</small> like this:
  88. </p>
  89. <div class="smallexample">
  90. <pre class="smallexample">$ gdb -q -iex &quot;set auto-load safe-path /home/user/gdb&quot; ./gdb
  91. </pre></div>
  92. <p>The list of trusted directories is controlled by the following commands:
  93. </p>
  94. <dl compact="compact">
  95. <dd><a name="set-auto_002dload-safe_002dpath"></a><a name="index-set-auto_002dload-safe_002dpath"></a>
  96. </dd>
  97. <dt><code>set auto-load safe-path <span class="roman">[</span><var>directories</var><span class="roman">]</span></code></dt>
  98. <dd><p>Set the list of directories (and their subdirectories) trusted for automatic
  99. loading and execution of scripts. You can also enter a specific trusted file.
  100. Each directory can also be a shell wildcard pattern; wildcards do not match
  101. directory separator - see <code>FNM_PATHNAME</code> for system function <code>fnmatch</code>
  102. (see <a href="http://www.gnu.org/software/libc/manual/html_node/Wildcard-Matching.html#Wildcard-Matching">fnmatch</a> in <cite>GNU C Library Reference Manual</cite>).
  103. If you omit <var>directories</var>, &lsquo;<samp>auto-load safe-path</samp>&rsquo; will be reset to
  104. its default value as specified during <small>GDB</small> compilation.
  105. </p>
  106. <p>The list of directories uses path separator (&lsquo;<samp>:</samp>&rsquo; on GNU and Unix
  107. systems, &lsquo;<samp>;</samp>&rsquo; on MS-Windows and MS-DOS) to separate directories, similarly
  108. to the <code>PATH</code> environment variable.
  109. </p>
  110. <a name="show-auto_002dload-safe_002dpath"></a><a name="index-show-auto_002dload-safe_002dpath"></a>
  111. </dd>
  112. <dt><code>show auto-load safe-path</code></dt>
  113. <dd><p>Show the list of directories trusted for automatic loading and execution of
  114. scripts.
  115. </p>
  116. <a name="add_002dauto_002dload_002dsafe_002dpath"></a><a name="index-add_002dauto_002dload_002dsafe_002dpath"></a>
  117. </dd>
  118. <dt><code>add-auto-load-safe-path</code></dt>
  119. <dd><p>Add an entry (or list of entries) to the list of directories trusted for
  120. automatic loading and execution of scripts. Multiple entries may be delimited
  121. by the host platform path separator in use.
  122. </p></dd>
  123. </dl>
  124. <p>This variable defaults to what <code>--with-auto-load-dir</code> has been configured
  125. to (see <a href="objfile_002dgdbdotext-file.html#with_002dauto_002dload_002ddir">with-auto-load-dir</a>). <samp>$debugdir</samp> and <samp>$datadir</samp>
  126. substitution applies the same as for <a href="objfile_002dgdbdotext-file.html#set-auto_002dload-scripts_002ddirectory">set auto-load scripts-directory</a>.
  127. The default <code>set auto-load safe-path</code> value can be also overriden by
  128. <small>GDB</small> configuration option <samp>--with-auto-load-safe-path</samp>.
  129. </p>
  130. <p>Setting this variable to <samp>/</samp> disables this security protection,
  131. corresponding <small>GDB</small> configuration option is
  132. <samp>--without-auto-load-safe-path</samp>.
  133. This variable is supposed to be set to the system directories writable by the
  134. system superuser only. Users can add their source directories in init files in
  135. their home directories (see <a href="Startup.html#Home-Directory-Init-File">Home Directory Init File</a>). See also deprecated
  136. init file in the current directory
  137. (see <a href="Startup.html#Init-File-in-the-Current-Directory-during-Startup">Init File in the Current Directory during Startup</a>).
  138. </p>
  139. <p>To force <small>GDB</small> to load the files it declined to load in the previous
  140. example, you could use one of the following ways:
  141. </p>
  142. <dl compact="compact">
  143. <dt><samp>~/.gdbinit</samp>: &lsquo;<samp>add-auto-load-safe-path ~/src/gdb</samp>&rsquo;</dt>
  144. <dd><p>Specify this trusted directory (or a file) as additional component of the list.
  145. You have to specify also any existing directories displayed by
  146. by &lsquo;<samp>show auto-load safe-path</samp>&rsquo; (such as &lsquo;<samp>/usr:/bin</samp>&rsquo; in this example).
  147. </p>
  148. </dd>
  149. <dt><kbd>gdb -iex &quot;set auto-load safe-path /usr:/bin:~/src/gdb&quot; &hellip;</kbd></dt>
  150. <dd><p>Specify this directory as in the previous case but just for a single
  151. <small>GDB</small> session.
  152. </p>
  153. </dd>
  154. <dt><kbd>gdb -iex &quot;set auto-load safe-path /&quot; &hellip;</kbd></dt>
  155. <dd><p>Disable auto-loading safety for a single <small>GDB</small> session.
  156. This assumes all the files you debug during this <small>GDB</small> session will come
  157. from trusted sources.
  158. </p>
  159. </dd>
  160. <dt><kbd>./configure --without-auto-load-safe-path</kbd></dt>
  161. <dd><p>During compilation of <small>GDB</small> you may disable any auto-loading safety.
  162. This assumes all the files you will ever debug with this <small>GDB</small> come from
  163. trusted sources.
  164. </p></dd>
  165. </dl>
  166. <p>On the other hand you can also explicitly forbid automatic files loading which
  167. also suppresses any such warning messages:
  168. </p>
  169. <dl compact="compact">
  170. <dt><kbd>gdb -iex &quot;set auto-load no&quot; &hellip;</kbd></dt>
  171. <dd><p>You can use <small>GDB</small> command-line option for a single <small>GDB</small> session.
  172. </p>
  173. </dd>
  174. <dt><samp>~/.gdbinit</samp>: &lsquo;<samp>set auto-load no</samp>&rsquo;</dt>
  175. <dd><p>Disable auto-loading globally for the user
  176. (see <a href="Startup.html#Home-Directory-Init-File">Home Directory Init File</a>). While it is improbable, you could also
  177. use system init file instead (see <a href="System_002dwide-configuration.html#System_002dwide-configuration">System-wide configuration</a>).
  178. </p></dd>
  179. </dl>
  180. <p>This setting applies to the file names as entered by user. If no entry matches
  181. <small>GDB</small> tries as a last resort to also resolve all the file names into
  182. their canonical form (typically resolving symbolic links) and compare the
  183. entries again. <small>GDB</small> already canonicalizes most of the filenames on its
  184. own before starting the comparison so a canonical form of directories is
  185. recommended to be entered.
  186. </p>
  187. <hr>
  188. <div class="header">
  189. <p>
  190. Next: <a href="Auto_002dloading-verbose-mode.html#Auto_002dloading-verbose-mode" accesskey="n" rel="next">Auto-loading verbose mode</a>, Previous: <a href="libthread_005fdb_002eso_002e1-file.html#libthread_005fdb_002eso_002e1-file" accesskey="p" rel="previous">libthread_db.so.1 file</a>, Up: <a href="Auto_002dloading.html#Auto_002dloading" accesskey="u" rel="up">Auto-loading</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>
  191. </div>
  192. </body>
  193. </html>