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