Basic-Guile.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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: Basic Guile</title>
  16. <meta name="description" content="Debugging with GDB: Basic Guile">
  17. <meta name="keywords" content="Debugging with GDB: Basic Guile">
  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="Guile-API.html#Guile-API" rel="up" title="Guile API">
  26. <link href="Guile-Configuration.html#Guile-Configuration" rel="next" title="Guile Configuration">
  27. <link href="Guile-API.html#Guile-API" rel="previous" title="Guile API">
  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="Basic-Guile"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Guile-Configuration.html#Guile-Configuration" accesskey="n" rel="next">Guile Configuration</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</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="Basic-Guile-1"></a>
  65. <h4 class="subsubsection">23.3.3.1 Basic Guile</h4>
  66. <a name="index-guile-stdout"></a>
  67. <a name="index-guile-pagination"></a>
  68. <p>At startup, <small>GDB</small> overrides Guile&rsquo;s <code>current-output-port</code> and
  69. <code>current-error-port</code> to print using <small>GDB</small>&rsquo;s output-paging streams.
  70. A Guile program which outputs to one of these streams may have its
  71. output interrupted by the user (see <a href="Screen-Size.html#Screen-Size">Screen Size</a>). In this
  72. situation, a Guile <code>signal</code> exception is thrown with value <code>SIGINT</code>.
  73. </p>
  74. <p>Guile&rsquo;s history mechanism uses the same naming as <small>GDB</small>&rsquo;s,
  75. namely the user of dollar-variables (e.g., $1, $2, etc.).
  76. The results of evaluations in Guile and in GDB are counted separately,
  77. <code>$1</code> in Guile is not the same value as <code>$1</code> in <small>GDB</small>.
  78. </p>
  79. <p><small>GDB</small> is not thread-safe. If your Guile program uses multiple
  80. threads, you must be careful to only call <small>GDB</small>-specific
  81. functions in the <small>GDB</small> thread.
  82. </p>
  83. <p>Some care must be taken when writing Guile code to run in
  84. <small>GDB</small>. Two things are worth noting in particular:
  85. </p>
  86. <ul>
  87. <li> <small>GDB</small> installs handlers for <code>SIGCHLD</code> and <code>SIGINT</code>.
  88. Guile code must not override these, or even change the options using
  89. <code>sigaction</code>. If your program changes the handling of these
  90. signals, <small>GDB</small> will most likely stop working correctly. Note
  91. that it is unfortunately common for GUI toolkits to install a
  92. <code>SIGCHLD</code> handler.
  93. </li><li> <small>GDB</small> takes care to mark its internal file descriptors as
  94. close-on-exec. However, this cannot be done in a thread-safe way on
  95. all platforms. Your Guile programs should be aware of this and
  96. should both create new file descriptors with the close-on-exec flag
  97. set and arrange to close unneeded file descriptors before starting a
  98. child process.
  99. </li></ul>
  100. <a name="index-guile-gdb-module"></a>
  101. <p><small>GDB</small> introduces a new Guile module, named <code>gdb</code>. All
  102. methods and classes added by <small>GDB</small> are placed in this module.
  103. <small>GDB</small> does not automatically <code>import</code> the <code>gdb</code> module,
  104. scripts must do this themselves. There are various options for how to
  105. import a module, so <small>GDB</small> leaves the choice of how the <code>gdb</code>
  106. module is imported to the user.
  107. To simplify interactive use, it is recommended to add one of the following
  108. to your ~/.gdbinit.
  109. </p>
  110. <div class="smallexample">
  111. <pre class="smallexample">guile (use-modules (gdb))
  112. </pre></div>
  113. <div class="smallexample">
  114. <pre class="smallexample">guile (use-modules ((gdb) #:renamer (symbol-prefix-proc 'gdb:)))
  115. </pre></div>
  116. <p>Which one to choose depends on your preference.
  117. The second one adds <code>gdb:</code> as a prefix to all module functions
  118. and variables.
  119. </p>
  120. <p>The rest of this manual assumes the <code>gdb</code> module has been imported
  121. without any prefix. See the Guile documentation for <code>use-modules</code>
  122. for more information
  123. (see <a href="http://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html#Using-Guile-Modules">Using Guile Modules</a> in <cite>GNU Guile Reference Manual</cite>).
  124. </p>
  125. <p>Example:
  126. </p>
  127. <div class="smallexample">
  128. <pre class="smallexample">(gdb) guile (value-type (make-value 1))
  129. ERROR: Unbound variable: value-type
  130. Error while executing Scheme code.
  131. (gdb) guile (use-modules (gdb))
  132. (gdb) guile (value-type (make-value 1))
  133. int
  134. (gdb)
  135. </pre></div>
  136. <p>The <code>(gdb)</code> module provides these basic Guile functions.
  137. </p>
  138. <dl>
  139. <dt><a name="index-execute"></a>Scheme Procedure: <strong>execute</strong> <em>command <span class="roman">[</span>#:from-tty boolean<span class="roman">]</span> <span class="roman">[</span>#:to-string boolean<span class="roman">]</span></em></dt>
  140. <dd><p>Evaluate <var>command</var>, a string, as a <small>GDB</small> CLI command.
  141. If a <small>GDB</small> exception happens while <var>command</var> runs, it is
  142. translated as described in
  143. <a href="Guile-Exception-Handling.html#Guile-Exception-Handling">Guile Exception Handling</a>.
  144. </p>
  145. <p><var>from-tty</var> specifies whether <small>GDB</small> ought to consider this
  146. command as having originated from the user invoking it interactively.
  147. It must be a boolean value. If omitted, it defaults to <code>#f</code>.
  148. </p>
  149. <p>By default, any output produced by <var>command</var> is sent to
  150. <small>GDB</small>&rsquo;s standard output (and to the log output if logging is
  151. turned on). If the <var>to-string</var> parameter is
  152. <code>#t</code>, then output will be collected by <code>execute</code> and
  153. returned as a string. The default is <code>#f</code>, in which case the
  154. return value is unspecified. If <var>to-string</var> is <code>#t</code>, the
  155. <small>GDB</small> virtual terminal will be temporarily set to unlimited width
  156. and height, and its pagination will be disabled; see <a href="Screen-Size.html#Screen-Size">Screen Size</a>.
  157. </p></dd></dl>
  158. <dl>
  159. <dt><a name="index-history_002dref"></a>Scheme Procedure: <strong>history-ref</strong> <em>number</em></dt>
  160. <dd><p>Return a value from <small>GDB</small>&rsquo;s value history (see <a href="Value-History.html#Value-History">Value History</a>). The <var>number</var> argument indicates which history element to return.
  161. If <var>number</var> is negative, then <small>GDB</small> will take its absolute value
  162. and count backward from the last element (i.e., the most recent element) to
  163. find the value to return. If <var>number</var> is zero, then <small>GDB</small> will
  164. return the most recent element. If the element specified by <var>number</var>
  165. doesn&rsquo;t exist in the value history, a <code>gdb:error</code> exception will be
  166. raised.
  167. </p>
  168. <p>If no exception is raised, the return value is always an instance of
  169. <code>&lt;gdb:value&gt;</code> (see <a href="Values-From-Inferior-In-Guile.html#Values-From-Inferior-In-Guile">Values From Inferior In Guile</a>).
  170. </p>
  171. <p><em>Note:</em> <small>GDB</small>&rsquo;s value history is independent of Guile&rsquo;s.
  172. <code>$1</code> in <small>GDB</small>&rsquo;s value history contains the result of evaluating
  173. an expression from <small>GDB</small>&rsquo;s command line and <code>$1</code> from Guile&rsquo;s
  174. history contains the result of evaluating an expression from Guile&rsquo;s
  175. command line.
  176. </p></dd></dl>
  177. <dl>
  178. <dt><a name="index-history_002dappend_0021"></a>Scheme Procedure: <strong>history-append!</strong> <em>value</em></dt>
  179. <dd><p>Append <var>value</var>, an instance of <code>&lt;gdb:value&gt;</code>, to <small>GDB</small>&rsquo;s
  180. value history. Return its index in the history.
  181. </p>
  182. <p>Putting into history values returned by Guile extensions will allow
  183. the user convenient access to those values via CLI history
  184. facilities.
  185. </p></dd></dl>
  186. <dl>
  187. <dt><a name="index-parse_002dand_002deval"></a>Scheme Procedure: <strong>parse-and-eval</strong> <em>expression</em></dt>
  188. <dd><p>Parse <var>expression</var> as an expression in the current language,
  189. evaluate it, and return the result as a <code>&lt;gdb:value&gt;</code>.
  190. The <var>expression</var> must be a string.
  191. </p>
  192. <p>This function can be useful when implementing a new command
  193. (see <a href="Commands-In-Guile.html#Commands-In-Guile">Commands In Guile</a>), as it provides a way to parse the
  194. command&rsquo;s arguments as an expression.
  195. It is also is useful when computing values.
  196. For example, it is the only way to get the value of a
  197. convenience variable (see <a href="Convenience-Vars.html#Convenience-Vars">Convenience Vars</a>) as a <code>&lt;gdb:value&gt;</code>.
  198. </p></dd></dl>
  199. <hr>
  200. <div class="header">
  201. <p>
  202. Next: <a href="Guile-Configuration.html#Guile-Configuration" accesskey="n" rel="next">Guile Configuration</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</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>
  203. </div>
  204. </body>
  205. </html>