選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

228 行
9.6KB

  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>Blocks In Python (Debugging with GDB)</title>
  17. <meta name="description" content="Blocks In Python (Debugging with GDB)">
  18. <meta name="keywords" content="Blocks In Python (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="Python-API.html#Python-API" rel="up" title="Python API">
  26. <link href="Symbols-In-Python.html#Symbols-In-Python" rel="next" title="Symbols In Python">
  27. <link href="Frames-In-Python.html#Frames-In-Python" rel="prev" title="Frames In Python">
  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="Blocks-In-Python"></a>
  58. <div class="header">
  59. <p>
  60. 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> &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="Accessing-blocks-from-Python"></a>
  64. <h4 class="subsubsection">23.2.2.26 Accessing blocks from Python</h4>
  65. <a name="index-blocks-in-python"></a>
  66. <a name="index-gdb_002eBlock"></a>
  67. <p>In <small>GDB</small>, symbols are stored in blocks. A block corresponds
  68. roughly to a scope in the source code. Blocks are organized
  69. hierarchically, and are represented individually in Python as a
  70. <code>gdb.Block</code>. Blocks rely on debugging information being
  71. available.
  72. </p>
  73. <p>A frame has a block. Please see <a href="Frames-In-Python.html#Frames-In-Python">Frames In Python</a>, for a more
  74. in-depth discussion of frames.
  75. </p>
  76. <p>The outermost block is known as the <em>global block</em>. The global
  77. block typically holds public global variables and functions.
  78. </p>
  79. <p>The block nested just inside the global block is the <em>static
  80. block</em>. The static block typically holds file-scoped variables and
  81. functions.
  82. </p>
  83. <p><small>GDB</small> provides a method to get a block&rsquo;s superblock, but there
  84. is currently no way to examine the sub-blocks of a block, or to
  85. 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>).
  86. </p>
  87. <p>Here is a short example that should help explain blocks:
  88. </p>
  89. <div class="smallexample">
  90. <pre class="smallexample">/* This is in the global block. */
  91. int global;
  92. /* This is in the static block. */
  93. static int file_scope;
  94. /* 'function' is in the global block, and 'argument' is
  95. in a block nested inside of 'function'. */
  96. int function (int argument)
  97. {
  98. /* 'local' is in a block inside 'function'. It may or may
  99. not be in the same block as 'argument'. */
  100. int local;
  101. {
  102. /* 'inner' is in a block whose superblock is the one holding
  103. 'local'. */
  104. int inner;
  105. /* If this call is expanded by the compiler, you may see
  106. a nested block here whose function is 'inline_function'
  107. and whose superblock is the one holding 'inner'. */
  108. inline_function ();
  109. }
  110. }
  111. </pre></div>
  112. <p>A <code>gdb.Block</code> is iterable. The iterator returns the symbols
  113. (see <a href="Symbols-In-Python.html#Symbols-In-Python">Symbols In Python</a>) local to the block. Python programs
  114. should not assume that a specific block object will always contain a
  115. given symbol, since changes in <small>GDB</small> features and
  116. infrastructure may cause symbols move across blocks in a symbol
  117. table. You can also use Python&rsquo;s <em>dictionary syntax</em> to access
  118. variables in this block, e.g.:
  119. </p>
  120. <div class="smallexample">
  121. <pre class="smallexample">symbol = some_block['variable'] # symbol is of type gdb.Symbol
  122. </pre></div>
  123. <p>The following block-related functions are available in the <code>gdb</code>
  124. module:
  125. </p>
  126. <a name="index-gdb_002eblock_005ffor_005fpc"></a>
  127. <dl>
  128. <dt><a name="index-gdb_002eblock_005ffor_005fpc-1"></a>Function: <strong>gdb.block_for_pc</strong> <em>(pc)</em></dt>
  129. <dd><p>Return the innermost <code>gdb.Block</code> containing the given <var>pc</var>
  130. value. If the block cannot be found for the <var>pc</var> value specified,
  131. the function will return <code>None</code>. This is identical to
  132. <code>gdb.current_progspace().block_for_pc(pc)</code> and is included for
  133. historical compatibility.
  134. </p></dd></dl>
  135. <p>A <code>gdb.Block</code> object has the following methods:
  136. </p>
  137. <dl>
  138. <dt><a name="index-Block_002eis_005fvalid"></a>Function: <strong>Block.is_valid</strong> <em>()</em></dt>
  139. <dd><p>Returns <code>True</code> if the <code>gdb.Block</code> object is valid,
  140. <code>False</code> if not. A block object can become invalid if the block it
  141. refers to doesn&rsquo;t exist anymore in the inferior. All other
  142. <code>gdb.Block</code> methods will throw an exception if it is invalid at
  143. the time the method is called. The block&rsquo;s validity is also checked
  144. during iteration over symbols of the block.
  145. </p></dd></dl>
  146. <p>A <code>gdb.Block</code> object has the following attributes:
  147. </p>
  148. <dl>
  149. <dt><a name="index-Block_002estart"></a>Variable: <strong>Block.start</strong></dt>
  150. <dd><p>The start address of the block. This attribute is not writable.
  151. </p></dd></dl>
  152. <dl>
  153. <dt><a name="index-Block_002eend"></a>Variable: <strong>Block.end</strong></dt>
  154. <dd><p>One past the last address that appears in the block. This attribute
  155. is not writable.
  156. </p></dd></dl>
  157. <dl>
  158. <dt><a name="index-Block_002efunction"></a>Variable: <strong>Block.function</strong></dt>
  159. <dd><p>The name of the block represented as a <code>gdb.Symbol</code>. If the
  160. block is not named, then this attribute holds <code>None</code>. This
  161. attribute is not writable.
  162. </p>
  163. <p>For ordinary function blocks, the superblock is the static block.
  164. However, you should note that it is possible for a function block to
  165. have a superblock that is not the static block &ndash; for instance this
  166. happens for an inlined function.
  167. </p></dd></dl>
  168. <dl>
  169. <dt><a name="index-Block_002esuperblock"></a>Variable: <strong>Block.superblock</strong></dt>
  170. <dd><p>The block containing this block. If this parent block does not exist,
  171. this attribute holds <code>None</code>. This attribute is not writable.
  172. </p></dd></dl>
  173. <dl>
  174. <dt><a name="index-Block_002eglobal_005fblock"></a>Variable: <strong>Block.global_block</strong></dt>
  175. <dd><p>The global block associated with this block. This attribute is not
  176. writable.
  177. </p></dd></dl>
  178. <dl>
  179. <dt><a name="index-Block_002estatic_005fblock"></a>Variable: <strong>Block.static_block</strong></dt>
  180. <dd><p>The static block associated with this block. This attribute is not
  181. writable.
  182. </p></dd></dl>
  183. <dl>
  184. <dt><a name="index-Block_002eis_005fglobal"></a>Variable: <strong>Block.is_global</strong></dt>
  185. <dd><p><code>True</code> if the <code>gdb.Block</code> object is a global block,
  186. <code>False</code> if not. This attribute is not
  187. writable.
  188. </p></dd></dl>
  189. <dl>
  190. <dt><a name="index-Block_002eis_005fstatic"></a>Variable: <strong>Block.is_static</strong></dt>
  191. <dd><p><code>True</code> if the <code>gdb.Block</code> object is a static block,
  192. <code>False</code> if not. This attribute is not writable.
  193. </p></dd></dl>
  194. <hr>
  195. <div class="header">
  196. <p>
  197. 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> &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>
  198. </div>
  199. </body>
  200. </html>