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">
12 Node:
<a name=
"GDB%2fMI%20Program%20Control">GDB/MI Program Control
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"GDB-MI-Miscellaneous-Commands.html#GDB%2fMI%20Miscellaneous%20Commands">GDB/MI Miscellaneous Commands
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"GDB-MI-Data-Manipulation.html#GDB%2fMI%20Data%20Manipulation">GDB/MI Data Manipulation
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"GDB-MI.html#GDB%2fMI">GDB/MI
</a>
19 <h3 class=
"section"><small>GDB/MI
</small> Program control
</h3>
21 <h5 class=
"subsubheading">Program termination
</h5>
23 <p>As a result of execution, the inferior program can run to completion, if
24 it doesn't encounter any breakpoints. In this case the output will
25 include an exit code, if the program has exited exceptionally.
27 <h5 class=
"subsubheading">Examples
</h5>
29 <p>Program exited normally:
31 <pre class=
"smallexample"> (gdb)
36 *stopped,
reason=
"exited-normally"
40 <p>Program exited exceptionally:
42 <pre class=
"smallexample"> (gdb)
47 *stopped,
reason=
"exited",
exit-code=
"01"
51 <p>Another way the program can terminate is if it receives a signal such as
52 <code>SIGINT
</code>. In this case,
<small>GDB/MI
</small> displays this:
54 <pre class=
"smallexample"> (gdb)
55 *stopped,
reason=
"exited-signalled",
signal-name=
"SIGINT",
56 signal-meaning=
"Interrupt"
59 <h4 class=
"subheading">The
<code>-exec-abort
</code> Command
</h4>
61 <h5 class=
"subsubheading">Synopsis
</h5>
63 <pre class=
"example"> -exec-abort
66 <p>Kill the inferior running program.
68 <h5 class=
"subsubheading">GDB Command
</h5>
70 <p>The corresponding GDB command is
<code>kill
</code>.
72 <h5 class=
"subsubheading">Example
</h5>
76 <h4 class=
"subheading">The
<code>-exec-arguments
</code> Command
</h4>
78 <h5 class=
"subsubheading">Synopsis
</h5>
80 <pre class=
"example"> -exec-arguments
<var>args
</var>
83 <p>Set the inferior program arguments, to be used in the next
84 <code>-exec-run
</code>.
86 <h5 class=
"subsubheading">GDB Command
</h5>
88 <p>The corresponding GDB command is
<code>set args
</code>.
90 <h5 class=
"subsubheading">Example
</h5>
92 <p>Don't have one around.
94 <h4 class=
"subheading">The
<code>-exec-continue
</code> Command
</h4>
96 <h5 class=
"subsubheading">Synopsis
</h5>
98 <pre class=
"example"> -exec-continue
101 <p>Asynchronous command. Resumes the execution of the inferior program
102 until a breakpoint is encountered, or until the inferior exits.
104 <h5 class=
"subsubheading">GDB Command
</h5>
106 <p>The corresponding GDB corresponding is
<code>continue
</code>.
108 <h5 class=
"subsubheading">Example
</h5>
110 <pre class=
"smallexample"> -exec-continue
114 *stopped,
reason=
"breakpoint-hit",
bkptno=
"2",frame={
func=
"foo",args=[],
115 file=
"hello.c",
line=
"13"}
119 <h4 class=
"subheading">The
<code>-exec-finish
</code> Command
</h4>
121 <h5 class=
"subsubheading">Synopsis
</h5>
123 <pre class=
"example"> -exec-finish
126 <p>Asynchronous command. Resumes the execution of the inferior program
127 until the current function is exited. Displays the results returned by
130 <h5 class=
"subsubheading">GDB Command
</h5>
132 <p>The corresponding GDB command is
<code>finish
</code>.
134 <h5 class=
"subsubheading">Example
</h5>
136 <p>Function returning
<code>void
</code>.
138 <pre class=
"smallexample"> -exec-finish
142 *stopped,
reason=
"function-finished",frame={
func=
"main",args=[],
143 file=
"hello.c",
line=
"7"}
147 <p>Function returning other than
<code>void
</code>. The name of the internal
148 GDB variable storing the result is printed, together with the
151 <pre class=
"smallexample"> -exec-finish
154 *stopped,
reason=
"function-finished",frame={
addr=
"0x000107b0",
func=
"foo",
155 args=[{
name=
"a",
value=
"1"],{
name=
"b",
value=
"9"}},
156 file=
"recursive2.c",
line=
"14"},
157 gdb-result-var=
"$1",
return-value=
"0"
161 <h4 class=
"subheading">The
<code>-exec-interrupt
</code> Command
</h4>
163 <h5 class=
"subsubheading">Synopsis
</h5>
165 <pre class=
"example"> -exec-interrupt
168 <p>Asynchronous command. Interrupts the background execution of the target.
169 Note how the token associated with the stop message is the one for the
170 execution command that has been interrupted. The token for the interrupt
171 itself only appears in the
<code>^done
</code> output. If the user is trying to
172 interrupt a non-running program, an error message will be printed.
174 <h5 class=
"subsubheading">GDB Command
</h5>
176 <p>The corresponding GDB command is
<code>interrupt
</code>.
178 <h5 class=
"subsubheading">Example
</h5>
180 <pre class=
"smallexample"> (gdb)
188 111*stopped,
signal-name=
"SIGINT",
signal-meaning=
"Interrupt",
189 frame={
addr=
"0x00010140",
func=
"foo",args=[],
file=
"try.c",
line=
"13"}
194 ^error,
msg=
"mi_cmd_exec_interrupt: Inferior not executing."
198 <h4 class=
"subheading">The
<code>-exec-next
</code> Command
</h4>
200 <h5 class=
"subsubheading">Synopsis
</h5>
202 <pre class=
"example"> -exec-next
205 <p>Asynchronous command. Resumes execution of the inferior program, stopping
206 when the beginning of the next source line is reached.
208 <h5 class=
"subsubheading">GDB Command
</h5>
210 <p>The corresponding GDB command is
<code>next
</code>.
212 <h5 class=
"subsubheading">Example
</h5>
214 <pre class=
"smallexample"> -exec-next
217 *stopped,
reason=
"end-stepping-range",
line=
"8",
file=
"hello.c"
221 <h4 class=
"subheading">The
<code>-exec-next-instruction
</code> Command
</h4>
223 <h5 class=
"subsubheading">Synopsis
</h5>
225 <pre class=
"example"> -exec-next-instruction
228 <p>Asynchronous command. Executes one machine instruction. If the
229 instruction is a function call continues until the function returns. If
230 the program stops at an instruction in the middle of a source line, the
231 address will be printed as well.
233 <h5 class=
"subsubheading">GDB Command
</h5>
235 <p>The corresponding GDB command is
<code>nexti
</code>.
237 <h5 class=
"subsubheading">Example
</h5>
239 <pre class=
"smallexample"> (gdb)
240 -exec-next-instruction
244 *stopped,
reason=
"end-stepping-range",
245 addr=
"0x000100d4",
line=
"5",
file=
"hello.c"
249 <h4 class=
"subheading">The
<code>-exec-return
</code> Command
</h4>
251 <h5 class=
"subsubheading">Synopsis
</h5>
253 <pre class=
"example"> -exec-return
256 <p>Makes current function return immediately. Doesn't execute the inferior.
257 Displays the new current frame.
259 <h5 class=
"subsubheading">GDB Command
</h5>
261 <p>The corresponding GDB command is
<code>return
</code>.
263 <h5 class=
"subsubheading">Example
</h5>
265 <pre class=
"smallexample"> (gdb)
266 200-break-insert callee4
267 200^done,bkpt={
number=
"1",
addr=
"0x00010734",
268 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"8"}
273 000*stopped,
reason=
"breakpoint-hit",
bkptno=
"1",
274 frame={
func=
"callee4",args=[],
275 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"8"}
281 111^done,frame={
level=
"0 ",
func=
"callee3",
282 args=[{
name=
"strarg",
283 value=
"0x11940 \"A string argument.\
""}],
284 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"18"}
288 <h4 class=
"subheading">The
<code>-exec-run
</code> Command
</h4>
290 <h5 class=
"subsubheading">Synopsis
</h5>
292 <pre class=
"example"> -exec-run
295 <p>Asynchronous command. Starts execution of the inferior from the
296 beginning. The inferior executes until either a breakpoint is
297 encountered or the program exits.
299 <h5 class=
"subsubheading">GDB Command
</h5>
301 <p>The corresponding GDB command is
<code>run
</code>.
303 <h5 class=
"subsubheading">Example
</h5>
305 <pre class=
"smallexample"> (gdb)
307 ^done,bkpt={
number=
"1",
addr=
"0x0001072c",
file=
"recursive2.c",
line=
"4"}
312 *stopped,
reason=
"breakpoint-hit",
bkptno=
"1",
313 frame={
func=
"main",args=[],
file=
"recursive2.c",
line=
"4"}
317 <h4 class=
"subheading">The
<code>-exec-show-arguments
</code> Command
</h4>
319 <h5 class=
"subsubheading">Synopsis
</h5>
321 <pre class=
"example"> -exec-show-arguments
324 <p>Print the arguments of the program.
326 <h5 class=
"subsubheading">GDB Command
</h5>
328 <p>The corresponding GDB command is
<code>show args
</code>.
330 <h5 class=
"subsubheading">Example
</h5>
334 <h4 class=
"subheading">The
<code>-exec-step
</code> Command
</h4>
336 <h5 class=
"subsubheading">Synopsis
</h5>
338 <pre class=
"example"> -exec-step
341 <p>Asynchronous command. Resumes execution of the inferior program, stopping
342 when the beginning of the next source line is reached, if the next
343 source line is not a function call. If it is, stop at the first
344 instruction of the called function.
346 <h5 class=
"subsubheading">GDB Command
</h5>
348 <p>The corresponding GDB command is
<code>step
</code>.
350 <h5 class=
"subsubheading">Example
</h5>
352 <p>Stepping into a function:
354 <pre class=
"smallexample"> -exec-step
357 *stopped,
reason=
"end-stepping-range",
358 frame={
func=
"foo",args=[{
name=
"a",
value=
"10"},
359 {
name=
"b",
value=
"0"}],
file=
"recursive2.c",
line=
"11"}
365 <pre class=
"smallexample"> -exec-step
368 *stopped,
reason=
"end-stepping-range",
line=
"14",
file=
"recursive2.c"
372 <h4 class=
"subheading">The
<code>-exec-step-instruction
</code> Command
</h4>
374 <h5 class=
"subsubheading">Synopsis
</h5>
376 <pre class=
"example"> -exec-step-instruction
379 <p>Asynchronous command. Resumes the inferior which executes one machine
380 instruction. The output, once GDB has stopped, will vary depending on
381 whether we have stopped in the middle of a source line or not. In the
382 former case, the address at which the program stopped will be printed as
385 <h5 class=
"subsubheading">GDB Command
</h5>
387 <p>The corresponding GDB command is
<code>stepi
</code>.
389 <h5 class=
"subsubheading">Example
</h5>
391 <pre class=
"smallexample"> (gdb)
392 -exec-step-instruction
396 *stopped,
reason=
"end-stepping-range",
397 frame={
func=
"foo",args=[],
file=
"try.c",
line=
"10"}
399 -exec-step-instruction
403 *stopped,
reason=
"end-stepping-range",
404 frame={
addr=
"0x000100f4",
func=
"foo",args=[],
file=
"try.c",
line=
"10"}
408 <h4 class=
"subheading">The
<code>-exec-until
</code> Command
</h4>
410 <h5 class=
"subsubheading">Synopsis
</h5>
412 <pre class=
"example"> -exec-until [
<var>location
</var> ]
415 <p>Asynchronous command. Executes the inferior until the
<var>location
</var>
416 specified in the argument is reached. If there is no argument, the inferior
417 executes until a source line greater than the current one is reached.
418 The reason for stopping in this case will be
<code>location-reached
</code>.
420 <h5 class=
"subsubheading">GDB Command
</h5>
422 <p>The corresponding GDB command is
<code>until
</code>.
424 <h5 class=
"subsubheading">Example
</h5>
426 <pre class=
"smallexample"> (gdb)
427 -exec-until recursive2.c:
6
431 *stopped,
reason=
"location-reached",frame={
func=
"main",args=[],
432 file=
"recursive2.c",
line=
"6"}
436 <h4 class=
"subheading">The
<code>-file-exec-and-symbols
</code> Command
</h4>
438 <h5 class=
"subsubheading">Synopsis
</h5>
440 <pre class=
"example"> -file-exec-and-symbols
<var>file
</var>
443 <p>Specify the executable file to be debugged. This file is the one from
444 which the symbol table is also read. If no file is specified, the
445 command clears the executable and symbol information. If breakpoints
446 are set when using this command with no arguments, GDB will produce
447 error messages. Otherwise, no output is produced, except a completion
450 <h5 class=
"subsubheading">GDB Command
</h5>
452 <p>The corresponding GDB command is
<code>file
</code>.
454 <h5 class=
"subsubheading">Example
</h5>
456 <pre class=
"smallexample"> (gdb)
457 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
462 <h4 class=
"subheading">The
<code>-file-exec-file
</code> Command
</h4>
464 <h5 class=
"subsubheading">Synopsis
</h5>
466 <pre class=
"example"> -file-exec-file
<var>file
</var>
469 <p>Specify the executable file to be debugged. Unlike
470 <code>-file-exec-and-symbols
</code>, the symbol table is
<em>not
</em> read
471 from this file. If used without argument, GDB clears the information
472 about the executable file. No output is produced, except a completion
475 <h5 class=
"subsubheading">GDB Command
</h5>
477 <p>The corresponding GDB command is
<code>exec-file
</code>.
479 <h5 class=
"subsubheading">Example
</h5>
481 <pre class=
"smallexample"> (gdb)
482 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
487 <h4 class=
"subheading">The
<code>-file-list-exec-sections
</code> Command
</h4>
489 <h5 class=
"subsubheading">Synopsis
</h5>
491 <pre class=
"example"> -file-list-exec-sections
494 <p>List the sections of the current executable file.
496 <h5 class=
"subsubheading">GDB Command
</h5>
498 <p>The GDB command
<code>info file
</code> shows, among the rest, the same
499 information as this command.
<code>gdbtk
</code> has a corresponding command
500 <code>gdb_load_info
</code>.
502 <h5 class=
"subsubheading">Example
</h5>
506 <h4 class=
"subheading">The
<code>-file-list-exec-source-files
</code> Command
</h4>
508 <h5 class=
"subsubheading">Synopsis
</h5>
510 <pre class=
"example"> -file-list-exec-source-files
513 <p>List the source files for the current executable.
515 <h5 class=
"subsubheading">GDB Command
</h5>
517 <p>There's no GDB command which directly corresponds to this one.
518 <code>gdbtk
</code> has an analogous command
<code>gdb_listfiles
</code>.
520 <h5 class=
"subsubheading">Example
</h5>
524 <h4 class=
"subheading">The
<code>-file-list-shared-libraries
</code> Command
</h4>
526 <h5 class=
"subsubheading">Synopsis
</h5>
528 <pre class=
"example"> -file-list-shared-libraries
531 <p>List the shared libraries in the program.
533 <h5 class=
"subsubheading">GDB Command
</h5>
535 <p>The corresponding GDB command is
<code>info shared
</code>.
537 <h5 class=
"subsubheading">Example
</h5>
541 <h4 class=
"subheading">The
<code>-file-list-symbol-files
</code> Command
</h4>
543 <h5 class=
"subsubheading">Synopsis
</h5>
545 <pre class=
"example"> -file-list-symbol-files
548 <p>List symbol files.
550 <h5 class=
"subsubheading">GDB Command
</h5>
552 <p>The corresponding GDB command is
<code>info file
</code> (part of it).
554 <h5 class=
"subsubheading">Example
</h5>
558 <h4 class=
"subheading">The
<code>-file-symbol-file
</code> Command
</h4>
560 <h5 class=
"subsubheading">Synopsis
</h5>
562 <pre class=
"example"> -file-symbol-file
<var>file
</var>
565 <p>Read symbol table info from the specified
<var>file
</var> argument. When
566 used without arguments, clears GDB's symbol table info. No output is
567 produced, except for a completion notification.
569 <h5 class=
"subsubheading">GDB Command
</h5>
571 <p>The corresponding GDB command is
<code>symbol-file
</code>.
573 <h5 class=
"subsubheading">Example
</h5>
575 <pre class=
"smallexample"> (gdb)
576 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx