[Dwarf-Discuss] file pc from source filename+source linenumber
Robinson, Paul T JCTL-NonStop
Sat Jul 31 16:40:06 GMT 2010
>Another thing I tried to do without much success so far, is a back
>mapping from source filename+linenumber to pc address.
>i.e., I can see how .debug_line can be used to get the source
>filename+linenumber from pc address but the converse operation
>somewhat escapes me.
>I tried looking into the .debug_info information but I can see only a
>start line number for functions. Maybe there is someone around who can
>point me in the right direction ?
A single source line can contribute to many instructions.
With optimization, these instructions are not necessarily contiguous.
If the source line is in a header (e.g. a C++ template function)
the source might contribute to instructions in many different functions
or even different compilation units.
Therefore, mapping source position to instruction address is a
You would have to search for the filename in all the relevant
compilation units, and then search for references to the line within
each compilation unit that the file contributes to.
If you are able to restrict the number of compilation units somehow,
that would make your search more efficient. But given how .debug_line
is encoded, the efficiency of finding all references to a particular
line would depend on how you unpack the .debug_line section.
More information about the Dwarf-discuss