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: Blocks In Guile</title> 18 19<meta name="description" content="Debugging with GDB: Blocks In Guile"> 20<meta name="keywords" content="Debugging with GDB: Blocks In 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="Symbols-In-Guile.html#Symbols-In-Guile" rel="next" title="Symbols In Guile"> 30<link href="Frames-In-Guile.html#Frames-In-Guile" rel="previous" title="Frames In Guile"> 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="Blocks-In-Guile"></a> 65<div class="header"> 66<p> 67Next: <a href="Symbols-In-Guile.html#Symbols-In-Guile" accesskey="n" rel="next">Symbols In Guile</a>, Previous: <a href="Frames-In-Guile.html#Frames-In-Guile" accesskey="p" rel="previous">Frames In Guile</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="Accessing-blocks-from-Guile_002e"></a> 71<h4 class="subsubsection">23.3.3.16 Accessing blocks from Guile.</h4> 72 73<a name="index-blocks-in-guile"></a> 74<a name="index-_003cgdb_003ablock_003e"></a> 75 76<p>In <small>GDB</small>, symbols are stored in blocks. A block corresponds 77roughly to a scope in the source code. Blocks are organized 78hierarchically, and are represented individually in Guile as an object 79of type <code><gdb:block></code>. Blocks rely on debugging information being 80available. 81</p> 82<p>A frame has a block. Please see <a href="Frames-In-Guile.html#Frames-In-Guile">Frames In Guile</a>, for a more 83in-depth discussion of frames. 84</p> 85<p>The outermost block is known as the <em>global block</em>. The global 86block typically holds public global variables and functions. 87</p> 88<p>The block nested just inside the global block is the <em>static 89block</em>. The static block typically holds file-scoped variables and 90functions. 91</p> 92<p><small>GDB</small> provides a method to get a block’s superblock, but there 93is currently no way to examine the sub-blocks of a block, or to 94iterate over all the blocks in a symbol table (see <a href="Symbol-Tables-In-Guile.html#Symbol-Tables-In-Guile">Symbol Tables In Guile</a>). 95</p> 96<p>Here is a short example that should help explain blocks: 97</p> 98<div class="smallexample"> 99<pre class="smallexample">/* This is in the global block. */ 100int global; 101 102/* This is in the static block. */ 103static int file_scope; 104 105/* 'function' is in the global block, and 'argument' is 106 in a block nested inside of 'function'. */ 107int function (int argument) 108{ 109 /* 'local' is in a block inside 'function'. It may or may 110 not be in the same block as 'argument'. */ 111 int local; 112 113 { 114 /* 'inner' is in a block whose superblock is the one holding 115 'local'. */ 116 int inner; 117 118 /* If this call is expanded by the compiler, you may see 119 a nested block here whose function is 'inline_function' 120 and whose superblock is the one holding 'inner'. */ 121 inline_function (); 122 } 123} 124</pre></div> 125 126<p>The following block-related procedures are provided by the 127<code>(gdb)</code> module: 128</p> 129<dl> 130<dt><a name="index-block_003f"></a>Scheme Procedure: <strong>block?</strong> <em>object</em></dt> 131<dd><p>Return <code>#t</code> if <var>object</var> is a <code><gdb:block></code> object. 132Otherwise return <code>#f</code>. 133</p></dd></dl> 134 135<dl> 136<dt><a name="index-block_002dvalid_003f"></a>Scheme Procedure: <strong>block-valid?</strong> <em>block</em></dt> 137<dd><p>Returns <code>#t</code> if <code><gdb:block></code> <var>block</var> is valid, 138<code>#f</code> if not. A block object can become invalid if the block it 139refers to doesn’t exist anymore in the inferior. All other 140<code><gdb:block></code> methods will throw an exception if it is invalid at 141the time the procedure is called. The block’s validity is also checked 142during iteration over symbols of the block. 143</p></dd></dl> 144 145<dl> 146<dt><a name="index-block_002dstart"></a>Scheme Procedure: <strong>block-start</strong> <em>block</em></dt> 147<dd><p>Return the start address of <code><gdb:block></code> <var>block</var>. 148</p></dd></dl> 149 150<dl> 151<dt><a name="index-block_002dend"></a>Scheme Procedure: <strong>block-end</strong> <em>block</em></dt> 152<dd><p>Return the end address of <code><gdb:block></code> <var>block</var>. 153</p></dd></dl> 154 155<dl> 156<dt><a name="index-block_002dfunction"></a>Scheme Procedure: <strong>block-function</strong> <em>block</em></dt> 157<dd><p>Return the name of <code><gdb:block></code> <var>block</var> represented as a 158<code><gdb:symbol></code> object. 159If the block is not named, then <code>#f</code> is returned. 160</p> 161<p>For ordinary function blocks, the superblock is the static block. 162However, you should note that it is possible for a function block to 163have a superblock that is not the static block – for instance this 164happens for an inlined function. 165</p></dd></dl> 166 167<dl> 168<dt><a name="index-block_002dsuperblock"></a>Scheme Procedure: <strong>block-superblock</strong> <em>block</em></dt> 169<dd><p>Return the block containing <code><gdb:block></code> <var>block</var>. 170If the parent block does not exist, then <code>#f</code> is returned. 171</p></dd></dl> 172 173<dl> 174<dt><a name="index-block_002dglobal_002dblock"></a>Scheme Procedure: <strong>block-global-block</strong> <em>block</em></dt> 175<dd><p>Return the global block associated with <code><gdb:block></code> <var>block</var>. 176</p></dd></dl> 177 178<dl> 179<dt><a name="index-block_002dstatic_002dblock"></a>Scheme Procedure: <strong>block-static-block</strong> <em>block</em></dt> 180<dd><p>Return the static block associated with <code><gdb:block></code> <var>block</var>. 181</p></dd></dl> 182 183<dl> 184<dt><a name="index-block_002dglobal_003f"></a>Scheme Procedure: <strong>block-global?</strong> <em>block</em></dt> 185<dd><p>Return <code>#t</code> if <code><gdb:block></code> <var>block</var> is a global block. 186Otherwise return <code>#f</code>. 187</p></dd></dl> 188 189<dl> 190<dt><a name="index-block_002dstatic_003f"></a>Scheme Procedure: <strong>block-static?</strong> <em>block</em></dt> 191<dd><p>Return <code>#t</code> if <code><gdb:block></code> <var>block</var> is a static block. 192Otherwise return <code>#f</code>. 193</p></dd></dl> 194 195<dl> 196<dt><a name="index-block_002dsymbols"></a>Scheme Procedure: <strong>block-symbols</strong></dt> 197<dd><p>Return a list of all symbols (as <gdb:symbol> objects) in 198<code><gdb:block></code> <var>block</var>. 199</p></dd></dl> 200 201<dl> 202<dt><a name="index-make_002dblock_002dsymbols_002diterator"></a>Scheme Procedure: <strong>make-block-symbols-iterator</strong> <em>block</em></dt> 203<dd><p>Return an object of type <code><gdb:iterator></code> that will iterate 204over all symbols of the block. 205Guile programs should not assume that a specific block object will 206always contain a given symbol, since changes in <small>GDB</small> features and 207infrastructure may cause symbols move across blocks in a symbol table. 208See <a href="Iterators-In-Guile.html#Iterators-In-Guile">Iterators In Guile</a>. 209</p></dd></dl> 210 211<dl> 212<dt><a name="index-block_002dsymbols_002dprogress_003f"></a>Scheme Procedure: <strong>block-symbols-progress?</strong></dt> 213<dd><p>Return #t if the object is a <gdb:block-symbols-progress> object. 214This object would be obtained from the <code>progress</code> element of the 215<code><gdb:iterator></code> object returned by <code>make-block-symbols-iterator</code>. 216</p></dd></dl> 217 218<dl> 219<dt><a name="index-lookup_002dblock"></a>Scheme Procedure: <strong>lookup-block</strong> <em>pc</em></dt> 220<dd><p>Return the innermost <code><gdb:block></code> containing the given <var>pc</var> 221value. If the block cannot be found for the <var>pc</var> value specified, 222the function will return <code>#f</code>. 223</p></dd></dl> 224 225<hr> 226<div class="header"> 227<p> 228Next: <a href="Symbols-In-Guile.html#Symbols-In-Guile" accesskey="n" rel="next">Symbols In Guile</a>, Previous: <a href="Frames-In-Guile.html#Frames-In-Guile" accesskey="p" rel="previous">Frames In Guile</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> 229</div> 230 231 232 233</body> 234</html> 235