Description
Proposal Details
One use case for the LineReader
might be to iterate through all the line entries for a function -- perhaps to find the statement boundaries or the prologue end.
One might know about the bounds of a function from dwarf, the symbol table, or pclntab. In any case, it's likely to seek to the first PC of a function. This PC, at least for functions that have prologues is not generally covered by the line table.
The LineReader.Seek method explicitly says that it will return an error if passed a pc that is not covered by a line entry:
If pc is not covered by any entry in this line table, SeekPC returns ErrUnknownPC. In this case, *entry and the final seek position are unspecified.
This is rather unfortunate when all the user wants is to be positioned to an entry that the LineReader
has already found!
The comment goes on to say:
Note that DWARF line tables only permit sequential, forward scans. Hence, in the worst case, this takes time linear in the size of the line table. If the caller wishes to do repeated fast PC lookups, it should build an appropriate index of the line table.
This is quite an expensive proposition and, for cases where the client has already arranged the to look up PC ranges in order, doesn't generally need an index to find the PCs that are or are not covered.
This proposal is to add a new method SeekToPC
that is like SeekPC
but instead of returning an error if the pc is not covered by a line entry, then the iterator seeks to the first line entry following that pc.