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
linetable function (see Symbol Tables In Python).
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:
The source line number for this line table entry. This number corresponds to the actual line of source. This attribute is not writable.
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
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.
symtab = gdb.selected_frame().find_sal().symtab linetable = symtab.linetable() for line in linetable: print "Line: "+str(line.line)+" Address: "+hex(line.pc)
This will have the following output:
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
In addition to being able to iterate over a
LineTable, it also
has the following direct access methods:
Return a Python
LineTableEntryobjects 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
Return a Python
Booleanindicating whether there is an entry in the line table for this source line. Return
Trueif an entry is found, or