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: Guile Exception Handling</title> 18 19<meta name="description" content="Debugging with GDB: Guile Exception Handling"> 20<meta name="keywords" content="Debugging with GDB: Guile Exception Handling"> 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="Values-From-Inferior-In-Guile.html#Values-From-Inferior-In-Guile" rel="next" title="Values From Inferior In Guile"> 30<link href="GDB-Scheme-Data-Types.html#GDB-Scheme-Data-Types" rel="previous" title="GDB Scheme Data Types"> 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="Guile-Exception-Handling"></a> 65<div class="header"> 66<p> 67Next: <a href="Values-From-Inferior-In-Guile.html#Values-From-Inferior-In-Guile" accesskey="n" rel="next">Values From Inferior In Guile</a>, Previous: <a href="GDB-Scheme-Data-Types.html#GDB-Scheme-Data-Types" accesskey="p" rel="previous">GDB Scheme Data Types</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="Guile-Exception-Handling-1"></a> 71<h4 class="subsubsection">23.3.3.4 Guile Exception Handling</h4> 72<a name="index-guile-exceptions"></a> 73<a name="index-exceptions_002c-guile"></a> 74<a name="index-set-guile-print_002dstack"></a> 75 76<p>When executing the <code>guile</code> command, Guile exceptions 77uncaught within the Guile code are translated to calls to the 78<small>GDB</small> error-reporting mechanism. If the command that called 79<code>guile</code> does not handle the error, <small>GDB</small> will 80terminate it and report the error according to the setting of 81the <code>guile print-stack</code> parameter. 82</p> 83<p>The <code>guile print-stack</code> parameter has three settings: 84</p> 85<dl compact="compact"> 86<dt><code>none</code></dt> 87<dd><p>Nothing is printed. 88</p> 89</dd> 90<dt><code>message</code></dt> 91<dd><p>An error message is printed containing the Guile exception name, 92the associated value, and the Guile call stack backtrace at the 93point where the exception was raised. Example: 94</p> 95<div class="smallexample"> 96<pre class="smallexample">(gdb) guile (display foo) 97ERROR: In procedure memoize-variable-access!: 98ERROR: Unbound variable: foo 99Error while executing Scheme code. 100</pre></div> 101 102</dd> 103<dt><code>full</code></dt> 104<dd><p>In addition to an error message a full backtrace is printed. 105</p> 106<div class="smallexample"> 107<pre class="smallexample">(gdb) set guile print-stack full 108(gdb) guile (display foo) 109Guile Backtrace: 110In ice-9/boot-9.scm: 111 157: 10 [catch #t #<catch-closure 2c76e20> ...] 112In unknown file: 113 ?: 9 [apply-smob/1 #<catch-closure 2c76e20>] 114In ice-9/boot-9.scm: 115 157: 8 [catch #t #<catch-closure 2c76d20> ...] 116In unknown file: 117 ?: 7 [apply-smob/1 #<catch-closure 2c76d20>] 118 ?: 6 [call-with-input-string "(display foo)" ...] 119In ice-9/boot-9.scm: 1202320: 5 [save-module-excursion #<procedure 2c2dc30 ... ()>] 121In ice-9/eval-string.scm: 122 44: 4 [read-and-eval #<input: string 27cb410> #:lang ...] 123 37: 3 [lp (display foo)] 124In ice-9/eval.scm: 125 387: 2 [eval # ()] 126 393: 1 [eval #<memoized foo> ()] 127In unknown file: 128 ?: 0 [memoize-variable-access! #<memoized foo> ...] 129 130ERROR: In procedure memoize-variable-access!: 131ERROR: Unbound variable: foo 132Error while executing Scheme code. 133</pre></div> 134</dd> 135</dl> 136 137<p><small>GDB</small> errors that happen in <small>GDB</small> commands invoked by 138Guile code are converted to Guile exceptions. The type of the 139Guile exception depends on the error. 140</p> 141<p>Guile procedures provided by <small>GDB</small> can throw the standard 142Guile exceptions like <code>wrong-type-arg</code> and <code>out-of-range</code>. 143</p> 144<p>User interrupt (via <kbd>C-c</kbd> or by typing <kbd>q</kbd> at a pagination 145prompt) is translated to a Guile <code>signal</code> exception with value 146<code>SIGINT</code>. 147</p> 148<p><small>GDB</small> Guile procedures can also throw these exceptions: 149</p> 150<dl compact="compact"> 151<dt><code>gdb:error</code> 152<a name="index-gdb_003aerror"></a> 153</dt> 154<dd><p>This exception is a catch-all for errors generated from within <small>GDB</small>. 155</p> 156</dd> 157<dt><code>gdb:invalid-object</code> 158<a name="index-gdb_003ainvalid_002dobject"></a> 159</dt> 160<dd><p>This exception is thrown when accessing Guile objects that wrap underlying 161<small>GDB</small> objects have become invalid. For example, a 162<code><gdb:breakpoint></code> object becomes invalid if the user deletes it 163from the command line. The object still exists in Guile, but the 164object it represents is gone. Further operations on this breakpoint 165will throw this exception. 166</p> 167</dd> 168<dt><code>gdb:memory-error</code> 169<a name="index-gdb_003amemory_002derror"></a> 170</dt> 171<dd><p>This exception is thrown when an operation tried to access invalid 172memory in the inferior. 173</p> 174</dd> 175<dt><code>gdb:pp-type-error</code> 176<a name="index-gdb_003app_002dtype_002derror"></a> 177</dt> 178<dd><p>This exception is thrown when a Guile pretty-printer passes a bad object 179to <small>GDB</small>. 180</p></dd> 181</dl> 182 183<p>The following exception-related procedures are provided by the 184<code>(gdb)</code> module. 185</p> 186<dl> 187<dt><a name="index-make_002dexception"></a>Scheme Procedure: <strong>make-exception</strong> <em>key args</em></dt> 188<dd><p>Return a <code><gdb:exception></code> object given by its <var>key</var> and 189<var>args</var>, which are the standard Guile parameters of an exception. 190See the Guile documentation for more information (see <a href="http://www.gnu.org/software/guile/manual/html_node/Exceptions.html#Exceptions">Exceptions</a> in <cite>GNU Guile Reference Manual</cite>). 191</p></dd></dl> 192 193<dl> 194<dt><a name="index-exception_003f"></a>Scheme Procedure: <strong>exception?</strong> <em>object</em></dt> 195<dd><p>Return <code>#t</code> if <var>object</var> is a <code><gdb:exception></code> object. 196Otherwise return <code>#f</code>. 197</p></dd></dl> 198 199<dl> 200<dt><a name="index-exception_002dkey"></a>Scheme Procedure: <strong>exception-key</strong> <em>exception</em></dt> 201<dd><p>Return the <var>args</var> field of a <code><gdb:exception></code> object. 202</p></dd></dl> 203 204<dl> 205<dt><a name="index-exception_002dargs"></a>Scheme Procedure: <strong>exception-args</strong> <em>exception</em></dt> 206<dd><p>Return the <var>args</var> field of a <code><gdb:exception></code> object. 207</p></dd></dl> 208 209<hr> 210<div class="header"> 211<p> 212Next: <a href="Values-From-Inferior-In-Guile.html#Values-From-Inferior-In-Guile" accesskey="n" rel="next">Values From Inferior In Guile</a>, Previous: <a href="GDB-Scheme-Data-Types.html#GDB-Scheme-Data-Types" accesskey="p" rel="previous">GDB Scheme Data Types</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> 213</div> 214 215 216 217</body> 218</html> 219