Files.html 37 KB

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