23.2.2.27 Manipulating line tables using Python

Python code can request and inspect line table information from a
symbol table that is loaded in gdb. 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 linetable function (see Symbol Tables In Python).

A gdb.LineTable is iterable. The iterator returns
LineTableEntry objects that correspond to the source line and
address for each line table entry. LineTableEntry objects have
the following attributes:

— Variable: LineTableEntry.line

The source line number for this line table entry. This number
corresponds to the actual line of source. This attribute is not
writable.

— Variable: LineTableEntry.pc

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.

As there can be multiple addresses for a single source line, you may
receive multiple LineTableEntry objects with matching
line attributes, but with different pc attributes. The
iterator is sorted in ascending pc order. Here is a small
example illustrating iterating over a line table.

In addition to being able to iterate over a LineTable, it also
has the following direct access methods:

— Function: LineTable.line (line)

Return a Python Tuple of LineTableEntry objects for any
entries in the line table for the given line, which specifies
the source code line. If there are no entries for that source code
line, the Python None is returned.

— Function: LineTable.has_line (line)

Return a Python Boolean indicating whether there is an entry in
the line table for this source line. Return True if an entry
is found, or False if not.

— Function: LineTable.source_lines ()

Return a Python List of the source line numbers in the symbol
table. Only lines with executable code locations are returned. The
contents of the List will just be the source line entries
represented as Python Long values.