Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Files.html
blob2b645d7148c23f92d86f2b6702901d5315591938
1 <html lang="en">
2 <head>
3 <title>Debugging with GDB</title>
4 <meta http-equiv="Content-Type" content="text/html">
5 <meta name="description" content="Debugging with GDB">
6 <meta name="generator" content="makeinfo 4.3">
7 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
8 </head>
9 <body>
10 <div class="node">
11 <p>
12 Node:<a name="Files">Files</a>,
13 Next:<a rel="next" accesskey="n" href="Symbol-Errors.html#Symbol%20Errors">Symbol Errors</a>,
14 Up:<a rel="up" accesskey="u" href="GDB-Files.html#GDB%20Files">GDB Files</a>
15 <hr><br>
16 </div>
18 <h3 class="section">Commands to specify files</h3>
20 <p>You may want to specify executable and core dump file names. The usual
21 way to do this is at start-up time, using the arguments to
22 GDB's start-up commands (see <a href="Invocation.html#Invocation">Getting In and Out of GDB</a>).
24 <p>Occasionally it is necessary to change to a different file during a
25 GDB session. Or you may run GDB and forget to specify
26 a file you want to use. In these situations the GDB commands
27 to specify new files are useful.
29 <dl>
30 <dt><code>file </code><var>filename</var><code></code>
31 <dd>Use <var>filename</var> as the program to be debugged. It is read for its
32 symbols and for the contents of pure memory. It is also the program
33 executed when you use the <code>run</code> command. If you do not specify a
34 directory and the file is not found in the GDB working directory,
35 GDB uses the environment variable <code>PATH</code> as a list of
36 directories to search, just as the shell does when looking for a program
37 to run. You can change the value of this variable, for both GDB
38 and your program, using the <code>path</code> command.
40 <p>On systems with memory-mapped files, an auxiliary file named
41 <code></code><var>filename</var><code>.syms</code> may hold symbol table information for
42 <var>filename</var>. If so, GDB maps in the symbol table from
43 <code></code><var>filename</var><code>.syms</code>, starting up more quickly. See the
44 descriptions of the file options <code>-mapped</code> and <code>-readnow</code>
45 (available on the command line, and with the commands <code>file</code>,
46 <code>symbol-file</code>, or <code>add-symbol-file</code>, described below),
47 for more information.
49 <br><dt><code>file</code>
50 <dd><code>file</code> with no argument makes GDB discard any information it
51 has on both executable file and the symbol table.
53 <br><dt><code>exec-file </code>[<code> </code><var>filename</var><code> </code>]<code></code>
54 <dd>Specify that the program to be run (but not the symbol table) is found
55 in <var>filename</var>. GDB searches the environment variable <code>PATH</code>
56 if necessary to locate your program. Omitting <var>filename</var> means to
57 discard information on the executable file.
59 <br><dt><code>symbol-file </code>[<code> </code><var>filename</var><code> </code>]<code></code>
60 <dd>Read symbol table information from file <var>filename</var>. <code>PATH</code> is
61 searched when necessary. Use the <code>file</code> command to get both symbol
62 table and program to run from the same file.
64 <p><code>symbol-file</code> with no argument clears out GDB information on your
65 program's symbol table.
67 <p>The <code>symbol-file</code> command causes GDB to forget the contents
68 of its convenience variables, the value history, and all breakpoints and
69 auto-display expressions. This is because they may contain pointers to
70 the internal data recording symbols and data types, which are part of
71 the old symbol table data being discarded inside GDB.
73 <p><code>symbol-file</code> does not repeat if you press &lt;RET&gt; again after
74 executing it once.
76 <p>When GDB is configured for a particular environment, it
77 understands debugging information in whatever format is the standard
78 generated for that environment; you may use either a <small>GNU</small> compiler, or
79 other compilers that adhere to the local conventions.
80 Best results are usually obtained from <small>GNU</small> compilers; for example,
81 using <code>gcc</code> you can generate debugging information for
82 optimized code.
84 <p>For most kinds of object files, with the exception of old SVR3 systems
85 using COFF, the <code>symbol-file</code> command does not normally read the
86 symbol table in full right away. Instead, it scans the symbol table
87 quickly to find which source files and which symbols are present. The
88 details are read later, one source file at a time, as they are needed.
90 <p>The purpose of this two-stage reading strategy is to make GDB
91 start up faster. For the most part, it is invisible except for
92 occasional pauses while the symbol table details for a particular source
93 file are being read. (The <code>set verbose</code> command can turn these
94 pauses into messages if desired. See <a href="Messages-Warnings.html#Messages%2fWarnings">Optional warnings and messages</a>.)
96 <p>We have not implemented the two-stage strategy for COFF yet. When the
97 symbol table is stored in COFF format, <code>symbol-file</code> reads the
98 symbol table data in full right away. Note that "stabs-in-COFF"
99 still does the two-stage strategy, since the debug info is actually
100 in stabs format.
102 <br><dt><code>symbol-file </code><var>filename</var><code> </code>[<code> -readnow </code>]<code> </code>[<code> -mapped </code>]<code></code>
103 <dd><dt><code>file </code><var>filename</var><code> </code>[<code> -readnow </code>]<code> </code>[<code> -mapped </code>]<code></code>
104 <dd>You can override the GDB two-stage strategy for reading symbol
105 tables by using the <code>-readnow</code> option with any of the commands that
106 load symbol table information, if you want to be sure GDB has the
107 entire symbol table available.
109 <p>If memory-mapped files are available on your system through the
110 <code>mmap</code> system call, you can use another option, <code>-mapped</code>, to
111 cause GDB to write the symbols for your program into a reusable
112 file. Future GDB debugging sessions map in symbol information
113 from this auxiliary symbol file (if the program has not changed), rather
114 than spending time reading the symbol table from the executable
115 program. Using the <code>-mapped</code> option has the same effect as
116 starting GDB with the <code>-mapped</code> command-line option.
118 <p>You can use both options together, to make sure the auxiliary symbol
119 file has all the symbol information for your program.
121 <p>The auxiliary symbol file for a program called <var>myprog</var> is called
122 <code></code><var>myprog</var><code>.syms</code>. Once this file exists (so long as it is newer
123 than the corresponding executable), GDB always attempts to use
124 it when you debug <var>myprog</var>; no special options or commands are
125 needed.
127 <p>The <code>.syms</code> file is specific to the host machine where you run
128 GDB. It holds an exact image of the internal GDB
129 symbol table. It cannot be shared across multiple host platforms.
131 <br><dt><code>core-file </code>[<code> </code><var>filename</var><code> </code>]<code></code>
132 <dd>Specify the whereabouts of a core dump file to be used as the "contents
133 of memory". Traditionally, core files contain only some parts of the
134 address space of the process that generated them; GDB can access the
135 executable file itself for other parts.
137 <p><code>core-file</code> with no argument specifies that no core file is
138 to be used.
140 <p>Note that the core file is ignored when your program is actually running
141 under GDB. So, if you have been running your program and you
142 wish to debug a core file instead, you must kill the subprocess in which
143 the program is running. To do this, use the <code>kill</code> command
144 (see <a href="Kill-Process.html#Kill%20Process">Killing the child process</a>).
146 <br><dt><code>add-symbol-file </code><var>filename</var><code> </code><var>address</var><code></code>
147 <dd><dt><code>add-symbol-file </code><var>filename</var><code> </code><var>address</var><code> </code>[<code> -readnow </code>]<code> </code>[<code> -mapped </code>]<code></code>
148 <dd><dt><code>add-symbol-file </code><var>filename</var><code> </code>-s<code></code><var>section</var><code> </code><var>address</var><code> ...</code>
149 <dd>The <code>add-symbol-file</code> command reads additional symbol table
150 information from the file <var>filename</var>. You would use this command
151 when <var>filename</var> has been dynamically loaded (by some other means)
152 into the program that is running. <var>address</var> should be the memory
153 address at which the file has been loaded; GDB cannot figure
154 this out for itself. You can additionally specify an arbitrary number
155 of <code></code>-s<code></code><var>section</var><code> </code><var>address</var><code></code> pairs, to give an explicit
156 section name and base address for that section. You can specify any
157 <var>address</var> as an expression.
159 <p>The symbol table of the file <var>filename</var> is added to the symbol table
160 originally read with the <code>symbol-file</code> command. You can use the
161 <code>add-symbol-file</code> command any number of times; the new symbol data
162 thus read keeps adding to the old. To discard all old symbol data
163 instead, use the <code>symbol-file</code> command without any arguments.
165 <p>Although <var>filename</var> is typically a shared library file, an
166 executable file, or some other object file which has been fully
167 relocated for loading into a process, you can also load symbolic
168 information from relocatable <code>.o</code> files, as long as:
170 <ul>
171 <li>the file's symbolic information refers only to linker symbols defined in
172 that file, not to symbols defined by other object files,
173 <li>every section the file's symbolic information refers to has actually
174 been loaded into the inferior, as it appears in the file, and
175 <li>you can determine the address at which every section was loaded, and
176 provide these to the <code>add-symbol-file</code> command.
177 </ul>
179 <p>Some embedded operating systems, like Sun Chorus and VxWorks, can load
180 relocatable files into an already running program; such systems
181 typically make the requirements above easy to meet. However, it's
182 important to recognize that many native systems use complex link
183 procedures (<code>.linkonce</code> section factoring and C++ constructor table
184 assembly, for example) that make the requirements difficult to meet. In
185 general, one cannot assume that using <code>add-symbol-file</code> to read a
186 relocatable object file's symbolic information will have the same effect
187 as linking the relocatable object file into the program in the normal
188 way.
190 <p><code>add-symbol-file</code> does not repeat if you press &lt;RET&gt; after using it.
192 <p>You can use the <code>-mapped</code> and <code>-readnow</code> options just as with
193 the <code>symbol-file</code> command, to change how GDB manages the symbol
194 table information for <var>filename</var>.
196 <br><dt><code>add-shared-symbol-file</code>
197 <dd>The <code>add-shared-symbol-file</code> command can be used only under Harris' CXUX
198 operating system for the Motorola 88k. GDB automatically looks for
199 shared libraries, however if GDB does not find yours, you can run
200 <code>add-shared-symbol-file</code>. It takes no arguments.
202 <br><dt><code>section</code>
203 <dd>The <code>section</code> command changes the base address of section SECTION of
204 the exec file to ADDR. This can be used if the exec file does not contain
205 section addresses, (such as in the a.out format), or when the addresses
206 specified in the file itself are wrong. Each section must be changed
207 separately. The <code>info files</code> command, described below, lists all
208 the sections and their addresses.
210 <br><dt><code>info files</code>
211 <dd><dt><code>info target</code>
212 <dd><code>info files</code> and <code>info target</code> are synonymous; both print the
213 current target (see <a href="Targets.html#Targets">Specifying a Debugging Target</a>),
214 including the names of the executable and core dump files currently in
215 use by GDB, and the files from which symbols were loaded. The
216 command <code>help target</code> lists all possible targets rather than
217 current ones.
219 <br><dt><code>maint info sections</code>
220 <dd>Another command that can give you extra information about program sections
221 is <code>maint info sections</code>. In addition to the section information
222 displayed by <code>info files</code>, this command displays the flags and file
223 offset of each section in the executable and core dump files. In addition,
224 <code>maint info sections</code> provides the following command options (which
225 may be arbitrarily combined):
227 <dl>
228 <dt><code>ALLOBJ</code>
229 <dd>Display sections for all loaded object files, including shared libraries.
230 <br><dt><code></code><var>sections</var><code></code>
231 <dd>Display info only for named <var>sections</var>.
232 <br><dt><code></code><var>section-flags</var><code></code>
233 <dd>Display info only for sections for which <var>section-flags</var> are true.
234 The section flags that GDB currently knows about are:
235 <dl>
236 <dt><code>ALLOC</code>
237 <dd>Section will have space allocated in the process when loaded.
238 Set for all sections except those containing debug information.
239 <br><dt><code>LOAD</code>
240 <dd>Section will be loaded from the file into the child process memory.
241 Set for pre-initialized code and data, clear for <code>.bss</code> sections.
242 <br><dt><code>RELOC</code>
243 <dd>Section needs to be relocated before loading.
244 <br><dt><code>READONLY</code>
245 <dd>Section cannot be modified by the child process.
246 <br><dt><code>CODE</code>
247 <dd>Section contains executable code only.
248 <br><dt><code>DATA</code>
249 <dd>Section contains data only (no executable code).
250 <br><dt><code>ROM</code>
251 <dd>Section will reside in ROM.
252 <br><dt><code>CONSTRUCTOR</code>
253 <dd>Section contains data for constructor/destructor lists.
254 <br><dt><code>HAS_CONTENTS</code>
255 <dd>Section is not empty.
256 <br><dt><code>NEVER_LOAD</code>
257 <dd>An instruction to the linker to not output the section.
258 <br><dt><code>COFF_SHARED_LIBRARY</code>
259 <dd>A notification to the linker that the section contains
260 COFF shared library information.
261 <br><dt><code>IS_COMMON</code>
262 <dd>Section contains common symbols.
263 </dl>
264 </dl>
265 <br><dt><code>set trust-readonly-sections on</code>
266 <dd>Tell GDB that readonly sections in your object file
267 really are read-only (i.e. that their contents will not change).
268 In that case, GDB can fetch values from these sections
269 out of the object file, rather than from the target program.
270 For some targets (notably embedded ones), this can be a significant
271 enhancement to debugging performance.
273 <p>The default is off.
275 <br><dt><code>set trust-readonly-sections off</code>
276 <dd>Tell GDB not to trust readonly sections. This means that
277 the contents of the section might change while the program is running,
278 and must therefore be fetched from the target when needed.
279 </dl>
281 <p>All file-specifying commands allow both absolute and relative file names
282 as arguments. GDB always converts the file name to an absolute file
283 name and remembers it that way.
285 GDB supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
286 libraries.
288 GDB automatically loads symbol definitions from shared libraries
289 when you use the <code>run</code> command, or when you examine a core file.
290 (Before you issue the <code>run</code> command, GDB does not understand
291 references to a function in a shared library, however--unless you are
292 debugging a core file).
294 <p>On HP-UX, if the program loads a library explicitly, GDB
295 automatically loads the symbols at the time of the <code>shl_load</code> call.
297 <p>There are times, however, when you may wish to not automatically load
298 symbol definitions from shared libraries, such as when they are
299 particularly large or there are many of them.
301 <p>To control the automatic loading of shared library symbols, use the
302 commands:
304 <dl>
305 <dt><code>set auto-solib-add </code><var>mode</var><code></code>
306 <dd>If <var>mode</var> is <code>on</code>, symbols from all shared object libraries
307 will be loaded automatically when the inferior begins execution, you
308 attach to an independently started inferior, or when the dynamic linker
309 informs GDB that a new library has been loaded. If <var>mode</var>
310 is <code>off</code>, symbols must be loaded manually, using the
311 <code>sharedlibrary</code> command. The default value is <code>on</code>.
313 <br><dt><code>show auto-solib-add</code>
314 <dd>Display the current autoloading mode.
315 </dl>
317 <p>To explicitly load shared library symbols, use the <code>sharedlibrary</code>
318 command:
320 <dl>
321 <dt><code>info share</code>
322 <dd><dt><code>info sharedlibrary</code>
323 <dd>Print the names of the shared libraries which are currently loaded.
325 <br><dt><code>sharedlibrary </code><var>regex</var><code></code>
326 <dd><dt><code>share </code><var>regex</var><code></code>
327 <dd>Load shared object library symbols for files matching a
328 Unix regular expression.
329 As with files loaded automatically, it only loads shared libraries
330 required by your program for a core file or after typing <code>run</code>. If
331 <var>regex</var> is omitted all shared libraries required by your program are
332 loaded.
333 </dl>
335 <p>On some systems, such as HP-UX systems, GDB supports
336 autoloading shared library symbols until a limiting threshold size is
337 reached. This provides the benefit of allowing autoloading to remain on
338 by default, but avoids autoloading excessively large shared libraries,
339 up to a threshold that is initially set, but which you can modify if you
340 wish.
342 <p>Beyond that threshold, symbols from shared libraries must be explicitly
343 loaded. To load these symbols, use the command <code>sharedlibrary
344 </code><var>filename</var><code></code>. The base address of the shared library is determined
345 automatically by GDB and need not be specified.
347 <p>To display or set the threshold, use the commands:
349 <dl>
350 <dt><code>set auto-solib-limit </code><var>threshold</var><code></code>
351 <dd>Set the autoloading size threshold, in an integral number of megabytes.
352 If <var>threshold</var> is nonzero and shared library autoloading is enabled,
353 symbols from all shared object libraries will be loaded until the total
354 size of the loaded shared library symbols exceeds this threshold.
355 Otherwise, symbols must be loaded manually, using the
356 <code>sharedlibrary</code> command. The default threshold is 100 (i.e. 100
357 Mb).
359 <br><dt><code>show auto-solib-limit</code>
360 <dd>Display the current autoloading size threshold, in megabytes.
361 </dl>
363 </body></html>