GDB_002fMI-Simple-Examples.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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: GDB/MI Simple Examples</title>
  16. <meta name="description" content="Debugging with GDB: GDB/MI Simple Examples">
  17. <meta name="keywords" content="Debugging with GDB: GDB/MI Simple Examples">
  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_002fMI.html#GDB_002fMI" rel="up" title="GDB/MI">
  26. <link href="GDB_002fMI-Command-Description-Format.html#GDB_002fMI-Command-Description-Format" rel="next" title="GDB/MI Command Description Format">
  27. <link href="GDB_002fMI-Ada-Exception-Information.html#GDB_002fMI-Ada-Exception-Information" rel="previous" title="GDB/MI Ada Exception Information">
  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="GDB_002fMI-Simple-Examples"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="GDB_002fMI-Command-Description-Format.html#GDB_002fMI-Command-Description-Format" accesskey="n" rel="next">GDB/MI Command Description Format</a>, Previous: <a href="GDB_002fMI-Output-Records.html#GDB_002fMI-Output-Records" accesskey="p" rel="previous">GDB/MI Output Records</a>, Up: <a href="GDB_002fMI.html#GDB_002fMI" accesskey="u" rel="up">GDB/MI</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="Simple-Examples-of-GDB_002fMI-Interaction"></a>
  65. <h3 class="section">27.6 Simple Examples of <small>GDB/MI</small> Interaction</h3>
  66. <a name="index-GDB_002fMI_002c-simple-examples"></a>
  67. <p>This subsection presents several simple examples of interaction using
  68. the <small>GDB/MI</small> interface. In these examples, &lsquo;<samp>-&gt;</samp>&rsquo; means that the
  69. following line is passed to <small>GDB/MI</small> as input, while &lsquo;<samp>&lt;-</samp>&rsquo; means
  70. the output received from <small>GDB/MI</small>.
  71. </p>
  72. <p>Note the line breaks shown in the examples are here only for
  73. readability, they don&rsquo;t appear in the real output.
  74. </p>
  75. <a name="Setting-a-Breakpoint"></a>
  76. <h4 class="subheading">Setting a Breakpoint</h4>
  77. <p>Setting a breakpoint generates synchronous output which contains detailed
  78. information of the breakpoint.
  79. </p>
  80. <div class="smallexample">
  81. <pre class="smallexample">-&gt; -break-insert main
  82. &lt;- ^done,bkpt={number=&quot;1&quot;,type=&quot;breakpoint&quot;,disp=&quot;keep&quot;,
  83. enabled=&quot;y&quot;,addr=&quot;0x08048564&quot;,func=&quot;main&quot;,file=&quot;myprog.c&quot;,
  84. fullname=&quot;/home/nickrob/myprog.c&quot;,line=&quot;68&quot;,thread-groups=[&quot;i1&quot;],
  85. times=&quot;0&quot;}
  86. &lt;- (gdb)
  87. </pre></div>
  88. <a name="Program-Execution"></a>
  89. <h4 class="subheading">Program Execution</h4>
  90. <p>Program execution generates asynchronous records and MI gives the
  91. reason that execution stopped.
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample">-&gt; -exec-run
  95. &lt;- ^running
  96. &lt;- (gdb)
  97. &lt;- *stopped,reason=&quot;breakpoint-hit&quot;,disp=&quot;keep&quot;,bkptno=&quot;1&quot;,thread-id=&quot;0&quot;,
  98. frame={addr=&quot;0x08048564&quot;,func=&quot;main&quot;,
  99. args=[{name=&quot;argc&quot;,value=&quot;1&quot;},{name=&quot;argv&quot;,value=&quot;0xbfc4d4d4&quot;}],
  100. file=&quot;myprog.c&quot;,fullname=&quot;/home/nickrob/myprog.c&quot;,line=&quot;68&quot;,
  101. arch=&quot;i386:x86_64&quot;}
  102. &lt;- (gdb)
  103. -&gt; -exec-continue
  104. &lt;- ^running
  105. &lt;- (gdb)
  106. &lt;- *stopped,reason=&quot;exited-normally&quot;
  107. &lt;- (gdb)
  108. </pre></div>
  109. <a name="Quitting-GDB-2"></a>
  110. <h4 class="subheading">Quitting <small>GDB</small></h4>
  111. <p>Quitting <small>GDB</small> just prints the result class &lsquo;<samp>^exit</samp>&rsquo;.
  112. </p>
  113. <div class="smallexample">
  114. <pre class="smallexample">-&gt; (gdb)
  115. &lt;- -gdb-exit
  116. &lt;- ^exit
  117. </pre></div>
  118. <p>Please note that &lsquo;<samp>^exit</samp>&rsquo; is printed immediately, but it might
  119. take some time for <small>GDB</small> to actually exit. During that time, <small>GDB</small>
  120. performs necessary cleanups, including killing programs being debugged
  121. or disconnecting from debug hardware, so the frontend should wait till
  122. <small>GDB</small> exits and should only forcibly kill <small>GDB</small> if it
  123. fails to exit in reasonable time.
  124. </p>
  125. <a name="A-Bad-Command"></a>
  126. <h4 class="subheading">A Bad Command</h4>
  127. <p>Here&rsquo;s what happens if you pass a non-existent command:
  128. </p>
  129. <div class="smallexample">
  130. <pre class="smallexample">-&gt; -rubbish
  131. &lt;- ^error,msg=&quot;Undefined MI command: rubbish&quot;
  132. &lt;- (gdb)
  133. </pre></div>
  134. </body>
  135. </html>