Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Basic-Guile.html 11KB

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