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-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Basic Guile</title> 18 19<meta name="description" content="Debugging with GDB: Basic Guile"> 20<meta name="keywords" content="Debugging with GDB: Basic Guile"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Guile-API.html#Guile-API" rel="up" title="Guile API"> 29<link href="Guile-Configuration.html#Guile-Configuration" rel="next" title="Guile Configuration"> 30<link href="Guile-API.html#Guile-API" rel="previous" title="Guile API"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Basic-Guile"></a> 65<div class="header"> 66<p> 67Next: <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> [<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> 68</div> 69<hr> 70<a name="Basic-Guile-1"></a> 71<h4 class="subsubsection">23.3.3.1 Basic Guile</h4> 72 73<a name="index-guile-stdout"></a> 74<a name="index-guile-pagination"></a> 75<p>At startup, <small>GDB</small> overrides Guile’s <code>current-output-port</code> and 76<code>current-error-port</code> to print using <small>GDB</small>’s output-paging streams. 77A Guile program which outputs to one of these streams may have its 78output interrupted by the user (see <a href="Screen-Size.html#Screen-Size">Screen Size</a>). In this 79situation, a Guile <code>signal</code> exception is thrown with value <code>SIGINT</code>. 80</p> 81<p>Guile’s history mechanism uses the same naming as <small>GDB</small>’s, 82namely the user of dollar-variables (e.g., $1, $2, etc.). 83The results of evaluations in Guile and in GDB are counted separately, 84<code>$1</code> in Guile is not the same value as <code>$1</code> in <small>GDB</small>. 85</p> 86<p><small>GDB</small> is not thread-safe. If your Guile program uses multiple 87threads, you must be careful to only call <small>GDB</small>-specific 88functions in the <small>GDB</small> thread. 89</p> 90<p>Some care must be taken when writing Guile code to run in 91<small>GDB</small>. Two things are worth noting in particular: 92</p> 93<ul> 94<li> <small>GDB</small> installs handlers for <code>SIGCHLD</code> and <code>SIGINT</code>. 95Guile code must not override these, or even change the options using 96<code>sigaction</code>. If your program changes the handling of these 97signals, <small>GDB</small> will most likely stop working correctly. Note 98that it is unfortunately common for GUI toolkits to install a 99<code>SIGCHLD</code> handler. 100 101</li><li> <small>GDB</small> takes care to mark its internal file descriptors as 102close-on-exec. However, this cannot be done in a thread-safe way on 103all platforms. Your Guile programs should be aware of this and 104should both create new file descriptors with the close-on-exec flag 105set and arrange to close unneeded file descriptors before starting a 106child process. 107</li></ul> 108 109<a name="index-guile-gdb-module"></a> 110<p><small>GDB</small> introduces a new Guile module, named <code>gdb</code>. All 111methods and classes added by <small>GDB</small> are placed in this module. 112<small>GDB</small> does not automatically <code>import</code> the <code>gdb</code> module, 113scripts must do this themselves. There are various options for how to 114import a module, so <small>GDB</small> leaves the choice of how the <code>gdb</code> 115module is imported to the user. 116To simplify interactive use, it is recommended to add one of the following 117to your ~/.gdbinit. 118</p> 119<div class="smallexample"> 120<pre class="smallexample">guile (use-modules (gdb)) 121</pre></div> 122 123<div class="smallexample"> 124<pre class="smallexample">guile (use-modules ((gdb) #:renamer (symbol-prefix-proc 'gdb:))) 125</pre></div> 126 127<p>Which one to choose depends on your preference. 128The second one adds <code>gdb:</code> as a prefix to all module functions 129and variables. 130</p> 131<p>The rest of this manual assumes the <code>gdb</code> module has been imported 132without any prefix. See the Guile documentation for <code>use-modules</code> 133for more information 134(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>). 135</p> 136<p>Example: 137</p> 138<div class="smallexample"> 139<pre class="smallexample">(gdb) guile (value-type (make-value 1)) 140ERROR: Unbound variable: value-type 141Error while executing Scheme code. 142(gdb) guile (use-modules (gdb)) 143(gdb) guile (value-type (make-value 1)) 144int 145(gdb) 146</pre></div> 147 148<p>The <code>(gdb)</code> module provides these basic Guile functions. 149</p> 150<dl> 151<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> 152<dd><p>Evaluate <var>command</var>, a string, as a <small>GDB</small> CLI command. 153If a <small>GDB</small> exception happens while <var>command</var> runs, it is 154translated as described in 155<a href="Guile-Exception-Handling.html#Guile-Exception-Handling">Guile Exception Handling</a>. 156</p> 157<p><var>from-tty</var> specifies whether <small>GDB</small> ought to consider this 158command as having originated from the user invoking it interactively. 159It must be a boolean value. If omitted, it defaults to <code>#f</code>. 160</p> 161<p>By default, any output produced by <var>command</var> is sent to 162<small>GDB</small>’s standard output (and to the log output if logging is 163turned on). If the <var>to-string</var> parameter is 164<code>#t</code>, then output will be collected by <code>execute</code> and 165returned as a string. The default is <code>#f</code>, in which case the 166return value is unspecified. If <var>to-string</var> is <code>#t</code>, the 167<small>GDB</small> virtual terminal will be temporarily set to unlimited width 168and height, and its pagination will be disabled; see <a href="Screen-Size.html#Screen-Size">Screen Size</a>. 169</p></dd></dl> 170 171<dl> 172<dt><a name="index-history_002dref"></a>Scheme Procedure: <strong>history-ref</strong> <em>number</em></dt> 173<dd><p>Return a value from <small>GDB</small>’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. 174If <var>number</var> is negative, then <small>GDB</small> will take its absolute value 175and count backward from the last element (i.e., the most recent element) to 176find the value to return. If <var>number</var> is zero, then <small>GDB</small> will 177return the most recent element. If the element specified by <var>number</var> 178doesn’t exist in the value history, a <code>gdb:error</code> exception will be 179raised. 180</p> 181<p>If no exception is raised, the return value is always an instance of 182<code><gdb:value></code> (see <a href="Values-From-Inferior-In-Guile.html#Values-From-Inferior-In-Guile">Values From Inferior In Guile</a>). 183</p> 184<p><em>Note:</em> <small>GDB</small>’s value history is independent of Guile’s. 185<code>$1</code> in <small>GDB</small>’s value history contains the result of evaluating 186an expression from <small>GDB</small>’s command line and <code>$1</code> from Guile’s 187history contains the result of evaluating an expression from Guile’s 188command line. 189</p></dd></dl> 190 191<dl> 192<dt><a name="index-history_002dappend_0021"></a>Scheme Procedure: <strong>history-append!</strong> <em>value</em></dt> 193<dd><p>Append <var>value</var>, an instance of <code><gdb:value></code>, to <small>GDB</small>’s 194value history. Return its index in the history. 195</p> 196<p>Putting into history values returned by Guile extensions will allow 197the user convenient access to those values via CLI history 198facilities. 199</p></dd></dl> 200 201<dl> 202<dt><a name="index-parse_002dand_002deval"></a>Scheme Procedure: <strong>parse-and-eval</strong> <em>expression</em></dt> 203<dd><p>Parse <var>expression</var> as an expression in the current language, 204evaluate it, and return the result as a <code><gdb:value></code>. 205The <var>expression</var> must be a string. 206</p> 207<p>This function can be useful when implementing a new command 208(see <a href="Commands-In-Guile.html#Commands-In-Guile">Commands In Guile</a>), as it provides a way to parse the 209command’s arguments as an expression. 210It is also is useful when computing values. 211For example, it is the only way to get the value of a 212convenience variable (see <a href="Convenience-Vars.html#Convenience-Vars">Convenience Vars</a>) as a <code><gdb:value></code>. 213</p></dd></dl> 214 215<hr> 216<div class="header"> 217<p> 218Next: <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> [<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> 219</div> 220 221 222 223</body> 224</html> 225