You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
6.5KB

  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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>GDB/MI Simple Examples (Debugging with GDB)</title>
  17. <meta name="description" content="GDB/MI Simple Examples (Debugging with GDB)">
  18. <meta name="keywords" content="GDB/MI Simple Examples (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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="prev" title="GDB/MI Ada Exception Information">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="GDB_002fMI-Simple-Examples"></a>
  58. <div class="header">
  59. <p>
  60. 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="prev">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>
  61. </div>
  62. <hr>
  63. <a name="Simple-Examples-of-GDB_002fMI-Interaction"></a>
  64. <h3 class="section">27.6 Simple Examples of <small>GDB/MI</small> Interaction</h3>
  65. <a name="index-GDB_002fMI_002c-simple-examples"></a>
  66. <p>This subsection presents several simple examples of interaction using
  67. the <small>GDB/MI</small> interface. In these examples, &lsquo;<samp>-&gt;</samp>&rsquo; means that the
  68. following line is passed to <small>GDB/MI</small> as input, while &lsquo;<samp>&lt;-</samp>&rsquo; means
  69. the output received from <small>GDB/MI</small>.
  70. </p>
  71. <p>Note the line breaks shown in the examples are here only for
  72. readability, they don&rsquo;t appear in the real output.
  73. </p>
  74. <a name="Setting-a-Breakpoint"></a>
  75. <h4 class="subheading">Setting a Breakpoint</h4>
  76. <p>Setting a breakpoint generates synchronous output which contains detailed
  77. information of the breakpoint.
  78. </p>
  79. <div class="smallexample">
  80. <pre class="smallexample">-&gt; -break-insert main
  81. &lt;- ^done,bkpt={number=&quot;1&quot;,type=&quot;breakpoint&quot;,disp=&quot;keep&quot;,
  82. enabled=&quot;y&quot;,addr=&quot;0x08048564&quot;,func=&quot;main&quot;,file=&quot;myprog.c&quot;,
  83. fullname=&quot;/home/nickrob/myprog.c&quot;,line=&quot;68&quot;,thread-groups=[&quot;i1&quot;],
  84. times=&quot;0&quot;}
  85. &lt;- (gdb)
  86. </pre></div>
  87. <a name="Program-Execution"></a>
  88. <h4 class="subheading">Program Execution</h4>
  89. <p>Program execution generates asynchronous records and MI gives the
  90. reason that execution stopped.
  91. </p>
  92. <div class="smallexample">
  93. <pre class="smallexample">-&gt; -exec-run
  94. &lt;- ^running
  95. &lt;- (gdb)
  96. &lt;- *stopped,reason=&quot;breakpoint-hit&quot;,disp=&quot;keep&quot;,bkptno=&quot;1&quot;,thread-id=&quot;0&quot;,
  97. frame={addr=&quot;0x08048564&quot;,func=&quot;main&quot;,
  98. args=[{name=&quot;argc&quot;,value=&quot;1&quot;},{name=&quot;argv&quot;,value=&quot;0xbfc4d4d4&quot;}],
  99. file=&quot;myprog.c&quot;,fullname=&quot;/home/nickrob/myprog.c&quot;,line=&quot;68&quot;,
  100. arch=&quot;i386:x86_64&quot;}
  101. &lt;- (gdb)
  102. -&gt; -exec-continue
  103. &lt;- ^running
  104. &lt;- (gdb)
  105. &lt;- *stopped,reason=&quot;exited-normally&quot;
  106. &lt;- (gdb)
  107. </pre></div>
  108. <a name="Quitting-GDB-2"></a>
  109. <h4 class="subheading">Quitting <small>GDB</small></h4>
  110. <p>Quitting <small>GDB</small> just prints the result class &lsquo;<samp>^exit</samp>&rsquo;.
  111. </p>
  112. <div class="smallexample">
  113. <pre class="smallexample">-&gt; (gdb)
  114. &lt;- -gdb-exit
  115. &lt;- ^exit
  116. </pre></div>
  117. <p>Please note that &lsquo;<samp>^exit</samp>&rsquo; is printed immediately, but it might
  118. take some time for <small>GDB</small> to actually exit. During that time, <small>GDB</small>
  119. performs necessary cleanups, including killing programs being debugged
  120. or disconnecting from debug hardware, so the frontend should wait till
  121. <small>GDB</small> exits and should only forcibly kill <small>GDB</small> if it
  122. fails to exit in reasonable time.
  123. </p>
  124. <a name="A-Bad-Command"></a>
  125. <h4 class="subheading">A Bad Command</h4>
  126. <p>Here&rsquo;s what happens if you pass a non-existent command:
  127. </p>
  128. <div class="smallexample">
  129. <pre class="smallexample">-&gt; -rubbish
  130. &lt;- ^error,msg=&quot;Undefined MI command: rubbish&quot;
  131. &lt;- (gdb)
  132. </pre></div>
  133. </body>
  134. </html>