You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Line-Tables-In-Python.html 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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>Line Tables In Python (Debugging with GDB)</title>
  17. <meta name="description" content="Line Tables In Python (Debugging with GDB)">
  18. <meta name="keywords" content="Line Tables 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="Breakpoints-In-Python.html#Breakpoints-In-Python" rel="next" title="Breakpoints In Python">
  27. <link href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python" rel="prev" title="Symbol Tables 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="Line-Tables-In-Python"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Breakpoints-In-Python.html#Breakpoints-In-Python" accesskey="n" rel="next">Breakpoints In Python</a>, Previous: <a href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python" accesskey="p" rel="prev">Symbol Tables 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="Manipulating-line-tables-using-Python"></a>
  64. <h4 class="subsubsection">23.2.2.29 Manipulating line tables using Python</h4>
  65. <a name="index-line-tables-in-python"></a>
  66. <a name="index-gdb_002eLineTable"></a>
  67. <p>Python code can request and inspect line table information from a
  68. symbol table that is loaded in <small>GDB</small>. A line table is a
  69. mapping of source lines to their executable locations in memory. To
  70. acquire the line table information for a particular symbol table, use
  71. the <code>linetable</code> function (see <a href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python">Symbol Tables In Python</a>).
  72. </p>
  73. <p>A <code>gdb.LineTable</code> is iterable. The iterator returns
  74. <code>LineTableEntry</code> objects that correspond to the source line and
  75. address for each line table entry. <code>LineTableEntry</code> objects have
  76. the following attributes:
  77. </p>
  78. <dl>
  79. <dt><a name="index-LineTableEntry_002eline"></a>Variable: <strong>LineTableEntry.line</strong></dt>
  80. <dd><p>The source line number for this line table entry. This number
  81. corresponds to the actual line of source. This attribute is not
  82. writable.
  83. </p></dd></dl>
  84. <dl>
  85. <dt><a name="index-LineTableEntry_002epc"></a>Variable: <strong>LineTableEntry.pc</strong></dt>
  86. <dd><p>The address that is associated with the line table entry where the
  87. executable code for that source line resides in memory. This
  88. attribute is not writable.
  89. </p></dd></dl>
  90. <p>As there can be multiple addresses for a single source line, you may
  91. receive multiple <code>LineTableEntry</code> objects with matching
  92. <code>line</code> attributes, but with different <code>pc</code> attributes. The
  93. iterator is sorted in ascending <code>pc</code> order. Here is a small
  94. example illustrating iterating over a line table.
  95. </p>
  96. <div class="smallexample">
  97. <pre class="smallexample">symtab = gdb.selected_frame().find_sal().symtab
  98. linetable = symtab.linetable()
  99. for line in linetable:
  100. print &quot;Line: &quot;+str(line.line)+&quot; Address: &quot;+hex(line.pc)
  101. </pre></div>
  102. <p>This will have the following output:
  103. </p>
  104. <div class="smallexample">
  105. <pre class="smallexample">Line: 33 Address: 0x4005c8L
  106. Line: 37 Address: 0x4005caL
  107. Line: 39 Address: 0x4005d2L
  108. Line: 40 Address: 0x4005f8L
  109. Line: 42 Address: 0x4005ffL
  110. Line: 44 Address: 0x400608L
  111. Line: 42 Address: 0x40060cL
  112. Line: 45 Address: 0x400615L
  113. </pre></div>
  114. <p>In addition to being able to iterate over a <code>LineTable</code>, it also
  115. has the following direct access methods:
  116. </p>
  117. <dl>
  118. <dt><a name="index-LineTable_002eline"></a>Function: <strong>LineTable.line</strong> <em>(line)</em></dt>
  119. <dd><p>Return a Python <code>Tuple</code> of <code>LineTableEntry</code> objects for any
  120. entries in the line table for the given <var>line</var>, which specifies
  121. the source code line. If there are no entries for that source code
  122. <var>line</var>, the Python <code>None</code> is returned.
  123. </p></dd></dl>
  124. <dl>
  125. <dt><a name="index-LineTable_002ehas_005fline"></a>Function: <strong>LineTable.has_line</strong> <em>(line)</em></dt>
  126. <dd><p>Return a Python <code>Boolean</code> indicating whether there is an entry in
  127. the line table for this source line. Return <code>True</code> if an entry
  128. is found, or <code>False</code> if not.
  129. </p></dd></dl>
  130. <dl>
  131. <dt><a name="index-LineTable_002esource_005flines"></a>Function: <strong>LineTable.source_lines</strong> <em>()</em></dt>
  132. <dd><p>Return a Python <code>List</code> of the source line numbers in the symbol
  133. table. Only lines with executable code locations are returned. The
  134. contents of the <code>List</code> will just be the source line entries
  135. represented as Python <code>Long</code> values.
  136. </p></dd></dl>
  137. <hr>
  138. <div class="header">
  139. <p>
  140. Next: <a href="Breakpoints-In-Python.html#Breakpoints-In-Python" accesskey="n" rel="next">Breakpoints In Python</a>, Previous: <a href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python" accesskey="p" rel="prev">Symbol Tables 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>
  141. </div>
  142. </body>
  143. </html>