You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
9.4 KiB
HTML
223 lines
9.4 KiB
HTML
4 years ago
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html>
|
||
|
<!-- Copyright (C) 1988-2019 Free Software Foundation, Inc.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with the
|
||
|
Invariant Sections being "Free Software" and "Free Software Needs
|
||
|
Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
|
||
|
and with the Back-Cover Texts as in (a) below.
|
||
|
|
||
|
(a) The FSF's Back-Cover Text is: "You are free to copy and modify
|
||
|
this GNU Manual. Buying copies from GNU Press supports the FSF in
|
||
|
developing GNU and promoting software freedom." -->
|
||
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<title>Blocks In Python (Debugging with GDB)</title>
|
||
|
|
||
|
<meta name="description" content="Blocks In Python (Debugging with GDB)">
|
||
|
<meta name="keywords" content="Blocks In Python (Debugging with GDB)">
|
||
|
<meta name="resource-type" content="document">
|
||
|
<meta name="distribution" content="global">
|
||
|
<meta name="Generator" content="makeinfo">
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<link href="index.html#Top" rel="start" title="Top">
|
||
|
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
|
||
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
||
|
<link href="Python-API.html#Python-API" rel="up" title="Python API">
|
||
|
<link href="Symbols-In-Python.html#Symbols-In-Python" rel="next" title="Symbols In Python">
|
||
|
<link href="Frames-In-Python.html#Frames-In-Python" rel="prev" title="Frames In Python">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.summary-letter {text-decoration: none}
|
||
|
blockquote.indentedblock {margin-right: 0em}
|
||
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
||
|
blockquote.smallquotation {font-size: smaller}
|
||
|
div.display {margin-left: 3.2em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
div.lisp {margin-left: 3.2em}
|
||
|
div.smalldisplay {margin-left: 3.2em}
|
||
|
div.smallexample {margin-left: 3.2em}
|
||
|
div.smalllisp {margin-left: 3.2em}
|
||
|
kbd {font-style: oblique}
|
||
|
pre.display {font-family: inherit}
|
||
|
pre.format {font-family: inherit}
|
||
|
pre.menu-comment {font-family: serif}
|
||
|
pre.menu-preformatted {font-family: serif}
|
||
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
||
|
pre.smallexample {font-size: smaller}
|
||
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
||
|
pre.smalllisp {font-size: smaller}
|
||
|
span.nolinebreak {white-space: nowrap}
|
||
|
span.roman {font-family: initial; font-weight: normal}
|
||
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
||
|
ul.no-bullet {list-style: none}
|
||
|
-->
|
||
|
</style>
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en">
|
||
|
<a name="Blocks-In-Python"></a>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="Symbols-In-Python.html#Symbols-In-Python" accesskey="n" rel="next">Symbols In Python</a>, Previous: <a href="Frames-In-Python.html#Frames-In-Python" accesskey="p" rel="prev">Frames In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python 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>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<a name="Accessing-blocks-from-Python"></a>
|
||
|
<h4 class="subsubsection">23.2.2.26 Accessing blocks from Python</h4>
|
||
|
|
||
|
<a name="index-blocks-in-python"></a>
|
||
|
<a name="index-gdb_002eBlock"></a>
|
||
|
|
||
|
<p>In <small>GDB</small>, symbols are stored in blocks. A block corresponds
|
||
|
roughly to a scope in the source code. Blocks are organized
|
||
|
hierarchically, and are represented individually in Python as a
|
||
|
<code>gdb.Block</code>. Blocks rely on debugging information being
|
||
|
available.
|
||
|
</p>
|
||
|
<p>A frame has a block. Please see <a href="Frames-In-Python.html#Frames-In-Python">Frames In Python</a>, for a more
|
||
|
in-depth discussion of frames.
|
||
|
</p>
|
||
|
<p>The outermost block is known as the <em>global block</em>. The global
|
||
|
block typically holds public global variables and functions.
|
||
|
</p>
|
||
|
<p>The block nested just inside the global block is the <em>static
|
||
|
block</em>. The static block typically holds file-scoped variables and
|
||
|
functions.
|
||
|
</p>
|
||
|
<p><small>GDB</small> provides a method to get a block’s superblock, but there
|
||
|
is currently no way to examine the sub-blocks of a block, or to
|
||
|
iterate over all the blocks in a symbol table (see <a href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python">Symbol Tables In Python</a>).
|
||
|
</p>
|
||
|
<p>Here is a short example that should help explain blocks:
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample">/* This is in the global block. */
|
||
|
int global;
|
||
|
|
||
|
/* This is in the static block. */
|
||
|
static int file_scope;
|
||
|
|
||
|
/* 'function' is in the global block, and 'argument' is
|
||
|
in a block nested inside of 'function'. */
|
||
|
int function (int argument)
|
||
|
{
|
||
|
/* 'local' is in a block inside 'function'. It may or may
|
||
|
not be in the same block as 'argument'. */
|
||
|
int local;
|
||
|
|
||
|
{
|
||
|
/* 'inner' is in a block whose superblock is the one holding
|
||
|
'local'. */
|
||
|
int inner;
|
||
|
|
||
|
/* If this call is expanded by the compiler, you may see
|
||
|
a nested block here whose function is 'inline_function'
|
||
|
and whose superblock is the one holding 'inner'. */
|
||
|
inline_function ();
|
||
|
}
|
||
|
}
|
||
|
</pre></div>
|
||
|
|
||
|
<p>A <code>gdb.Block</code> is iterable. The iterator returns the symbols
|
||
|
(see <a href="Symbols-In-Python.html#Symbols-In-Python">Symbols In Python</a>) local to the block. Python programs
|
||
|
should not assume that a specific block object will always contain a
|
||
|
given symbol, since changes in <small>GDB</small> features and
|
||
|
infrastructure may cause symbols move across blocks in a symbol
|
||
|
table.
|
||
|
</p>
|
||
|
<p>The following block-related functions are available in the <code>gdb</code>
|
||
|
module:
|
||
|
</p>
|
||
|
<a name="index-gdb_002eblock_005ffor_005fpc"></a>
|
||
|
<dl>
|
||
|
<dt><a name="index-gdb_002eblock_005ffor_005fpc-1"></a>Function: <strong>gdb.block_for_pc</strong> <em>(pc)</em></dt>
|
||
|
<dd><p>Return the innermost <code>gdb.Block</code> containing the given <var>pc</var>
|
||
|
value. If the block cannot be found for the <var>pc</var> value specified,
|
||
|
the function will return <code>None</code>. This is identical to
|
||
|
<code>gdb.current_progspace().block_for_pc(pc)</code> and is included for
|
||
|
historical compatibility.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<p>A <code>gdb.Block</code> object has the following methods:
|
||
|
</p>
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002eis_005fvalid"></a>Function: <strong>Block.is_valid</strong> <em>()</em></dt>
|
||
|
<dd><p>Returns <code>True</code> if the <code>gdb.Block</code> object is valid,
|
||
|
<code>False</code> if not. A block object can become invalid if the block it
|
||
|
refers to doesn’t exist anymore in the inferior. All other
|
||
|
<code>gdb.Block</code> methods will throw an exception if it is invalid at
|
||
|
the time the method is called. The block’s validity is also checked
|
||
|
during iteration over symbols of the block.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<p>A <code>gdb.Block</code> object has the following attributes:
|
||
|
</p>
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002estart"></a>Variable: <strong>Block.start</strong></dt>
|
||
|
<dd><p>The start address of the block. This attribute is not writable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002eend"></a>Variable: <strong>Block.end</strong></dt>
|
||
|
<dd><p>One past the last address that appears in the block. This attribute
|
||
|
is not writable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002efunction"></a>Variable: <strong>Block.function</strong></dt>
|
||
|
<dd><p>The name of the block represented as a <code>gdb.Symbol</code>. If the
|
||
|
block is not named, then this attribute holds <code>None</code>. This
|
||
|
attribute is not writable.
|
||
|
</p>
|
||
|
<p>For ordinary function blocks, the superblock is the static block.
|
||
|
However, you should note that it is possible for a function block to
|
||
|
have a superblock that is not the static block – for instance this
|
||
|
happens for an inlined function.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002esuperblock"></a>Variable: <strong>Block.superblock</strong></dt>
|
||
|
<dd><p>The block containing this block. If this parent block does not exist,
|
||
|
this attribute holds <code>None</code>. This attribute is not writable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002eglobal_005fblock"></a>Variable: <strong>Block.global_block</strong></dt>
|
||
|
<dd><p>The global block associated with this block. This attribute is not
|
||
|
writable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002estatic_005fblock"></a>Variable: <strong>Block.static_block</strong></dt>
|
||
|
<dd><p>The static block associated with this block. This attribute is not
|
||
|
writable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002eis_005fglobal"></a>Variable: <strong>Block.is_global</strong></dt>
|
||
|
<dd><p><code>True</code> if the <code>gdb.Block</code> object is a global block,
|
||
|
<code>False</code> if not. This attribute is not
|
||
|
writable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl>
|
||
|
<dt><a name="index-Block_002eis_005fstatic"></a>Variable: <strong>Block.is_static</strong></dt>
|
||
|
<dd><p><code>True</code> if the <code>gdb.Block</code> object is a static block,
|
||
|
<code>False</code> if not. This attribute is not writable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<hr>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="Symbols-In-Python.html#Symbols-In-Python" accesskey="n" rel="next">Symbols In Python</a>, Previous: <a href="Frames-In-Python.html#Frames-In-Python" accesskey="p" rel="prev">Frames In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python 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>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|