| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- Copyright (C) 1988-2015 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 5.2, http://www.gnu.org/software/texinfo/ --> |
| <head> |
| <title>Debugging with GDB: Line Tables In Python</title> |
| |
| <meta name="description" content="Debugging with GDB: Line Tables In Python"> |
| <meta name="keywords" content="Debugging with GDB: Line Tables In Python"> |
| <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="Breakpoints-In-Python.html#Breakpoints-In-Python" rel="next" title="Breakpoints In Python"> |
| <link href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python" rel="prev" title="Symbol Tables In Python"> |
| <style type="text/css"> |
| <!-- |
| a.summary-letter {text-decoration: none} |
| blockquote.smallquotation {font-size: smaller} |
| div.display {margin-left: 3.2em} |
| div.example {margin-left: 3.2em} |
| div.indentedblock {margin-left: 3.2em} |
| div.lisp {margin-left: 3.2em} |
| div.smalldisplay {margin-left: 3.2em} |
| div.smallexample {margin-left: 3.2em} |
| div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| 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.nocodebreak {white-space:nowrap} |
| span.nolinebreak {white-space:nowrap} |
| span.roman {font-family:serif; font-weight:normal} |
| span.sansserif {font-family:sans-serif; font-weight:normal} |
| ul.no-bullet {list-style: none} |
| --> |
| </style> |
| |
| |
| </head> |
| |
| <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| <a name="Line-Tables-In-Python"></a> |
| <div class="header"> |
| <p> |
| 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> [<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="Manipulating-line-tables-using-Python"></a> |
| <h4 class="subsubsection">23.2.2.28 Manipulating line tables using Python</h4> |
| |
| <a name="index-line-tables-in-python"></a> |
| <a name="index-gdb_002eLineTable"></a> |
| |
| <p>Python code can request and inspect line table information from a |
| symbol table that is loaded in <small>GDB</small>. A line table is a |
| mapping of source lines to their executable locations in memory. To |
| acquire the line table information for a particular symbol table, use |
| the <code>linetable</code> function (see <a href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python">Symbol Tables In Python</a>). |
| </p> |
| <p>A <code>gdb.LineTable</code> is iterable. The iterator returns |
| <code>LineTableEntry</code> objects that correspond to the source line and |
| address for each line table entry. <code>LineTableEntry</code> objects have |
| the following attributes: |
| </p> |
| <dl> |
| <dt><a name="index-LineTableEntry_002eline"></a>Variable: <strong>LineTableEntry.line</strong></dt> |
| <dd><p>The source line number for this line table entry. This number |
| corresponds to the actual line of source. This attribute is not |
| writable. |
| </p></dd></dl> |
| |
| <dl> |
| <dt><a name="index-LineTableEntry_002epc"></a>Variable: <strong>LineTableEntry.pc</strong></dt> |
| <dd><p>The address that is associated with the line table entry where the |
| executable code for that source line resides in memory. This |
| attribute is not writable. |
| </p></dd></dl> |
| |
| <p>As there can be multiple addresses for a single source line, you may |
| receive multiple <code>LineTableEntry</code> objects with matching |
| <code>line</code> attributes, but with different <code>pc</code> attributes. The |
| iterator is sorted in ascending <code>pc</code> order. Here is a small |
| example illustrating iterating over a line table. |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample">symtab = gdb.selected_frame().find_sal().symtab |
| linetable = symtab.linetable() |
| for line in linetable: |
| print "Line: "+str(line.line)+" Address: "+hex(line.pc) |
| </pre></div> |
| |
| <p>This will have the following output: |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample">Line: 33 Address: 0x4005c8L |
| Line: 37 Address: 0x4005caL |
| Line: 39 Address: 0x4005d2L |
| Line: 40 Address: 0x4005f8L |
| Line: 42 Address: 0x4005ffL |
| Line: 44 Address: 0x400608L |
| Line: 42 Address: 0x40060cL |
| Line: 45 Address: 0x400615L |
| </pre></div> |
| |
| <p>In addition to being able to iterate over a <code>LineTable</code>, it also |
| has the following direct access methods: |
| </p> |
| <dl> |
| <dt><a name="index-LineTable_002eline"></a>Function: <strong>LineTable.line</strong> <em>(line)</em></dt> |
| <dd><p>Return a Python <code>Tuple</code> of <code>LineTableEntry</code> objects for any |
| entries in the line table for the given <var>line</var>, which specifies |
| the source code line. If there are no entries for that source code |
| <var>line</var>, the Python <code>None</code> is returned. |
| </p></dd></dl> |
| |
| <dl> |
| <dt><a name="index-LineTable_002ehas_005fline"></a>Function: <strong>LineTable.has_line</strong> <em>(line)</em></dt> |
| <dd><p>Return a Python <code>Boolean</code> indicating whether there is an entry in |
| the line table for this source line. Return <code>True</code> if an entry |
| is found, or <code>False</code> if not. |
| </p></dd></dl> |
| |
| <dl> |
| <dt><a name="index-LineTable_002esource_005flines"></a>Function: <strong>LineTable.source_lines</strong> <em>()</em></dt> |
| <dd><p>Return a Python <code>List</code> of the source line numbers in the symbol |
| table. Only lines with executable code locations are returned. The |
| contents of the <code>List</code> will just be the source line entries |
| represented as Python <code>Long</code> values. |
| </p></dd></dl> |
| |
| <hr> |
| <div class="header"> |
| <p> |
| 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> [<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> |