Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

779 Zeilen
37KB

  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>Files (Debugging with GDB)</title>
  17. <meta name="description" content="Files (Debugging with GDB)">
  18. <meta name="keywords" content="Files (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="GDB-Files.html#GDB-Files" rel="up" title="GDB Files">
  26. <link href="File-Caching.html#File-Caching" rel="next" title="File Caching">
  27. <link href="GDB-Files.html#GDB-Files" rel="prev" title="GDB Files">
  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="Files"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="File-Caching.html#File-Caching" accesskey="n" rel="next">File Caching</a>, Up: <a href="GDB-Files.html#GDB-Files" accesskey="u" rel="up">GDB Files</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="Commands-to-Specify-Files"></a>
  64. <h3 class="section">18.1 Commands to Specify Files</h3>
  65. <a name="index-symbol-table"></a>
  66. <a name="index-core-dump-file"></a>
  67. <p>You may want to specify executable and core dump file names. The usual
  68. way to do this is at start-up time, using the arguments to
  69. <small>GDB</small>&rsquo;s start-up commands (see <a href="Invocation.html#Invocation">Getting In and
  70. Out of <small>GDB</small></a>).
  71. </p>
  72. <p>Occasionally it is necessary to change to a different file during a
  73. <small>GDB</small> session. Or you may run <small>GDB</small> and forget to
  74. specify a file you want to use. Or you are debugging a remote target
  75. via <code>gdbserver</code> (see <a href="Server.html#Server">Using the <code>gdbserver</code>
  76. Program</a>). In these situations the <small>GDB</small> commands to specify
  77. new files are useful.
  78. </p>
  79. <dl compact="compact">
  80. <dd><a name="index-executable-file"></a>
  81. <a name="index-file"></a>
  82. </dd>
  83. <dt><code>file <var>filename</var></code></dt>
  84. <dd><p>Use <var>filename</var> as the program to be debugged. It is read for its
  85. symbols and for the contents of pure memory. It is also the program
  86. executed when you use the <code>run</code> command. If you do not specify a
  87. directory and the file is not found in the <small>GDB</small> working directory,
  88. <small>GDB</small> uses the environment variable <code>PATH</code> as a list of
  89. directories to search, just as the shell does when looking for a program
  90. to run. You can change the value of this variable, for both <small>GDB</small>
  91. and your program, using the <code>path</code> command.
  92. </p>
  93. <a name="index-unlinked-object-files"></a>
  94. <a name="index-patching-object-files"></a>
  95. <p>You can load unlinked object <samp>.o</samp> files into <small>GDB</small> using
  96. the <code>file</code> command. You will not be able to &ldquo;run&rdquo; an object
  97. file, but you can disassemble functions and inspect variables. Also,
  98. if the underlying BFD functionality supports it, you could use
  99. <kbd>gdb -write</kbd> to patch object files using this technique. Note
  100. that <small>GDB</small> can neither interpret nor modify relocations in this
  101. case, so branches and some initialized variables will appear to go to
  102. the wrong place. But this feature is still handy from time to time.
  103. </p>
  104. </dd>
  105. <dt><code>file</code></dt>
  106. <dd><p><code>file</code> with no argument makes <small>GDB</small> discard any information it
  107. has on both executable file and the symbol table.
  108. </p>
  109. <a name="index-exec_002dfile"></a>
  110. </dd>
  111. <dt><code>exec-file <span class="roman">[</span> <var>filename</var> <span class="roman">]</span></code></dt>
  112. <dd><p>Specify that the program to be run (but not the symbol table) is found
  113. in <var>filename</var>. <small>GDB</small> searches the environment variable <code>PATH</code>
  114. if necessary to locate your program. Omitting <var>filename</var> means to
  115. discard information on the executable file.
  116. </p>
  117. <a name="index-symbol_002dfile"></a>
  118. </dd>
  119. <dt><code>symbol-file <span class="roman">[</span> <var>filename</var> <span class="roman">[</span> -o <var>offset</var> <span class="roman">]]</span></code></dt>
  120. <dd><p>Read symbol table information from file <var>filename</var>. <code>PATH</code> is
  121. searched when necessary. Use the <code>file</code> command to get both symbol
  122. table and program to run from the same file.
  123. </p>
  124. <p>If an optional <var>offset</var> is specified, it is added to the start
  125. address of each section in the symbol file. This is useful if the
  126. program is relocated at runtime, such as the Linux kernel with kASLR
  127. enabled.
  128. </p>
  129. <p><code>symbol-file</code> with no argument clears out <small>GDB</small> information on your
  130. program&rsquo;s symbol table.
  131. </p>
  132. <p>The <code>symbol-file</code> command causes <small>GDB</small> to forget the contents of
  133. some breakpoints and auto-display expressions. This is because they may
  134. contain pointers to the internal data recording symbols and data types,
  135. which are part of the old symbol table data being discarded inside
  136. <small>GDB</small>.
  137. </p>
  138. <p><code>symbol-file</code> does not repeat if you press <tt class="key">RET</tt> again after
  139. executing it once.
  140. </p>
  141. <p>When <small>GDB</small> is configured for a particular environment, it
  142. understands debugging information in whatever format is the standard
  143. generated for that environment; you may use either a <small>GNU</small> compiler, or
  144. other compilers that adhere to the local conventions.
  145. Best results are usually obtained from <small>GNU</small> compilers; for example,
  146. using <code><small>GCC</small></code> you can generate debugging information for
  147. optimized code.
  148. </p>
  149. <p>For most kinds of object files, with the exception of old SVR3 systems
  150. using COFF, the <code>symbol-file</code> command does not normally read the
  151. symbol table in full right away. Instead, it scans the symbol table
  152. quickly to find which source files and which symbols are present. The
  153. details are read later, one source file at a time, as they are needed.
  154. </p>
  155. <p>The purpose of this two-stage reading strategy is to make <small>GDB</small>
  156. start up faster. For the most part, it is invisible except for
  157. occasional pauses while the symbol table details for a particular source
  158. file are being read. (The <code>set verbose</code> command can turn these
  159. pauses into messages if desired. See <a href="Messages_002fWarnings.html#Messages_002fWarnings">Optional
  160. Warnings and Messages</a>.)
  161. </p>
  162. <p>We have not implemented the two-stage strategy for COFF yet. When the
  163. symbol table is stored in COFF format, <code>symbol-file</code> reads the
  164. symbol table data in full right away. Note that &ldquo;stabs-in-COFF&rdquo;
  165. still does the two-stage strategy, since the debug info is actually
  166. in stabs format.
  167. </p>
  168. <a name="index-readnow"></a>
  169. <a name="index-reading-symbols-immediately"></a>
  170. <a name="index-symbols_002c-reading-immediately"></a>
  171. </dd>
  172. <dt><code>symbol-file <span class="roman">[</span> -readnow <span class="roman">]</span> <var>filename</var></code></dt>
  173. <dt><code>file <span class="roman">[</span> -readnow <span class="roman">]</span> <var>filename</var></code></dt>
  174. <dd><p>You can override the <small>GDB</small> two-stage strategy for reading symbol
  175. tables by using the &lsquo;<samp>-readnow</samp>&rsquo; option with any of the commands that
  176. load symbol table information, if you want to be sure <small>GDB</small> has the
  177. entire symbol table available.
  178. </p>
  179. <a name="index-_002dreadnever_002c-option-for-symbol_002dfile-command"></a>
  180. <a name="index-never-read-symbols"></a>
  181. <a name="index-symbols_002c-never-read"></a>
  182. </dd>
  183. <dt><code>symbol-file <span class="roman">[</span> -readnever <span class="roman">]</span> <var>filename</var></code></dt>
  184. <dt><code>file <span class="roman">[</span> -readnever <span class="roman">]</span> <var>filename</var></code></dt>
  185. <dd><p>You can instruct <small>GDB</small> to never read the symbolic information
  186. contained in <var>filename</var> by using the &lsquo;<samp>-readnever</samp>&rsquo; option.
  187. See <a href="File-Options.html#g_t_002d_002dreadnever">--readnever</a>.
  188. </p>
  189. <a name="index-core_002dfile"></a>
  190. </dd>
  191. <dt><code>core-file <span class="roman">[</span><var>filename</var><span class="roman">]</span></code></dt>
  192. <dt><code>core</code></dt>
  193. <dd><p>Specify the whereabouts of a core dump file to be used as the &ldquo;contents
  194. of memory&rdquo;. Traditionally, core files contain only some parts of the
  195. address space of the process that generated them; <small>GDB</small> can access the
  196. executable file itself for other parts.
  197. </p>
  198. <p><code>core-file</code> with no argument specifies that no core file is
  199. to be used.
  200. </p>
  201. <p>Note that the core file is ignored when your program is actually running
  202. under <small>GDB</small>. So, if you have been running your program and you
  203. wish to debug a core file instead, you must kill the subprocess in which
  204. the program is running. To do this, use the <code>kill</code> command
  205. (see <a href="Kill-Process.html#Kill-Process">Killing the Child Process</a>).
  206. </p>
  207. <a name="index-add_002dsymbol_002dfile"></a>
  208. <a name="index-dynamic-linking"></a>
  209. </dd>
  210. <dt><code>add-symbol-file <var>filename</var> <span class="roman">[</span> -readnow <span class="roman">|</span> -readnever <span class="roman">]</span> <span class="roman">[</span> -o <var>offset</var> <span class="roman">]</span> <span class="roman">[</span> <var>textaddress</var> <span class="roman">]</span> <span class="roman">[</span> -s <var>section</var> <var>address</var> &hellip; <span class="roman">]</span></code></dt>
  211. <dd><p>The <code>add-symbol-file</code> command reads additional symbol table
  212. information from the file <var>filename</var>. You would use this command
  213. when <var>filename</var> has been dynamically loaded (by some other means)
  214. into the program that is running. The <var>textaddress</var> parameter gives
  215. the memory address at which the file&rsquo;s text section has been loaded.
  216. You can additionally specify the base address of other sections using
  217. an arbitrary number of &lsquo;<samp>-s <var>section</var> <var>address</var></samp>&rsquo; pairs.
  218. If a section is omitted, <small>GDB</small> will use its default addresses
  219. as found in <var>filename</var>. Any <var>address</var> or <var>textaddress</var>
  220. can be given as an expression.
  221. </p>
  222. <p>If an optional <var>offset</var> is specified, it is added to the start
  223. address of each section, except those for which the address was
  224. specified explicitly.
  225. </p>
  226. <p>The symbol table of the file <var>filename</var> is added to the symbol table
  227. originally read with the <code>symbol-file</code> command. You can use the
  228. <code>add-symbol-file</code> command any number of times; the new symbol data
  229. thus read is kept in addition to the old.
  230. </p>
  231. <p>Changes can be reverted using the command <code>remove-symbol-file</code>.
  232. </p>
  233. <a name="index-relocatable-object-files_002c-reading-symbols-from"></a>
  234. <a name="index-object-files_002c-relocatable_002c-reading-symbols-from"></a>
  235. <a name="index-reading-symbols-from-relocatable-object-files"></a>
  236. <a name="index-symbols_002c-reading-from-relocatable-object-files"></a>
  237. <a name="index-_002eo-files_002c-reading-symbols-from"></a>
  238. <p>Although <var>filename</var> is typically a shared library file, an
  239. executable file, or some other object file which has been fully
  240. relocated for loading into a process, you can also load symbolic
  241. information from relocatable <samp>.o</samp> files, as long as:
  242. </p>
  243. <ul>
  244. <li> the file&rsquo;s symbolic information refers only to linker symbols defined in
  245. that file, not to symbols defined by other object files,
  246. </li><li> every section the file&rsquo;s symbolic information refers to has actually
  247. been loaded into the inferior, as it appears in the file, and
  248. </li><li> you can determine the address at which every section was loaded, and
  249. provide these to the <code>add-symbol-file</code> command.
  250. </li></ul>
  251. <p>Some embedded operating systems, like Sun Chorus and VxWorks, can load
  252. relocatable files into an already running program; such systems
  253. typically make the requirements above easy to meet. However, it&rsquo;s
  254. important to recognize that many native systems use complex link
  255. procedures (<code>.linkonce</code> section factoring and C<tt>++</tt> constructor table
  256. assembly, for example) that make the requirements difficult to meet. In
  257. general, one cannot assume that using <code>add-symbol-file</code> to read a
  258. relocatable object file&rsquo;s symbolic information will have the same effect
  259. as linking the relocatable object file into the program in the normal
  260. way.
  261. </p>
  262. <p><code>add-symbol-file</code> does not repeat if you press <tt class="key">RET</tt> after using it.
  263. </p>
  264. <a name="index-remove_002dsymbol_002dfile"></a>
  265. </dd>
  266. <dt><code>remove-symbol-file <var>filename</var></code></dt>
  267. <dt><code>remove-symbol-file -a <var>address</var></code></dt>
  268. <dd><p>Remove a symbol file added via the <code>add-symbol-file</code> command. The
  269. file to remove can be identified by its <var>filename</var> or by an <var>address</var>
  270. that lies within the boundaries of this symbol file in memory. Example:
  271. </p>
  272. <div class="smallexample">
  273. <pre class="smallexample">(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
  274. add symbol table from file &quot;/home/user/gdb/mylib.so&quot; at
  275. .text_addr = 0x7ffff7ff9480
  276. (y or n) y
  277. Reading symbols from /home/user/gdb/mylib.so...
  278. (gdb) remove-symbol-file -a 0x7ffff7ff9480
  279. Remove symbol table from file &quot;/home/user/gdb/mylib.so&quot;? (y or n) y
  280. (gdb)
  281. </pre></div>
  282. <p><code>remove-symbol-file</code> does not repeat if you press <tt class="key">RET</tt> after using it.
  283. </p>
  284. <a name="index-add_002dsymbol_002dfile_002dfrom_002dmemory"></a>
  285. <a name="index-syscall-DSO"></a>
  286. <a name="index-load-symbols-from-memory"></a>
  287. </dd>
  288. <dt><code>add-symbol-file-from-memory <var>address</var></code></dt>
  289. <dd><p>Load symbols from the given <var>address</var> in a dynamically loaded
  290. object file whose image is mapped directly into the inferior&rsquo;s memory.
  291. For example, the Linux kernel maps a <code>syscall DSO</code> into each
  292. process&rsquo;s address space; this DSO provides kernel-specific code for
  293. some system calls. The argument can be any expression whose
  294. evaluation yields the address of the file&rsquo;s shared object file header.
  295. For this command to work, you must have used <code>symbol-file</code> or
  296. <code>exec-file</code> commands in advance.
  297. </p>
  298. <a name="index-section"></a>
  299. </dd>
  300. <dt><code>section <var>section</var> <var>addr</var></code></dt>
  301. <dd><p>The <code>section</code> command changes the base address of the named
  302. <var>section</var> of the exec file to <var>addr</var>. This can be used if the
  303. exec file does not contain section addresses, (such as in the
  304. <code>a.out</code> format), or when the addresses specified in the file
  305. itself are wrong. Each section must be changed separately. The
  306. <code>info files</code> command, described below, lists all the sections and
  307. their addresses.
  308. </p>
  309. <a name="index-info-files"></a>
  310. <a name="index-info-target"></a>
  311. </dd>
  312. <dt><code>info files</code></dt>
  313. <dt><code>info target</code></dt>
  314. <dd><p><code>info files</code> and <code>info target</code> are synonymous; both print the
  315. current target (see <a href="Targets.html#Targets">Specifying a Debugging Target</a>),
  316. including the names of the executable and core dump files currently in
  317. use by <small>GDB</small>, and the files from which symbols were loaded. The
  318. command <code>help target</code> lists all possible targets rather than
  319. current ones.
  320. </p>
  321. <a name="index-maint-info-sections"></a>
  322. </dd>
  323. <dt><code>maint info sections</code></dt>
  324. <dd><p>Another command that can give you extra information about program sections
  325. is <code>maint info sections</code>. In addition to the section information
  326. displayed by <code>info files</code>, this command displays the flags and file
  327. offset of each section in the executable and core dump files. In addition,
  328. <code>maint info sections</code> provides the following command options (which
  329. may be arbitrarily combined):
  330. </p>
  331. <dl compact="compact">
  332. <dt><code>ALLOBJ</code></dt>
  333. <dd><p>Display sections for all loaded object files, including shared libraries.
  334. </p></dd>
  335. <dt><code><var>sections</var></code></dt>
  336. <dd><p>Display info only for named <var>sections</var>.
  337. </p></dd>
  338. <dt><code><var>section-flags</var></code></dt>
  339. <dd><p>Display info only for sections for which <var>section-flags</var> are true.
  340. The section flags that <small>GDB</small> currently knows about are:
  341. </p><dl compact="compact">
  342. <dt><code>ALLOC</code></dt>
  343. <dd><p>Section will have space allocated in the process when loaded.
  344. Set for all sections except those containing debug information.
  345. </p></dd>
  346. <dt><code>LOAD</code></dt>
  347. <dd><p>Section will be loaded from the file into the child process memory.
  348. Set for pre-initialized code and data, clear for <code>.bss</code> sections.
  349. </p></dd>
  350. <dt><code>RELOC</code></dt>
  351. <dd><p>Section needs to be relocated before loading.
  352. </p></dd>
  353. <dt><code>READONLY</code></dt>
  354. <dd><p>Section cannot be modified by the child process.
  355. </p></dd>
  356. <dt><code>CODE</code></dt>
  357. <dd><p>Section contains executable code only.
  358. </p></dd>
  359. <dt><code>DATA</code></dt>
  360. <dd><p>Section contains data only (no executable code).
  361. </p></dd>
  362. <dt><code>ROM</code></dt>
  363. <dd><p>Section will reside in ROM.
  364. </p></dd>
  365. <dt><code>CONSTRUCTOR</code></dt>
  366. <dd><p>Section contains data for constructor/destructor lists.
  367. </p></dd>
  368. <dt><code>HAS_CONTENTS</code></dt>
  369. <dd><p>Section is not empty.
  370. </p></dd>
  371. <dt><code>NEVER_LOAD</code></dt>
  372. <dd><p>An instruction to the linker to not output the section.
  373. </p></dd>
  374. <dt><code>COFF_SHARED_LIBRARY</code></dt>
  375. <dd><p>A notification to the linker that the section contains
  376. COFF shared library information.
  377. </p></dd>
  378. <dt><code>IS_COMMON</code></dt>
  379. <dd><p>Section contains common symbols.
  380. </p></dd>
  381. </dl>
  382. </dd>
  383. </dl>
  384. <a name="index-set-trust_002dreadonly_002dsections"></a>
  385. <a name="index-read_002donly-sections"></a>
  386. </dd>
  387. <dt><code>set trust-readonly-sections on</code></dt>
  388. <dd><p>Tell <small>GDB</small> that readonly sections in your object file
  389. really are read-only (i.e. that their contents will not change).
  390. In that case, <small>GDB</small> can fetch values from these sections
  391. out of the object file, rather than from the target program.
  392. For some targets (notably embedded ones), this can be a significant
  393. enhancement to debugging performance.
  394. </p>
  395. <p>The default is off.
  396. </p>
  397. </dd>
  398. <dt><code>set trust-readonly-sections off</code></dt>
  399. <dd><p>Tell <small>GDB</small> not to trust readonly sections. This means that
  400. the contents of the section might change while the program is running,
  401. and must therefore be fetched from the target when needed.
  402. </p>
  403. </dd>
  404. <dt><code>show trust-readonly-sections</code></dt>
  405. <dd><p>Show the current setting of trusting readonly sections.
  406. </p></dd>
  407. </dl>
  408. <p>All file-specifying commands allow both absolute and relative file names
  409. as arguments. <small>GDB</small> always converts the file name to an absolute file
  410. name and remembers it that way.
  411. </p>
  412. <a name="index-shared-libraries"></a>
  413. <a name="Shared-Libraries"></a><p><small>GDB</small> supports <small>GNU</small>/Linux, MS-Windows, SunOS,
  414. Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
  415. DSBT (TIC6X) shared libraries.
  416. </p>
  417. <p>On MS-Windows <small>GDB</small> must be linked with the Expat library to support
  418. shared libraries. See <a href="Requirements.html#Expat">Expat</a>.
  419. </p>
  420. <p><small>GDB</small> automatically loads symbol definitions from shared libraries
  421. when you use the <code>run</code> command, or when you examine a core file.
  422. (Before you issue the <code>run</code> command, <small>GDB</small> does not understand
  423. references to a function in a shared library, however&mdash;unless you are
  424. debugging a core file).
  425. </p>
  426. <p>There are times, however, when you may wish to not automatically load
  427. symbol definitions from shared libraries, such as when they are
  428. particularly large or there are many of them.
  429. </p>
  430. <p>To control the automatic loading of shared library symbols, use the
  431. commands:
  432. </p>
  433. <dl compact="compact">
  434. <dd><a name="index-set-auto_002dsolib_002dadd"></a>
  435. </dd>
  436. <dt><code>set auto-solib-add <var>mode</var></code></dt>
  437. <dd><p>If <var>mode</var> is <code>on</code>, symbols from all shared object libraries
  438. will be loaded automatically when the inferior begins execution, you
  439. attach to an independently started inferior, or when the dynamic linker
  440. informs <small>GDB</small> that a new library has been loaded. If <var>mode</var>
  441. is <code>off</code>, symbols must be loaded manually, using the
  442. <code>sharedlibrary</code> command. The default value is <code>on</code>.
  443. </p>
  444. <a name="index-memory-used-for-symbol-tables"></a>
  445. <p>If your program uses lots of shared libraries with debug info that
  446. takes large amounts of memory, you can decrease the <small>GDB</small>
  447. memory footprint by preventing it from automatically loading the
  448. symbols from shared libraries. To that end, type <kbd>set
  449. auto-solib-add off</kbd> before running the inferior, then load each
  450. library whose debug symbols you do need with <kbd>sharedlibrary
  451. <var>regexp</var></kbd>, where <var>regexp</var> is a regular expression that matches
  452. the libraries whose symbols you want to be loaded.
  453. </p>
  454. <a name="index-show-auto_002dsolib_002dadd"></a>
  455. </dd>
  456. <dt><code>show auto-solib-add</code></dt>
  457. <dd><p>Display the current autoloading mode.
  458. </p></dd>
  459. </dl>
  460. <a name="index-load-shared-library"></a>
  461. <p>To explicitly load shared library symbols, use the <code>sharedlibrary</code>
  462. command:
  463. </p>
  464. <dl compact="compact">
  465. <dd><a name="index-info-sharedlibrary"></a>
  466. <a name="index-info-share"></a>
  467. </dd>
  468. <dt><code>info share <var>regex</var></code></dt>
  469. <dt><code>info sharedlibrary <var>regex</var></code></dt>
  470. <dd><p>Print the names of the shared libraries which are currently loaded
  471. that match <var>regex</var>. If <var>regex</var> is omitted then print
  472. all shared libraries that are loaded.
  473. </p>
  474. <a name="index-info-dll"></a>
  475. </dd>
  476. <dt><code>info dll <var>regex</var></code></dt>
  477. <dd><p>This is an alias of <code>info sharedlibrary</code>.
  478. </p>
  479. <a name="index-sharedlibrary"></a>
  480. <a name="index-share"></a>
  481. </dd>
  482. <dt><code>sharedlibrary <var>regex</var></code></dt>
  483. <dt><code>share <var>regex</var></code></dt>
  484. <dd><p>Load shared object library symbols for files matching a
  485. Unix regular expression.
  486. As with files loaded automatically, it only loads shared libraries
  487. required by your program for a core file or after typing <code>run</code>. If
  488. <var>regex</var> is omitted all shared libraries required by your program are
  489. loaded.
  490. </p>
  491. </dd>
  492. <dt><code>nosharedlibrary</code></dt>
  493. <dd><a name="index-nosharedlibrary"></a>
  494. <a name="index-unload-symbols-from-shared-libraries"></a>
  495. <p>Unload all shared object library symbols. This discards all symbols
  496. that have been loaded from all shared libraries. Symbols from shared
  497. libraries that were loaded by explicit user requests are not
  498. discarded.
  499. </p></dd>
  500. </dl>
  501. <p>Sometimes you may wish that <small>GDB</small> stops and gives you control
  502. when any of shared library events happen. The best way to do this is
  503. to use <code>catch load</code> and <code>catch unload</code> (see <a href="Set-Catchpoints.html#Set-Catchpoints">Set Catchpoints</a>).
  504. </p>
  505. <p><small>GDB</small> also supports the <code>set stop-on-solib-events</code>
  506. command for this. This command exists for historical reasons. It is
  507. less useful than setting a catchpoint, because it does not allow for
  508. conditions or commands as a catchpoint does.
  509. </p>
  510. <dl compact="compact">
  511. <dt><code>set stop-on-solib-events</code></dt>
  512. <dd><a name="index-set-stop_002don_002dsolib_002devents"></a>
  513. <p>This command controls whether <small>GDB</small> should give you control
  514. when the dynamic linker notifies it about some shared library event.
  515. The most common event of interest is loading or unloading of a new
  516. shared library.
  517. </p>
  518. </dd>
  519. <dt><code>show stop-on-solib-events</code></dt>
  520. <dd><a name="index-show-stop_002don_002dsolib_002devents"></a>
  521. <p>Show whether <small>GDB</small> stops and gives you control when shared
  522. library events happen.
  523. </p></dd>
  524. </dl>
  525. <p>Shared libraries are also supported in many cross or remote debugging
  526. configurations. <small>GDB</small> needs to have access to the target&rsquo;s libraries;
  527. this can be accomplished either by providing copies of the libraries
  528. on the host system, or by asking <small>GDB</small> to automatically retrieve the
  529. libraries from the target. If copies of the target libraries are
  530. provided, they need to be the same as the target libraries, although the
  531. copies on the target can be stripped as long as the copies on the host are
  532. not.
  533. </p>
  534. <a name="index-where-to-look-for-shared-libraries"></a>
  535. <p>For remote debugging, you need to tell <small>GDB</small> where the target
  536. libraries are, so that it can load the correct copies&mdash;otherwise, it
  537. may try to load the host&rsquo;s libraries. <small>GDB</small> has two variables
  538. to specify the search directories for target libraries.
  539. </p>
  540. <dl compact="compact">
  541. <dd><a name="index-prefix-for-executable-and-shared-library-file-names"></a>
  542. <a name="index-system-root_002c-alternate"></a>
  543. <a name="index-set-solib_002dabsolute_002dprefix"></a>
  544. <a name="index-set-sysroot"></a>
  545. </dd>
  546. <dt><code>set sysroot <var>path</var></code></dt>
  547. <dd><p>Use <var>path</var> as the system root for the program being debugged. Any
  548. absolute shared library paths will be prefixed with <var>path</var>; many
  549. runtime loaders store the absolute paths to the shared library in the
  550. target program&rsquo;s memory. When starting processes remotely, and when
  551. attaching to already-running processes (local or remote), their
  552. executable filenames will be prefixed with <var>path</var> if reported to
  553. <small>GDB</small> as absolute by the operating system. If you use
  554. <code>set sysroot</code> to find executables and shared libraries, they need
  555. to be laid out in the same way that they are on the target, with
  556. e.g. a <samp>/bin</samp>, <samp>/lib</samp> and <samp>/usr/lib</samp> hierarchy under
  557. <var>path</var>.
  558. </p>
  559. <p>If <var>path</var> starts with the sequence <samp>target:</samp> and the target
  560. system is remote then <small>GDB</small> will retrieve the target binaries
  561. from the remote system. This is only supported when using a remote
  562. target that supports the <code>remote get</code> command (see <a href="File-Transfer.html#File-Transfer">Sending files to a remote system</a>). The part of <var>path</var>
  563. following the initial <samp>target:</samp> (if present) is used as system
  564. root prefix on the remote file system. If <var>path</var> starts with the
  565. sequence <samp>remote:</samp> this is converted to the sequence
  566. <samp>target:</samp> by <code>set sysroot</code><a name="DOCF15" href="#FOOT15"><sup>15</sup></a>. If you want
  567. to specify a local system root using a directory that happens to be
  568. named <samp>target:</samp> or <samp>remote:</samp>, you need to use some
  569. equivalent variant of the name like <samp>./target:</samp>.
  570. </p>
  571. <p>For targets with an MS-DOS based filesystem, such as MS-Windows and
  572. SymbianOS, <small>GDB</small> tries prefixing a few variants of the target
  573. absolute file name with <var>path</var>. But first, on Unix hosts,
  574. <small>GDB</small> converts all backslash directory separators into forward
  575. slashes, because the backslash is not a directory separator on Unix:
  576. </p>
  577. <div class="smallexample">
  578. <pre class="smallexample"> c:\foo\bar.dll &rArr; c:/foo/bar.dll
  579. </pre></div>
  580. <p>Then, <small>GDB</small> attempts prefixing the target file name with
  581. <var>path</var>, and looks for the resulting file name in the host file
  582. system:
  583. </p>
  584. <div class="smallexample">
  585. <pre class="smallexample"> c:/foo/bar.dll &rArr; /path/to/sysroot/c:/foo/bar.dll
  586. </pre></div>
  587. <p>If that does not find the binary, <small>GDB</small> tries removing
  588. the &lsquo;<samp>:</samp>&rsquo; character from the drive spec, both for convenience, and,
  589. for the case of the host file system not supporting file names with
  590. colons:
  591. </p>
  592. <div class="smallexample">
  593. <pre class="smallexample"> c:/foo/bar.dll &rArr; /path/to/sysroot/c/foo/bar.dll
  594. </pre></div>
  595. <p>This makes it possible to have a system root that mirrors a target
  596. with more than one drive. E.g., you may want to setup your local
  597. copies of the target system shared libraries like so (note &lsquo;<samp>c</samp>&rsquo; vs
  598. &lsquo;<samp>z</samp>&rsquo;):
  599. </p>
  600. <div class="smallexample">
  601. <pre class="smallexample"> <samp>/path/to/sysroot/c/sys/bin/foo.dll</samp>
  602. <samp>/path/to/sysroot/c/sys/bin/bar.dll</samp>
  603. <samp>/path/to/sysroot/z/sys/bin/bar.dll</samp>
  604. </pre></div>
  605. <p>and point the system root at <samp>/path/to/sysroot</samp>, so that
  606. <small>GDB</small> can find the correct copies of both
  607. <samp>c:\sys\bin\foo.dll</samp>, and <samp>z:\sys\bin\bar.dll</samp>.
  608. </p>
  609. <p>If that still does not find the binary, <small>GDB</small> tries
  610. removing the whole drive spec from the target file name:
  611. </p>
  612. <div class="smallexample">
  613. <pre class="smallexample"> c:/foo/bar.dll &rArr; /path/to/sysroot/foo/bar.dll
  614. </pre></div>
  615. <p>This last lookup makes it possible to not care about the drive name,
  616. if you don&rsquo;t want or need to.
  617. </p>
  618. <p>The <code>set solib-absolute-prefix</code> command is an alias for <code>set
  619. sysroot</code>.
  620. </p>
  621. <a name="index-default-system-root"></a>
  622. <a name="index-_002d_002dwith_002dsysroot"></a>
  623. <p>You can set the default system root by using the configure-time
  624. &lsquo;<samp>--with-sysroot</samp>&rsquo; option. If the system root is inside
  625. <small>GDB</small>&rsquo;s configured binary prefix (set with &lsquo;<samp>--prefix</samp>&rsquo; or
  626. &lsquo;<samp>--exec-prefix</samp>&rsquo;), then the default system root will be updated
  627. automatically if the installed <small>GDB</small> is moved to a new
  628. location.
  629. </p>
  630. <a name="index-show-sysroot"></a>
  631. </dd>
  632. <dt><code>show sysroot</code></dt>
  633. <dd><p>Display the current executable and shared library prefix.
  634. </p>
  635. <a name="index-set-solib_002dsearch_002dpath"></a>
  636. </dd>
  637. <dt><code>set solib-search-path <var>path</var></code></dt>
  638. <dd><p>If this variable is set, <var>path</var> is a colon-separated list of
  639. directories to search for shared libraries. &lsquo;<samp>solib-search-path</samp>&rsquo;
  640. is used after &lsquo;<samp>sysroot</samp>&rsquo; fails to locate the library, or if the
  641. path to the library is relative instead of absolute. If you want to
  642. use &lsquo;<samp>solib-search-path</samp>&rsquo; instead of &lsquo;<samp>sysroot</samp>&rsquo;, be sure to set
  643. &lsquo;<samp>sysroot</samp>&rsquo; to a nonexistent directory to prevent <small>GDB</small> from
  644. finding your host&rsquo;s libraries. &lsquo;<samp>sysroot</samp>&rsquo; is preferred; setting
  645. it to a nonexistent directory may interfere with automatic loading
  646. of shared library symbols.
  647. </p>
  648. <a name="index-show-solib_002dsearch_002dpath"></a>
  649. </dd>
  650. <dt><code>show solib-search-path</code></dt>
  651. <dd><p>Display the current shared library search path.
  652. </p>
  653. <a name="index-DOS-file_002dname-semantics-of-file-names_002e"></a>
  654. <a name="index-set-target_002dfile_002dsystem_002dkind-_0028unix_007cdos_002dbased_007cauto_0029"></a>
  655. <a name="index-show-target_002dfile_002dsystem_002dkind"></a>
  656. </dd>
  657. <dt><code>set target-file-system-kind <var>kind</var></code></dt>
  658. <dd><p>Set assumed file system kind for target reported file names.
  659. </p>
  660. <p>Shared library file names as reported by the target system may not
  661. make sense as is on the system <small>GDB</small> is running on. For
  662. example, when remote debugging a target that has MS-DOS based file
  663. system semantics, from a Unix host, the target may be reporting to
  664. <small>GDB</small> a list of loaded shared libraries with file names such as
  665. <samp>c:\Windows\kernel32.dll</samp>. On Unix hosts, there&rsquo;s no concept of
  666. drive letters, so the &lsquo;<samp>c:\</samp>&rsquo; prefix is not normally understood as
  667. indicating an absolute file name, and neither is the backslash
  668. normally considered a directory separator character. In that case,
  669. the native file system would interpret this whole absolute file name
  670. as a relative file name with no directory components. This would make
  671. it impossible to point <small>GDB</small> at a copy of the remote target&rsquo;s
  672. shared libraries on the host using <code>set sysroot</code>, and impractical
  673. with <code>set solib-search-path</code>. Setting
  674. <code>target-file-system-kind</code> to <code>dos-based</code> tells <small>GDB</small>
  675. to interpret such file names similarly to how the target would, and to
  676. map them to file names valid on <small>GDB</small>&rsquo;s native file system
  677. semantics. The value of <var>kind</var> can be <code>&quot;auto&quot;</code>, in addition
  678. to one of the supported file system kinds. In that case, <small>GDB</small>
  679. tries to determine the appropriate file system variant based on the
  680. current target&rsquo;s operating system (see <a href="ABI.html#ABI">Configuring the
  681. Current ABI</a>). The supported file system settings are:
  682. </p>
  683. <dl compact="compact">
  684. <dt><code>unix</code></dt>
  685. <dd><p>Instruct <small>GDB</small> to assume the target file system is of Unix
  686. kind. Only file names starting the forward slash (&lsquo;<samp>/</samp>&rsquo;) character
  687. are considered absolute, and the directory separator character is also
  688. the forward slash.
  689. </p>
  690. </dd>
  691. <dt><code>dos-based</code></dt>
  692. <dd><p>Instruct <small>GDB</small> to assume the target file system is DOS based.
  693. File names starting with either a forward slash, or a drive letter
  694. followed by a colon (e.g., &lsquo;<samp>c:</samp>&rsquo;), are considered absolute, and
  695. both the slash (&lsquo;<samp>/</samp>&rsquo;) and the backslash (&lsquo;<samp>\\</samp>&rsquo;) characters are
  696. considered directory separators.
  697. </p>
  698. </dd>
  699. <dt><code>auto</code></dt>
  700. <dd><p>Instruct <small>GDB</small> to use the file system kind associated with the
  701. target operating system (see <a href="ABI.html#ABI">Configuring the Current ABI</a>).
  702. This is the default.
  703. </p></dd>
  704. </dl>
  705. </dd>
  706. </dl>
  707. <a name="index-file-name-canonicalization"></a>
  708. <a name="index-base-name-differences"></a>
  709. <p>When processing file names provided by the user, <small>GDB</small>
  710. frequently needs to compare them to the file names recorded in the
  711. program&rsquo;s debug info. Normally, <small>GDB</small> compares just the
  712. <em>base names</em> of the files as strings, which is reasonably fast
  713. even for very large programs. (The base name of a file is the last
  714. portion of its name, after stripping all the leading directories.)
  715. This shortcut in comparison is based upon the assumption that files
  716. cannot have more than one base name. This is usually true, but
  717. references to files that use symlinks or similar filesystem
  718. facilities violate that assumption. If your program records files
  719. using such facilities, or if you provide file names to <small>GDB</small>
  720. using symlinks etc., you can set <code>basenames-may-differ</code> to
  721. <code>true</code> to instruct <small>GDB</small> to completely canonicalize each
  722. pair of file names it needs to compare. This will make file-name
  723. comparisons accurate, but at a price of a significant slowdown.
  724. </p>
  725. <dl compact="compact">
  726. <dt><code>set basenames-may-differ</code></dt>
  727. <dd><a name="index-set-basenames_002dmay_002ddiffer"></a>
  728. <p>Set whether a source file may have multiple base names.
  729. </p>
  730. </dd>
  731. <dt><code>show basenames-may-differ</code></dt>
  732. <dd><a name="index-show-basenames_002dmay_002ddiffer"></a>
  733. <p>Show whether a source file may have multiple base names.
  734. </p></dd>
  735. </dl>
  736. <div class="footnote">
  737. <hr>
  738. <h4 class="footnotes-heading">Footnotes</h4>
  739. <h3><a name="FOOT15" href="#DOCF15">(15)</a></h3>
  740. <p>Historically the
  741. functionality to retrieve binaries from the remote system was
  742. provided by prefixing <var>path</var> with <samp>remote:</samp></p>
  743. </div>
  744. <hr>
  745. <div class="header">
  746. <p>
  747. Next: <a href="File-Caching.html#File-Caching" accesskey="n" rel="next">File Caching</a>, Up: <a href="GDB-Files.html#GDB-Files" accesskey="u" rel="up">GDB Files</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>
  748. </div>
  749. </body>
  750. </html>