blob: 467158a25cf9c44d72854d64e4f6cf468af291f6 [file] [log] [blame]
<html lang="en">
<head>
<title>GDB/MI Simple Examples - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="GDB_002fMI.html#GDB_002fMI" title="GDB/MI">
<link rel="prev" href="GDB_002fMI-Output-Records.html#GDB_002fMI-Output-Records" title="GDB/MI Output Records">
<link rel="next" href="GDB_002fMI-Command-Description-Format.html#GDB_002fMI-Command-Description-Format" title="GDB/MI Command Description Format">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="GDB%2fMI-Simple-Examples"></a>
<a name="GDB_002fMI-Simple-Examples"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="GDB_002fMI-Command-Description-Format.html#GDB_002fMI-Command-Description-Format">GDB/MI Command Description Format</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="GDB_002fMI-Output-Records.html#GDB_002fMI-Output-Records">GDB/MI Output Records</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="GDB_002fMI.html#GDB_002fMI">GDB/MI</a>
<hr>
</div>
<h3 class="section">27.6 Simple Examples of <span class="sc">gdb/mi</span> Interaction</h3>
<p><a name="index-g_t_0040sc_007bgdb_002fmi_007d_002c-simple-examples-2979"></a>
This subsection presents several simple examples of interaction using
the <span class="sc">gdb/mi</span> interface. In these examples, &lsquo;<samp><span class="samp">-&gt;</span></samp>&rsquo; means that the
following line is passed to <span class="sc">gdb/mi</span> as input, while &lsquo;<samp><span class="samp">&lt;-</span></samp>&rsquo; means
the output received from <span class="sc">gdb/mi</span>.
<p>Note the line breaks shown in the examples are here only for
readability, they don't appear in the real output.
<h4 class="subheading">Setting a Breakpoint</h4>
<p>Setting a breakpoint generates synchronous output which contains detailed
information of the breakpoint.
<pre class="smallexample"> -&gt; -break-insert main
&lt;- ^done,bkpt={number="1",type="breakpoint",disp="keep",
enabled="y",addr="0x08048564",func="main",file="myprog.c",
fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
times="0"}
&lt;- (gdb)
</pre>
<h4 class="subheading">Program Execution</h4>
<p>Program execution generates asynchronous records and MI gives the
reason that execution stopped.
<pre class="smallexample"> -&gt; -exec-run
&lt;- ^running
&lt;- (gdb)
&lt;- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
frame={addr="0x08048564",func="main",
args=[{name="argc",value="1"},{name="argv",value="0xbfc4d4d4"}],
file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
arch="i386:x86_64"}
&lt;- (gdb)
-&gt; -exec-continue
&lt;- ^running
&lt;- (gdb)
&lt;- *stopped,reason="exited-normally"
&lt;- (gdb)
</pre>
<h4 class="subheading">Quitting <span class="sc">gdb</span></h4>
<p>Quitting <span class="sc">gdb</span> just prints the result class &lsquo;<samp><span class="samp">^exit</span></samp>&rsquo;.
<pre class="smallexample"> -&gt; (gdb)
&lt;- -gdb-exit
&lt;- ^exit
</pre>
<p>Please note that &lsquo;<samp><span class="samp">^exit</span></samp>&rsquo; is printed immediately, but it might
take some time for <span class="sc">gdb</span> to actually exit. During that time, <span class="sc">gdb</span>
performs necessary cleanups, including killing programs being debugged
or disconnecting from debug hardware, so the frontend should wait till
<span class="sc">gdb</span> exits and should only forcibly kill <span class="sc">gdb</span> if it
fails to exit in reasonable time.
<h4 class="subheading">A Bad Command</h4>
<p>Here's what happens if you pass a non-existent command:
<pre class="smallexample"> -&gt; -rubbish
&lt;- ^error,msg="Undefined MI command: rubbish"
&lt;- (gdb)
</pre>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
</body></html>